1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2021 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 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
98 #define dwarf_read_debug_printf(fmt, ...) \
99 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
102 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
104 #define dwarf_read_debug_printf_v(fmt, ...) \
105 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
108 /* When non-zero, dump DIEs after they are read in. */
109 static unsigned int dwarf_die_debug
= 0;
111 /* When non-zero, dump line number entries as they are read in. */
112 unsigned int dwarf_line_debug
= 0;
114 /* When true, cross-check physname against demangler. */
115 static bool check_physname
= false;
117 /* When true, do not reject deprecated .gdb_index sections. */
118 static bool use_deprecated_index_sections
= false;
120 /* This is used to store the data that is always per objfile. */
121 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
123 /* These are used to store the dwarf2_per_bfd objects.
125 objfiles having the same BFD, which doesn't require relocations, are going to
126 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
128 Other objfiles are not going to share a dwarf2_per_bfd with any other
129 objfiles, so they'll have their own version kept in the _objfile_data_key
131 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
132 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
134 /* The "aclass" indices for various kinds of computed DWARF symbols. */
136 static int dwarf2_locexpr_index
;
137 static int dwarf2_loclist_index
;
138 static int dwarf2_locexpr_block_index
;
139 static int dwarf2_loclist_block_index
;
141 /* Size of .debug_loclists section header for 32-bit DWARF format. */
142 #define LOCLIST_HEADER_SIZE32 12
144 /* Size of .debug_loclists section header for 64-bit DWARF format. */
145 #define LOCLIST_HEADER_SIZE64 20
147 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
148 #define RNGLIST_HEADER_SIZE32 12
150 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
151 #define RNGLIST_HEADER_SIZE64 20
153 /* An index into a (C++) symbol name component in a symbol name as
154 recorded in the mapped_index's symbol table. For each C++ symbol
155 in the symbol table, we record one entry for the start of each
156 component in the symbol in a table of name components, and then
157 sort the table, in order to be able to binary search symbol names,
158 ignoring leading namespaces, both completion and regular look up.
159 For example, for symbol "A::B::C", we'll have an entry that points
160 to "A::B::C", another that points to "B::C", and another for "C".
161 Note that function symbols in GDB index have no parameter
162 information, just the function/method names. You can convert a
163 name_component to a "const char *" using the
164 'mapped_index::symbol_name_at(offset_type)' method. */
166 struct name_component
168 /* Offset in the symbol name where the component starts. Stored as
169 a (32-bit) offset instead of a pointer to save memory and improve
170 locality on 64-bit architectures. */
171 offset_type name_offset
;
173 /* The symbol's index in the symbol and constant pool tables of a
178 /* Base class containing bits shared by both .gdb_index and
179 .debug_name indexes. */
181 struct mapped_index_base
183 mapped_index_base () = default;
184 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
186 /* The name_component table (a sorted vector). See name_component's
187 description above. */
188 std::vector
<name_component
> name_components
;
190 /* How NAME_COMPONENTS is sorted. */
191 enum case_sensitivity name_components_casing
;
193 /* Return the number of names in the symbol table. */
194 virtual size_t symbol_name_count () const = 0;
196 /* Get the name of the symbol at IDX in the symbol table. */
197 virtual const char *symbol_name_at
198 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
200 /* Return whether the name at IDX in the symbol table should be
202 virtual bool symbol_name_slot_invalid (offset_type idx
) const
207 /* Build the symbol name component sorted vector, if we haven't
209 void build_name_components (dwarf2_per_objfile
*per_objfile
);
211 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
212 possible matches for LN_NO_PARAMS in the name component
214 std::pair
<std::vector
<name_component
>::const_iterator
,
215 std::vector
<name_component
>::const_iterator
>
216 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
218 dwarf2_per_objfile
*per_objfile
) const;
220 /* Prevent deleting/destroying via a base class pointer. */
222 ~mapped_index_base() = default;
225 /* A description of the mapped index. The file format is described in
226 a comment by the code that writes the index. */
227 struct mapped_index final
: public mapped_index_base
229 /* A slot/bucket in the symbol table hash. */
230 struct symbol_table_slot
232 const offset_type name
;
233 const offset_type vec
;
236 /* Index data format version. */
239 /* The address table data. */
240 gdb::array_view
<const gdb_byte
> address_table
;
242 /* The symbol table, implemented as a hash table. */
243 gdb::array_view
<symbol_table_slot
> symbol_table
;
245 /* A pointer to the constant pool. */
246 const char *constant_pool
= nullptr;
248 bool symbol_name_slot_invalid (offset_type idx
) const override
250 const auto &bucket
= this->symbol_table
[idx
];
251 return bucket
.name
== 0 && bucket
.vec
== 0;
254 /* Convenience method to get at the name of the symbol at IDX in the
256 const char *symbol_name_at
257 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
258 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
260 size_t symbol_name_count () const override
261 { return this->symbol_table
.size (); }
264 /* A description of the mapped .debug_names.
265 Uninitialized map has CU_COUNT 0. */
266 struct mapped_debug_names final
: public mapped_index_base
268 bfd_endian dwarf5_byte_order
;
269 bool dwarf5_is_dwarf64
;
270 bool augmentation_is_gdb
;
272 uint32_t cu_count
= 0;
273 uint32_t tu_count
, bucket_count
, name_count
;
274 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
275 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
276 const gdb_byte
*name_table_string_offs_reordered
;
277 const gdb_byte
*name_table_entry_offs_reordered
;
278 const gdb_byte
*entry_pool
;
285 /* Attribute name DW_IDX_*. */
288 /* Attribute form DW_FORM_*. */
291 /* Value if FORM is DW_FORM_implicit_const. */
292 LONGEST implicit_const
;
294 std::vector
<attr
> attr_vec
;
297 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
299 const char *namei_to_name
300 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
302 /* Implementation of the mapped_index_base virtual interface, for
303 the name_components cache. */
305 const char *symbol_name_at
306 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
307 { return namei_to_name (idx
, per_objfile
); }
309 size_t symbol_name_count () const override
310 { return this->name_count
; }
313 /* See dwarf2read.h. */
316 get_dwarf2_per_objfile (struct objfile
*objfile
)
318 return dwarf2_objfile_data_key
.get (objfile
);
321 /* Default names of the debugging sections. */
323 /* Note that if the debugging section has been compressed, it might
324 have a name like .zdebug_info. */
326 static const struct dwarf2_debug_sections dwarf2_elf_names
=
328 { ".debug_info", ".zdebug_info" },
329 { ".debug_abbrev", ".zdebug_abbrev" },
330 { ".debug_line", ".zdebug_line" },
331 { ".debug_loc", ".zdebug_loc" },
332 { ".debug_loclists", ".zdebug_loclists" },
333 { ".debug_macinfo", ".zdebug_macinfo" },
334 { ".debug_macro", ".zdebug_macro" },
335 { ".debug_str", ".zdebug_str" },
336 { ".debug_str_offsets", ".zdebug_str_offsets" },
337 { ".debug_line_str", ".zdebug_line_str" },
338 { ".debug_ranges", ".zdebug_ranges" },
339 { ".debug_rnglists", ".zdebug_rnglists" },
340 { ".debug_types", ".zdebug_types" },
341 { ".debug_addr", ".zdebug_addr" },
342 { ".debug_frame", ".zdebug_frame" },
343 { ".eh_frame", NULL
},
344 { ".gdb_index", ".zgdb_index" },
345 { ".debug_names", ".zdebug_names" },
346 { ".debug_aranges", ".zdebug_aranges" },
350 /* List of DWO/DWP sections. */
352 static const struct dwop_section_names
354 struct dwarf2_section_names abbrev_dwo
;
355 struct dwarf2_section_names info_dwo
;
356 struct dwarf2_section_names line_dwo
;
357 struct dwarf2_section_names loc_dwo
;
358 struct dwarf2_section_names loclists_dwo
;
359 struct dwarf2_section_names macinfo_dwo
;
360 struct dwarf2_section_names macro_dwo
;
361 struct dwarf2_section_names rnglists_dwo
;
362 struct dwarf2_section_names str_dwo
;
363 struct dwarf2_section_names str_offsets_dwo
;
364 struct dwarf2_section_names types_dwo
;
365 struct dwarf2_section_names cu_index
;
366 struct dwarf2_section_names tu_index
;
370 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
371 { ".debug_info.dwo", ".zdebug_info.dwo" },
372 { ".debug_line.dwo", ".zdebug_line.dwo" },
373 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
374 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
375 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
376 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
377 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
378 { ".debug_str.dwo", ".zdebug_str.dwo" },
379 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
380 { ".debug_types.dwo", ".zdebug_types.dwo" },
381 { ".debug_cu_index", ".zdebug_cu_index" },
382 { ".debug_tu_index", ".zdebug_tu_index" },
385 /* local data types */
387 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
388 begin with a header, which contains the following information. */
389 struct loclists_rnglists_header
391 /* A 4-byte or 12-byte length containing the length of the
392 set of entries for this compilation unit, not including the
393 length field itself. */
396 /* A 2-byte version identifier. */
399 /* A 1-byte unsigned integer containing the size in bytes of an address on
400 the target system. */
401 unsigned char addr_size
;
403 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
404 on the target system. */
405 unsigned char segment_collector_size
;
407 /* A 4-byte count of the number of offsets that follow the header. */
408 unsigned int offset_entry_count
;
411 /* Type used for delaying computation of method physnames.
412 See comments for compute_delayed_physnames. */
413 struct delayed_method_info
415 /* The type to which the method is attached, i.e., its parent class. */
418 /* The index of the method in the type's function fieldlists. */
421 /* The index of the method in the fieldlist. */
424 /* The name of the DIE. */
427 /* The DIE associated with this method. */
428 struct die_info
*die
;
431 /* Internal state when decoding a particular compilation unit. */
434 explicit dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
435 dwarf2_per_objfile
*per_objfile
);
437 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
439 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
440 Create the set of symtabs used by this TU, or if this TU is sharing
441 symtabs with another TU and the symtabs have already been created
442 then restore those symtabs in the line header.
443 We don't need the pc/line-number mapping for type units. */
444 void setup_type_unit_groups (struct die_info
*die
);
446 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
447 buildsym_compunit constructor. */
448 struct compunit_symtab
*start_symtab (const char *name
,
449 const char *comp_dir
,
452 /* Reset the builder. */
453 void reset_builder () { m_builder
.reset (); }
455 /* Return a type that is a generic pointer type, the size of which
456 matches the address size given in the compilation unit header for
458 struct type
*addr_type () const;
460 /* Find an integer type the same size as the address size given in
461 the compilation unit header for this CU. UNSIGNED_P controls if
462 the integer is unsigned or not. */
463 struct type
*addr_sized_int_type (bool unsigned_p
) const;
465 /* The header of the compilation unit. */
466 struct comp_unit_head header
{};
468 /* Base address of this compilation unit. */
469 gdb::optional
<CORE_ADDR
> base_address
;
471 /* The language we are debugging. */
472 enum language language
= language_unknown
;
473 const struct language_defn
*language_defn
= nullptr;
475 const char *producer
= nullptr;
478 /* The symtab builder for this CU. This is only non-NULL when full
479 symbols are being read. */
480 std::unique_ptr
<buildsym_compunit
> m_builder
;
483 /* The generic symbol table building routines have separate lists for
484 file scope symbols and all all other scopes (local scopes). So
485 we need to select the right one to pass to add_symbol_to_list().
486 We do it by keeping a pointer to the correct list in list_in_scope.
488 FIXME: The original dwarf code just treated the file scope as the
489 first local scope, and all other local scopes as nested local
490 scopes, and worked fine. Check to see if we really need to
491 distinguish these in buildsym.c. */
492 struct pending
**list_in_scope
= nullptr;
494 /* Hash table holding all the loaded partial DIEs
495 with partial_die->offset.SECT_OFF as hash. */
496 htab_t partial_dies
= nullptr;
498 /* Storage for things with the same lifetime as this read-in compilation
499 unit, including partial DIEs. */
500 auto_obstack comp_unit_obstack
;
502 /* Backlink to our per_cu entry. */
503 struct dwarf2_per_cu_data
*per_cu
;
505 /* The dwarf2_per_objfile that owns this. */
506 dwarf2_per_objfile
*per_objfile
;
508 /* How many compilation units ago was this CU last referenced? */
511 /* A hash table of DIE cu_offset for following references with
512 die_info->offset.sect_off as hash. */
513 htab_t die_hash
= nullptr;
515 /* Full DIEs if read in. */
516 struct die_info
*dies
= nullptr;
518 /* A set of pointers to dwarf2_per_cu_data objects for compilation
519 units referenced by this one. Only set during full symbol processing;
520 partial symbol tables do not have dependencies. */
521 htab_t dependencies
= nullptr;
523 /* Header data from the line table, during full symbol processing. */
524 struct line_header
*line_header
= nullptr;
525 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
526 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
527 this is the DW_TAG_compile_unit die for this CU. We'll hold on
528 to the line header as long as this DIE is being processed. See
529 process_die_scope. */
530 die_info
*line_header_die_owner
= nullptr;
532 /* A list of methods which need to have physnames computed
533 after all type information has been read. */
534 std::vector
<delayed_method_info
> method_list
;
536 /* To be copied to symtab->call_site_htab. */
537 htab_t call_site_htab
= nullptr;
539 /* Non-NULL if this CU came from a DWO file.
540 There is an invariant here that is important to remember:
541 Except for attributes copied from the top level DIE in the "main"
542 (or "stub") file in preparation for reading the DWO file
543 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
544 Either there isn't a DWO file (in which case this is NULL and the point
545 is moot), or there is and either we're not going to read it (in which
546 case this is NULL) or there is and we are reading it (in which case this
548 struct dwo_unit
*dwo_unit
= nullptr;
550 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
551 Note this value comes from the Fission stub CU/TU's DIE. */
552 gdb::optional
<ULONGEST
> addr_base
;
554 /* The DW_AT_GNU_ranges_base attribute, if present.
556 This is only relevant in the context of pre-DWARF 5 split units. In this
557 context, there is a .debug_ranges section in the linked executable,
558 containing all the ranges data for all the compilation units. Each
559 skeleton/stub unit has (if needed) a DW_AT_GNU_ranges_base attribute that
560 indicates the base of its contribution to that section. The DW_AT_ranges
561 attributes in the split-unit are of the form DW_FORM_sec_offset and point
562 into the .debug_ranges section of the linked file. However, they are not
563 "true" DW_FORM_sec_offset, because they are relative to the base of their
564 compilation unit's contribution, rather than relative to the beginning of
565 the section. The DW_AT_GNU_ranges_base value must be added to it to make
566 it relative to the beginning of the section.
568 Note that the value is zero when we are not in a pre-DWARF 5 split-unit
569 case, so this value can be added without needing to know whether we are in
572 N.B. If a DW_AT_ranges attribute is found on the DW_TAG_compile_unit in the
573 skeleton/stub, it must not have the base added, as it already points to the
574 right place. And since the DW_TAG_compile_unit DIE in the split-unit can't
575 have a DW_AT_ranges attribute, we can use the
577 die->tag != DW_AT_compile_unit
579 to determine whether the base should be added or not. */
580 ULONGEST gnu_ranges_base
= 0;
582 /* The DW_AT_rnglists_base attribute, if present.
584 This is used when processing attributes of form DW_FORM_rnglistx in
585 non-split units. Attributes of this form found in a split unit don't
586 use it, as split-unit files have their own non-shared .debug_rnglists.dwo
588 ULONGEST rnglists_base
= 0;
590 /* The DW_AT_loclists_base attribute if present. */
591 ULONGEST loclist_base
= 0;
593 /* When reading debug info generated by older versions of rustc, we
594 have to rewrite some union types to be struct types with a
595 variant part. This rewriting must be done after the CU is fully
596 read in, because otherwise at the point of rewriting some struct
597 type might not have been fully processed. So, we keep a list of
598 all such types here and process them after expansion. */
599 std::vector
<struct type
*> rust_unions
;
601 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
602 files, the value is implicitly zero. For DWARF 5 version DWO files, the
603 value is often implicit and is the size of the header of
604 .debug_str_offsets section (8 or 4, depending on the address size). */
605 gdb::optional
<ULONGEST
> str_offsets_base
;
607 /* Mark used when releasing cached dies. */
610 /* This CU references .debug_loc. See the symtab->locations_valid field.
611 This test is imperfect as there may exist optimized debug code not using
612 any location list and still facing inlining issues if handled as
613 unoptimized code. For a future better test see GCC PR other/32998. */
614 bool has_loclist
: 1;
616 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
617 if all the producer_is_* fields are valid. This information is cached
618 because profiling CU expansion showed excessive time spent in
619 producer_is_gxx_lt_4_6. */
620 bool checked_producer
: 1;
621 bool producer_is_gxx_lt_4_6
: 1;
622 bool producer_is_gcc_lt_4_3
: 1;
623 bool producer_is_icc
: 1;
624 bool producer_is_icc_lt_14
: 1;
625 bool producer_is_codewarrior
: 1;
627 /* When true, the file that we're processing is known to have
628 debugging info for C++ namespaces. GCC 3.3.x did not produce
629 this information, but later versions do. */
631 bool processing_has_namespace_info
: 1;
633 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
635 /* If this CU was inherited by another CU (via specification,
636 abstract_origin, etc), this is the ancestor CU. */
639 /* Get the buildsym_compunit for this CU. */
640 buildsym_compunit
*get_builder ()
642 /* If this CU has a builder associated with it, use that. */
643 if (m_builder
!= nullptr)
644 return m_builder
.get ();
646 /* Otherwise, search ancestors for a valid builder. */
647 if (ancestor
!= nullptr)
648 return ancestor
->get_builder ();
654 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
655 This includes type_unit_group and quick_file_names. */
657 struct stmt_list_hash
659 /* The DWO unit this table is from or NULL if there is none. */
660 struct dwo_unit
*dwo_unit
;
662 /* Offset in .debug_line or .debug_line.dwo. */
663 sect_offset line_sect_off
;
666 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
667 an object of this type. This contains elements of type unit groups
668 that can be shared across objfiles. The non-shareable parts are in
669 type_unit_group_unshareable. */
671 struct type_unit_group
673 /* dwarf2read.c's main "handle" on a TU symtab.
674 To simplify things we create an artificial CU that "includes" all the
675 type units using this stmt_list so that the rest of the code still has
676 a "per_cu" handle on the symtab. */
677 struct dwarf2_per_cu_data per_cu
;
679 /* The TUs that share this DW_AT_stmt_list entry.
680 This is added to while parsing type units to build partial symtabs,
681 and is deleted afterwards and not used again. */
682 std::vector
<signatured_type
*> *tus
;
684 /* The data used to construct the hash key. */
685 struct stmt_list_hash hash
;
688 /* These sections are what may appear in a (real or virtual) DWO file. */
692 struct dwarf2_section_info abbrev
;
693 struct dwarf2_section_info line
;
694 struct dwarf2_section_info loc
;
695 struct dwarf2_section_info loclists
;
696 struct dwarf2_section_info macinfo
;
697 struct dwarf2_section_info macro
;
698 struct dwarf2_section_info rnglists
;
699 struct dwarf2_section_info str
;
700 struct dwarf2_section_info str_offsets
;
701 /* In the case of a virtual DWO file, these two are unused. */
702 struct dwarf2_section_info info
;
703 std::vector
<dwarf2_section_info
> types
;
706 /* CUs/TUs in DWP/DWO files. */
710 /* Backlink to the containing struct dwo_file. */
711 struct dwo_file
*dwo_file
;
713 /* The "id" that distinguishes this CU/TU.
714 .debug_info calls this "dwo_id", .debug_types calls this "signature".
715 Since signatures came first, we stick with it for consistency. */
718 /* The section this CU/TU lives in, in the DWO file. */
719 struct dwarf2_section_info
*section
;
721 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
722 sect_offset sect_off
;
725 /* For types, offset in the type's DIE of the type defined by this TU. */
726 cu_offset type_offset_in_tu
;
729 /* include/dwarf2.h defines the DWP section codes.
730 It defines a max value but it doesn't define a min value, which we
731 use for error checking, so provide one. */
733 enum dwp_v2_section_ids
738 /* Data for one DWO file.
740 This includes virtual DWO files (a virtual DWO file is a DWO file as it
741 appears in a DWP file). DWP files don't really have DWO files per se -
742 comdat folding of types "loses" the DWO file they came from, and from
743 a high level view DWP files appear to contain a mass of random types.
744 However, to maintain consistency with the non-DWP case we pretend DWP
745 files contain virtual DWO files, and we assign each TU with one virtual
746 DWO file (generally based on the line and abbrev section offsets -
747 a heuristic that seems to work in practice). */
751 dwo_file () = default;
752 DISABLE_COPY_AND_ASSIGN (dwo_file
);
754 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
755 For virtual DWO files the name is constructed from the section offsets
756 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
757 from related CU+TUs. */
758 const char *dwo_name
= nullptr;
760 /* The DW_AT_comp_dir attribute. */
761 const char *comp_dir
= nullptr;
763 /* The bfd, when the file is open. Otherwise this is NULL.
764 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
765 gdb_bfd_ref_ptr dbfd
;
767 /* The sections that make up this DWO file.
768 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
769 sections (for lack of a better name). */
770 struct dwo_sections sections
{};
772 /* The CUs in the file.
773 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
774 an extension to handle LLVM's Link Time Optimization output (where
775 multiple source files may be compiled into a single object/dwo pair). */
778 /* Table of TUs in the file.
779 Each element is a struct dwo_unit. */
783 /* These sections are what may appear in a DWP file. */
787 /* These are used by all DWP versions (1, 2 and 5). */
788 struct dwarf2_section_info str
;
789 struct dwarf2_section_info cu_index
;
790 struct dwarf2_section_info tu_index
;
792 /* These are only used by DWP version 2 and version 5 files.
793 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
794 sections are referenced by section number, and are not recorded here.
795 In DWP version 2 or 5 there is at most one copy of all these sections,
796 each section being (effectively) comprised of the concatenation of all of
797 the individual sections that exist in the version 1 format.
798 To keep the code simple we treat each of these concatenated pieces as a
799 section itself (a virtual section?). */
800 struct dwarf2_section_info abbrev
;
801 struct dwarf2_section_info info
;
802 struct dwarf2_section_info line
;
803 struct dwarf2_section_info loc
;
804 struct dwarf2_section_info loclists
;
805 struct dwarf2_section_info macinfo
;
806 struct dwarf2_section_info macro
;
807 struct dwarf2_section_info rnglists
;
808 struct dwarf2_section_info str_offsets
;
809 struct dwarf2_section_info types
;
812 /* These sections are what may appear in a virtual DWO file in DWP version 1.
813 A virtual DWO file is a DWO file as it appears in a DWP file. */
815 struct virtual_v1_dwo_sections
817 struct dwarf2_section_info abbrev
;
818 struct dwarf2_section_info line
;
819 struct dwarf2_section_info loc
;
820 struct dwarf2_section_info macinfo
;
821 struct dwarf2_section_info macro
;
822 struct dwarf2_section_info str_offsets
;
823 /* Each DWP hash table entry records one CU or one TU.
824 That is recorded here, and copied to dwo_unit.section. */
825 struct dwarf2_section_info info_or_types
;
828 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
829 In version 2, the sections of the DWO files are concatenated together
830 and stored in one section of that name. Thus each ELF section contains
831 several "virtual" sections. */
833 struct virtual_v2_or_v5_dwo_sections
835 bfd_size_type abbrev_offset
;
836 bfd_size_type abbrev_size
;
838 bfd_size_type line_offset
;
839 bfd_size_type line_size
;
841 bfd_size_type loc_offset
;
842 bfd_size_type loc_size
;
844 bfd_size_type loclists_offset
;
845 bfd_size_type loclists_size
;
847 bfd_size_type macinfo_offset
;
848 bfd_size_type macinfo_size
;
850 bfd_size_type macro_offset
;
851 bfd_size_type macro_size
;
853 bfd_size_type rnglists_offset
;
854 bfd_size_type rnglists_size
;
856 bfd_size_type str_offsets_offset
;
857 bfd_size_type str_offsets_size
;
859 /* Each DWP hash table entry records one CU or one TU.
860 That is recorded here, and copied to dwo_unit.section. */
861 bfd_size_type info_or_types_offset
;
862 bfd_size_type info_or_types_size
;
865 /* Contents of DWP hash tables. */
867 struct dwp_hash_table
869 uint32_t version
, nr_columns
;
870 uint32_t nr_units
, nr_slots
;
871 const gdb_byte
*hash_table
, *unit_table
;
876 const gdb_byte
*indices
;
880 /* This is indexed by column number and gives the id of the section
882 #define MAX_NR_V2_DWO_SECTIONS \
883 (1 /* .debug_info or .debug_types */ \
884 + 1 /* .debug_abbrev */ \
885 + 1 /* .debug_line */ \
886 + 1 /* .debug_loc */ \
887 + 1 /* .debug_str_offsets */ \
888 + 1 /* .debug_macro or .debug_macinfo */)
889 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
890 const gdb_byte
*offsets
;
891 const gdb_byte
*sizes
;
895 /* This is indexed by column number and gives the id of the section
897 #define MAX_NR_V5_DWO_SECTIONS \
898 (1 /* .debug_info */ \
899 + 1 /* .debug_abbrev */ \
900 + 1 /* .debug_line */ \
901 + 1 /* .debug_loclists */ \
902 + 1 /* .debug_str_offsets */ \
903 + 1 /* .debug_macro */ \
904 + 1 /* .debug_rnglists */)
905 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
906 const gdb_byte
*offsets
;
907 const gdb_byte
*sizes
;
912 /* Data for one DWP file. */
916 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
918 dbfd (std::move (abfd
))
922 /* Name of the file. */
925 /* File format version. */
929 gdb_bfd_ref_ptr dbfd
;
931 /* Section info for this file. */
932 struct dwp_sections sections
{};
934 /* Table of CUs in the file. */
935 const struct dwp_hash_table
*cus
= nullptr;
937 /* Table of TUs in the file. */
938 const struct dwp_hash_table
*tus
= nullptr;
940 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
944 /* Table to map ELF section numbers to their sections.
945 This is only needed for the DWP V1 file format. */
946 unsigned int num_sections
= 0;
947 asection
**elf_sections
= nullptr;
950 /* Struct used to pass misc. parameters to read_die_and_children, et
951 al. which are used for both .debug_info and .debug_types dies.
952 All parameters here are unchanging for the life of the call. This
953 struct exists to abstract away the constant parameters of die reading. */
955 struct die_reader_specs
957 /* The bfd of die_section. */
960 /* The CU of the DIE we are parsing. */
961 struct dwarf2_cu
*cu
;
963 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
964 struct dwo_file
*dwo_file
;
966 /* The section the die comes from.
967 This is either .debug_info or .debug_types, or the .dwo variants. */
968 struct dwarf2_section_info
*die_section
;
970 /* die_section->buffer. */
971 const gdb_byte
*buffer
;
973 /* The end of the buffer. */
974 const gdb_byte
*buffer_end
;
976 /* The abbreviation table to use when reading the DIEs. */
977 struct abbrev_table
*abbrev_table
;
980 /* A subclass of die_reader_specs that holds storage and has complex
981 constructor and destructor behavior. */
983 class cutu_reader
: public die_reader_specs
987 cutu_reader (dwarf2_per_cu_data
*this_cu
,
988 dwarf2_per_objfile
*per_objfile
,
989 struct abbrev_table
*abbrev_table
,
990 dwarf2_cu
*existing_cu
,
993 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
994 dwarf2_per_objfile
*per_objfile
,
995 struct dwarf2_cu
*parent_cu
= nullptr,
996 struct dwo_file
*dwo_file
= nullptr);
998 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
1000 const gdb_byte
*info_ptr
= nullptr;
1001 struct die_info
*comp_unit_die
= nullptr;
1002 bool dummy_p
= false;
1004 /* Release the new CU, putting it on the chain. This cannot be done
1009 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
1010 dwarf2_per_objfile
*per_objfile
,
1011 dwarf2_cu
*existing_cu
);
1013 struct dwarf2_per_cu_data
*m_this_cu
;
1014 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
1016 /* The ordinary abbreviation table. */
1017 abbrev_table_up m_abbrev_table_holder
;
1019 /* The DWO abbreviation table. */
1020 abbrev_table_up m_dwo_abbrev_table
;
1023 /* When we construct a partial symbol table entry we only
1024 need this much information. */
1025 struct partial_die_info
: public allocate_on_obstack
1027 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1029 /* Disable assign but still keep copy ctor, which is needed
1030 load_partial_dies. */
1031 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1033 /* Adjust the partial die before generating a symbol for it. This
1034 function may set the is_external flag or change the DIE's
1036 void fixup (struct dwarf2_cu
*cu
);
1038 /* Read a minimal amount of information into the minimal die
1040 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1041 const struct abbrev_info
&abbrev
,
1042 const gdb_byte
*info_ptr
);
1044 /* Compute the name of this partial DIE. This memoizes the
1045 result, so it is safe to call multiple times. */
1046 const char *name (dwarf2_cu
*cu
);
1048 /* Offset of this DIE. */
1049 const sect_offset sect_off
;
1051 /* DWARF-2 tag for this DIE. */
1052 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1054 /* Assorted flags describing the data found in this DIE. */
1055 const unsigned int has_children
: 1;
1057 unsigned int is_external
: 1;
1058 unsigned int is_declaration
: 1;
1059 unsigned int has_type
: 1;
1060 unsigned int has_specification
: 1;
1061 unsigned int has_pc_info
: 1;
1062 unsigned int may_be_inlined
: 1;
1064 /* This DIE has been marked DW_AT_main_subprogram. */
1065 unsigned int main_subprogram
: 1;
1067 /* Flag set if the SCOPE field of this structure has been
1069 unsigned int scope_set
: 1;
1071 /* Flag set if the DIE has a byte_size attribute. */
1072 unsigned int has_byte_size
: 1;
1074 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1075 unsigned int has_const_value
: 1;
1077 /* Flag set if any of the DIE's children are template arguments. */
1078 unsigned int has_template_arguments
: 1;
1080 /* Flag set if fixup has been called on this die. */
1081 unsigned int fixup_called
: 1;
1083 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1084 unsigned int is_dwz
: 1;
1086 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1087 unsigned int spec_is_dwz
: 1;
1089 unsigned int canonical_name
: 1;
1091 /* The name of this DIE. Normally the value of DW_AT_name, but
1092 sometimes a default name for unnamed DIEs. */
1093 const char *raw_name
= nullptr;
1095 /* The linkage name, if present. */
1096 const char *linkage_name
= nullptr;
1098 /* The scope to prepend to our children. This is generally
1099 allocated on the comp_unit_obstack, so will disappear
1100 when this compilation unit leaves the cache. */
1101 const char *scope
= nullptr;
1103 /* Some data associated with the partial DIE. The tag determines
1104 which field is live. */
1107 /* The location description associated with this DIE, if any. */
1108 struct dwarf_block
*locdesc
;
1109 /* The offset of an import, for DW_TAG_imported_unit. */
1110 sect_offset sect_off
;
1113 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1114 CORE_ADDR lowpc
= 0;
1115 CORE_ADDR highpc
= 0;
1117 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1118 DW_AT_sibling, if any. */
1119 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1120 could return DW_AT_sibling values to its caller load_partial_dies. */
1121 const gdb_byte
*sibling
= nullptr;
1123 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1124 DW_AT_specification (or DW_AT_abstract_origin or
1125 DW_AT_extension). */
1126 sect_offset spec_offset
{};
1128 /* Pointers to this DIE's parent, first child, and next sibling,
1130 struct partial_die_info
*die_parent
= nullptr;
1131 struct partial_die_info
*die_child
= nullptr;
1132 struct partial_die_info
*die_sibling
= nullptr;
1134 friend struct partial_die_info
*
1135 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1138 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1139 partial_die_info (sect_offset sect_off
)
1140 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1144 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1146 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1151 has_specification
= 0;
1154 main_subprogram
= 0;
1157 has_const_value
= 0;
1158 has_template_arguments
= 0;
1166 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1167 but this would require a corresponding change in unpack_field_as_long
1169 static int bits_per_byte
= 8;
1171 struct variant_part_builder
;
1173 /* When reading a variant, we track a bit more information about the
1174 field, and store it in an object of this type. */
1176 struct variant_field
1178 int first_field
= -1;
1179 int last_field
= -1;
1181 /* A variant can contain other variant parts. */
1182 std::vector
<variant_part_builder
> variant_parts
;
1184 /* If we see a DW_TAG_variant, then this will be set if this is the
1186 bool default_branch
= false;
1187 /* If we see a DW_AT_discr_value, then this will be the discriminant
1189 ULONGEST discriminant_value
= 0;
1190 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1192 struct dwarf_block
*discr_list_data
= nullptr;
1195 /* This represents a DW_TAG_variant_part. */
1197 struct variant_part_builder
1199 /* The offset of the discriminant field. */
1200 sect_offset discriminant_offset
{};
1202 /* Variants that are direct children of this variant part. */
1203 std::vector
<variant_field
> variants
;
1205 /* True if we're currently reading a variant. */
1206 bool processing_variant
= false;
1211 int accessibility
= 0;
1213 /* Variant parts need to find the discriminant, which is a DIE
1214 reference. We track the section offset of each field to make
1217 struct field field
{};
1222 const char *name
= nullptr;
1223 std::vector
<struct fn_field
> fnfields
;
1226 /* The routines that read and process dies for a C struct or C++ class
1227 pass lists of data member fields and lists of member function fields
1228 in an instance of a field_info structure, as defined below. */
1231 /* List of data member and baseclasses fields. */
1232 std::vector
<struct nextfield
> fields
;
1233 std::vector
<struct nextfield
> baseclasses
;
1235 /* Set if the accessibility of one of the fields is not public. */
1236 bool non_public_fields
= false;
1238 /* Member function fieldlist array, contains name of possibly overloaded
1239 member function, number of overloaded member functions and a pointer
1240 to the head of the member function field chain. */
1241 std::vector
<struct fnfieldlist
> fnfieldlists
;
1243 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1244 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1245 std::vector
<struct decl_field
> typedef_field_list
;
1247 /* Nested types defined by this class and the number of elements in this
1249 std::vector
<struct decl_field
> nested_types_list
;
1251 /* If non-null, this is the variant part we are currently
1253 variant_part_builder
*current_variant_part
= nullptr;
1254 /* This holds all the top-level variant parts attached to the type
1256 std::vector
<variant_part_builder
> variant_parts
;
1258 /* Return the total number of fields (including baseclasses). */
1259 int nfields () const
1261 return fields
.size () + baseclasses
.size ();
1265 /* Loaded secondary compilation units are kept in memory until they
1266 have not been referenced for the processing of this many
1267 compilation units. Set this to zero to disable caching. Cache
1268 sizes of up to at least twenty will improve startup time for
1269 typical inter-CU-reference binaries, at an obvious memory cost. */
1270 static int dwarf_max_cache_age
= 5;
1272 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1273 struct cmd_list_element
*c
, const char *value
)
1275 fprintf_filtered (file
, _("The upper bound on the age of cached "
1276 "DWARF compilation units is %s.\n"),
1280 /* local function prototypes */
1282 static void dwarf2_find_base_address (struct die_info
*die
,
1283 struct dwarf2_cu
*cu
);
1285 static dwarf2_psymtab
*create_partial_symtab
1286 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1289 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1290 const gdb_byte
*info_ptr
,
1291 struct die_info
*type_unit_die
);
1293 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1295 static void scan_partial_symbols (struct partial_die_info
*,
1296 CORE_ADDR
*, CORE_ADDR
*,
1297 int, struct dwarf2_cu
*);
1299 static void add_partial_symbol (struct partial_die_info
*,
1300 struct dwarf2_cu
*);
1302 static void add_partial_namespace (struct partial_die_info
*pdi
,
1303 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1304 int set_addrmap
, struct dwarf2_cu
*cu
);
1306 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1307 CORE_ADDR
*highpc
, int set_addrmap
,
1308 struct dwarf2_cu
*cu
);
1310 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1311 struct dwarf2_cu
*cu
);
1313 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1314 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1315 int need_pc
, struct dwarf2_cu
*cu
);
1317 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1319 static struct partial_die_info
*load_partial_dies
1320 (const struct die_reader_specs
*, const gdb_byte
*, int);
1322 /* A pair of partial_die_info and compilation unit. */
1323 struct cu_partial_die_info
1325 /* The compilation unit of the partial_die_info. */
1326 struct dwarf2_cu
*cu
;
1327 /* A partial_die_info. */
1328 struct partial_die_info
*pdi
;
1330 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1336 cu_partial_die_info () = delete;
1339 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1340 struct dwarf2_cu
*);
1342 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1343 struct attribute
*, struct attr_abbrev
*,
1346 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1347 struct attribute
*attr
, dwarf_tag tag
);
1349 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1351 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1352 dwarf2_section_info
*, sect_offset
);
1354 static const char *read_indirect_string
1355 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1356 const struct comp_unit_head
*, unsigned int *);
1358 static const char *read_indirect_string_at_offset
1359 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1361 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1365 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1366 ULONGEST str_index
);
1368 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1369 ULONGEST str_index
);
1371 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1373 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1374 struct dwarf2_cu
*);
1376 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1377 struct dwarf2_cu
*cu
);
1379 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1381 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1382 struct dwarf2_cu
*cu
);
1384 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1386 static struct die_info
*die_specification (struct die_info
*die
,
1387 struct dwarf2_cu
**);
1389 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1390 struct dwarf2_cu
*cu
);
1392 static void dwarf_decode_lines (struct line_header
*, const char *,
1393 struct dwarf2_cu
*, dwarf2_psymtab
*,
1394 CORE_ADDR
, int decode_mapping
);
1396 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1399 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1400 struct dwarf2_cu
*, struct symbol
* = NULL
);
1402 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1403 struct dwarf2_cu
*);
1405 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1408 struct obstack
*obstack
,
1409 struct dwarf2_cu
*cu
, LONGEST
*value
,
1410 const gdb_byte
**bytes
,
1411 struct dwarf2_locexpr_baton
**baton
);
1413 static struct type
*read_subrange_index_type (struct die_info
*die
,
1414 struct dwarf2_cu
*cu
);
1416 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1418 static int need_gnat_info (struct dwarf2_cu
*);
1420 static struct type
*die_descriptive_type (struct die_info
*,
1421 struct dwarf2_cu
*);
1423 static void set_descriptive_type (struct type
*, struct die_info
*,
1424 struct dwarf2_cu
*);
1426 static struct type
*die_containing_type (struct die_info
*,
1427 struct dwarf2_cu
*);
1429 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1430 struct dwarf2_cu
*);
1432 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1434 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1436 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1438 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1439 const char *suffix
, int physname
,
1440 struct dwarf2_cu
*cu
);
1442 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1444 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1446 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1448 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1450 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1452 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1454 /* Return the .debug_loclists section to use for cu. */
1455 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1457 /* Return the .debug_rnglists section to use for cu. */
1458 static struct dwarf2_section_info
*cu_debug_rnglists_section
1459 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1461 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1462 values. Keep the items ordered with increasing constraints compliance. */
1465 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1466 PC_BOUNDS_NOT_PRESENT
,
1468 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1469 were present but they do not form a valid range of PC addresses. */
1472 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1475 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1479 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1480 CORE_ADDR
*, CORE_ADDR
*,
1484 static void get_scope_pc_bounds (struct die_info
*,
1485 CORE_ADDR
*, CORE_ADDR
*,
1486 struct dwarf2_cu
*);
1488 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1489 CORE_ADDR
, struct dwarf2_cu
*);
1491 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1492 struct dwarf2_cu
*);
1494 static void dwarf2_attach_fields_to_type (struct field_info
*,
1495 struct type
*, struct dwarf2_cu
*);
1497 static void dwarf2_add_member_fn (struct field_info
*,
1498 struct die_info
*, struct type
*,
1499 struct dwarf2_cu
*);
1501 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1503 struct dwarf2_cu
*);
1505 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1507 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1509 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1511 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1513 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1515 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1517 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1519 static struct type
*read_module_type (struct die_info
*die
,
1520 struct dwarf2_cu
*cu
);
1522 static const char *namespace_name (struct die_info
*die
,
1523 int *is_anonymous
, struct dwarf2_cu
*);
1525 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1527 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1530 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1531 struct dwarf2_cu
*);
1533 static struct die_info
*read_die_and_siblings_1
1534 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1537 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1538 const gdb_byte
*info_ptr
,
1539 const gdb_byte
**new_info_ptr
,
1540 struct die_info
*parent
);
1542 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1543 struct die_info
**, const gdb_byte
*,
1546 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1547 struct die_info
**, const gdb_byte
*);
1549 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1551 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1554 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1556 static const char *dwarf2_full_name (const char *name
,
1557 struct die_info
*die
,
1558 struct dwarf2_cu
*cu
);
1560 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1561 struct dwarf2_cu
*cu
);
1563 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1564 struct dwarf2_cu
**);
1566 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1568 static void dump_die_for_error (struct die_info
*);
1570 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1573 /*static*/ void dump_die (struct die_info
*, int max_level
);
1575 static void store_in_ref_table (struct die_info
*,
1576 struct dwarf2_cu
*);
1578 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1579 const struct attribute
*,
1580 struct dwarf2_cu
**);
1582 static struct die_info
*follow_die_ref (struct die_info
*,
1583 const struct attribute
*,
1584 struct dwarf2_cu
**);
1586 static struct die_info
*follow_die_sig (struct die_info
*,
1587 const struct attribute
*,
1588 struct dwarf2_cu
**);
1590 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1591 struct dwarf2_cu
*);
1593 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1594 const struct attribute
*,
1595 struct dwarf2_cu
*);
1597 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1598 dwarf2_per_objfile
*per_objfile
);
1600 static void read_signatured_type (signatured_type
*sig_type
,
1601 dwarf2_per_objfile
*per_objfile
);
1603 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1604 struct die_info
*die
, struct dwarf2_cu
*cu
,
1605 struct dynamic_prop
*prop
, struct type
*type
);
1607 /* memory allocation interface */
1609 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1611 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1613 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1615 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1616 struct dwarf2_loclist_baton
*baton
,
1617 const struct attribute
*attr
);
1619 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1621 struct dwarf2_cu
*cu
,
1624 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1625 const gdb_byte
*info_ptr
,
1626 struct abbrev_info
*abbrev
);
1628 static hashval_t
partial_die_hash (const void *item
);
1630 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1632 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1633 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1634 dwarf2_per_objfile
*per_objfile
);
1636 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1637 struct die_info
*comp_unit_die
,
1638 enum language pretend_language
);
1640 static struct type
*set_die_type (struct die_info
*, struct type
*,
1641 struct dwarf2_cu
*, bool = false);
1643 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1645 static int create_all_type_units (dwarf2_per_objfile
*per_objfile
);
1647 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1648 dwarf2_per_objfile
*per_objfile
,
1649 dwarf2_cu
*existing_cu
,
1651 enum language pretend_language
);
1653 static void process_full_comp_unit (dwarf2_cu
*cu
,
1654 enum language pretend_language
);
1656 static void process_full_type_unit (dwarf2_cu
*cu
,
1657 enum language pretend_language
);
1659 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1660 struct dwarf2_per_cu_data
*);
1662 static void dwarf2_mark (struct dwarf2_cu
*);
1664 static struct type
*get_die_type_at_offset (sect_offset
,
1665 dwarf2_per_cu_data
*per_cu
,
1666 dwarf2_per_objfile
*per_objfile
);
1668 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1670 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1671 dwarf2_per_objfile
*per_objfile
,
1672 enum language pretend_language
);
1674 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1676 /* Class, the destructor of which frees all allocated queue entries. This
1677 will only have work to do if an error was thrown while processing the
1678 dwarf. If no error was thrown then the queue entries should have all
1679 been processed, and freed, as we went along. */
1681 class dwarf2_queue_guard
1684 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1685 : m_per_objfile (per_objfile
)
1689 /* Free any entries remaining on the queue. There should only be
1690 entries left if we hit an error while processing the dwarf. */
1691 ~dwarf2_queue_guard ()
1693 /* Ensure that no memory is allocated by the queue. */
1694 std::queue
<dwarf2_queue_item
> empty
;
1695 std::swap (m_per_objfile
->per_bfd
->queue
, empty
);
1698 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1701 dwarf2_per_objfile
*m_per_objfile
;
1704 dwarf2_queue_item::~dwarf2_queue_item ()
1706 /* Anything still marked queued is likely to be in an
1707 inconsistent state, so discard it. */
1710 per_objfile
->remove_cu (per_cu
);
1715 /* The return type of find_file_and_directory. Note, the enclosed
1716 string pointers are only valid while this object is valid. */
1718 struct file_and_directory
1720 /* The filename. This is never NULL. */
1723 /* The compilation directory. NULL if not known. If we needed to
1724 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1725 points directly to the DW_AT_comp_dir string attribute owned by
1726 the obstack that owns the DIE. */
1727 const char *comp_dir
;
1729 /* If we needed to build a new string for comp_dir, this is what
1730 owns the storage. */
1731 std::string comp_dir_storage
;
1734 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1735 struct dwarf2_cu
*cu
);
1737 static htab_up
allocate_signatured_type_table ();
1739 static htab_up
allocate_dwo_unit_table ();
1741 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1742 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1743 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1745 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1747 static struct dwo_unit
*lookup_dwo_comp_unit
1748 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1749 ULONGEST signature
);
1751 static struct dwo_unit
*lookup_dwo_type_unit
1752 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1754 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1756 /* A unique pointer to a dwo_file. */
1758 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1760 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1762 static void check_producer (struct dwarf2_cu
*cu
);
1764 static void free_line_header_voidp (void *arg
);
1766 /* Various complaints about symbol reading that don't abort the process. */
1769 dwarf2_debug_line_missing_file_complaint (void)
1771 complaint (_(".debug_line section has line data without a file"));
1775 dwarf2_debug_line_missing_end_sequence_complaint (void)
1777 complaint (_(".debug_line section has line "
1778 "program sequence without an end"));
1782 dwarf2_complex_location_expr_complaint (void)
1784 complaint (_("location expression too complex"));
1788 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1791 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1796 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1798 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1802 /* Hash function for line_header_hash. */
1805 line_header_hash (const struct line_header
*ofs
)
1807 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1810 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1813 line_header_hash_voidp (const void *item
)
1815 const struct line_header
*ofs
= (const struct line_header
*) item
;
1817 return line_header_hash (ofs
);
1820 /* Equality function for line_header_hash. */
1823 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1825 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1826 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1828 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1829 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1834 /* See declaration. */
1836 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1839 can_copy (can_copy_
)
1842 names
= &dwarf2_elf_names
;
1844 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1845 locate_sections (obfd
, sec
, *names
);
1848 dwarf2_per_bfd::~dwarf2_per_bfd ()
1850 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1851 per_cu
->imported_symtabs_free ();
1853 for (signatured_type
*sig_type
: all_type_units
)
1854 sig_type
->per_cu
.imported_symtabs_free ();
1856 /* Everything else should be on this->obstack. */
1862 dwarf2_per_objfile::remove_all_cus ()
1864 for (auto pair
: m_dwarf2_cus
)
1867 m_dwarf2_cus
.clear ();
1870 /* A helper class that calls free_cached_comp_units on
1873 class free_cached_comp_units
1877 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1878 : m_per_objfile (per_objfile
)
1882 ~free_cached_comp_units ()
1884 m_per_objfile
->remove_all_cus ();
1887 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1891 dwarf2_per_objfile
*m_per_objfile
;
1897 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1899 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1901 return this->m_symtabs
[per_cu
->index
] != nullptr;
1907 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1909 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1911 return this->m_symtabs
[per_cu
->index
];
1917 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1918 compunit_symtab
*symtab
)
1920 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1921 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1923 this->m_symtabs
[per_cu
->index
] = symtab
;
1926 /* Try to locate the sections we need for DWARF 2 debugging
1927 information and return true if we have enough to do something.
1928 NAMES points to the dwarf2 section names, or is NULL if the standard
1929 ELF names are used. CAN_COPY is true for formats where symbol
1930 interposition is possible and so symbol values must follow copy
1931 relocation rules. */
1934 dwarf2_has_info (struct objfile
*objfile
,
1935 const struct dwarf2_debug_sections
*names
,
1938 if (objfile
->flags
& OBJF_READNEVER
)
1941 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1943 if (per_objfile
== NULL
)
1945 dwarf2_per_bfd
*per_bfd
;
1947 /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
1948 doesn't require relocations and if there aren't partial symbols
1949 from some other reader. */
1950 if (!objfile_has_partial_symbols (objfile
)
1951 && !gdb_bfd_requires_relocations (objfile
->obfd
))
1953 /* See if one has been created for this BFD yet. */
1954 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1956 if (per_bfd
== nullptr)
1958 /* No, create it now. */
1959 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1960 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1965 /* No sharing possible, create one specifically for this objfile. */
1966 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1967 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1970 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1973 return (!per_objfile
->per_bfd
->info
.is_virtual
1974 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1975 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1976 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1979 /* When loading sections, we look either for uncompressed section or for
1980 compressed section names. */
1983 section_is_p (const char *section_name
,
1984 const struct dwarf2_section_names
*names
)
1986 if (names
->normal
!= NULL
1987 && strcmp (section_name
, names
->normal
) == 0)
1989 if (names
->compressed
!= NULL
1990 && strcmp (section_name
, names
->compressed
) == 0)
1995 /* See declaration. */
1998 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1999 const dwarf2_debug_sections
&names
)
2001 flagword aflag
= bfd_section_flags (sectp
);
2003 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2006 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2007 > bfd_get_file_size (abfd
))
2009 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2010 warning (_("Discarding section %s which has a section size (%s"
2011 ") larger than the file size [in module %s]"),
2012 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2013 bfd_get_filename (abfd
));
2015 else if (section_is_p (sectp
->name
, &names
.info
))
2017 this->info
.s
.section
= sectp
;
2018 this->info
.size
= bfd_section_size (sectp
);
2020 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2022 this->abbrev
.s
.section
= sectp
;
2023 this->abbrev
.size
= bfd_section_size (sectp
);
2025 else if (section_is_p (sectp
->name
, &names
.line
))
2027 this->line
.s
.section
= sectp
;
2028 this->line
.size
= bfd_section_size (sectp
);
2030 else if (section_is_p (sectp
->name
, &names
.loc
))
2032 this->loc
.s
.section
= sectp
;
2033 this->loc
.size
= bfd_section_size (sectp
);
2035 else if (section_is_p (sectp
->name
, &names
.loclists
))
2037 this->loclists
.s
.section
= sectp
;
2038 this->loclists
.size
= bfd_section_size (sectp
);
2040 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2042 this->macinfo
.s
.section
= sectp
;
2043 this->macinfo
.size
= bfd_section_size (sectp
);
2045 else if (section_is_p (sectp
->name
, &names
.macro
))
2047 this->macro
.s
.section
= sectp
;
2048 this->macro
.size
= bfd_section_size (sectp
);
2050 else if (section_is_p (sectp
->name
, &names
.str
))
2052 this->str
.s
.section
= sectp
;
2053 this->str
.size
= bfd_section_size (sectp
);
2055 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
2057 this->str_offsets
.s
.section
= sectp
;
2058 this->str_offsets
.size
= bfd_section_size (sectp
);
2060 else if (section_is_p (sectp
->name
, &names
.line_str
))
2062 this->line_str
.s
.section
= sectp
;
2063 this->line_str
.size
= bfd_section_size (sectp
);
2065 else if (section_is_p (sectp
->name
, &names
.addr
))
2067 this->addr
.s
.section
= sectp
;
2068 this->addr
.size
= bfd_section_size (sectp
);
2070 else if (section_is_p (sectp
->name
, &names
.frame
))
2072 this->frame
.s
.section
= sectp
;
2073 this->frame
.size
= bfd_section_size (sectp
);
2075 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2077 this->eh_frame
.s
.section
= sectp
;
2078 this->eh_frame
.size
= bfd_section_size (sectp
);
2080 else if (section_is_p (sectp
->name
, &names
.ranges
))
2082 this->ranges
.s
.section
= sectp
;
2083 this->ranges
.size
= bfd_section_size (sectp
);
2085 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2087 this->rnglists
.s
.section
= sectp
;
2088 this->rnglists
.size
= bfd_section_size (sectp
);
2090 else if (section_is_p (sectp
->name
, &names
.types
))
2092 struct dwarf2_section_info type_section
;
2094 memset (&type_section
, 0, sizeof (type_section
));
2095 type_section
.s
.section
= sectp
;
2096 type_section
.size
= bfd_section_size (sectp
);
2098 this->types
.push_back (type_section
);
2100 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2102 this->gdb_index
.s
.section
= sectp
;
2103 this->gdb_index
.size
= bfd_section_size (sectp
);
2105 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2107 this->debug_names
.s
.section
= sectp
;
2108 this->debug_names
.size
= bfd_section_size (sectp
);
2110 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2112 this->debug_aranges
.s
.section
= sectp
;
2113 this->debug_aranges
.size
= bfd_section_size (sectp
);
2116 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2117 && bfd_section_vma (sectp
) == 0)
2118 this->has_section_at_zero
= true;
2121 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2125 dwarf2_get_section_info (struct objfile
*objfile
,
2126 enum dwarf2_section_enum sect
,
2127 asection
**sectp
, const gdb_byte
**bufp
,
2128 bfd_size_type
*sizep
)
2130 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2131 struct dwarf2_section_info
*info
;
2133 /* We may see an objfile without any DWARF, in which case we just
2135 if (per_objfile
== NULL
)
2144 case DWARF2_DEBUG_FRAME
:
2145 info
= &per_objfile
->per_bfd
->frame
;
2147 case DWARF2_EH_FRAME
:
2148 info
= &per_objfile
->per_bfd
->eh_frame
;
2151 gdb_assert_not_reached ("unexpected section");
2154 info
->read (objfile
);
2156 *sectp
= info
->get_bfd_section ();
2157 *bufp
= info
->buffer
;
2158 *sizep
= info
->size
;
2161 /* A helper function to find the sections for a .dwz file. */
2164 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, dwz_file
*dwz_file
)
2166 /* Note that we only support the standard ELF names, because .dwz
2167 is ELF-only (at the time of writing). */
2168 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2170 dwz_file
->abbrev
.s
.section
= sectp
;
2171 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2173 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2175 dwz_file
->info
.s
.section
= sectp
;
2176 dwz_file
->info
.size
= bfd_section_size (sectp
);
2178 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2180 dwz_file
->str
.s
.section
= sectp
;
2181 dwz_file
->str
.size
= bfd_section_size (sectp
);
2183 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2185 dwz_file
->line
.s
.section
= sectp
;
2186 dwz_file
->line
.size
= bfd_section_size (sectp
);
2188 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2190 dwz_file
->macro
.s
.section
= sectp
;
2191 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2193 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2195 dwz_file
->gdb_index
.s
.section
= sectp
;
2196 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2198 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2200 dwz_file
->debug_names
.s
.section
= sectp
;
2201 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2205 /* Attempt to find a .dwz file (whose full path is represented by
2206 FILENAME) in all of the specified debug file directories provided.
2208 Return the equivalent gdb_bfd_ref_ptr of the .dwz file found, or
2209 nullptr if it could not find anything. */
2211 static gdb_bfd_ref_ptr
2212 dwz_search_other_debugdirs (std::string
&filename
, bfd_byte
*buildid
,
2215 /* Let's assume that the path represented by FILENAME has the
2216 "/.dwz/" subpath in it. This is what (most) GNU/Linux
2217 distributions do, anyway. */
2218 size_t dwz_pos
= filename
.find ("/.dwz/");
2220 if (dwz_pos
== std::string::npos
)
2223 /* This is an obvious assertion, but it's here more to educate
2224 future readers of this code that FILENAME at DWZ_POS *must*
2225 contain a directory separator. */
2226 gdb_assert (IS_DIR_SEPARATOR (filename
[dwz_pos
]));
2228 gdb_bfd_ref_ptr dwz_bfd
;
2229 std::vector
<gdb::unique_xmalloc_ptr
<char>> debugdir_vec
2230 = dirnames_to_char_ptr_vec (debug_file_directory
);
2232 for (const gdb::unique_xmalloc_ptr
<char> &debugdir
: debugdir_vec
)
2234 /* The idea is to iterate over the
2235 debug file directories provided by the user and
2236 replace the hard-coded path in the "filename" by each
2237 debug-file-directory.
2239 For example, suppose that filename is:
2241 /usr/lib/debug/.dwz/foo.dwz
2243 And suppose that we have "$HOME/bar" as the
2244 debug-file-directory. We would then adjust filename
2247 $HOME/bar/.dwz/foo.dwz
2249 which would hopefully allow us to find the alt debug
2251 std::string ddir
= debugdir
.get ();
2256 /* Make sure the current debug-file-directory ends with a
2257 directory separator. This is needed because, if FILENAME
2258 contains something like "/usr/lib/abcde/.dwz/foo.dwz" and
2259 DDIR is "/usr/lib/abc", then could wrongfully skip it
2261 if (!IS_DIR_SEPARATOR (ddir
.back ()))
2262 ddir
+= SLASH_STRING
;
2264 /* Check whether the beginning of FILENAME is DDIR. If it is,
2265 then we are dealing with a file which we already attempted to
2266 open before, so we just skip it and continue processing the
2267 remaining debug file directories. */
2268 if (filename
.size () > ddir
.size ()
2269 && filename
.compare (0, ddir
.size (), ddir
) == 0)
2272 /* Replace FILENAME's default debug-file-directory with
2274 std::string new_filename
= ddir
+ &filename
[dwz_pos
+ 1];
2276 dwz_bfd
= gdb_bfd_open (new_filename
.c_str (), gnutarget
);
2278 if (dwz_bfd
== nullptr)
2281 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2283 dwz_bfd
.reset (nullptr);
2294 /* See dwarf2read.h. */
2297 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
)
2299 bfd_size_type buildid_len_arg
;
2303 if (per_bfd
->dwz_file
!= NULL
)
2304 return per_bfd
->dwz_file
.get ();
2306 bfd_set_error (bfd_error_no_error
);
2307 gdb::unique_xmalloc_ptr
<char> data
2308 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2309 &buildid_len_arg
, &buildid
));
2312 if (bfd_get_error () == bfd_error_no_error
)
2314 error (_("could not read '.gnu_debugaltlink' section: %s"),
2315 bfd_errmsg (bfd_get_error ()));
2318 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2320 buildid_len
= (size_t) buildid_len_arg
;
2322 std::string filename
= data
.get ();
2324 if (!IS_ABSOLUTE_PATH (filename
.c_str ()))
2326 gdb::unique_xmalloc_ptr
<char> abs
2327 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2329 filename
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2332 /* First try the file name given in the section. If that doesn't
2333 work, try to use the build-id instead. */
2334 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
.c_str (), gnutarget
));
2335 if (dwz_bfd
!= NULL
)
2337 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2338 dwz_bfd
.reset (nullptr);
2341 if (dwz_bfd
== NULL
)
2342 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2344 if (dwz_bfd
== nullptr)
2346 /* If the user has provided us with different
2347 debug file directories, we can try them in order. */
2348 dwz_bfd
= dwz_search_other_debugdirs (filename
, buildid
, buildid_len
);
2351 if (dwz_bfd
== nullptr)
2353 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2354 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2356 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2363 /* File successfully retrieved from server. */
2364 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2366 if (dwz_bfd
== nullptr)
2367 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2368 alt_filename
.get ());
2369 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2370 dwz_bfd
.reset (nullptr);
2374 if (dwz_bfd
== NULL
)
2375 error (_("could not find '.gnu_debugaltlink' file for %s"),
2376 bfd_get_filename (per_bfd
->obfd
));
2378 std::unique_ptr
<struct dwz_file
> result
2379 (new struct dwz_file (std::move (dwz_bfd
)));
2381 for (asection
*sec
: gdb_bfd_sections (result
->dwz_bfd
))
2382 locate_dwz_sections (result
->dwz_bfd
.get (), sec
, result
.get ());
2384 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2385 per_bfd
->dwz_file
= std::move (result
);
2386 return per_bfd
->dwz_file
.get ();
2389 /* DWARF quick_symbols_functions support. */
2391 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2392 unique line tables, so we maintain a separate table of all .debug_line
2393 derived entries to support the sharing.
2394 All the quick functions need is the list of file names. We discard the
2395 line_header when we're done and don't need to record it here. */
2396 struct quick_file_names
2398 /* The data used to construct the hash key. */
2399 struct stmt_list_hash hash
;
2401 /* The number of entries in file_names, real_names. */
2402 unsigned int num_file_names
;
2404 /* The file names from the line table, after being run through
2406 const char **file_names
;
2408 /* The file names from the line table after being run through
2409 gdb_realpath. These are computed lazily. */
2410 const char **real_names
;
2413 /* When using the index (and thus not using psymtabs), each CU has an
2414 object of this type. This is used to hold information needed by
2415 the various "quick" methods. */
2416 struct dwarf2_per_cu_quick_data
2418 /* The file table. This can be NULL if there was no file table
2419 or it's currently not read in.
2420 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2421 struct quick_file_names
*file_names
;
2423 /* A temporary mark bit used when iterating over all CUs in
2424 expand_symtabs_matching. */
2425 unsigned int mark
: 1;
2427 /* True if we've tried to read the file table and found there isn't one.
2428 There will be no point in trying to read it again next time. */
2429 unsigned int no_file_data
: 1;
2432 /* Utility hash function for a stmt_list_hash. */
2435 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2439 if (stmt_list_hash
->dwo_unit
!= NULL
)
2440 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2441 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2445 /* Utility equality function for a stmt_list_hash. */
2448 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2449 const struct stmt_list_hash
*rhs
)
2451 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2453 if (lhs
->dwo_unit
!= NULL
2454 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2457 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2460 /* Hash function for a quick_file_names. */
2463 hash_file_name_entry (const void *e
)
2465 const struct quick_file_names
*file_data
2466 = (const struct quick_file_names
*) e
;
2468 return hash_stmt_list_entry (&file_data
->hash
);
2471 /* Equality function for a quick_file_names. */
2474 eq_file_name_entry (const void *a
, const void *b
)
2476 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2477 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2479 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2482 /* Delete function for a quick_file_names. */
2485 delete_file_name_entry (void *e
)
2487 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2490 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2492 xfree ((void*) file_data
->file_names
[i
]);
2493 if (file_data
->real_names
)
2494 xfree ((void*) file_data
->real_names
[i
]);
2497 /* The space for the struct itself lives on the obstack, so we don't
2501 /* Create a quick_file_names hash table. */
2504 create_quick_file_names_table (unsigned int nr_initial_entries
)
2506 return htab_up (htab_create_alloc (nr_initial_entries
,
2507 hash_file_name_entry
, eq_file_name_entry
,
2508 delete_file_name_entry
, xcalloc
, xfree
));
2511 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2512 function is unrelated to symtabs, symtab would have to be created afterwards.
2513 You should call age_cached_comp_units after processing the CU. */
2516 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2519 if (per_cu
->is_debug_types
)
2520 load_full_type_unit (per_cu
, per_objfile
);
2522 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2523 skip_partial
, language_minimal
);
2525 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2527 return nullptr; /* Dummy CU. */
2529 dwarf2_find_base_address (cu
->dies
, cu
);
2534 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2537 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2538 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2540 /* Skip type_unit_groups, reading the type units they contain
2541 is handled elsewhere. */
2542 if (per_cu
->type_unit_group_p ())
2545 /* The destructor of dwarf2_queue_guard frees any entries left on
2546 the queue. After this point we're guaranteed to leave this function
2547 with the dwarf queue empty. */
2548 dwarf2_queue_guard
q_guard (per_objfile
);
2550 if (!per_objfile
->symtab_set_p (per_cu
))
2552 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2553 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2555 /* If we just loaded a CU from a DWO, and we're working with an index
2556 that may badly handle TUs, load all the TUs in that DWO as well.
2557 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2558 if (!per_cu
->is_debug_types
2560 && cu
->dwo_unit
!= NULL
2561 && per_objfile
->per_bfd
->index_table
!= NULL
2562 && per_objfile
->per_bfd
->index_table
->version
<= 7
2563 /* DWP files aren't supported yet. */
2564 && get_dwp_file (per_objfile
) == NULL
)
2565 queue_and_load_all_dwo_tus (cu
);
2568 process_queue (per_objfile
);
2570 /* Age the cache, releasing compilation units that have not
2571 been used recently. */
2572 per_objfile
->age_comp_units ();
2575 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2576 the per-objfile for which this symtab is instantiated.
2578 Returns the resulting symbol table. */
2580 static struct compunit_symtab
*
2581 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2582 dwarf2_per_objfile
*per_objfile
,
2585 gdb_assert (per_objfile
->per_bfd
->using_index
);
2587 if (!per_objfile
->symtab_set_p (per_cu
))
2589 free_cached_comp_units
freer (per_objfile
);
2590 scoped_restore decrementer
= increment_reading_symtab ();
2591 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2592 process_cu_includes (per_objfile
);
2595 return per_objfile
->get_symtab (per_cu
);
2598 /* See declaration. */
2600 dwarf2_per_cu_data
*
2601 dwarf2_per_bfd::get_cutu (int index
)
2603 if (index
>= this->all_comp_units
.size ())
2605 index
-= this->all_comp_units
.size ();
2606 gdb_assert (index
< this->all_type_units
.size ());
2607 return &this->all_type_units
[index
]->per_cu
;
2610 return this->all_comp_units
[index
];
2613 /* See declaration. */
2615 dwarf2_per_cu_data
*
2616 dwarf2_per_bfd::get_cu (int index
)
2618 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2620 return this->all_comp_units
[index
];
2623 /* See declaration. */
2626 dwarf2_per_bfd::get_tu (int index
)
2628 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2630 return this->all_type_units
[index
];
2635 dwarf2_per_cu_data
*
2636 dwarf2_per_bfd::allocate_per_cu ()
2638 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2639 result
->per_bfd
= this;
2640 result
->index
= m_num_psymtabs
++;
2647 dwarf2_per_bfd::allocate_signatured_type ()
2649 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2650 result
->per_cu
.per_bfd
= this;
2651 result
->per_cu
.index
= m_num_psymtabs
++;
2655 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2656 obstack, and constructed with the specified field values. */
2658 static dwarf2_per_cu_data
*
2659 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2660 struct dwarf2_section_info
*section
,
2662 sect_offset sect_off
, ULONGEST length
)
2664 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2665 the_cu
->sect_off
= sect_off
;
2666 the_cu
->length
= length
;
2667 the_cu
->section
= section
;
2668 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2669 struct dwarf2_per_cu_quick_data
);
2670 the_cu
->is_dwz
= is_dwz
;
2674 /* A helper for create_cus_from_index that handles a given list of
2678 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2679 const gdb_byte
*cu_list
, offset_type n_elements
,
2680 struct dwarf2_section_info
*section
,
2683 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2685 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2687 sect_offset sect_off
2688 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2689 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2692 dwarf2_per_cu_data
*per_cu
2693 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2695 per_bfd
->all_comp_units
.push_back (per_cu
);
2699 /* Read the CU list from the mapped index, and use it to create all
2700 the CU objects for PER_BFD. */
2703 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2704 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2705 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2707 gdb_assert (per_bfd
->all_comp_units
.empty ());
2708 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2710 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2713 if (dwz_elements
== 0)
2716 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2717 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2721 /* Create the signatured type hash table from the index. */
2724 create_signatured_type_table_from_index
2725 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2726 const gdb_byte
*bytes
, offset_type elements
)
2728 gdb_assert (per_bfd
->all_type_units
.empty ());
2729 per_bfd
->all_type_units
.reserve (elements
/ 3);
2731 htab_up sig_types_hash
= allocate_signatured_type_table ();
2733 for (offset_type i
= 0; i
< elements
; i
+= 3)
2735 struct signatured_type
*sig_type
;
2738 cu_offset type_offset_in_tu
;
2740 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2741 sect_offset sect_off
2742 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2744 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2746 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2749 sig_type
= per_bfd
->allocate_signatured_type ();
2750 sig_type
->signature
= signature
;
2751 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2752 sig_type
->per_cu
.is_debug_types
= 1;
2753 sig_type
->per_cu
.section
= section
;
2754 sig_type
->per_cu
.sect_off
= sect_off
;
2755 sig_type
->per_cu
.v
.quick
2756 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2757 struct dwarf2_per_cu_quick_data
);
2759 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2762 per_bfd
->all_type_units
.push_back (sig_type
);
2765 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2768 /* Create the signatured type hash table from .debug_names. */
2771 create_signatured_type_table_from_debug_names
2772 (dwarf2_per_objfile
*per_objfile
,
2773 const mapped_debug_names
&map
,
2774 struct dwarf2_section_info
*section
,
2775 struct dwarf2_section_info
*abbrev_section
)
2777 struct objfile
*objfile
= per_objfile
->objfile
;
2779 section
->read (objfile
);
2780 abbrev_section
->read (objfile
);
2782 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
2783 per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2785 htab_up sig_types_hash
= allocate_signatured_type_table ();
2787 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2789 struct signatured_type
*sig_type
;
2792 sect_offset sect_off
2793 = (sect_offset
) (extract_unsigned_integer
2794 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2796 map
.dwarf5_byte_order
));
2798 comp_unit_head cu_header
;
2799 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2801 section
->buffer
+ to_underlying (sect_off
),
2804 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2805 sig_type
->signature
= cu_header
.signature
;
2806 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2807 sig_type
->per_cu
.is_debug_types
= 1;
2808 sig_type
->per_cu
.section
= section
;
2809 sig_type
->per_cu
.sect_off
= sect_off
;
2810 sig_type
->per_cu
.v
.quick
2811 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2812 struct dwarf2_per_cu_quick_data
);
2814 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2817 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2820 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2823 /* Read the address map data from the mapped index, and use it to
2824 populate the objfile's psymtabs_addrmap. */
2827 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2828 struct mapped_index
*index
)
2830 struct objfile
*objfile
= per_objfile
->objfile
;
2831 struct gdbarch
*gdbarch
= objfile
->arch ();
2832 const gdb_byte
*iter
, *end
;
2833 struct addrmap
*mutable_map
;
2836 auto_obstack temp_obstack
;
2838 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2840 iter
= index
->address_table
.data ();
2841 end
= iter
+ index
->address_table
.size ();
2843 baseaddr
= objfile
->text_section_offset ();
2847 ULONGEST hi
, lo
, cu_index
;
2848 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2850 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2852 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2857 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2858 hex_string (lo
), hex_string (hi
));
2862 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
2864 complaint (_(".gdb_index address table has invalid CU number %u"),
2865 (unsigned) cu_index
);
2869 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2870 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2871 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2872 per_objfile
->per_bfd
->get_cu (cu_index
));
2875 objfile
->partial_symtabs
->psymtabs_addrmap
2876 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2879 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2880 populate the objfile's psymtabs_addrmap. */
2883 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2884 struct dwarf2_section_info
*section
)
2886 struct objfile
*objfile
= per_objfile
->objfile
;
2887 bfd
*abfd
= objfile
->obfd
;
2888 struct gdbarch
*gdbarch
= objfile
->arch ();
2889 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2891 auto_obstack temp_obstack
;
2892 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2894 std::unordered_map
<sect_offset
,
2895 dwarf2_per_cu_data
*,
2896 gdb::hash_enum
<sect_offset
>>
2897 debug_info_offset_to_per_cu
;
2898 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
2900 const auto insertpair
2901 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2902 if (!insertpair
.second
)
2904 warning (_("Section .debug_aranges in %s has duplicate "
2905 "debug_info_offset %s, ignoring .debug_aranges."),
2906 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2911 section
->read (objfile
);
2913 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2915 const gdb_byte
*addr
= section
->buffer
;
2917 while (addr
< section
->buffer
+ section
->size
)
2919 const gdb_byte
*const entry_addr
= addr
;
2920 unsigned int bytes_read
;
2922 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2926 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2927 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2928 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2929 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2931 warning (_("Section .debug_aranges in %s entry at offset %s "
2932 "length %s exceeds section length %s, "
2933 "ignoring .debug_aranges."),
2934 objfile_name (objfile
),
2935 plongest (entry_addr
- section
->buffer
),
2936 plongest (bytes_read
+ entry_length
),
2937 pulongest (section
->size
));
2941 /* The version number. */
2942 const uint16_t version
= read_2_bytes (abfd
, addr
);
2946 warning (_("Section .debug_aranges in %s entry at offset %s "
2947 "has unsupported version %d, ignoring .debug_aranges."),
2948 objfile_name (objfile
),
2949 plongest (entry_addr
- section
->buffer
), version
);
2953 const uint64_t debug_info_offset
2954 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2955 addr
+= offset_size
;
2956 const auto per_cu_it
2957 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2958 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2960 warning (_("Section .debug_aranges in %s entry at offset %s "
2961 "debug_info_offset %s does not exists, "
2962 "ignoring .debug_aranges."),
2963 objfile_name (objfile
),
2964 plongest (entry_addr
- section
->buffer
),
2965 pulongest (debug_info_offset
));
2968 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2970 const uint8_t address_size
= *addr
++;
2971 if (address_size
< 1 || address_size
> 8)
2973 warning (_("Section .debug_aranges in %s entry at offset %s "
2974 "address_size %u is invalid, ignoring .debug_aranges."),
2975 objfile_name (objfile
),
2976 plongest (entry_addr
- section
->buffer
), address_size
);
2980 const uint8_t segment_selector_size
= *addr
++;
2981 if (segment_selector_size
!= 0)
2983 warning (_("Section .debug_aranges in %s entry at offset %s "
2984 "segment_selector_size %u is not supported, "
2985 "ignoring .debug_aranges."),
2986 objfile_name (objfile
),
2987 plongest (entry_addr
- section
->buffer
),
2988 segment_selector_size
);
2992 /* Must pad to an alignment boundary that is twice the address
2993 size. It is undocumented by the DWARF standard but GCC does
2995 for (size_t padding
= ((-(addr
- section
->buffer
))
2996 & (2 * address_size
- 1));
2997 padding
> 0; padding
--)
3000 warning (_("Section .debug_aranges in %s entry at offset %s "
3001 "padding is not zero, ignoring .debug_aranges."),
3002 objfile_name (objfile
),
3003 plongest (entry_addr
- section
->buffer
));
3009 if (addr
+ 2 * address_size
> entry_end
)
3011 warning (_("Section .debug_aranges in %s entry at offset %s "
3012 "address list is not properly terminated, "
3013 "ignoring .debug_aranges."),
3014 objfile_name (objfile
),
3015 plongest (entry_addr
- section
->buffer
));
3018 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3020 addr
+= address_size
;
3021 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3023 addr
+= address_size
;
3024 if (start
== 0 && length
== 0)
3026 if (start
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
3028 /* Symbol was eliminated due to a COMDAT group. */
3031 ULONGEST end
= start
+ length
;
3032 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3034 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3036 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3040 objfile
->partial_symtabs
->psymtabs_addrmap
3041 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3044 /* Find a slot in the mapped index INDEX for the object named NAME.
3045 If NAME is found, set *VEC_OUT to point to the CU vector in the
3046 constant pool and return true. If NAME cannot be found, return
3050 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3051 offset_type
**vec_out
)
3054 offset_type slot
, step
;
3055 int (*cmp
) (const char *, const char *);
3057 gdb::unique_xmalloc_ptr
<char> without_params
;
3058 if (current_language
->la_language
== language_cplus
3059 || current_language
->la_language
== language_fortran
3060 || current_language
->la_language
== language_d
)
3062 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3065 if (strchr (name
, '(') != NULL
)
3067 without_params
= cp_remove_params (name
);
3069 if (without_params
!= NULL
)
3070 name
= without_params
.get ();
3074 /* Index version 4 did not support case insensitive searches. But the
3075 indices for case insensitive languages are built in lowercase, therefore
3076 simulate our NAME being searched is also lowercased. */
3077 hash
= mapped_index_string_hash ((index
->version
== 4
3078 && case_sensitivity
== case_sensitive_off
3079 ? 5 : index
->version
),
3082 slot
= hash
& (index
->symbol_table
.size () - 1);
3083 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3084 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3090 const auto &bucket
= index
->symbol_table
[slot
];
3091 if (bucket
.name
== 0 && bucket
.vec
== 0)
3094 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3095 if (!cmp (name
, str
))
3097 *vec_out
= (offset_type
*) (index
->constant_pool
3098 + MAYBE_SWAP (bucket
.vec
));
3102 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3106 /* A helper function that reads the .gdb_index from BUFFER and fills
3107 in MAP. FILENAME is the name of the file containing the data;
3108 it is used for error reporting. DEPRECATED_OK is true if it is
3109 ok to use deprecated sections.
3111 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3112 out parameters that are filled in with information about the CU and
3113 TU lists in the section.
3115 Returns true if all went well, false otherwise. */
3118 read_gdb_index_from_buffer (const char *filename
,
3120 gdb::array_view
<const gdb_byte
> buffer
,
3121 struct mapped_index
*map
,
3122 const gdb_byte
**cu_list
,
3123 offset_type
*cu_list_elements
,
3124 const gdb_byte
**types_list
,
3125 offset_type
*types_list_elements
)
3127 const gdb_byte
*addr
= &buffer
[0];
3129 /* Version check. */
3130 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3131 /* Versions earlier than 3 emitted every copy of a psymbol. This
3132 causes the index to behave very poorly for certain requests. Version 3
3133 contained incomplete addrmap. So, it seems better to just ignore such
3137 static int warning_printed
= 0;
3138 if (!warning_printed
)
3140 warning (_("Skipping obsolete .gdb_index section in %s."),
3142 warning_printed
= 1;
3146 /* Index version 4 uses a different hash function than index version
3149 Versions earlier than 6 did not emit psymbols for inlined
3150 functions. Using these files will cause GDB not to be able to
3151 set breakpoints on inlined functions by name, so we ignore these
3152 indices unless the user has done
3153 "set use-deprecated-index-sections on". */
3154 if (version
< 6 && !deprecated_ok
)
3156 static int warning_printed
= 0;
3157 if (!warning_printed
)
3160 Skipping deprecated .gdb_index section in %s.\n\
3161 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3162 to use the section anyway."),
3164 warning_printed
= 1;
3168 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3169 of the TU (for symbols coming from TUs),
3170 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3171 Plus gold-generated indices can have duplicate entries for global symbols,
3172 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3173 These are just performance bugs, and we can't distinguish gdb-generated
3174 indices from gold-generated ones, so issue no warning here. */
3176 /* Indexes with higher version than the one supported by GDB may be no
3177 longer backward compatible. */
3181 map
->version
= version
;
3183 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3186 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3187 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3191 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3192 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3193 - MAYBE_SWAP (metadata
[i
]))
3197 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3198 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3200 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3203 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3204 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3206 = gdb::array_view
<mapped_index::symbol_table_slot
>
3207 ((mapped_index::symbol_table_slot
*) symbol_table
,
3208 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3211 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3216 /* Callback types for dwarf2_read_gdb_index. */
3218 typedef gdb::function_view
3219 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3220 get_gdb_index_contents_ftype
;
3221 typedef gdb::function_view
3222 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3223 get_gdb_index_contents_dwz_ftype
;
3225 /* Read .gdb_index. If everything went ok, initialize the "quick"
3226 elements of all the CUs and return 1. Otherwise, return 0. */
3229 dwarf2_read_gdb_index
3230 (dwarf2_per_objfile
*per_objfile
,
3231 get_gdb_index_contents_ftype get_gdb_index_contents
,
3232 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3234 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3235 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3236 struct dwz_file
*dwz
;
3237 struct objfile
*objfile
= per_objfile
->objfile
;
3238 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3240 gdb::array_view
<const gdb_byte
> main_index_contents
3241 = get_gdb_index_contents (objfile
, per_bfd
);
3243 if (main_index_contents
.empty ())
3246 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3247 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3248 use_deprecated_index_sections
,
3249 main_index_contents
, map
.get (), &cu_list
,
3250 &cu_list_elements
, &types_list
,
3251 &types_list_elements
))
3254 /* Don't use the index if it's empty. */
3255 if (map
->symbol_table
.empty ())
3258 /* If there is a .dwz file, read it so we can get its CU list as
3260 dwz
= dwarf2_get_dwz_file (per_bfd
);
3263 struct mapped_index dwz_map
;
3264 const gdb_byte
*dwz_types_ignore
;
3265 offset_type dwz_types_elements_ignore
;
3267 gdb::array_view
<const gdb_byte
> dwz_index_content
3268 = get_gdb_index_contents_dwz (objfile
, dwz
);
3270 if (dwz_index_content
.empty ())
3273 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3274 1, dwz_index_content
, &dwz_map
,
3275 &dwz_list
, &dwz_list_elements
,
3277 &dwz_types_elements_ignore
))
3279 warning (_("could not read '.gdb_index' section from %s; skipping"),
3280 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3285 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
3288 if (types_list_elements
)
3290 /* We can only handle a single .debug_types when we have an
3292 if (per_bfd
->types
.size () != 1)
3295 dwarf2_section_info
*section
= &per_bfd
->types
[0];
3297 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
3298 types_list_elements
);
3301 create_addrmap_from_index (per_objfile
, map
.get ());
3303 per_bfd
->index_table
= std::move (map
);
3304 per_bfd
->using_index
= 1;
3305 per_bfd
->quick_file_names_table
=
3306 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
3308 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
3309 objfiles using the same BFD. */
3310 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
3311 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
3316 /* die_reader_func for dw2_get_file_names. */
3319 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3320 const gdb_byte
*info_ptr
,
3321 struct die_info
*comp_unit_die
)
3323 struct dwarf2_cu
*cu
= reader
->cu
;
3324 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3325 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3326 struct dwarf2_per_cu_data
*lh_cu
;
3327 struct attribute
*attr
;
3329 struct quick_file_names
*qfn
;
3331 gdb_assert (! this_cu
->is_debug_types
);
3333 /* Our callers never want to match partial units -- instead they
3334 will match the enclosing full CU. */
3335 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3337 this_cu
->v
.quick
->no_file_data
= 1;
3345 sect_offset line_offset
{};
3347 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3348 if (attr
!= nullptr && attr
->form_is_unsigned ())
3350 struct quick_file_names find_entry
;
3352 line_offset
= (sect_offset
) attr
->as_unsigned ();
3354 /* We may have already read in this line header (TU line header sharing).
3355 If we have we're done. */
3356 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3357 find_entry
.hash
.line_sect_off
= line_offset
;
3358 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3359 &find_entry
, INSERT
);
3362 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3366 lh
= dwarf_decode_line_header (line_offset
, cu
);
3370 lh_cu
->v
.quick
->no_file_data
= 1;
3374 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3375 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3376 qfn
->hash
.line_sect_off
= line_offset
;
3377 gdb_assert (slot
!= NULL
);
3380 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3383 if (strcmp (fnd
.name
, "<unknown>") != 0)
3386 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3388 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3389 qfn
->num_file_names
);
3391 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3392 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3393 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3394 fnd
.comp_dir
).release ();
3395 qfn
->real_names
= NULL
;
3397 lh_cu
->v
.quick
->file_names
= qfn
;
3400 /* A helper for the "quick" functions which attempts to read the line
3401 table for THIS_CU. */
3403 static struct quick_file_names
*
3404 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3405 dwarf2_per_objfile
*per_objfile
)
3407 /* This should never be called for TUs. */
3408 gdb_assert (! this_cu
->is_debug_types
);
3409 /* Nor type unit groups. */
3410 gdb_assert (! this_cu
->type_unit_group_p ());
3412 if (this_cu
->v
.quick
->file_names
!= NULL
)
3413 return this_cu
->v
.quick
->file_names
;
3414 /* If we know there is no line data, no point in looking again. */
3415 if (this_cu
->v
.quick
->no_file_data
)
3418 cutu_reader
reader (this_cu
, per_objfile
);
3419 if (!reader
.dummy_p
)
3420 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3422 if (this_cu
->v
.quick
->no_file_data
)
3424 return this_cu
->v
.quick
->file_names
;
3427 /* A helper for the "quick" functions which computes and caches the
3428 real path for a given file name from the line table. */
3431 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3432 struct quick_file_names
*qfn
, int index
)
3434 if (qfn
->real_names
== NULL
)
3435 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3436 qfn
->num_file_names
, const char *);
3438 if (qfn
->real_names
[index
] == NULL
)
3439 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3441 return qfn
->real_names
[index
];
3444 static struct symtab
*
3445 dw2_find_last_source_symtab (struct objfile
*objfile
)
3447 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3448 dwarf2_per_cu_data
*dwarf_cu
= per_objfile
->per_bfd
->all_comp_units
.back ();
3449 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3454 return compunit_primary_filetab (cust
);
3457 /* Traversal function for dw2_forget_cached_source_info. */
3460 dw2_free_cached_file_names (void **slot
, void *info
)
3462 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3464 if (file_data
->real_names
)
3468 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3470 xfree ((void*) file_data
->real_names
[i
]);
3471 file_data
->real_names
[i
] = NULL
;
3479 dw2_forget_cached_source_info (struct objfile
*objfile
)
3481 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3483 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3484 dw2_free_cached_file_names
, NULL
);
3487 /* Helper function for dw2_map_symtabs_matching_filename that expands
3488 the symtabs and calls the iterator. */
3491 dw2_map_expand_apply (struct objfile
*objfile
,
3492 struct dwarf2_per_cu_data
*per_cu
,
3493 const char *name
, const char *real_path
,
3494 gdb::function_view
<bool (symtab
*)> callback
)
3496 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3498 /* Don't visit already-expanded CUs. */
3499 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3500 if (per_objfile
->symtab_set_p (per_cu
))
3503 /* This may expand more than one symtab, and we want to iterate over
3505 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3507 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3508 last_made
, callback
);
3511 /* Implementation of the map_symtabs_matching_filename method. */
3514 dw2_map_symtabs_matching_filename
3515 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3516 gdb::function_view
<bool (symtab
*)> callback
)
3518 const char *name_basename
= lbasename (name
);
3519 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3521 /* The rule is CUs specify all the files, including those used by
3522 any TU, so there's no need to scan TUs here. */
3524 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3526 /* We only need to look at symtabs not already expanded. */
3527 if (per_objfile
->symtab_set_p (per_cu
))
3530 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3531 if (file_data
== NULL
)
3534 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3536 const char *this_name
= file_data
->file_names
[j
];
3537 const char *this_real_name
;
3539 if (compare_filenames_for_search (this_name
, name
))
3541 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3547 /* Before we invoke realpath, which can get expensive when many
3548 files are involved, do a quick comparison of the basenames. */
3549 if (! basenames_may_differ
3550 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3553 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3554 if (compare_filenames_for_search (this_real_name
, name
))
3556 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3562 if (real_path
!= NULL
)
3564 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3565 gdb_assert (IS_ABSOLUTE_PATH (name
));
3566 if (this_real_name
!= NULL
3567 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3569 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3581 /* Struct used to manage iterating over all CUs looking for a symbol. */
3583 struct dw2_symtab_iterator
3585 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3586 dwarf2_per_objfile
*per_objfile
;
3587 /* If set, only look for symbols that match that block. Valid values are
3588 GLOBAL_BLOCK and STATIC_BLOCK. */
3589 gdb::optional
<block_enum
> block_index
;
3590 /* The kind of symbol we're looking for. */
3592 /* The list of CUs from the index entry of the symbol,
3593 or NULL if not found. */
3595 /* The next element in VEC to look at. */
3597 /* The number of elements in VEC, or zero if there is no match. */
3599 /* Have we seen a global version of the symbol?
3600 If so we can ignore all further global instances.
3601 This is to work around gold/15646, inefficient gold-generated
3606 /* Initialize the index symtab iterator ITER, common part. */
3609 dw2_symtab_iter_init_common (struct dw2_symtab_iterator
*iter
,
3610 dwarf2_per_objfile
*per_objfile
,
3611 gdb::optional
<block_enum
> block_index
,
3614 iter
->per_objfile
= per_objfile
;
3615 iter
->block_index
= block_index
;
3616 iter
->domain
= domain
;
3618 iter
->global_seen
= 0;
3623 /* Initialize the index symtab iterator ITER, const char *NAME variant. */
3626 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3627 dwarf2_per_objfile
*per_objfile
,
3628 gdb::optional
<block_enum
> block_index
,
3632 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3634 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3635 /* index is NULL if OBJF_READNOW. */
3639 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3640 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3643 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3646 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3647 dwarf2_per_objfile
*per_objfile
,
3648 gdb::optional
<block_enum
> block_index
,
3649 domain_enum domain
, offset_type namei
)
3651 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3653 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3654 /* index is NULL if OBJF_READNOW. */
3658 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3659 const auto &bucket
= index
->symbol_table
[namei
];
3661 iter
->vec
= (offset_type
*) (index
->constant_pool
3662 + MAYBE_SWAP (bucket
.vec
));
3663 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3666 /* Return the next matching CU or NULL if there are no more. */
3668 static struct dwarf2_per_cu_data
*
3669 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3671 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3673 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3675 offset_type cu_index_and_attrs
=
3676 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3677 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3678 gdb_index_symbol_kind symbol_kind
=
3679 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3680 /* Only check the symbol attributes if they're present.
3681 Indices prior to version 7 don't record them,
3682 and indices >= 7 may elide them for certain symbols
3683 (gold does this). */
3685 (per_objfile
->per_bfd
->index_table
->version
>= 7
3686 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3688 /* Don't crash on bad data. */
3689 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
3690 + per_objfile
->per_bfd
->all_type_units
.size ()))
3692 complaint (_(".gdb_index entry has bad CU index"
3693 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3697 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
3699 /* Skip if already read in. */
3700 if (per_objfile
->symtab_set_p (per_cu
))
3703 /* Check static vs global. */
3706 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3708 if (iter
->block_index
.has_value ())
3710 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3712 if (is_static
!= want_static
)
3716 /* Work around gold/15646. */
3718 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3720 if (iter
->global_seen
)
3723 iter
->global_seen
= 1;
3727 /* Only check the symbol's kind if it has one. */
3730 switch (iter
->domain
)
3733 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3734 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3735 /* Some types are also in VAR_DOMAIN. */
3736 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3740 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3744 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3748 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3763 static struct compunit_symtab
*
3764 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3765 const char *name
, domain_enum domain
)
3767 struct compunit_symtab
*stab_best
= NULL
;
3768 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3770 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3772 struct dw2_symtab_iterator iter
;
3773 struct dwarf2_per_cu_data
*per_cu
;
3775 dw2_symtab_iter_init (&iter
, per_objfile
, block_index
, domain
, name
);
3777 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3779 struct symbol
*sym
, *with_opaque
= NULL
;
3780 struct compunit_symtab
*stab
3781 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3782 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3783 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3785 sym
= block_find_symbol (block
, name
, domain
,
3786 block_find_non_opaque_type_preferred
,
3789 /* Some caution must be observed with overloaded functions
3790 and methods, since the index will not contain any overload
3791 information (but NAME might contain it). */
3794 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3796 if (with_opaque
!= NULL
3797 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3800 /* Keep looking through other CUs. */
3807 dw2_print_stats (struct objfile
*objfile
)
3809 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3810 int total
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3811 + per_objfile
->per_bfd
->all_type_units
.size ());
3814 for (int i
= 0; i
< total
; ++i
)
3816 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3818 if (!per_objfile
->symtab_set_p (per_cu
))
3821 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3822 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3825 /* This dumps minimal information about the index.
3826 It is called via "mt print objfiles".
3827 One use is to verify .gdb_index has been loaded by the
3828 gdb.dwarf2/gdb-index.exp testcase. */
3831 dw2_dump (struct objfile
*objfile
)
3833 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3835 gdb_assert (per_objfile
->per_bfd
->using_index
);
3836 printf_filtered (".gdb_index:");
3837 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3839 printf_filtered (" version %d\n",
3840 per_objfile
->per_bfd
->index_table
->version
);
3843 printf_filtered (" faked for \"readnow\"\n");
3844 printf_filtered ("\n");
3848 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3849 const char *func_name
)
3851 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3853 struct dw2_symtab_iterator iter
;
3854 struct dwarf2_per_cu_data
*per_cu
;
3856 dw2_symtab_iter_init (&iter
, per_objfile
, {}, VAR_DOMAIN
, func_name
);
3858 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3859 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3864 dw2_expand_all_symtabs (struct objfile
*objfile
)
3866 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3867 int total_units
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3868 + per_objfile
->per_bfd
->all_type_units
.size ());
3870 for (int i
= 0; i
< total_units
; ++i
)
3872 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3874 /* We don't want to directly expand a partial CU, because if we
3875 read it with the wrong language, then assertion failures can
3876 be triggered later on. See PR symtab/23010. So, tell
3877 dw2_instantiate_symtab to skip partial CUs -- any important
3878 partial CU will be read via DW_TAG_imported_unit anyway. */
3879 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3884 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3885 const char *fullname
)
3887 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3889 /* We don't need to consider type units here.
3890 This is only called for examining code, e.g. expand_line_sal.
3891 There can be an order of magnitude (or more) more type units
3892 than comp units, and we avoid them if we can. */
3894 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3896 /* We only need to look at symtabs not already expanded. */
3897 if (per_objfile
->symtab_set_p (per_cu
))
3900 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3901 if (file_data
== NULL
)
3904 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3906 const char *this_fullname
= file_data
->file_names
[j
];
3908 if (filename_cmp (this_fullname
, fullname
) == 0)
3910 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3918 dw2_expand_symtabs_matching_symbol
3919 (mapped_index_base
&index
,
3920 const lookup_name_info
&lookup_name_in
,
3921 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3922 enum search_domain kind
,
3923 gdb::function_view
<bool (offset_type
)> match_callback
,
3924 dwarf2_per_objfile
*per_objfile
);
3927 dw2_expand_symtabs_matching_one
3928 (dwarf2_per_cu_data
*per_cu
,
3929 dwarf2_per_objfile
*per_objfile
,
3930 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3931 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3934 dw2_map_matching_symbols
3935 (struct objfile
*objfile
,
3936 const lookup_name_info
&name
, domain_enum domain
,
3938 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3939 symbol_compare_ftype
*ordered_compare
)
3942 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3944 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3946 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3948 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3950 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3951 auto matcher
= [&] (const char *symname
)
3953 if (ordered_compare
== nullptr)
3955 return ordered_compare (symname
, match_name
) == 0;
3958 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3959 [&] (offset_type namei
)
3961 struct dw2_symtab_iterator iter
;
3962 struct dwarf2_per_cu_data
*per_cu
;
3964 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3966 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3967 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3974 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3975 proceed assuming all symtabs have been read in. */
3978 for (compunit_symtab
*cust
: objfile
->compunits ())
3980 const struct block
*block
;
3984 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3985 if (!iterate_over_symbols_terminated (block
, name
,
3991 /* Starting from a search name, return the string that finds the upper
3992 bound of all strings that start with SEARCH_NAME in a sorted name
3993 list. Returns the empty string to indicate that the upper bound is
3994 the end of the list. */
3997 make_sort_after_prefix_name (const char *search_name
)
3999 /* When looking to complete "func", we find the upper bound of all
4000 symbols that start with "func" by looking for where we'd insert
4001 the closest string that would follow "func" in lexicographical
4002 order. Usually, that's "func"-with-last-character-incremented,
4003 i.e. "fund". Mind non-ASCII characters, though. Usually those
4004 will be UTF-8 multi-byte sequences, but we can't be certain.
4005 Especially mind the 0xff character, which is a valid character in
4006 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4007 rule out compilers allowing it in identifiers. Note that
4008 conveniently, strcmp/strcasecmp are specified to compare
4009 characters interpreted as unsigned char. So what we do is treat
4010 the whole string as a base 256 number composed of a sequence of
4011 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4012 to 0, and carries 1 to the following more-significant position.
4013 If the very first character in SEARCH_NAME ends up incremented
4014 and carries/overflows, then the upper bound is the end of the
4015 list. The string after the empty string is also the empty
4018 Some examples of this operation:
4020 SEARCH_NAME => "+1" RESULT
4024 "\xff" "a" "\xff" => "\xff" "b"
4029 Then, with these symbols for example:
4035 completing "func" looks for symbols between "func" and
4036 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4037 which finds "func" and "func1", but not "fund".
4041 funcÿ (Latin1 'ÿ' [0xff])
4045 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4046 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4050 ÿÿ (Latin1 'ÿ' [0xff])
4053 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4054 the end of the list.
4056 std::string after
= search_name
;
4057 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4059 if (!after
.empty ())
4060 after
.back () = (unsigned char) after
.back () + 1;
4064 /* See declaration. */
4066 std::pair
<std::vector
<name_component
>::const_iterator
,
4067 std::vector
<name_component
>::const_iterator
>
4068 mapped_index_base::find_name_components_bounds
4069 (const lookup_name_info
&lookup_name_without_params
, language lang
,
4070 dwarf2_per_objfile
*per_objfile
) const
4073 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4075 const char *lang_name
4076 = lookup_name_without_params
.language_lookup_name (lang
);
4078 /* Comparison function object for lower_bound that matches against a
4079 given symbol name. */
4080 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4083 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
4084 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4085 return name_cmp (elem_name
, name
) < 0;
4088 /* Comparison function object for upper_bound that matches against a
4089 given symbol name. */
4090 auto lookup_compare_upper
= [&] (const char *name
,
4091 const name_component
&elem
)
4093 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
4094 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4095 return name_cmp (name
, elem_name
) < 0;
4098 auto begin
= this->name_components
.begin ();
4099 auto end
= this->name_components
.end ();
4101 /* Find the lower bound. */
4104 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4107 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4110 /* Find the upper bound. */
4113 if (lookup_name_without_params
.completion_mode ())
4115 /* In completion mode, we want UPPER to point past all
4116 symbols names that have the same prefix. I.e., with
4117 these symbols, and completing "func":
4119 function << lower bound
4121 other_function << upper bound
4123 We find the upper bound by looking for the insertion
4124 point of "func"-with-last-character-incremented,
4126 std::string after
= make_sort_after_prefix_name (lang_name
);
4129 return std::lower_bound (lower
, end
, after
.c_str (),
4130 lookup_compare_lower
);
4133 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4136 return {lower
, upper
};
4139 /* See declaration. */
4142 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
4144 if (!this->name_components
.empty ())
4147 this->name_components_casing
= case_sensitivity
;
4149 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4151 /* The code below only knows how to break apart components of C++
4152 symbol names (and other languages that use '::' as
4153 namespace/module separator) and Ada symbol names. */
4154 auto count
= this->symbol_name_count ();
4155 for (offset_type idx
= 0; idx
< count
; idx
++)
4157 if (this->symbol_name_slot_invalid (idx
))
4160 const char *name
= this->symbol_name_at (idx
, per_objfile
);
4162 /* Add each name component to the name component table. */
4163 unsigned int previous_len
= 0;
4165 if (strstr (name
, "::") != nullptr)
4167 for (unsigned int current_len
= cp_find_first_component (name
);
4168 name
[current_len
] != '\0';
4169 current_len
+= cp_find_first_component (name
+ current_len
))
4171 gdb_assert (name
[current_len
] == ':');
4172 this->name_components
.push_back ({previous_len
, idx
});
4173 /* Skip the '::'. */
4175 previous_len
= current_len
;
4180 /* Handle the Ada encoded (aka mangled) form here. */
4181 for (const char *iter
= strstr (name
, "__");
4183 iter
= strstr (iter
, "__"))
4185 this->name_components
.push_back ({previous_len
, idx
});
4187 previous_len
= iter
- name
;
4191 this->name_components
.push_back ({previous_len
, idx
});
4194 /* Sort name_components elements by name. */
4195 auto name_comp_compare
= [&] (const name_component
&left
,
4196 const name_component
&right
)
4198 const char *left_qualified
4199 = this->symbol_name_at (left
.idx
, per_objfile
);
4200 const char *right_qualified
4201 = this->symbol_name_at (right
.idx
, per_objfile
);
4203 const char *left_name
= left_qualified
+ left
.name_offset
;
4204 const char *right_name
= right_qualified
+ right
.name_offset
;
4206 return name_cmp (left_name
, right_name
) < 0;
4209 std::sort (this->name_components
.begin (),
4210 this->name_components
.end (),
4214 /* Helper for dw2_expand_symtabs_matching that works with a
4215 mapped_index_base instead of the containing objfile. This is split
4216 to a separate function in order to be able to unit test the
4217 name_components matching using a mock mapped_index_base. For each
4218 symbol name that matches, calls MATCH_CALLBACK, passing it the
4219 symbol's index in the mapped_index_base symbol table. */
4222 dw2_expand_symtabs_matching_symbol
4223 (mapped_index_base
&index
,
4224 const lookup_name_info
&lookup_name_in
,
4225 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4226 enum search_domain kind
,
4227 gdb::function_view
<bool (offset_type
)> match_callback
,
4228 dwarf2_per_objfile
*per_objfile
)
4230 lookup_name_info lookup_name_without_params
4231 = lookup_name_in
.make_ignore_params ();
4233 /* Build the symbol name component sorted vector, if we haven't
4235 index
.build_name_components (per_objfile
);
4237 /* The same symbol may appear more than once in the range though.
4238 E.g., if we're looking for symbols that complete "w", and we have
4239 a symbol named "w1::w2", we'll find the two name components for
4240 that same symbol in the range. To be sure we only call the
4241 callback once per symbol, we first collect the symbol name
4242 indexes that matched in a temporary vector and ignore
4244 std::vector
<offset_type
> matches
;
4246 struct name_and_matcher
4248 symbol_name_matcher_ftype
*matcher
;
4251 bool operator== (const name_and_matcher
&other
) const
4253 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4257 /* A vector holding all the different symbol name matchers, for all
4259 std::vector
<name_and_matcher
> matchers
;
4261 for (int i
= 0; i
< nr_languages
; i
++)
4263 enum language lang_e
= (enum language
) i
;
4265 const language_defn
*lang
= language_def (lang_e
);
4266 symbol_name_matcher_ftype
*name_matcher
4267 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
4269 name_and_matcher key
{
4271 lookup_name_without_params
.language_lookup_name (lang_e
)
4274 /* Don't insert the same comparison routine more than once.
4275 Note that we do this linear walk. This is not a problem in
4276 practice because the number of supported languages is
4278 if (std::find (matchers
.begin (), matchers
.end (), key
)
4281 matchers
.push_back (std::move (key
));
4284 = index
.find_name_components_bounds (lookup_name_without_params
,
4285 lang_e
, per_objfile
);
4287 /* Now for each symbol name in range, check to see if we have a name
4288 match, and if so, call the MATCH_CALLBACK callback. */
4290 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4292 const char *qualified
4293 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4295 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4296 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4299 matches
.push_back (bounds
.first
->idx
);
4303 std::sort (matches
.begin (), matches
.end ());
4305 /* Finally call the callback, once per match. */
4307 for (offset_type idx
: matches
)
4311 if (!match_callback (idx
))
4317 /* Above we use a type wider than idx's for 'prev', since 0 and
4318 (offset_type)-1 are both possible values. */
4319 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4324 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4326 /* A mock .gdb_index/.debug_names-like name index table, enough to
4327 exercise dw2_expand_symtabs_matching_symbol, which works with the
4328 mapped_index_base interface. Builds an index from the symbol list
4329 passed as parameter to the constructor. */
4330 class mock_mapped_index
: public mapped_index_base
4333 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4334 : m_symbol_table (symbols
)
4337 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4339 /* Return the number of names in the symbol table. */
4340 size_t symbol_name_count () const override
4342 return m_symbol_table
.size ();
4345 /* Get the name of the symbol at IDX in the symbol table. */
4346 const char *symbol_name_at
4347 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4349 return m_symbol_table
[idx
];
4353 gdb::array_view
<const char *> m_symbol_table
;
4356 /* Convenience function that converts a NULL pointer to a "<null>"
4357 string, to pass to print routines. */
4360 string_or_null (const char *str
)
4362 return str
!= NULL
? str
: "<null>";
4365 /* Check if a lookup_name_info built from
4366 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4367 index. EXPECTED_LIST is the list of expected matches, in expected
4368 matching order. If no match expected, then an empty list is
4369 specified. Returns true on success. On failure prints a warning
4370 indicating the file:line that failed, and returns false. */
4373 check_match (const char *file
, int line
,
4374 mock_mapped_index
&mock_index
,
4375 const char *name
, symbol_name_match_type match_type
,
4376 bool completion_mode
,
4377 std::initializer_list
<const char *> expected_list
,
4378 dwarf2_per_objfile
*per_objfile
)
4380 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4382 bool matched
= true;
4384 auto mismatch
= [&] (const char *expected_str
,
4387 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4388 "expected=\"%s\", got=\"%s\"\n"),
4390 (match_type
== symbol_name_match_type::FULL
4392 name
, string_or_null (expected_str
), string_or_null (got
));
4396 auto expected_it
= expected_list
.begin ();
4397 auto expected_end
= expected_list
.end ();
4399 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4401 [&] (offset_type idx
)
4403 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4404 const char *expected_str
4405 = expected_it
== expected_end
? NULL
: *expected_it
++;
4407 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4408 mismatch (expected_str
, matched_name
);
4412 const char *expected_str
4413 = expected_it
== expected_end
? NULL
: *expected_it
++;
4414 if (expected_str
!= NULL
)
4415 mismatch (expected_str
, NULL
);
4420 /* The symbols added to the mock mapped_index for testing (in
4422 static const char *test_symbols
[] = {
4431 "ns2::tmpl<int>::foo2",
4432 "(anonymous namespace)::A::B::C",
4434 /* These are used to check that the increment-last-char in the
4435 matching algorithm for completion doesn't match "t1_fund" when
4436 completing "t1_func". */
4442 /* A UTF-8 name with multi-byte sequences to make sure that
4443 cp-name-parser understands this as a single identifier ("função"
4444 is "function" in PT). */
4447 /* \377 (0xff) is Latin1 'ÿ'. */
4450 /* \377 (0xff) is Latin1 'ÿ'. */
4454 /* A name with all sorts of complications. Starts with "z" to make
4455 it easier for the completion tests below. */
4456 #define Z_SYM_NAME \
4457 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4458 "::tuple<(anonymous namespace)::ui*, " \
4459 "std::default_delete<(anonymous namespace)::ui>, void>"
4464 /* Returns true if the mapped_index_base::find_name_component_bounds
4465 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4466 in completion mode. */
4469 check_find_bounds_finds (mapped_index_base
&index
,
4470 const char *search_name
,
4471 gdb::array_view
<const char *> expected_syms
,
4472 dwarf2_per_objfile
*per_objfile
)
4474 lookup_name_info
lookup_name (search_name
,
4475 symbol_name_match_type::FULL
, true);
4477 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4481 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4482 if (distance
!= expected_syms
.size ())
4485 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4487 auto nc_elem
= bounds
.first
+ exp_elem
;
4488 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4489 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4496 /* Test the lower-level mapped_index::find_name_component_bounds
4500 test_mapped_index_find_name_component_bounds ()
4502 mock_mapped_index
mock_index (test_symbols
);
4504 mock_index
.build_name_components (NULL
/* per_objfile */);
4506 /* Test the lower-level mapped_index::find_name_component_bounds
4507 method in completion mode. */
4509 static const char *expected_syms
[] = {
4514 SELF_CHECK (check_find_bounds_finds
4515 (mock_index
, "t1_func", expected_syms
,
4516 NULL
/* per_objfile */));
4519 /* Check that the increment-last-char in the name matching algorithm
4520 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4522 static const char *expected_syms1
[] = {
4526 SELF_CHECK (check_find_bounds_finds
4527 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4529 static const char *expected_syms2
[] = {
4532 SELF_CHECK (check_find_bounds_finds
4533 (mock_index
, "\377\377", expected_syms2
,
4534 NULL
/* per_objfile */));
4538 /* Test dw2_expand_symtabs_matching_symbol. */
4541 test_dw2_expand_symtabs_matching_symbol ()
4543 mock_mapped_index
mock_index (test_symbols
);
4545 /* We let all tests run until the end even if some fails, for debug
4547 bool any_mismatch
= false;
4549 /* Create the expected symbols list (an initializer_list). Needed
4550 because lists have commas, and we need to pass them to CHECK,
4551 which is a macro. */
4552 #define EXPECT(...) { __VA_ARGS__ }
4554 /* Wrapper for check_match that passes down the current
4555 __FILE__/__LINE__. */
4556 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4557 any_mismatch |= !check_match (__FILE__, __LINE__, \
4559 NAME, MATCH_TYPE, COMPLETION_MODE, \
4560 EXPECTED_LIST, NULL)
4562 /* Identity checks. */
4563 for (const char *sym
: test_symbols
)
4565 /* Should be able to match all existing symbols. */
4566 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4569 /* Should be able to match all existing symbols with
4571 std::string with_params
= std::string (sym
) + "(int)";
4572 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4575 /* Should be able to match all existing symbols with
4576 parameters and qualifiers. */
4577 with_params
= std::string (sym
) + " ( int ) const";
4578 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4581 /* This should really find sym, but cp-name-parser.y doesn't
4582 know about lvalue/rvalue qualifiers yet. */
4583 with_params
= std::string (sym
) + " ( int ) &&";
4584 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4588 /* Check that the name matching algorithm for completion doesn't get
4589 confused with Latin1 'ÿ' / 0xff. */
4591 static const char str
[] = "\377";
4592 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4593 EXPECT ("\377", "\377\377123"));
4596 /* Check that the increment-last-char in the matching algorithm for
4597 completion doesn't match "t1_fund" when completing "t1_func". */
4599 static const char str
[] = "t1_func";
4600 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4601 EXPECT ("t1_func", "t1_func1"));
4604 /* Check that completion mode works at each prefix of the expected
4607 static const char str
[] = "function(int)";
4608 size_t len
= strlen (str
);
4611 for (size_t i
= 1; i
< len
; i
++)
4613 lookup
.assign (str
, i
);
4614 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4615 EXPECT ("function"));
4619 /* While "w" is a prefix of both components, the match function
4620 should still only be called once. */
4622 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4624 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4628 /* Same, with a "complicated" symbol. */
4630 static const char str
[] = Z_SYM_NAME
;
4631 size_t len
= strlen (str
);
4634 for (size_t i
= 1; i
< len
; i
++)
4636 lookup
.assign (str
, i
);
4637 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4638 EXPECT (Z_SYM_NAME
));
4642 /* In FULL mode, an incomplete symbol doesn't match. */
4644 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4648 /* A complete symbol with parameters matches any overload, since the
4649 index has no overload info. */
4651 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4652 EXPECT ("std::zfunction", "std::zfunction2"));
4653 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4654 EXPECT ("std::zfunction", "std::zfunction2"));
4655 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4656 EXPECT ("std::zfunction", "std::zfunction2"));
4659 /* Check that whitespace is ignored appropriately. A symbol with a
4660 template argument list. */
4662 static const char expected
[] = "ns::foo<int>";
4663 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4665 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4669 /* Check that whitespace is ignored appropriately. A symbol with a
4670 template argument list that includes a pointer. */
4672 static const char expected
[] = "ns::foo<char*>";
4673 /* Try both completion and non-completion modes. */
4674 static const bool completion_mode
[2] = {false, true};
4675 for (size_t i
= 0; i
< 2; i
++)
4677 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4678 completion_mode
[i
], EXPECT (expected
));
4679 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4680 completion_mode
[i
], EXPECT (expected
));
4682 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4683 completion_mode
[i
], EXPECT (expected
));
4684 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4685 completion_mode
[i
], EXPECT (expected
));
4690 /* Check method qualifiers are ignored. */
4691 static const char expected
[] = "ns::foo<char*>";
4692 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4693 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4694 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4695 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4696 CHECK_MATCH ("foo < char * > ( int ) const",
4697 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4698 CHECK_MATCH ("foo < char * > ( int ) &&",
4699 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4702 /* Test lookup names that don't match anything. */
4704 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4707 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4711 /* Some wild matching tests, exercising "(anonymous namespace)",
4712 which should not be confused with a parameter list. */
4714 static const char *syms
[] = {
4718 "A :: B :: C ( int )",
4723 for (const char *s
: syms
)
4725 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4726 EXPECT ("(anonymous namespace)::A::B::C"));
4731 static const char expected
[] = "ns2::tmpl<int>::foo2";
4732 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4734 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4738 SELF_CHECK (!any_mismatch
);
4747 test_mapped_index_find_name_component_bounds ();
4748 test_dw2_expand_symtabs_matching_symbol ();
4751 }} // namespace selftests::dw2_expand_symtabs_matching
4753 #endif /* GDB_SELF_TEST */
4755 /* If FILE_MATCHER is NULL or if PER_CU has
4756 dwarf2_per_cu_quick_data::MARK set (see
4757 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4758 EXPANSION_NOTIFY on it. */
4761 dw2_expand_symtabs_matching_one
4762 (dwarf2_per_cu_data
*per_cu
,
4763 dwarf2_per_objfile
*per_objfile
,
4764 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4765 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4767 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4769 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4771 compunit_symtab
*symtab
4772 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4773 gdb_assert (symtab
!= nullptr);
4775 if (expansion_notify
!= NULL
&& symtab_was_null
)
4776 expansion_notify (symtab
);
4780 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4781 matched, to expand corresponding CUs that were marked. IDX is the
4782 index of the symbol name that matched. */
4785 dw2_expand_marked_cus
4786 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4787 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4788 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4791 offset_type
*vec
, vec_len
, vec_idx
;
4792 bool global_seen
= false;
4793 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4795 vec
= (offset_type
*) (index
.constant_pool
4796 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4797 vec_len
= MAYBE_SWAP (vec
[0]);
4798 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4800 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4801 /* This value is only valid for index versions >= 7. */
4802 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4803 gdb_index_symbol_kind symbol_kind
=
4804 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4805 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4806 /* Only check the symbol attributes if they're present.
4807 Indices prior to version 7 don't record them,
4808 and indices >= 7 may elide them for certain symbols
4809 (gold does this). */
4812 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4814 /* Work around gold/15646. */
4817 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4825 /* Only check the symbol's kind if it has one. */
4830 case VARIABLES_DOMAIN
:
4831 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4834 case FUNCTIONS_DOMAIN
:
4835 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4839 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4842 case MODULES_DOMAIN
:
4843 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4851 /* Don't crash on bad data. */
4852 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
4853 + per_objfile
->per_bfd
->all_type_units
.size ()))
4855 complaint (_(".gdb_index entry has bad CU index"
4856 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4860 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
4861 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4866 /* If FILE_MATCHER is non-NULL, set all the
4867 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4868 that match FILE_MATCHER. */
4871 dw_expand_symtabs_matching_file_matcher
4872 (dwarf2_per_objfile
*per_objfile
,
4873 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4875 if (file_matcher
== NULL
)
4878 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4880 NULL
, xcalloc
, xfree
));
4881 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4883 NULL
, xcalloc
, xfree
));
4885 /* The rule is CUs specify all the files, including those used by
4886 any TU, so there's no need to scan TUs here. */
4888 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4892 per_cu
->v
.quick
->mark
= 0;
4894 /* We only need to look at symtabs not already expanded. */
4895 if (per_objfile
->symtab_set_p (per_cu
))
4898 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4899 if (file_data
== NULL
)
4902 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4904 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4906 per_cu
->v
.quick
->mark
= 1;
4910 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4912 const char *this_real_name
;
4914 if (file_matcher (file_data
->file_names
[j
], false))
4916 per_cu
->v
.quick
->mark
= 1;
4920 /* Before we invoke realpath, which can get expensive when many
4921 files are involved, do a quick comparison of the basenames. */
4922 if (!basenames_may_differ
4923 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4927 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4928 if (file_matcher (this_real_name
, false))
4930 per_cu
->v
.quick
->mark
= 1;
4935 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4936 ? visited_found
.get ()
4937 : visited_not_found
.get (),
4944 dw2_expand_symtabs_matching
4945 (struct objfile
*objfile
,
4946 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4947 const lookup_name_info
*lookup_name
,
4948 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4949 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4950 enum search_domain kind
)
4952 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4954 /* index_table is NULL if OBJF_READNOW. */
4955 if (!per_objfile
->per_bfd
->index_table
)
4958 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4960 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4962 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4966 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4967 file_matcher
, expansion_notify
);
4972 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4974 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4976 kind
, [&] (offset_type idx
)
4978 dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
, expansion_notify
,
4984 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4987 static struct compunit_symtab
*
4988 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4993 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4994 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4997 if (cust
->includes
== NULL
)
5000 for (i
= 0; cust
->includes
[i
]; ++i
)
5002 struct compunit_symtab
*s
= cust
->includes
[i
];
5004 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5012 static struct compunit_symtab
*
5013 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5014 struct bound_minimal_symbol msymbol
,
5016 struct obj_section
*section
,
5019 struct dwarf2_per_cu_data
*data
;
5020 struct compunit_symtab
*result
;
5022 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5025 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
5026 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5027 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5031 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5032 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
5033 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5034 paddress (objfile
->arch (), pc
));
5036 result
= recursively_find_pc_sect_compunit_symtab
5037 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
5039 gdb_assert (result
!= NULL
);
5044 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5045 void *data
, int need_fullname
)
5047 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5049 if (!per_objfile
->per_bfd
->filenames_cache
)
5051 per_objfile
->per_bfd
->filenames_cache
.emplace ();
5053 htab_up
visited (htab_create_alloc (10,
5054 htab_hash_pointer
, htab_eq_pointer
,
5055 NULL
, xcalloc
, xfree
));
5057 /* The rule is CUs specify all the files, including those used
5058 by any TU, so there's no need to scan TUs here. We can
5059 ignore file names coming from already-expanded CUs. */
5061 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5063 if (per_objfile
->symtab_set_p (per_cu
))
5065 void **slot
= htab_find_slot (visited
.get (),
5066 per_cu
->v
.quick
->file_names
,
5069 *slot
= per_cu
->v
.quick
->file_names
;
5073 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5075 /* We only need to look at symtabs not already expanded. */
5076 if (per_objfile
->symtab_set_p (per_cu
))
5079 quick_file_names
*file_data
5080 = dw2_get_file_names (per_cu
, per_objfile
);
5081 if (file_data
== NULL
)
5084 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5087 /* Already visited. */
5092 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5094 const char *filename
= file_data
->file_names
[j
];
5095 per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
5100 per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
5102 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5105 this_real_name
= gdb_realpath (filename
);
5106 (*fun
) (filename
, this_real_name
.get (), data
);
5111 dw2_has_symbols (struct objfile
*objfile
)
5116 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5119 dw2_find_last_source_symtab
,
5120 dw2_forget_cached_source_info
,
5121 dw2_map_symtabs_matching_filename
,
5126 dw2_expand_symtabs_for_function
,
5127 dw2_expand_all_symtabs
,
5128 dw2_expand_symtabs_with_fullname
,
5129 dw2_map_matching_symbols
,
5130 dw2_expand_symtabs_matching
,
5131 dw2_find_pc_sect_compunit_symtab
,
5133 dw2_map_symbol_filenames
5136 /* DWARF-5 debug_names reader. */
5138 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5139 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5141 /* A helper function that reads the .debug_names section in SECTION
5142 and fills in MAP. FILENAME is the name of the file containing the
5143 section; it is used for error reporting.
5145 Returns true if all went well, false otherwise. */
5148 read_debug_names_from_section (struct objfile
*objfile
,
5149 const char *filename
,
5150 struct dwarf2_section_info
*section
,
5151 mapped_debug_names
&map
)
5153 if (section
->empty ())
5156 /* Older elfutils strip versions could keep the section in the main
5157 executable while splitting it for the separate debug info file. */
5158 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5161 section
->read (objfile
);
5163 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
5165 const gdb_byte
*addr
= section
->buffer
;
5167 bfd
*const abfd
= section
->get_bfd_owner ();
5169 unsigned int bytes_read
;
5170 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5173 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5174 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5175 if (bytes_read
+ length
!= section
->size
)
5177 /* There may be multiple per-CU indices. */
5178 warning (_("Section .debug_names in %s length %s does not match "
5179 "section length %s, ignoring .debug_names."),
5180 filename
, plongest (bytes_read
+ length
),
5181 pulongest (section
->size
));
5185 /* The version number. */
5186 uint16_t version
= read_2_bytes (abfd
, addr
);
5190 warning (_("Section .debug_names in %s has unsupported version %d, "
5191 "ignoring .debug_names."),
5197 uint16_t padding
= read_2_bytes (abfd
, addr
);
5201 warning (_("Section .debug_names in %s has unsupported padding %d, "
5202 "ignoring .debug_names."),
5207 /* comp_unit_count - The number of CUs in the CU list. */
5208 map
.cu_count
= read_4_bytes (abfd
, addr
);
5211 /* local_type_unit_count - The number of TUs in the local TU
5213 map
.tu_count
= read_4_bytes (abfd
, addr
);
5216 /* foreign_type_unit_count - The number of TUs in the foreign TU
5218 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5220 if (foreign_tu_count
!= 0)
5222 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5223 "ignoring .debug_names."),
5224 filename
, static_cast<unsigned long> (foreign_tu_count
));
5228 /* bucket_count - The number of hash buckets in the hash lookup
5230 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5233 /* name_count - The number of unique names in the index. */
5234 map
.name_count
= read_4_bytes (abfd
, addr
);
5237 /* abbrev_table_size - The size in bytes of the abbreviations
5239 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5242 /* augmentation_string_size - The size in bytes of the augmentation
5243 string. This value is rounded up to a multiple of 4. */
5244 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5246 map
.augmentation_is_gdb
= ((augmentation_string_size
5247 == sizeof (dwarf5_augmentation
))
5248 && memcmp (addr
, dwarf5_augmentation
,
5249 sizeof (dwarf5_augmentation
)) == 0);
5250 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5251 addr
+= augmentation_string_size
;
5254 map
.cu_table_reordered
= addr
;
5255 addr
+= map
.cu_count
* map
.offset_size
;
5257 /* List of Local TUs */
5258 map
.tu_table_reordered
= addr
;
5259 addr
+= map
.tu_count
* map
.offset_size
;
5261 /* Hash Lookup Table */
5262 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5263 addr
+= map
.bucket_count
* 4;
5264 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5265 addr
+= map
.name_count
* 4;
5268 map
.name_table_string_offs_reordered
= addr
;
5269 addr
+= map
.name_count
* map
.offset_size
;
5270 map
.name_table_entry_offs_reordered
= addr
;
5271 addr
+= map
.name_count
* map
.offset_size
;
5273 const gdb_byte
*abbrev_table_start
= addr
;
5276 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5281 const auto insertpair
5282 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5283 if (!insertpair
.second
)
5285 warning (_("Section .debug_names in %s has duplicate index %s, "
5286 "ignoring .debug_names."),
5287 filename
, pulongest (index_num
));
5290 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5291 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5296 mapped_debug_names::index_val::attr attr
;
5297 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5299 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5301 if (attr
.form
== DW_FORM_implicit_const
)
5303 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5307 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5309 indexval
.attr_vec
.push_back (std::move (attr
));
5312 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5314 warning (_("Section .debug_names in %s has abbreviation_table "
5315 "of size %s vs. written as %u, ignoring .debug_names."),
5316 filename
, plongest (addr
- abbrev_table_start
),
5320 map
.entry_pool
= addr
;
5325 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5329 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5330 const mapped_debug_names
&map
,
5331 dwarf2_section_info
§ion
,
5334 if (!map
.augmentation_is_gdb
)
5336 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5338 sect_offset sect_off
5339 = (sect_offset
) (extract_unsigned_integer
5340 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5342 map
.dwarf5_byte_order
));
5343 /* We don't know the length of the CU, because the CU list in a
5344 .debug_names index can be incomplete, so we can't use the start
5345 of the next CU as end of this CU. We create the CUs here with
5346 length 0, and in cutu_reader::cutu_reader we'll fill in the
5348 dwarf2_per_cu_data
*per_cu
5349 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5351 per_bfd
->all_comp_units
.push_back (per_cu
);
5355 sect_offset sect_off_prev
;
5356 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5358 sect_offset sect_off_next
;
5359 if (i
< map
.cu_count
)
5362 = (sect_offset
) (extract_unsigned_integer
5363 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5365 map
.dwarf5_byte_order
));
5368 sect_off_next
= (sect_offset
) section
.size
;
5371 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5372 dwarf2_per_cu_data
*per_cu
5373 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5374 sect_off_prev
, length
);
5375 per_bfd
->all_comp_units
.push_back (per_cu
);
5377 sect_off_prev
= sect_off_next
;
5381 /* Read the CU list from the mapped index, and use it to create all
5382 the CU objects for this dwarf2_per_objfile. */
5385 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5386 const mapped_debug_names
&map
,
5387 const mapped_debug_names
&dwz_map
)
5389 gdb_assert (per_bfd
->all_comp_units
.empty ());
5390 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5392 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5393 false /* is_dwz */);
5395 if (dwz_map
.cu_count
== 0)
5398 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5399 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5403 /* Read .debug_names. If everything went ok, initialize the "quick"
5404 elements of all the CUs and return true. Otherwise, return false. */
5407 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
5409 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5410 mapped_debug_names dwz_map
;
5411 struct objfile
*objfile
= per_objfile
->objfile
;
5412 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5414 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5415 &per_objfile
->per_bfd
->debug_names
, *map
))
5418 /* Don't use the index if it's empty. */
5419 if (map
->name_count
== 0)
5422 /* If there is a .dwz file, read it so we can get its CU list as
5424 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5427 if (!read_debug_names_from_section (objfile
,
5428 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5429 &dwz
->debug_names
, dwz_map
))
5431 warning (_("could not read '.debug_names' section from %s; skipping"),
5432 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5437 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
5439 if (map
->tu_count
!= 0)
5441 /* We can only handle a single .debug_types when we have an
5443 if (per_bfd
->types
.size () != 1)
5446 dwarf2_section_info
*section
= &per_bfd
->types
[0];
5448 create_signatured_type_table_from_debug_names
5449 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
5452 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
5454 per_bfd
->debug_names_table
= std::move (map
);
5455 per_bfd
->using_index
= 1;
5456 per_bfd
->quick_file_names_table
=
5457 create_quick_file_names_table (per_objfile
->per_bfd
->all_comp_units
.size ());
5459 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
5460 objfiles using the same BFD. */
5461 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
5462 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
5467 /* Type used to manage iterating over all CUs looking for a symbol for
5470 class dw2_debug_names_iterator
5473 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5474 gdb::optional
<block_enum
> block_index
,
5476 const char *name
, dwarf2_per_objfile
*per_objfile
)
5477 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5478 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5479 m_per_objfile (per_objfile
)
5482 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5483 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5486 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5487 m_per_objfile (per_objfile
)
5490 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5491 block_enum block_index
, domain_enum domain
,
5492 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5493 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5494 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5495 m_per_objfile (per_objfile
)
5498 /* Return the next matching CU or NULL if there are no more. */
5499 dwarf2_per_cu_data
*next ();
5502 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5504 dwarf2_per_objfile
*per_objfile
);
5505 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5507 dwarf2_per_objfile
*per_objfile
);
5509 /* The internalized form of .debug_names. */
5510 const mapped_debug_names
&m_map
;
5512 /* If set, only look for symbols that match that block. Valid values are
5513 GLOBAL_BLOCK and STATIC_BLOCK. */
5514 const gdb::optional
<block_enum
> m_block_index
;
5516 /* The kind of symbol we're looking for. */
5517 const domain_enum m_domain
= UNDEF_DOMAIN
;
5518 const search_domain m_search
= ALL_DOMAIN
;
5520 /* The list of CUs from the index entry of the symbol, or NULL if
5522 const gdb_byte
*m_addr
;
5524 dwarf2_per_objfile
*m_per_objfile
;
5528 mapped_debug_names::namei_to_name
5529 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5531 const ULONGEST namei_string_offs
5532 = extract_unsigned_integer ((name_table_string_offs_reordered
5533 + namei
* offset_size
),
5536 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5539 /* Find a slot in .debug_names for the object named NAME. If NAME is
5540 found, return pointer to its pool data. If NAME cannot be found,
5544 dw2_debug_names_iterator::find_vec_in_debug_names
5545 (const mapped_debug_names
&map
, const char *name
,
5546 dwarf2_per_objfile
*per_objfile
)
5548 int (*cmp
) (const char *, const char *);
5550 gdb::unique_xmalloc_ptr
<char> without_params
;
5551 if (current_language
->la_language
== language_cplus
5552 || current_language
->la_language
== language_fortran
5553 || current_language
->la_language
== language_d
)
5555 /* NAME is already canonical. Drop any qualifiers as
5556 .debug_names does not contain any. */
5558 if (strchr (name
, '(') != NULL
)
5560 without_params
= cp_remove_params (name
);
5561 if (without_params
!= NULL
)
5562 name
= without_params
.get ();
5566 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5568 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5570 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5571 (map
.bucket_table_reordered
5572 + (full_hash
% map
.bucket_count
)), 4,
5573 map
.dwarf5_byte_order
);
5577 if (namei
>= map
.name_count
)
5579 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5581 namei
, map
.name_count
,
5582 objfile_name (per_objfile
->objfile
));
5588 const uint32_t namei_full_hash
5589 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5590 (map
.hash_table_reordered
+ namei
), 4,
5591 map
.dwarf5_byte_order
);
5592 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5595 if (full_hash
== namei_full_hash
)
5597 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5599 #if 0 /* An expensive sanity check. */
5600 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5602 complaint (_("Wrong .debug_names hash for string at index %u "
5604 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5609 if (cmp (namei_string
, name
) == 0)
5611 const ULONGEST namei_entry_offs
5612 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5613 + namei
* map
.offset_size
),
5614 map
.offset_size
, map
.dwarf5_byte_order
);
5615 return map
.entry_pool
+ namei_entry_offs
;
5620 if (namei
>= map
.name_count
)
5626 dw2_debug_names_iterator::find_vec_in_debug_names
5627 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5629 if (namei
>= map
.name_count
)
5631 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5633 namei
, map
.name_count
,
5634 objfile_name (per_objfile
->objfile
));
5638 const ULONGEST namei_entry_offs
5639 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5640 + namei
* map
.offset_size
),
5641 map
.offset_size
, map
.dwarf5_byte_order
);
5642 return map
.entry_pool
+ namei_entry_offs
;
5645 /* See dw2_debug_names_iterator. */
5647 dwarf2_per_cu_data
*
5648 dw2_debug_names_iterator::next ()
5653 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5654 struct objfile
*objfile
= m_per_objfile
->objfile
;
5655 bfd
*const abfd
= objfile
->obfd
;
5659 unsigned int bytes_read
;
5660 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5661 m_addr
+= bytes_read
;
5665 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5666 if (indexval_it
== m_map
.abbrev_map
.cend ())
5668 complaint (_("Wrong .debug_names undefined abbrev code %s "
5670 pulongest (abbrev
), objfile_name (objfile
));
5673 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5674 enum class symbol_linkage
{
5678 } symbol_linkage_
= symbol_linkage::unknown
;
5679 dwarf2_per_cu_data
*per_cu
= NULL
;
5680 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5685 case DW_FORM_implicit_const
:
5686 ull
= attr
.implicit_const
;
5688 case DW_FORM_flag_present
:
5692 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5693 m_addr
+= bytes_read
;
5696 ull
= read_4_bytes (abfd
, m_addr
);
5700 ull
= read_8_bytes (abfd
, m_addr
);
5703 case DW_FORM_ref_sig8
:
5704 ull
= read_8_bytes (abfd
, m_addr
);
5708 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5709 dwarf_form_name (attr
.form
),
5710 objfile_name (objfile
));
5713 switch (attr
.dw_idx
)
5715 case DW_IDX_compile_unit
:
5716 /* Don't crash on bad data. */
5717 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5719 complaint (_(".debug_names entry has bad CU index %s"
5722 objfile_name (objfile
));
5725 per_cu
= per_bfd
->get_cutu (ull
);
5727 case DW_IDX_type_unit
:
5728 /* Don't crash on bad data. */
5729 if (ull
>= per_bfd
->all_type_units
.size ())
5731 complaint (_(".debug_names entry has bad TU index %s"
5734 objfile_name (objfile
));
5737 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5739 case DW_IDX_die_offset
:
5740 /* In a per-CU index (as opposed to a per-module index), index
5741 entries without CU attribute implicitly refer to the single CU. */
5743 per_cu
= per_bfd
->get_cu (0);
5745 case DW_IDX_GNU_internal
:
5746 if (!m_map
.augmentation_is_gdb
)
5748 symbol_linkage_
= symbol_linkage::static_
;
5750 case DW_IDX_GNU_external
:
5751 if (!m_map
.augmentation_is_gdb
)
5753 symbol_linkage_
= symbol_linkage::extern_
;
5758 /* Skip if already read in. */
5759 if (m_per_objfile
->symtab_set_p (per_cu
))
5762 /* Check static vs global. */
5763 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5765 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5766 const bool symbol_is_static
=
5767 symbol_linkage_
== symbol_linkage::static_
;
5768 if (want_static
!= symbol_is_static
)
5772 /* Match dw2_symtab_iter_next, symbol_kind
5773 and debug_names::psymbol_tag. */
5777 switch (indexval
.dwarf_tag
)
5779 case DW_TAG_variable
:
5780 case DW_TAG_subprogram
:
5781 /* Some types are also in VAR_DOMAIN. */
5782 case DW_TAG_typedef
:
5783 case DW_TAG_structure_type
:
5790 switch (indexval
.dwarf_tag
)
5792 case DW_TAG_typedef
:
5793 case DW_TAG_structure_type
:
5800 switch (indexval
.dwarf_tag
)
5803 case DW_TAG_variable
:
5810 switch (indexval
.dwarf_tag
)
5822 /* Match dw2_expand_symtabs_matching, symbol_kind and
5823 debug_names::psymbol_tag. */
5826 case VARIABLES_DOMAIN
:
5827 switch (indexval
.dwarf_tag
)
5829 case DW_TAG_variable
:
5835 case FUNCTIONS_DOMAIN
:
5836 switch (indexval
.dwarf_tag
)
5838 case DW_TAG_subprogram
:
5845 switch (indexval
.dwarf_tag
)
5847 case DW_TAG_typedef
:
5848 case DW_TAG_structure_type
:
5854 case MODULES_DOMAIN
:
5855 switch (indexval
.dwarf_tag
)
5869 static struct compunit_symtab
*
5870 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5871 const char *name
, domain_enum domain
)
5873 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5875 const auto &mapp
= per_objfile
->per_bfd
->debug_names_table
;
5878 /* index is NULL if OBJF_READNOW. */
5881 const auto &map
= *mapp
;
5883 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
, per_objfile
);
5885 struct compunit_symtab
*stab_best
= NULL
;
5886 struct dwarf2_per_cu_data
*per_cu
;
5887 while ((per_cu
= iter
.next ()) != NULL
)
5889 struct symbol
*sym
, *with_opaque
= NULL
;
5890 compunit_symtab
*stab
5891 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5892 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5893 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5895 sym
= block_find_symbol (block
, name
, domain
,
5896 block_find_non_opaque_type_preferred
,
5899 /* Some caution must be observed with overloaded functions and
5900 methods, since the index will not contain any overload
5901 information (but NAME might contain it). */
5904 && strcmp_iw (sym
->search_name (), name
) == 0)
5906 if (with_opaque
!= NULL
5907 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5910 /* Keep looking through other CUs. */
5916 /* This dumps minimal information about .debug_names. It is called
5917 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5918 uses this to verify that .debug_names has been loaded. */
5921 dw2_debug_names_dump (struct objfile
*objfile
)
5923 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5925 gdb_assert (per_objfile
->per_bfd
->using_index
);
5926 printf_filtered (".debug_names:");
5927 if (per_objfile
->per_bfd
->debug_names_table
)
5928 printf_filtered (" exists\n");
5930 printf_filtered (" faked for \"readnow\"\n");
5931 printf_filtered ("\n");
5935 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5936 const char *func_name
)
5938 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5940 /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5941 if (per_objfile
->per_bfd
->debug_names_table
)
5943 const mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5945 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5948 struct dwarf2_per_cu_data
*per_cu
;
5949 while ((per_cu
= iter
.next ()) != NULL
)
5950 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5955 dw2_debug_names_map_matching_symbols
5956 (struct objfile
*objfile
,
5957 const lookup_name_info
&name
, domain_enum domain
,
5959 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5960 symbol_compare_ftype
*ordered_compare
)
5962 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5964 /* debug_names_table is NULL if OBJF_READNOW. */
5965 if (!per_objfile
->per_bfd
->debug_names_table
)
5968 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5969 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5971 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5972 auto matcher
= [&] (const char *symname
)
5974 if (ordered_compare
== nullptr)
5976 return ordered_compare (symname
, match_name
) == 0;
5979 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5980 [&] (offset_type namei
)
5982 /* The name was matched, now expand corresponding CUs that were
5984 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5987 struct dwarf2_per_cu_data
*per_cu
;
5988 while ((per_cu
= iter
.next ()) != NULL
)
5989 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5994 /* It's a shame we couldn't do this inside the
5995 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5996 that have already been expanded. Instead, this loop matches what
5997 the psymtab code does. */
5998 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
6000 compunit_symtab
*symtab
= per_objfile
->get_symtab (per_cu
);
6001 if (symtab
!= nullptr)
6003 const struct block
*block
6004 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
6005 if (!iterate_over_symbols_terminated (block
, name
,
6013 dw2_debug_names_expand_symtabs_matching
6014 (struct objfile
*objfile
,
6015 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6016 const lookup_name_info
*lookup_name
,
6017 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6018 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6019 enum search_domain kind
)
6021 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6023 /* debug_names_table is NULL if OBJF_READNOW. */
6024 if (!per_objfile
->per_bfd
->debug_names_table
)
6027 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
6029 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
6031 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
6035 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
6041 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
6043 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
6045 kind
, [&] (offset_type namei
)
6047 /* The name was matched, now expand corresponding CUs that were
6049 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
);
6051 struct dwarf2_per_cu_data
*per_cu
;
6052 while ((per_cu
= iter
.next ()) != NULL
)
6053 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
6059 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6062 dw2_find_last_source_symtab
,
6063 dw2_forget_cached_source_info
,
6064 dw2_map_symtabs_matching_filename
,
6065 dw2_debug_names_lookup_symbol
,
6068 dw2_debug_names_dump
,
6069 dw2_debug_names_expand_symtabs_for_function
,
6070 dw2_expand_all_symtabs
,
6071 dw2_expand_symtabs_with_fullname
,
6072 dw2_debug_names_map_matching_symbols
,
6073 dw2_debug_names_expand_symtabs_matching
,
6074 dw2_find_pc_sect_compunit_symtab
,
6076 dw2_map_symbol_filenames
6079 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6080 to either a dwarf2_per_bfd or dwz_file object. */
6082 template <typename T
>
6083 static gdb::array_view
<const gdb_byte
>
6084 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6086 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6088 if (section
->empty ())
6091 /* Older elfutils strip versions could keep the section in the main
6092 executable while splitting it for the separate debug info file. */
6093 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
6096 section
->read (obj
);
6098 /* dwarf2_section_info::size is a bfd_size_type, while
6099 gdb::array_view works with size_t. On 32-bit hosts, with
6100 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6101 is 32-bit. So we need an explicit narrowing conversion here.
6102 This is fine, because it's impossible to allocate or mmap an
6103 array/buffer larger than what size_t can represent. */
6104 return gdb::make_array_view (section
->buffer
, section
->size
);
6107 /* Lookup the index cache for the contents of the index associated to
6110 static gdb::array_view
<const gdb_byte
>
6111 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
6113 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6114 if (build_id
== nullptr)
6117 return global_index_cache
.lookup_gdb_index (build_id
,
6118 &dwarf2_per_bfd
->index_cache_res
);
6121 /* Same as the above, but for DWZ. */
6123 static gdb::array_view
<const gdb_byte
>
6124 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6126 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6127 if (build_id
== nullptr)
6130 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6133 /* See symfile.h. */
6136 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6138 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6139 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6141 /* If we're about to read full symbols, don't bother with the
6142 indices. In this case we also don't care if some other debug
6143 format is making psymtabs, because they are all about to be
6145 if ((objfile
->flags
& OBJF_READNOW
))
6147 /* When using READNOW, the using_index flag (set below) indicates that
6148 PER_BFD was already initialized, when we loaded some other objfile. */
6149 if (per_bfd
->using_index
)
6151 *index_kind
= dw_index_kind::GDB_INDEX
;
6152 per_objfile
->resize_symtabs ();
6156 per_bfd
->using_index
= 1;
6157 create_all_comp_units (per_objfile
);
6158 create_all_type_units (per_objfile
);
6159 per_bfd
->quick_file_names_table
6160 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
6161 per_objfile
->resize_symtabs ();
6163 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
6164 + per_bfd
->all_type_units
.size ()); ++i
)
6166 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
6168 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6169 struct dwarf2_per_cu_quick_data
);
6172 /* Return 1 so that gdb sees the "quick" functions. However,
6173 these functions will be no-ops because we will have expanded
6175 *index_kind
= dw_index_kind::GDB_INDEX
;
6179 /* Was a debug names index already read when we processed an objfile sharing
6181 if (per_bfd
->debug_names_table
!= nullptr)
6183 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6184 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6185 per_objfile
->resize_symtabs ();
6189 /* Was a GDB index already read when we processed an objfile sharing
6191 if (per_bfd
->index_table
!= nullptr)
6193 *index_kind
= dw_index_kind::GDB_INDEX
;
6194 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6195 per_objfile
->resize_symtabs ();
6199 /* There might already be partial symtabs built for this BFD. This happens
6200 when loading the same binary twice with the index-cache enabled. If so,
6201 don't try to read an index. The objfile / per_objfile initialization will
6202 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
6204 if (per_bfd
->partial_symtabs
!= nullptr)
6207 if (dwarf2_read_debug_names (per_objfile
))
6209 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6210 per_objfile
->resize_symtabs ();
6214 if (dwarf2_read_gdb_index (per_objfile
,
6215 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
6216 get_gdb_index_contents_from_section
<dwz_file
>))
6218 *index_kind
= dw_index_kind::GDB_INDEX
;
6219 per_objfile
->resize_symtabs ();
6223 /* ... otherwise, try to find the index in the index cache. */
6224 if (dwarf2_read_gdb_index (per_objfile
,
6225 get_gdb_index_contents_from_cache
,
6226 get_gdb_index_contents_from_cache_dwz
))
6228 global_index_cache
.hit ();
6229 *index_kind
= dw_index_kind::GDB_INDEX
;
6230 per_objfile
->resize_symtabs ();
6234 global_index_cache
.miss ();
6240 /* Build a partial symbol table. */
6243 dwarf2_build_psymtabs (struct objfile
*objfile
)
6245 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6246 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6248 if (per_bfd
->partial_symtabs
!= nullptr)
6250 /* Partial symbols were already read, so now we can simply
6252 objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6253 per_objfile
->resize_symtabs ();
6259 /* This isn't really ideal: all the data we allocate on the
6260 objfile's obstack is still uselessly kept around. However,
6261 freeing it seems unsafe. */
6262 psymtab_discarder
psymtabs (objfile
);
6263 dwarf2_build_psymtabs_hard (per_objfile
);
6266 per_objfile
->resize_symtabs ();
6268 /* (maybe) store an index in the cache. */
6269 global_index_cache
.store (per_objfile
);
6271 catch (const gdb_exception_error
&except
)
6273 exception_print (gdb_stderr
, except
);
6276 /* Finish by setting the local reference to partial symtabs, so that
6277 we don't try to read them again if reading another objfile with the same
6278 BFD. If we can't in fact share, this won't make a difference anyway as
6279 the dwarf2_per_bfd object won't be shared. */
6280 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
6283 /* Find the base address of the compilation unit for range lists and
6284 location lists. It will normally be specified by DW_AT_low_pc.
6285 In DWARF-3 draft 4, the base address could be overridden by
6286 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6287 compilation units with discontinuous ranges. */
6290 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6292 struct attribute
*attr
;
6294 cu
->base_address
.reset ();
6296 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6297 if (attr
!= nullptr)
6298 cu
->base_address
= attr
->as_address ();
6301 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6302 if (attr
!= nullptr)
6303 cu
->base_address
= attr
->as_address ();
6307 /* Helper function that returns the proper abbrev section for
6310 static struct dwarf2_section_info
*
6311 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6313 struct dwarf2_section_info
*abbrev
;
6314 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6316 if (this_cu
->is_dwz
)
6317 abbrev
= &dwarf2_get_dwz_file (per_bfd
)->abbrev
;
6319 abbrev
= &per_bfd
->abbrev
;
6324 /* Fetch the abbreviation table offset from a comp or type unit header. */
6327 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
6328 struct dwarf2_section_info
*section
,
6329 sect_offset sect_off
)
6331 bfd
*abfd
= section
->get_bfd_owner ();
6332 const gdb_byte
*info_ptr
;
6333 unsigned int initial_length_size
, offset_size
;
6336 section
->read (per_objfile
->objfile
);
6337 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6338 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6339 offset_size
= initial_length_size
== 4 ? 4 : 8;
6340 info_ptr
+= initial_length_size
;
6342 version
= read_2_bytes (abfd
, info_ptr
);
6346 /* Skip unit type and address size. */
6350 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6353 /* A partial symtab that is used only for include files. */
6354 struct dwarf2_include_psymtab
: public partial_symtab
6356 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6357 : partial_symtab (filename
, objfile
)
6361 void read_symtab (struct objfile
*objfile
) override
6363 /* It's an include file, no symbols to read for it.
6364 Everything is in the includer symtab. */
6366 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6367 expansion of the includer psymtab. We use the dependencies[0] field to
6368 model the includer. But if we go the regular route of calling
6369 expand_psymtab here, and having expand_psymtab call expand_dependencies
6370 to expand the includer, we'll only use expand_psymtab on the includer
6371 (making it a non-toplevel psymtab), while if we expand the includer via
6372 another path, we'll use read_symtab (making it a toplevel psymtab).
6373 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6374 psymtab, and trigger read_symtab on the includer here directly. */
6375 includer ()->read_symtab (objfile
);
6378 void expand_psymtab (struct objfile
*objfile
) override
6380 /* This is not called by read_symtab, and should not be called by any
6381 expand_dependencies. */
6385 bool readin_p (struct objfile
*objfile
) const override
6387 return includer ()->readin_p (objfile
);
6390 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6396 partial_symtab
*includer () const
6398 /* An include psymtab has exactly one dependency: the psymtab that
6400 gdb_assert (this->number_of_dependencies
== 1);
6401 return this->dependencies
[0];
6405 /* Allocate a new partial symtab for file named NAME and mark this new
6406 partial symtab as being an include of PST. */
6409 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6410 struct objfile
*objfile
)
6412 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6414 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6415 subpst
->dirname
= pst
->dirname
;
6417 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6418 subpst
->dependencies
[0] = pst
;
6419 subpst
->number_of_dependencies
= 1;
6422 /* Read the Line Number Program data and extract the list of files
6423 included by the source file represented by PST. Build an include
6424 partial symtab for each of these included files. */
6427 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6428 struct die_info
*die
,
6429 dwarf2_psymtab
*pst
)
6432 struct attribute
*attr
;
6434 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6435 if (attr
!= nullptr && attr
->form_is_unsigned ())
6436 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
6438 return; /* No linetable, so no includes. */
6440 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6441 that we pass in the raw text_low here; that is ok because we're
6442 only decoding the line table to make include partial symtabs, and
6443 so the addresses aren't really used. */
6444 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6445 pst
->raw_text_low (), 1);
6449 hash_signatured_type (const void *item
)
6451 const struct signatured_type
*sig_type
6452 = (const struct signatured_type
*) item
;
6454 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6455 return sig_type
->signature
;
6459 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6461 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6462 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6464 return lhs
->signature
== rhs
->signature
;
6467 /* Allocate a hash table for signatured types. */
6470 allocate_signatured_type_table ()
6472 return htab_up (htab_create_alloc (41,
6473 hash_signatured_type
,
6475 NULL
, xcalloc
, xfree
));
6478 /* A helper function to add a signatured type CU to a table. */
6481 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6483 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6484 std::vector
<signatured_type
*> *all_type_units
6485 = (std::vector
<signatured_type
*> *) datum
;
6487 all_type_units
->push_back (sigt
);
6492 /* A helper for create_debug_types_hash_table. Read types from SECTION
6493 and fill them into TYPES_HTAB. It will process only type units,
6494 therefore DW_UT_type. */
6497 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6498 struct dwo_file
*dwo_file
,
6499 dwarf2_section_info
*section
, htab_up
&types_htab
,
6500 rcuh_kind section_kind
)
6502 struct objfile
*objfile
= per_objfile
->objfile
;
6503 struct dwarf2_section_info
*abbrev_section
;
6505 const gdb_byte
*info_ptr
, *end_ptr
;
6507 abbrev_section
= (dwo_file
!= NULL
6508 ? &dwo_file
->sections
.abbrev
6509 : &per_objfile
->per_bfd
->abbrev
);
6511 dwarf_read_debug_printf ("Reading %s for %s:",
6512 section
->get_name (),
6513 abbrev_section
->get_file_name ());
6515 section
->read (objfile
);
6516 info_ptr
= section
->buffer
;
6518 if (info_ptr
== NULL
)
6521 /* We can't set abfd until now because the section may be empty or
6522 not present, in which case the bfd is unknown. */
6523 abfd
= section
->get_bfd_owner ();
6525 /* We don't use cutu_reader here because we don't need to read
6526 any dies: the signature is in the header. */
6528 end_ptr
= info_ptr
+ section
->size
;
6529 while (info_ptr
< end_ptr
)
6531 struct signatured_type
*sig_type
;
6532 struct dwo_unit
*dwo_tu
;
6534 const gdb_byte
*ptr
= info_ptr
;
6535 struct comp_unit_head header
;
6536 unsigned int length
;
6538 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6540 /* Initialize it due to a false compiler warning. */
6541 header
.signature
= -1;
6542 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6544 /* We need to read the type's signature in order to build the hash
6545 table, but we don't need anything else just yet. */
6547 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6548 abbrev_section
, ptr
, section_kind
);
6550 length
= header
.get_length ();
6552 /* Skip dummy type units. */
6553 if (ptr
>= info_ptr
+ length
6554 || peek_abbrev_code (abfd
, ptr
) == 0
6555 || (header
.unit_type
!= DW_UT_type
6556 && header
.unit_type
!= DW_UT_split_type
))
6562 if (types_htab
== NULL
)
6565 types_htab
= allocate_dwo_unit_table ();
6567 types_htab
= allocate_signatured_type_table ();
6573 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6574 dwo_tu
->dwo_file
= dwo_file
;
6575 dwo_tu
->signature
= header
.signature
;
6576 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6577 dwo_tu
->section
= section
;
6578 dwo_tu
->sect_off
= sect_off
;
6579 dwo_tu
->length
= length
;
6583 /* N.B.: type_offset is not usable if this type uses a DWO file.
6584 The real type_offset is in the DWO file. */
6586 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6587 sig_type
->signature
= header
.signature
;
6588 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6589 sig_type
->per_cu
.is_debug_types
= 1;
6590 sig_type
->per_cu
.section
= section
;
6591 sig_type
->per_cu
.sect_off
= sect_off
;
6592 sig_type
->per_cu
.length
= length
;
6595 slot
= htab_find_slot (types_htab
.get (),
6596 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6598 gdb_assert (slot
!= NULL
);
6601 sect_offset dup_sect_off
;
6605 const struct dwo_unit
*dup_tu
6606 = (const struct dwo_unit
*) *slot
;
6608 dup_sect_off
= dup_tu
->sect_off
;
6612 const struct signatured_type
*dup_tu
6613 = (const struct signatured_type
*) *slot
;
6615 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6618 complaint (_("debug type entry at offset %s is duplicate to"
6619 " the entry at offset %s, signature %s"),
6620 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6621 hex_string (header
.signature
));
6623 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6625 dwarf_read_debug_printf_v (" offset %s, signature %s",
6626 sect_offset_str (sect_off
),
6627 hex_string (header
.signature
));
6633 /* Create the hash table of all entries in the .debug_types
6634 (or .debug_types.dwo) section(s).
6635 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6636 otherwise it is NULL.
6638 The result is a pointer to the hash table or NULL if there are no types.
6640 Note: This function processes DWO files only, not DWP files. */
6643 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6644 struct dwo_file
*dwo_file
,
6645 gdb::array_view
<dwarf2_section_info
> type_sections
,
6646 htab_up
&types_htab
)
6648 for (dwarf2_section_info
§ion
: type_sections
)
6649 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6653 /* Create the hash table of all entries in the .debug_types section,
6654 and initialize all_type_units.
6655 The result is zero if there is an error (e.g. missing .debug_types section),
6656 otherwise non-zero. */
6659 create_all_type_units (dwarf2_per_objfile
*per_objfile
)
6663 create_debug_type_hash_table (per_objfile
, NULL
, &per_objfile
->per_bfd
->info
,
6664 types_htab
, rcuh_kind::COMPILE
);
6665 create_debug_types_hash_table (per_objfile
, NULL
, per_objfile
->per_bfd
->types
,
6667 if (types_htab
== NULL
)
6669 per_objfile
->per_bfd
->signatured_types
= NULL
;
6673 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6675 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
6676 per_objfile
->per_bfd
->all_type_units
.reserve
6677 (htab_elements (per_objfile
->per_bfd
->signatured_types
.get ()));
6679 htab_traverse_noresize (per_objfile
->per_bfd
->signatured_types
.get (),
6680 add_signatured_type_cu_to_table
,
6681 &per_objfile
->per_bfd
->all_type_units
);
6686 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6687 If SLOT is non-NULL, it is the entry to use in the hash table.
6688 Otherwise we find one. */
6690 static struct signatured_type
*
6691 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6693 if (per_objfile
->per_bfd
->all_type_units
.size ()
6694 == per_objfile
->per_bfd
->all_type_units
.capacity ())
6695 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6697 signatured_type
*sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6699 per_objfile
->resize_symtabs ();
6701 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6702 sig_type
->signature
= sig
;
6703 sig_type
->per_cu
.is_debug_types
= 1;
6704 if (per_objfile
->per_bfd
->using_index
)
6706 sig_type
->per_cu
.v
.quick
=
6707 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6708 struct dwarf2_per_cu_quick_data
);
6713 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6716 gdb_assert (*slot
== NULL
);
6718 /* The rest of sig_type must be filled in by the caller. */
6722 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6723 Fill in SIG_ENTRY with DWO_ENTRY. */
6726 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6727 struct signatured_type
*sig_entry
,
6728 struct dwo_unit
*dwo_entry
)
6730 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6732 /* Make sure we're not clobbering something we don't expect to. */
6733 gdb_assert (! sig_entry
->per_cu
.queued
);
6734 gdb_assert (per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6735 if (per_bfd
->using_index
)
6737 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6738 gdb_assert (!per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6741 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6742 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6743 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6744 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6745 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6747 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6748 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6749 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6750 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6751 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6752 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6753 sig_entry
->dwo_unit
= dwo_entry
;
6756 /* Subroutine of lookup_signatured_type.
6757 If we haven't read the TU yet, create the signatured_type data structure
6758 for a TU to be read in directly from a DWO file, bypassing the stub.
6759 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6760 using .gdb_index, then when reading a CU we want to stay in the DWO file
6761 containing that CU. Otherwise we could end up reading several other DWO
6762 files (due to comdat folding) to process the transitive closure of all the
6763 mentioned TUs, and that can be slow. The current DWO file will have every
6764 type signature that it needs.
6765 We only do this for .gdb_index because in the psymtab case we already have
6766 to read all the DWOs to build the type unit groups. */
6768 static struct signatured_type
*
6769 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6771 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6772 struct dwo_file
*dwo_file
;
6773 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6774 struct signatured_type find_sig_entry
, *sig_entry
;
6777 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6779 /* If TU skeletons have been removed then we may not have read in any
6781 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6782 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6784 /* We only ever need to read in one copy of a signatured type.
6785 Use the global signatured_types array to do our own comdat-folding
6786 of types. If this is the first time we're reading this TU, and
6787 the TU has an entry in .gdb_index, replace the recorded data from
6788 .gdb_index with this TU. */
6790 find_sig_entry
.signature
= sig
;
6791 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6792 &find_sig_entry
, INSERT
);
6793 sig_entry
= (struct signatured_type
*) *slot
;
6795 /* We can get here with the TU already read, *or* in the process of being
6796 read. Don't reassign the global entry to point to this DWO if that's
6797 the case. Also note that if the TU is already being read, it may not
6798 have come from a DWO, the program may be a mix of Fission-compiled
6799 code and non-Fission-compiled code. */
6801 /* Have we already tried to read this TU?
6802 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6803 needn't exist in the global table yet). */
6804 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6807 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6808 dwo_unit of the TU itself. */
6809 dwo_file
= cu
->dwo_unit
->dwo_file
;
6811 /* Ok, this is the first time we're reading this TU. */
6812 if (dwo_file
->tus
== NULL
)
6814 find_dwo_entry
.signature
= sig
;
6815 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6817 if (dwo_entry
== NULL
)
6820 /* If the global table doesn't have an entry for this TU, add one. */
6821 if (sig_entry
== NULL
)
6822 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6824 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6825 sig_entry
->per_cu
.tu_read
= 1;
6829 /* Subroutine of lookup_signatured_type.
6830 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6831 then try the DWP file. If the TU stub (skeleton) has been removed then
6832 it won't be in .gdb_index. */
6834 static struct signatured_type
*
6835 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6837 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6838 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6839 struct dwo_unit
*dwo_entry
;
6840 struct signatured_type find_sig_entry
, *sig_entry
;
6843 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6844 gdb_assert (dwp_file
!= NULL
);
6846 /* If TU skeletons have been removed then we may not have read in any
6848 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6849 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6851 find_sig_entry
.signature
= sig
;
6852 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6853 &find_sig_entry
, INSERT
);
6854 sig_entry
= (struct signatured_type
*) *slot
;
6856 /* Have we already tried to read this TU?
6857 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6858 needn't exist in the global table yet). */
6859 if (sig_entry
!= NULL
)
6862 if (dwp_file
->tus
== NULL
)
6864 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6865 1 /* is_debug_types */);
6866 if (dwo_entry
== NULL
)
6869 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6870 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6875 /* Lookup a signature based type for DW_FORM_ref_sig8.
6876 Returns NULL if signature SIG is not present in the table.
6877 It is up to the caller to complain about this. */
6879 static struct signatured_type
*
6880 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6882 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6884 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6886 /* We're in a DWO/DWP file, and we're using .gdb_index.
6887 These cases require special processing. */
6888 if (get_dwp_file (per_objfile
) == NULL
)
6889 return lookup_dwo_signatured_type (cu
, sig
);
6891 return lookup_dwp_signatured_type (cu
, sig
);
6895 struct signatured_type find_entry
, *entry
;
6897 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6899 find_entry
.signature
= sig
;
6900 entry
= ((struct signatured_type
*)
6901 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6907 /* Low level DIE reading support. */
6909 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6912 init_cu_die_reader (struct die_reader_specs
*reader
,
6913 struct dwarf2_cu
*cu
,
6914 struct dwarf2_section_info
*section
,
6915 struct dwo_file
*dwo_file
,
6916 struct abbrev_table
*abbrev_table
)
6918 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6919 reader
->abfd
= section
->get_bfd_owner ();
6921 reader
->dwo_file
= dwo_file
;
6922 reader
->die_section
= section
;
6923 reader
->buffer
= section
->buffer
;
6924 reader
->buffer_end
= section
->buffer
+ section
->size
;
6925 reader
->abbrev_table
= abbrev_table
;
6928 /* Subroutine of cutu_reader to simplify it.
6929 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6930 There's just a lot of work to do, and cutu_reader is big enough
6933 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6934 from it to the DIE in the DWO. If NULL we are skipping the stub.
6935 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6936 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6937 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6938 STUB_COMP_DIR may be non-NULL.
6939 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6940 are filled in with the info of the DIE from the DWO file.
6941 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6942 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6943 kept around for at least as long as *RESULT_READER.
6945 The result is non-zero if a valid (non-dummy) DIE was found. */
6948 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6949 struct dwo_unit
*dwo_unit
,
6950 struct die_info
*stub_comp_unit_die
,
6951 const char *stub_comp_dir
,
6952 struct die_reader_specs
*result_reader
,
6953 const gdb_byte
**result_info_ptr
,
6954 struct die_info
**result_comp_unit_die
,
6955 abbrev_table_up
*result_dwo_abbrev_table
)
6957 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6958 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6959 struct objfile
*objfile
= per_objfile
->objfile
;
6961 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6962 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6963 int i
,num_extra_attrs
;
6964 struct dwarf2_section_info
*dwo_abbrev_section
;
6965 struct die_info
*comp_unit_die
;
6967 /* At most one of these may be provided. */
6968 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6970 /* These attributes aren't processed until later:
6971 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6972 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6973 referenced later. However, these attributes are found in the stub
6974 which we won't have later. In order to not impose this complication
6975 on the rest of the code, we read them here and copy them to the
6984 if (stub_comp_unit_die
!= NULL
)
6986 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6988 if (!per_cu
->is_debug_types
)
6989 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6990 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6991 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6992 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6993 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6995 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6997 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6998 We need the value before we can process DW_AT_ranges values from the
7000 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
7002 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
7003 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
7004 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
7005 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
7007 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
7009 else if (stub_comp_dir
!= NULL
)
7011 /* Reconstruct the comp_dir attribute to simplify the code below. */
7012 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
7013 comp_dir
->name
= DW_AT_comp_dir
;
7014 comp_dir
->form
= DW_FORM_string
;
7015 comp_dir
->set_string_noncanonical (stub_comp_dir
);
7018 /* Set up for reading the DWO CU/TU. */
7019 cu
->dwo_unit
= dwo_unit
;
7020 dwarf2_section_info
*section
= dwo_unit
->section
;
7021 section
->read (objfile
);
7022 abfd
= section
->get_bfd_owner ();
7023 begin_info_ptr
= info_ptr
= (section
->buffer
7024 + to_underlying (dwo_unit
->sect_off
));
7025 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7027 if (per_cu
->is_debug_types
)
7029 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
7031 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7032 section
, dwo_abbrev_section
,
7033 info_ptr
, rcuh_kind::TYPE
);
7034 /* This is not an assert because it can be caused by bad debug info. */
7035 if (sig_type
->signature
!= cu
->header
.signature
)
7037 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7038 " TU at offset %s [in module %s]"),
7039 hex_string (sig_type
->signature
),
7040 hex_string (cu
->header
.signature
),
7041 sect_offset_str (dwo_unit
->sect_off
),
7042 bfd_get_filename (abfd
));
7044 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7045 /* For DWOs coming from DWP files, we don't know the CU length
7046 nor the type's offset in the TU until now. */
7047 dwo_unit
->length
= cu
->header
.get_length ();
7048 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7050 /* Establish the type offset that can be used to lookup the type.
7051 For DWO files, we don't know it until now. */
7052 sig_type
->type_offset_in_section
7053 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7057 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7058 section
, dwo_abbrev_section
,
7059 info_ptr
, rcuh_kind::COMPILE
);
7060 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7061 /* For DWOs coming from DWP files, we don't know the CU length
7063 dwo_unit
->length
= cu
->header
.get_length ();
7066 dwo_abbrev_section
->read (objfile
);
7067 *result_dwo_abbrev_table
7068 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
7069 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7070 result_dwo_abbrev_table
->get ());
7072 /* Read in the die, but leave space to copy over the attributes
7073 from the stub. This has the benefit of simplifying the rest of
7074 the code - all the work to maintain the illusion of a single
7075 DW_TAG_{compile,type}_unit DIE is done here. */
7076 num_extra_attrs
= ((stmt_list
!= NULL
)
7080 + (comp_dir
!= NULL
));
7081 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7084 /* Copy over the attributes from the stub to the DIE we just read in. */
7085 comp_unit_die
= *result_comp_unit_die
;
7086 i
= comp_unit_die
->num_attrs
;
7087 if (stmt_list
!= NULL
)
7088 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7090 comp_unit_die
->attrs
[i
++] = *low_pc
;
7091 if (high_pc
!= NULL
)
7092 comp_unit_die
->attrs
[i
++] = *high_pc
;
7094 comp_unit_die
->attrs
[i
++] = *ranges
;
7095 if (comp_dir
!= NULL
)
7096 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7097 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7099 if (dwarf_die_debug
)
7101 fprintf_unfiltered (gdb_stdlog
,
7102 "Read die from %s@0x%x of %s:\n",
7103 section
->get_name (),
7104 (unsigned) (begin_info_ptr
- section
->buffer
),
7105 bfd_get_filename (abfd
));
7106 dump_die (comp_unit_die
, dwarf_die_debug
);
7109 /* Skip dummy compilation units. */
7110 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7111 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7114 *result_info_ptr
= info_ptr
;
7118 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7119 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7120 signature is part of the header. */
7121 static gdb::optional
<ULONGEST
>
7122 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7124 if (cu
->header
.version
>= 5)
7125 return cu
->header
.signature
;
7126 struct attribute
*attr
;
7127 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7128 if (attr
== nullptr || !attr
->form_is_unsigned ())
7129 return gdb::optional
<ULONGEST
> ();
7130 return attr
->as_unsigned ();
7133 /* Subroutine of cutu_reader to simplify it.
7134 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7135 Returns NULL if the specified DWO unit cannot be found. */
7137 static struct dwo_unit
*
7138 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
7140 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7141 struct dwo_unit
*dwo_unit
;
7142 const char *comp_dir
;
7144 gdb_assert (cu
!= NULL
);
7146 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7147 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7148 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7150 if (per_cu
->is_debug_types
)
7151 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
7154 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7156 if (!signature
.has_value ())
7157 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7159 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
7161 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
7167 /* Subroutine of cutu_reader to simplify it.
7168 See it for a description of the parameters.
7169 Read a TU directly from a DWO file, bypassing the stub. */
7172 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
7173 dwarf2_per_objfile
*per_objfile
,
7174 dwarf2_cu
*existing_cu
)
7176 struct signatured_type
*sig_type
;
7178 /* Verify we can do the following downcast, and that we have the
7180 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7181 sig_type
= (struct signatured_type
*) this_cu
;
7182 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7186 if (existing_cu
!= nullptr)
7189 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
7190 /* There's no need to do the rereading_dwo_cu handling that
7191 cutu_reader does since we don't read the stub. */
7195 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7196 in per_objfile yet. */
7197 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7198 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7199 cu
= m_new_cu
.get ();
7202 /* A future optimization, if needed, would be to use an existing
7203 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7204 could share abbrev tables. */
7206 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
7207 NULL
/* stub_comp_unit_die */,
7208 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7211 &m_dwo_abbrev_table
) == 0)
7218 /* Initialize a CU (or TU) and read its DIEs.
7219 If the CU defers to a DWO file, read the DWO file as well.
7221 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7222 Otherwise the table specified in the comp unit header is read in and used.
7223 This is an optimization for when we already have the abbrev table.
7225 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7228 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7229 dwarf2_per_objfile
*per_objfile
,
7230 struct abbrev_table
*abbrev_table
,
7231 dwarf2_cu
*existing_cu
,
7233 : die_reader_specs
{},
7236 struct objfile
*objfile
= per_objfile
->objfile
;
7237 struct dwarf2_section_info
*section
= this_cu
->section
;
7238 bfd
*abfd
= section
->get_bfd_owner ();
7239 const gdb_byte
*begin_info_ptr
;
7240 struct signatured_type
*sig_type
= NULL
;
7241 struct dwarf2_section_info
*abbrev_section
;
7242 /* Non-zero if CU currently points to a DWO file and we need to
7243 reread it. When this happens we need to reread the skeleton die
7244 before we can reread the DWO file (this only applies to CUs, not TUs). */
7245 int rereading_dwo_cu
= 0;
7247 if (dwarf_die_debug
)
7248 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7249 this_cu
->is_debug_types
? "type" : "comp",
7250 sect_offset_str (this_cu
->sect_off
));
7252 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7253 file (instead of going through the stub), short-circuit all of this. */
7254 if (this_cu
->reading_dwo_directly
)
7256 /* Narrow down the scope of possibilities to have to understand. */
7257 gdb_assert (this_cu
->is_debug_types
);
7258 gdb_assert (abbrev_table
== NULL
);
7259 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
7263 /* This is cheap if the section is already read in. */
7264 section
->read (objfile
);
7266 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7268 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7272 if (existing_cu
!= nullptr)
7275 /* If this CU is from a DWO file we need to start over, we need to
7276 refetch the attributes from the skeleton CU.
7277 This could be optimized by retrieving those attributes from when we
7278 were here the first time: the previous comp_unit_die was stored in
7279 comp_unit_obstack. But there's no data yet that we need this
7281 if (cu
->dwo_unit
!= NULL
)
7282 rereading_dwo_cu
= 1;
7286 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7287 in per_objfile yet. */
7288 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7289 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7290 cu
= m_new_cu
.get ();
7293 /* Get the header. */
7294 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7296 /* We already have the header, there's no need to read it in again. */
7297 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7301 if (this_cu
->is_debug_types
)
7303 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7304 section
, abbrev_section
,
7305 info_ptr
, rcuh_kind::TYPE
);
7307 /* Since per_cu is the first member of struct signatured_type,
7308 we can go from a pointer to one to a pointer to the other. */
7309 sig_type
= (struct signatured_type
*) this_cu
;
7310 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7311 gdb_assert (sig_type
->type_offset_in_tu
7312 == cu
->header
.type_cu_offset_in_tu
);
7313 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7315 /* LENGTH has not been set yet for type units if we're
7316 using .gdb_index. */
7317 this_cu
->length
= cu
->header
.get_length ();
7319 /* Establish the type offset that can be used to lookup the type. */
7320 sig_type
->type_offset_in_section
=
7321 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7323 this_cu
->dwarf_version
= cu
->header
.version
;
7327 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7328 section
, abbrev_section
,
7330 rcuh_kind::COMPILE
);
7332 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7333 if (this_cu
->length
== 0)
7334 this_cu
->length
= cu
->header
.get_length ();
7336 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7337 this_cu
->dwarf_version
= cu
->header
.version
;
7341 /* Skip dummy compilation units. */
7342 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7343 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7349 /* If we don't have them yet, read the abbrevs for this compilation unit.
7350 And if we need to read them now, make sure they're freed when we're
7352 if (abbrev_table
!= NULL
)
7353 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7356 abbrev_section
->read (objfile
);
7357 m_abbrev_table_holder
7358 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
7359 abbrev_table
= m_abbrev_table_holder
.get ();
7362 /* Read the top level CU/TU die. */
7363 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7364 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7366 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7372 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7373 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7374 table from the DWO file and pass the ownership over to us. It will be
7375 referenced from READER, so we must make sure to free it after we're done
7378 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7379 DWO CU, that this test will fail (the attribute will not be present). */
7380 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7381 if (dwo_name
!= nullptr)
7383 struct dwo_unit
*dwo_unit
;
7384 struct die_info
*dwo_comp_unit_die
;
7386 if (comp_unit_die
->has_children
)
7388 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7389 " has children (offset %s) [in module %s]"),
7390 sect_offset_str (this_cu
->sect_off
),
7391 bfd_get_filename (abfd
));
7393 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7394 if (dwo_unit
!= NULL
)
7396 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7397 comp_unit_die
, NULL
,
7400 &m_dwo_abbrev_table
) == 0)
7406 comp_unit_die
= dwo_comp_unit_die
;
7410 /* Yikes, we couldn't find the rest of the DIE, we only have
7411 the stub. A complaint has already been logged. There's
7412 not much more we can do except pass on the stub DIE to
7413 die_reader_func. We don't want to throw an error on bad
7420 cutu_reader::keep ()
7422 /* Done, clean up. */
7423 gdb_assert (!dummy_p
);
7424 if (m_new_cu
!= NULL
)
7426 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7428 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7429 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7433 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7434 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7435 assumed to have already done the lookup to find the DWO file).
7437 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7438 THIS_CU->is_debug_types, but nothing else.
7440 We fill in THIS_CU->length.
7442 THIS_CU->cu is always freed when done.
7443 This is done in order to not leave THIS_CU->cu in a state where we have
7444 to care whether it refers to the "main" CU or the DWO CU.
7446 When parent_cu is passed, it is used to provide a default value for
7447 str_offsets_base and addr_base from the parent. */
7449 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7450 dwarf2_per_objfile
*per_objfile
,
7451 struct dwarf2_cu
*parent_cu
,
7452 struct dwo_file
*dwo_file
)
7453 : die_reader_specs
{},
7456 struct objfile
*objfile
= per_objfile
->objfile
;
7457 struct dwarf2_section_info
*section
= this_cu
->section
;
7458 bfd
*abfd
= section
->get_bfd_owner ();
7459 struct dwarf2_section_info
*abbrev_section
;
7460 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7462 if (dwarf_die_debug
)
7463 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7464 this_cu
->is_debug_types
? "type" : "comp",
7465 sect_offset_str (this_cu
->sect_off
));
7467 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7469 abbrev_section
= (dwo_file
!= NULL
7470 ? &dwo_file
->sections
.abbrev
7471 : get_abbrev_section_for_cu (this_cu
));
7473 /* This is cheap if the section is already read in. */
7474 section
->read (objfile
);
7476 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7478 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7479 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
7480 section
, abbrev_section
, info_ptr
,
7481 (this_cu
->is_debug_types
7483 : rcuh_kind::COMPILE
));
7485 if (parent_cu
!= nullptr)
7487 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7488 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7490 this_cu
->length
= m_new_cu
->header
.get_length ();
7492 /* Skip dummy compilation units. */
7493 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7494 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7500 abbrev_section
->read (objfile
);
7501 m_abbrev_table_holder
7502 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
7504 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7505 m_abbrev_table_holder
.get ());
7506 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7510 /* Type Unit Groups.
7512 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7513 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7514 so that all types coming from the same compilation (.o file) are grouped
7515 together. A future step could be to put the types in the same symtab as
7516 the CU the types ultimately came from. */
7519 hash_type_unit_group (const void *item
)
7521 const struct type_unit_group
*tu_group
7522 = (const struct type_unit_group
*) item
;
7524 return hash_stmt_list_entry (&tu_group
->hash
);
7528 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7530 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7531 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7533 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7536 /* Allocate a hash table for type unit groups. */
7539 allocate_type_unit_groups_table ()
7541 return htab_up (htab_create_alloc (3,
7542 hash_type_unit_group
,
7544 NULL
, xcalloc
, xfree
));
7547 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7548 partial symtabs. We combine several TUs per psymtab to not let the size
7549 of any one psymtab grow too big. */
7550 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7551 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7553 /* Helper routine for get_type_unit_group.
7554 Create the type_unit_group object used to hold one or more TUs. */
7556 static struct type_unit_group
*
7557 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7559 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7560 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7561 struct dwarf2_per_cu_data
*per_cu
;
7562 struct type_unit_group
*tu_group
;
7564 tu_group
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, type_unit_group
);
7565 per_cu
= &tu_group
->per_cu
;
7566 per_cu
->per_bfd
= per_bfd
;
7568 if (per_bfd
->using_index
)
7570 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7571 struct dwarf2_per_cu_quick_data
);
7575 unsigned int line_offset
= to_underlying (line_offset_struct
);
7576 dwarf2_psymtab
*pst
;
7579 /* Give the symtab a useful name for debug purposes. */
7580 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7581 name
= string_printf ("<type_units_%d>",
7582 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7584 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7586 pst
= create_partial_symtab (per_cu
, per_objfile
, name
.c_str ());
7587 pst
->anonymous
= true;
7590 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7591 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7596 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7597 STMT_LIST is a DW_AT_stmt_list attribute. */
7599 static struct type_unit_group
*
7600 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7602 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7603 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7604 struct type_unit_group
*tu_group
;
7606 unsigned int line_offset
;
7607 struct type_unit_group type_unit_group_for_lookup
;
7609 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7610 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7612 /* Do we need to create a new group, or can we use an existing one? */
7614 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
7616 line_offset
= stmt_list
->as_unsigned ();
7617 ++tu_stats
->nr_symtab_sharers
;
7621 /* Ugh, no stmt_list. Rare, but we have to handle it.
7622 We can do various things here like create one group per TU or
7623 spread them over multiple groups to split up the expansion work.
7624 To avoid worst case scenarios (too many groups or too large groups)
7625 we, umm, group them in bunches. */
7626 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7627 | (tu_stats
->nr_stmt_less_type_units
7628 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7629 ++tu_stats
->nr_stmt_less_type_units
;
7632 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7633 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7634 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7635 &type_unit_group_for_lookup
, INSERT
);
7638 tu_group
= (struct type_unit_group
*) *slot
;
7639 gdb_assert (tu_group
!= NULL
);
7643 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7644 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7646 ++tu_stats
->nr_symtabs
;
7652 /* Partial symbol tables. */
7654 /* Create a psymtab named NAME and assign it to PER_CU.
7656 The caller must fill in the following details:
7657 dirname, textlow, texthigh. */
7659 static dwarf2_psymtab
*
7660 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7661 dwarf2_per_objfile
*per_objfile
,
7664 struct objfile
*objfile
= per_objfile
->objfile
;
7665 dwarf2_psymtab
*pst
;
7667 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7669 pst
->psymtabs_addrmap_supported
= true;
7671 /* This is the glue that links PST into GDB's symbol API. */
7672 per_cu
->v
.psymtab
= pst
;
7677 /* DIE reader function for process_psymtab_comp_unit. */
7680 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7681 const gdb_byte
*info_ptr
,
7682 struct die_info
*comp_unit_die
,
7683 enum language pretend_language
)
7685 struct dwarf2_cu
*cu
= reader
->cu
;
7686 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7687 struct objfile
*objfile
= per_objfile
->objfile
;
7688 struct gdbarch
*gdbarch
= objfile
->arch ();
7689 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7691 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7692 dwarf2_psymtab
*pst
;
7693 enum pc_bounds_kind cu_bounds_kind
;
7694 const char *filename
;
7696 gdb_assert (! per_cu
->is_debug_types
);
7698 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7700 /* Allocate a new partial symbol table structure. */
7701 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7702 static const char artificial
[] = "<artificial>";
7703 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7704 if (filename
== NULL
)
7706 else if (strcmp (filename
, artificial
) == 0)
7708 debug_filename
.reset (concat (artificial
, "@",
7709 sect_offset_str (per_cu
->sect_off
),
7711 filename
= debug_filename
.get ();
7714 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7716 /* This must be done before calling dwarf2_build_include_psymtabs. */
7717 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7719 baseaddr
= objfile
->text_section_offset ();
7721 dwarf2_find_base_address (comp_unit_die
, cu
);
7723 /* Possibly set the default values of LOWPC and HIGHPC from
7725 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7726 &best_highpc
, cu
, pst
);
7727 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7730 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7733 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7735 /* Store the contiguous range if it is not empty; it can be
7736 empty for CUs with no code. */
7737 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7741 /* Check if comp unit has_children.
7742 If so, read the rest of the partial symbols from this comp unit.
7743 If not, there's no more debug_info for this comp unit. */
7744 if (comp_unit_die
->has_children
)
7746 struct partial_die_info
*first_die
;
7747 CORE_ADDR lowpc
, highpc
;
7749 lowpc
= ((CORE_ADDR
) -1);
7750 highpc
= ((CORE_ADDR
) 0);
7752 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7754 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7755 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7757 /* If we didn't find a lowpc, set it to highpc to avoid
7758 complaints from `maint check'. */
7759 if (lowpc
== ((CORE_ADDR
) -1))
7762 /* If the compilation unit didn't have an explicit address range,
7763 then use the information extracted from its child dies. */
7764 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7767 best_highpc
= highpc
;
7770 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7771 best_lowpc
+ baseaddr
)
7773 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7774 best_highpc
+ baseaddr
)
7779 if (!cu
->per_cu
->imported_symtabs_empty ())
7782 int len
= cu
->per_cu
->imported_symtabs_size ();
7784 /* Fill in 'dependencies' here; we fill in 'users' in a
7786 pst
->number_of_dependencies
= len
;
7788 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7789 for (i
= 0; i
< len
; ++i
)
7791 pst
->dependencies
[i
]
7792 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7795 cu
->per_cu
->imported_symtabs_free ();
7798 /* Get the list of files included in the current compilation unit,
7799 and build a psymtab for each of them. */
7800 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7802 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7803 ", %d global, %d static syms",
7804 per_cu
->is_debug_types
? "type" : "comp",
7805 sect_offset_str (per_cu
->sect_off
),
7806 paddress (gdbarch
, pst
->text_low (objfile
)),
7807 paddress (gdbarch
, pst
->text_high (objfile
)),
7808 (int) pst
->global_psymbols
.size (),
7809 (int) pst
->static_psymbols
.size ());
7812 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7813 Process compilation unit THIS_CU for a psymtab. */
7816 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7817 dwarf2_per_objfile
*per_objfile
,
7818 bool want_partial_unit
,
7819 enum language pretend_language
)
7821 /* If this compilation unit was already read in, free the
7822 cached copy in order to read it in again. This is
7823 necessary because we skipped some symbols when we first
7824 read in the compilation unit (see load_partial_dies).
7825 This problem could be avoided, but the benefit is unclear. */
7826 per_objfile
->remove_cu (this_cu
);
7828 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7830 switch (reader
.comp_unit_die
->tag
)
7832 case DW_TAG_compile_unit
:
7833 this_cu
->unit_type
= DW_UT_compile
;
7835 case DW_TAG_partial_unit
:
7836 this_cu
->unit_type
= DW_UT_partial
;
7846 else if (this_cu
->is_debug_types
)
7847 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7848 reader
.comp_unit_die
);
7849 else if (want_partial_unit
7850 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7851 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7852 reader
.comp_unit_die
,
7855 this_cu
->lang
= reader
.cu
->language
;
7857 /* Age out any secondary CUs. */
7858 per_objfile
->age_comp_units ();
7861 /* Reader function for build_type_psymtabs. */
7864 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7865 const gdb_byte
*info_ptr
,
7866 struct die_info
*type_unit_die
)
7868 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7869 struct dwarf2_cu
*cu
= reader
->cu
;
7870 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7871 struct signatured_type
*sig_type
;
7872 struct type_unit_group
*tu_group
;
7873 struct attribute
*attr
;
7874 struct partial_die_info
*first_die
;
7875 CORE_ADDR lowpc
, highpc
;
7876 dwarf2_psymtab
*pst
;
7878 gdb_assert (per_cu
->is_debug_types
);
7879 sig_type
= (struct signatured_type
*) per_cu
;
7881 if (! type_unit_die
->has_children
)
7884 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7885 tu_group
= get_type_unit_group (cu
, attr
);
7887 if (tu_group
->tus
== nullptr)
7888 tu_group
->tus
= new std::vector
<signatured_type
*>;
7889 tu_group
->tus
->push_back (sig_type
);
7891 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7892 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7893 pst
->anonymous
= true;
7895 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7897 lowpc
= (CORE_ADDR
) -1;
7898 highpc
= (CORE_ADDR
) 0;
7899 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7904 /* Struct used to sort TUs by their abbreviation table offset. */
7906 struct tu_abbrev_offset
7908 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7909 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7912 signatured_type
*sig_type
;
7913 sect_offset abbrev_offset
;
7916 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7919 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7920 const struct tu_abbrev_offset
&b
)
7922 return a
.abbrev_offset
< b
.abbrev_offset
;
7925 /* Efficiently read all the type units.
7926 This does the bulk of the work for build_type_psymtabs.
7928 The efficiency is because we sort TUs by the abbrev table they use and
7929 only read each abbrev table once. In one program there are 200K TUs
7930 sharing 8K abbrev tables.
7932 The main purpose of this function is to support building the
7933 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7934 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7935 can collapse the search space by grouping them by stmt_list.
7936 The savings can be significant, in the same program from above the 200K TUs
7937 share 8K stmt_list tables.
7939 FUNC is expected to call get_type_unit_group, which will create the
7940 struct type_unit_group if necessary and add it to
7941 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7944 build_type_psymtabs_1 (dwarf2_per_objfile
*per_objfile
)
7946 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7947 abbrev_table_up abbrev_table
;
7948 sect_offset abbrev_offset
;
7950 /* It's up to the caller to not call us multiple times. */
7951 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7953 if (per_objfile
->per_bfd
->all_type_units
.empty ())
7956 /* TUs typically share abbrev tables, and there can be way more TUs than
7957 abbrev tables. Sort by abbrev table to reduce the number of times we
7958 read each abbrev table in.
7959 Alternatives are to punt or to maintain a cache of abbrev tables.
7960 This is simpler and efficient enough for now.
7962 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7963 symtab to use). Typically TUs with the same abbrev offset have the same
7964 stmt_list value too so in practice this should work well.
7966 The basic algorithm here is:
7968 sort TUs by abbrev table
7969 for each TU with same abbrev table:
7970 read abbrev table if first user
7971 read TU top level DIE
7972 [IWBN if DWO skeletons had DW_AT_stmt_list]
7975 dwarf_read_debug_printf ("Building type unit groups ...");
7977 /* Sort in a separate table to maintain the order of all_type_units
7978 for .gdb_index: TU indices directly index all_type_units. */
7979 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7980 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
7982 for (signatured_type
*sig_type
: per_objfile
->per_bfd
->all_type_units
)
7983 sorted_by_abbrev
.emplace_back
7984 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->per_cu
.section
,
7985 sig_type
->per_cu
.sect_off
));
7987 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7988 sort_tu_by_abbrev_offset
);
7990 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7992 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7994 /* Switch to the next abbrev table if necessary. */
7995 if (abbrev_table
== NULL
7996 || tu
.abbrev_offset
!= abbrev_offset
)
7998 abbrev_offset
= tu
.abbrev_offset
;
7999 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
8001 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
8002 ++tu_stats
->nr_uniq_abbrev_tables
;
8005 cutu_reader
reader (&tu
.sig_type
->per_cu
, per_objfile
,
8006 abbrev_table
.get (), nullptr, false);
8007 if (!reader
.dummy_p
)
8008 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8009 reader
.comp_unit_die
);
8013 /* Print collected type unit statistics. */
8016 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
8018 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
8020 dwarf_read_debug_printf ("Type unit statistics:");
8021 dwarf_read_debug_printf (" %zu TUs",
8022 per_objfile
->per_bfd
->all_type_units
.size ());
8023 dwarf_read_debug_printf (" %d uniq abbrev tables",
8024 tu_stats
->nr_uniq_abbrev_tables
);
8025 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
8026 tu_stats
->nr_symtabs
);
8027 dwarf_read_debug_printf (" %d symtab sharers",
8028 tu_stats
->nr_symtab_sharers
);
8029 dwarf_read_debug_printf (" %d type units without a stmt_list",
8030 tu_stats
->nr_stmt_less_type_units
);
8031 dwarf_read_debug_printf (" %d all_type_units reallocs",
8032 tu_stats
->nr_all_type_units_reallocs
);
8035 /* Traversal function for build_type_psymtabs. */
8038 build_type_psymtab_dependencies (void **slot
, void *info
)
8040 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
8041 struct objfile
*objfile
= per_objfile
->objfile
;
8042 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8043 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8044 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8045 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8048 gdb_assert (len
> 0);
8049 gdb_assert (per_cu
->type_unit_group_p ());
8051 pst
->number_of_dependencies
= len
;
8052 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8053 for (i
= 0; i
< len
; ++i
)
8055 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8056 gdb_assert (iter
->per_cu
.is_debug_types
);
8057 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8058 iter
->type_unit_group
= tu_group
;
8061 delete tu_group
->tus
;
8062 tu_group
->tus
= nullptr;
8067 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8068 Build partial symbol tables for the .debug_types comp-units. */
8071 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
8073 if (! create_all_type_units (per_objfile
))
8076 build_type_psymtabs_1 (per_objfile
);
8079 /* Traversal function for process_skeletonless_type_unit.
8080 Read a TU in a DWO file and build partial symbols for it. */
8083 process_skeletonless_type_unit (void **slot
, void *info
)
8085 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8086 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
8087 struct signatured_type find_entry
, *entry
;
8089 /* If this TU doesn't exist in the global table, add it and read it in. */
8091 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
8092 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
8094 find_entry
.signature
= dwo_unit
->signature
;
8095 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
8096 &find_entry
, INSERT
);
8097 /* If we've already seen this type there's nothing to do. What's happening
8098 is we're doing our own version of comdat-folding here. */
8102 /* This does the job that create_all_type_units would have done for
8104 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
8105 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
8108 /* This does the job that build_type_psymtabs_1 would have done. */
8109 cutu_reader
reader (&entry
->per_cu
, per_objfile
, nullptr, nullptr, false);
8110 if (!reader
.dummy_p
)
8111 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8112 reader
.comp_unit_die
);
8117 /* Traversal function for process_skeletonless_type_units. */
8120 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8122 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8124 if (dwo_file
->tus
!= NULL
)
8125 htab_traverse_noresize (dwo_file
->tus
.get (),
8126 process_skeletonless_type_unit
, info
);
8131 /* Scan all TUs of DWO files, verifying we've processed them.
8132 This is needed in case a TU was emitted without its skeleton.
8133 Note: This can't be done until we know what all the DWO files are. */
8136 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
8138 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8139 if (get_dwp_file (per_objfile
) == NULL
8140 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
8142 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
8143 process_dwo_file_for_skeletonless_type_units
,
8148 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8151 set_partial_user (dwarf2_per_objfile
*per_objfile
)
8153 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8155 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8160 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8162 /* Set the 'user' field only if it is not already set. */
8163 if (pst
->dependencies
[j
]->user
== NULL
)
8164 pst
->dependencies
[j
]->user
= pst
;
8169 /* Build the partial symbol table by doing a quick pass through the
8170 .debug_info and .debug_abbrev sections. */
8173 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
8175 struct objfile
*objfile
= per_objfile
->objfile
;
8177 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
8178 objfile_name (objfile
));
8180 scoped_restore restore_reading_psyms
8181 = make_scoped_restore (&per_objfile
->per_bfd
->reading_partial_symbols
,
8184 per_objfile
->per_bfd
->info
.read (objfile
);
8186 /* Any cached compilation units will be linked by the per-objfile
8187 read_in_chain. Make sure to free them when we're done. */
8188 free_cached_comp_units
freer (per_objfile
);
8190 build_type_psymtabs (per_objfile
);
8192 create_all_comp_units (per_objfile
);
8194 /* Create a temporary address map on a temporary obstack. We later
8195 copy this to the final obstack. */
8196 auto_obstack temp_obstack
;
8198 scoped_restore save_psymtabs_addrmap
8199 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8200 addrmap_create_mutable (&temp_obstack
));
8202 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8204 if (per_cu
->v
.psymtab
!= NULL
)
8205 /* In case a forward DW_TAG_imported_unit has read the CU already. */
8207 process_psymtab_comp_unit (per_cu
, per_objfile
, false,
8211 /* This has to wait until we read the CUs, we need the list of DWOs. */
8212 process_skeletonless_type_units (per_objfile
);
8214 /* Now that all TUs have been processed we can fill in the dependencies. */
8215 if (per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
8217 htab_traverse_noresize (per_objfile
->per_bfd
->type_unit_groups
.get (),
8218 build_type_psymtab_dependencies
, per_objfile
);
8221 if (dwarf_read_debug
> 0)
8222 print_tu_stats (per_objfile
);
8224 set_partial_user (per_objfile
);
8226 objfile
->partial_symtabs
->psymtabs_addrmap
8227 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8228 objfile
->partial_symtabs
->obstack ());
8229 /* At this point we want to keep the address map. */
8230 save_psymtabs_addrmap
.release ();
8232 dwarf_read_debug_printf ("Done building psymtabs of %s",
8233 objfile_name (objfile
));
8236 /* Load the partial DIEs for a secondary CU into memory.
8237 This is also used when rereading a primary CU with load_all_dies. */
8240 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8241 dwarf2_per_objfile
*per_objfile
,
8242 dwarf2_cu
*existing_cu
)
8244 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8246 if (!reader
.dummy_p
)
8248 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8251 /* Check if comp unit has_children.
8252 If so, read the rest of the partial symbols from this comp unit.
8253 If not, there's no more debug_info for this comp unit. */
8254 if (reader
.comp_unit_die
->has_children
)
8255 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8262 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
8263 struct dwarf2_section_info
*section
,
8264 struct dwarf2_section_info
*abbrev_section
,
8265 unsigned int is_dwz
)
8267 const gdb_byte
*info_ptr
;
8268 struct objfile
*objfile
= per_objfile
->objfile
;
8270 dwarf_read_debug_printf ("Reading %s for %s",
8271 section
->get_name (),
8272 section
->get_file_name ());
8274 section
->read (objfile
);
8276 info_ptr
= section
->buffer
;
8278 while (info_ptr
< section
->buffer
+ section
->size
)
8280 struct dwarf2_per_cu_data
*this_cu
;
8282 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8284 comp_unit_head cu_header
;
8285 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
8286 abbrev_section
, info_ptr
,
8287 rcuh_kind::COMPILE
);
8289 /* Save the compilation unit for later lookup. */
8290 if (cu_header
.unit_type
!= DW_UT_type
)
8291 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
8294 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
8295 sig_type
->signature
= cu_header
.signature
;
8296 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8297 this_cu
= &sig_type
->per_cu
;
8299 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8300 this_cu
->sect_off
= sect_off
;
8301 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8302 this_cu
->is_dwz
= is_dwz
;
8303 this_cu
->section
= section
;
8305 per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8307 info_ptr
= info_ptr
+ this_cu
->length
;
8311 /* Create a list of all compilation units in OBJFILE.
8312 This is only done for -readnow and building partial symtabs. */
8315 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
8317 gdb_assert (per_objfile
->per_bfd
->all_comp_units
.empty ());
8318 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
8319 &per_objfile
->per_bfd
->abbrev
, 0);
8321 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
8323 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1);
8326 /* Process all loaded DIEs for compilation unit CU, starting at
8327 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8328 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8329 DW_AT_ranges). See the comments of add_partial_subprogram on how
8330 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8333 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8334 CORE_ADDR
*highpc
, int set_addrmap
,
8335 struct dwarf2_cu
*cu
)
8337 struct partial_die_info
*pdi
;
8339 /* Now, march along the PDI's, descending into ones which have
8340 interesting children but skipping the children of the other ones,
8341 until we reach the end of the compilation unit. */
8349 /* Anonymous namespaces or modules have no name but have interesting
8350 children, so we need to look at them. Ditto for anonymous
8353 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8354 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8355 || pdi
->tag
== DW_TAG_imported_unit
8356 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8360 case DW_TAG_subprogram
:
8361 case DW_TAG_inlined_subroutine
:
8362 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8363 if (cu
->language
== language_cplus
)
8364 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8367 case DW_TAG_constant
:
8368 case DW_TAG_variable
:
8369 case DW_TAG_typedef
:
8370 case DW_TAG_union_type
:
8371 if (!pdi
->is_declaration
8372 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8374 add_partial_symbol (pdi
, cu
);
8377 case DW_TAG_class_type
:
8378 case DW_TAG_interface_type
:
8379 case DW_TAG_structure_type
:
8380 if (!pdi
->is_declaration
)
8382 add_partial_symbol (pdi
, cu
);
8384 if ((cu
->language
== language_rust
8385 || cu
->language
== language_cplus
) && pdi
->has_children
)
8386 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8389 case DW_TAG_enumeration_type
:
8390 if (!pdi
->is_declaration
)
8391 add_partial_enumeration (pdi
, cu
);
8393 case DW_TAG_base_type
:
8394 case DW_TAG_subrange_type
:
8395 /* File scope base type definitions are added to the partial
8397 add_partial_symbol (pdi
, cu
);
8399 case DW_TAG_namespace
:
8400 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8403 if (!pdi
->is_declaration
)
8404 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8406 case DW_TAG_imported_unit
:
8408 struct dwarf2_per_cu_data
*per_cu
;
8410 /* For now we don't handle imported units in type units. */
8411 if (cu
->per_cu
->is_debug_types
)
8413 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8414 " supported in type units [in module %s]"),
8415 objfile_name (cu
->per_objfile
->objfile
));
8418 per_cu
= dwarf2_find_containing_comp_unit
8419 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8421 /* Go read the partial unit, if needed. */
8422 if (per_cu
->v
.psymtab
== NULL
)
8423 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8426 cu
->per_cu
->imported_symtabs_push (per_cu
);
8429 case DW_TAG_imported_declaration
:
8430 add_partial_symbol (pdi
, cu
);
8437 /* If the die has a sibling, skip to the sibling. */
8439 pdi
= pdi
->die_sibling
;
8443 /* Functions used to compute the fully scoped name of a partial DIE.
8445 Normally, this is simple. For C++, the parent DIE's fully scoped
8446 name is concatenated with "::" and the partial DIE's name.
8447 Enumerators are an exception; they use the scope of their parent
8448 enumeration type, i.e. the name of the enumeration type is not
8449 prepended to the enumerator.
8451 There are two complexities. One is DW_AT_specification; in this
8452 case "parent" means the parent of the target of the specification,
8453 instead of the direct parent of the DIE. The other is compilers
8454 which do not emit DW_TAG_namespace; in this case we try to guess
8455 the fully qualified name of structure types from their members'
8456 linkage names. This must be done using the DIE's children rather
8457 than the children of any DW_AT_specification target. We only need
8458 to do this for structures at the top level, i.e. if the target of
8459 any DW_AT_specification (if any; otherwise the DIE itself) does not
8462 /* Compute the scope prefix associated with PDI's parent, in
8463 compilation unit CU. The result will be allocated on CU's
8464 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8465 field. NULL is returned if no prefix is necessary. */
8467 partial_die_parent_scope (struct partial_die_info
*pdi
,
8468 struct dwarf2_cu
*cu
)
8470 const char *grandparent_scope
;
8471 struct partial_die_info
*parent
, *real_pdi
;
8473 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8474 then this means the parent of the specification DIE. */
8477 while (real_pdi
->has_specification
)
8479 auto res
= find_partial_die (real_pdi
->spec_offset
,
8480 real_pdi
->spec_is_dwz
, cu
);
8485 parent
= real_pdi
->die_parent
;
8489 if (parent
->scope_set
)
8490 return parent
->scope
;
8494 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8496 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8497 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8498 Work around this problem here. */
8499 if (cu
->language
== language_cplus
8500 && parent
->tag
== DW_TAG_namespace
8501 && strcmp (parent
->name (cu
), "::") == 0
8502 && grandparent_scope
== NULL
)
8504 parent
->scope
= NULL
;
8505 parent
->scope_set
= 1;
8509 /* Nested subroutines in Fortran get a prefix. */
8510 if (pdi
->tag
== DW_TAG_enumerator
)
8511 /* Enumerators should not get the name of the enumeration as a prefix. */
8512 parent
->scope
= grandparent_scope
;
8513 else if (parent
->tag
== DW_TAG_namespace
8514 || parent
->tag
== DW_TAG_module
8515 || parent
->tag
== DW_TAG_structure_type
8516 || parent
->tag
== DW_TAG_class_type
8517 || parent
->tag
== DW_TAG_interface_type
8518 || parent
->tag
== DW_TAG_union_type
8519 || parent
->tag
== DW_TAG_enumeration_type
8520 || (cu
->language
== language_fortran
8521 && parent
->tag
== DW_TAG_subprogram
8522 && pdi
->tag
== DW_TAG_subprogram
))
8524 if (grandparent_scope
== NULL
)
8525 parent
->scope
= parent
->name (cu
);
8527 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8529 parent
->name (cu
), 0, cu
);
8533 /* FIXME drow/2004-04-01: What should we be doing with
8534 function-local names? For partial symbols, we should probably be
8536 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8537 dwarf_tag_name (parent
->tag
),
8538 sect_offset_str (pdi
->sect_off
));
8539 parent
->scope
= grandparent_scope
;
8542 parent
->scope_set
= 1;
8543 return parent
->scope
;
8546 /* Return the fully scoped name associated with PDI, from compilation unit
8547 CU. The result will be allocated with malloc. */
8549 static gdb::unique_xmalloc_ptr
<char>
8550 partial_die_full_name (struct partial_die_info
*pdi
,
8551 struct dwarf2_cu
*cu
)
8553 const char *parent_scope
;
8555 /* If this is a template instantiation, we can not work out the
8556 template arguments from partial DIEs. So, unfortunately, we have
8557 to go through the full DIEs. At least any work we do building
8558 types here will be reused if full symbols are loaded later. */
8559 if (pdi
->has_template_arguments
)
8563 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8565 struct die_info
*die
;
8566 struct attribute attr
;
8567 struct dwarf2_cu
*ref_cu
= cu
;
8569 /* DW_FORM_ref_addr is using section offset. */
8570 attr
.name
= (enum dwarf_attribute
) 0;
8571 attr
.form
= DW_FORM_ref_addr
;
8572 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8573 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8575 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8579 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8580 if (parent_scope
== NULL
)
8583 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8589 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8591 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8592 struct objfile
*objfile
= per_objfile
->objfile
;
8593 struct gdbarch
*gdbarch
= objfile
->arch ();
8595 const char *actual_name
= NULL
;
8598 baseaddr
= objfile
->text_section_offset ();
8600 gdb::unique_xmalloc_ptr
<char> built_actual_name
8601 = partial_die_full_name (pdi
, cu
);
8602 if (built_actual_name
!= NULL
)
8603 actual_name
= built_actual_name
.get ();
8605 if (actual_name
== NULL
)
8606 actual_name
= pdi
->name (cu
);
8608 partial_symbol psymbol
;
8609 memset (&psymbol
, 0, sizeof (psymbol
));
8610 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8611 psymbol
.ginfo
.section
= -1;
8613 /* The code below indicates that the psymbol should be installed by
8615 gdb::optional
<psymbol_placement
> where
;
8619 case DW_TAG_inlined_subroutine
:
8620 case DW_TAG_subprogram
:
8621 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8623 if (pdi
->is_external
8624 || cu
->language
== language_ada
8625 || (cu
->language
== language_fortran
8626 && pdi
->die_parent
!= NULL
8627 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8629 /* Normally, only "external" DIEs are part of the global scope.
8630 But in Ada and Fortran, we want to be able to access nested
8631 procedures globally. So all Ada and Fortran subprograms are
8632 stored in the global scope. */
8633 where
= psymbol_placement::GLOBAL
;
8636 where
= psymbol_placement::STATIC
;
8638 psymbol
.domain
= VAR_DOMAIN
;
8639 psymbol
.aclass
= LOC_BLOCK
;
8640 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8641 psymbol
.ginfo
.value
.address
= addr
;
8643 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8644 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8646 case DW_TAG_constant
:
8647 psymbol
.domain
= VAR_DOMAIN
;
8648 psymbol
.aclass
= LOC_STATIC
;
8649 where
= (pdi
->is_external
8650 ? psymbol_placement::GLOBAL
8651 : psymbol_placement::STATIC
);
8653 case DW_TAG_variable
:
8655 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8659 && !per_objfile
->per_bfd
->has_section_at_zero
)
8661 /* A global or static variable may also have been stripped
8662 out by the linker if unused, in which case its address
8663 will be nullified; do not add such variables into partial
8664 symbol table then. */
8666 else if (pdi
->is_external
)
8669 Don't enter into the minimal symbol tables as there is
8670 a minimal symbol table entry from the ELF symbols already.
8671 Enter into partial symbol table if it has a location
8672 descriptor or a type.
8673 If the location descriptor is missing, new_symbol will create
8674 a LOC_UNRESOLVED symbol, the address of the variable will then
8675 be determined from the minimal symbol table whenever the variable
8677 The address for the partial symbol table entry is not
8678 used by GDB, but it comes in handy for debugging partial symbol
8681 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8683 psymbol
.domain
= VAR_DOMAIN
;
8684 psymbol
.aclass
= LOC_STATIC
;
8685 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8686 psymbol
.ginfo
.value
.address
= addr
;
8687 where
= psymbol_placement::GLOBAL
;
8692 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8694 /* Static Variable. Skip symbols whose value we cannot know (those
8695 without location descriptors or constant values). */
8696 if (!has_loc
&& !pdi
->has_const_value
)
8699 psymbol
.domain
= VAR_DOMAIN
;
8700 psymbol
.aclass
= LOC_STATIC
;
8701 psymbol
.ginfo
.section
= SECT_OFF_TEXT (objfile
);
8703 psymbol
.ginfo
.value
.address
= addr
;
8704 where
= psymbol_placement::STATIC
;
8707 case DW_TAG_array_type
:
8708 case DW_TAG_typedef
:
8709 case DW_TAG_base_type
:
8710 case DW_TAG_subrange_type
:
8711 psymbol
.domain
= VAR_DOMAIN
;
8712 psymbol
.aclass
= LOC_TYPEDEF
;
8713 where
= psymbol_placement::STATIC
;
8715 case DW_TAG_imported_declaration
:
8716 case DW_TAG_namespace
:
8717 psymbol
.domain
= VAR_DOMAIN
;
8718 psymbol
.aclass
= LOC_TYPEDEF
;
8719 where
= psymbol_placement::GLOBAL
;
8722 /* With Fortran 77 there might be a "BLOCK DATA" module
8723 available without any name. If so, we skip the module as it
8724 doesn't bring any value. */
8725 if (actual_name
!= nullptr)
8727 psymbol
.domain
= MODULE_DOMAIN
;
8728 psymbol
.aclass
= LOC_TYPEDEF
;
8729 where
= psymbol_placement::GLOBAL
;
8732 case DW_TAG_class_type
:
8733 case DW_TAG_interface_type
:
8734 case DW_TAG_structure_type
:
8735 case DW_TAG_union_type
:
8736 case DW_TAG_enumeration_type
:
8737 /* Skip external references. The DWARF standard says in the section
8738 about "Structure, Union, and Class Type Entries": "An incomplete
8739 structure, union or class type is represented by a structure,
8740 union or class entry that does not have a byte size attribute
8741 and that has a DW_AT_declaration attribute." */
8742 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8745 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8746 static vs. global. */
8747 psymbol
.domain
= STRUCT_DOMAIN
;
8748 psymbol
.aclass
= LOC_TYPEDEF
;
8749 where
= (cu
->language
== language_cplus
8750 ? psymbol_placement::GLOBAL
8751 : psymbol_placement::STATIC
);
8753 case DW_TAG_enumerator
:
8754 psymbol
.domain
= VAR_DOMAIN
;
8755 psymbol
.aclass
= LOC_CONST
;
8756 where
= (cu
->language
== language_cplus
8757 ? psymbol_placement::GLOBAL
8758 : psymbol_placement::STATIC
);
8764 if (where
.has_value ())
8766 if (built_actual_name
!= nullptr)
8767 actual_name
= objfile
->intern (actual_name
);
8768 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8769 psymbol
.ginfo
.set_linkage_name (actual_name
);
8772 psymbol
.ginfo
.set_demangled_name (actual_name
,
8773 &objfile
->objfile_obstack
);
8774 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8776 cu
->per_cu
->v
.psymtab
->add_psymbol (psymbol
, *where
, objfile
);
8780 /* Read a partial die corresponding to a namespace; also, add a symbol
8781 corresponding to that namespace to the symbol table. NAMESPACE is
8782 the name of the enclosing namespace. */
8785 add_partial_namespace (struct partial_die_info
*pdi
,
8786 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8787 int set_addrmap
, struct dwarf2_cu
*cu
)
8789 /* Add a symbol for the namespace. */
8791 add_partial_symbol (pdi
, cu
);
8793 /* Now scan partial symbols in that namespace. */
8795 if (pdi
->has_children
)
8796 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8799 /* Read a partial die corresponding to a Fortran module. */
8802 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8803 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8805 /* Add a symbol for the namespace. */
8807 add_partial_symbol (pdi
, cu
);
8809 /* Now scan partial symbols in that module. */
8811 if (pdi
->has_children
)
8812 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8815 /* Read a partial die corresponding to a subprogram or an inlined
8816 subprogram and create a partial symbol for that subprogram.
8817 When the CU language allows it, this routine also defines a partial
8818 symbol for each nested subprogram that this subprogram contains.
8819 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8820 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8822 PDI may also be a lexical block, in which case we simply search
8823 recursively for subprograms defined inside that lexical block.
8824 Again, this is only performed when the CU language allows this
8825 type of definitions. */
8828 add_partial_subprogram (struct partial_die_info
*pdi
,
8829 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8830 int set_addrmap
, struct dwarf2_cu
*cu
)
8832 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8834 if (pdi
->has_pc_info
)
8836 if (pdi
->lowpc
< *lowpc
)
8837 *lowpc
= pdi
->lowpc
;
8838 if (pdi
->highpc
> *highpc
)
8839 *highpc
= pdi
->highpc
;
8842 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8843 struct gdbarch
*gdbarch
= objfile
->arch ();
8845 CORE_ADDR this_highpc
;
8846 CORE_ADDR this_lowpc
;
8848 baseaddr
= objfile
->text_section_offset ();
8850 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8851 pdi
->lowpc
+ baseaddr
)
8854 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8855 pdi
->highpc
+ baseaddr
)
8857 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8858 this_lowpc
, this_highpc
- 1,
8859 cu
->per_cu
->v
.psymtab
);
8863 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8865 if (!pdi
->is_declaration
)
8866 /* Ignore subprogram DIEs that do not have a name, they are
8867 illegal. Do not emit a complaint at this point, we will
8868 do so when we convert this psymtab into a symtab. */
8870 add_partial_symbol (pdi
, cu
);
8874 if (! pdi
->has_children
)
8877 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8879 pdi
= pdi
->die_child
;
8883 if (pdi
->tag
== DW_TAG_subprogram
8884 || pdi
->tag
== DW_TAG_inlined_subroutine
8885 || pdi
->tag
== DW_TAG_lexical_block
)
8886 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8887 pdi
= pdi
->die_sibling
;
8892 /* Read a partial die corresponding to an enumeration type. */
8895 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8896 struct dwarf2_cu
*cu
)
8898 struct partial_die_info
*pdi
;
8900 if (enum_pdi
->name (cu
) != NULL
)
8901 add_partial_symbol (enum_pdi
, cu
);
8903 pdi
= enum_pdi
->die_child
;
8906 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8907 complaint (_("malformed enumerator DIE ignored"));
8909 add_partial_symbol (pdi
, cu
);
8910 pdi
= pdi
->die_sibling
;
8914 /* Return the initial uleb128 in the die at INFO_PTR. */
8917 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8919 unsigned int bytes_read
;
8921 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8924 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8925 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8927 Return the corresponding abbrev, or NULL if the number is zero (indicating
8928 an empty DIE). In either case *BYTES_READ will be set to the length of
8929 the initial number. */
8931 static struct abbrev_info
*
8932 peek_die_abbrev (const die_reader_specs
&reader
,
8933 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8935 dwarf2_cu
*cu
= reader
.cu
;
8936 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8937 unsigned int abbrev_number
8938 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8940 if (abbrev_number
== 0)
8943 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8946 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8947 " at offset %s [in module %s]"),
8948 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8949 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8955 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8956 Returns a pointer to the end of a series of DIEs, terminated by an empty
8957 DIE. Any children of the skipped DIEs will also be skipped. */
8959 static const gdb_byte
*
8960 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8964 unsigned int bytes_read
;
8965 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8968 return info_ptr
+ bytes_read
;
8970 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8974 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8975 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8976 abbrev corresponding to that skipped uleb128 should be passed in
8977 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8980 static const gdb_byte
*
8981 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8982 struct abbrev_info
*abbrev
)
8984 unsigned int bytes_read
;
8985 struct attribute attr
;
8986 bfd
*abfd
= reader
->abfd
;
8987 struct dwarf2_cu
*cu
= reader
->cu
;
8988 const gdb_byte
*buffer
= reader
->buffer
;
8989 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8990 unsigned int form
, i
;
8992 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8994 /* The only abbrev we care about is DW_AT_sibling. */
8995 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8997 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8998 if (attr
.form
== DW_FORM_ref_addr
)
8999 complaint (_("ignoring absolute DW_AT_sibling"));
9002 sect_offset off
= attr
.get_ref_die_offset ();
9003 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9005 if (sibling_ptr
< info_ptr
)
9006 complaint (_("DW_AT_sibling points backwards"));
9007 else if (sibling_ptr
> reader
->buffer_end
)
9008 reader
->die_section
->overflow_complaint ();
9014 /* If it isn't DW_AT_sibling, skip this attribute. */
9015 form
= abbrev
->attrs
[i
].form
;
9019 case DW_FORM_ref_addr
:
9020 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9021 and later it is offset sized. */
9022 if (cu
->header
.version
== 2)
9023 info_ptr
+= cu
->header
.addr_size
;
9025 info_ptr
+= cu
->header
.offset_size
;
9027 case DW_FORM_GNU_ref_alt
:
9028 info_ptr
+= cu
->header
.offset_size
;
9031 info_ptr
+= cu
->header
.addr_size
;
9039 case DW_FORM_flag_present
:
9040 case DW_FORM_implicit_const
:
9057 case DW_FORM_ref_sig8
:
9060 case DW_FORM_data16
:
9063 case DW_FORM_string
:
9064 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9065 info_ptr
+= bytes_read
;
9067 case DW_FORM_sec_offset
:
9069 case DW_FORM_GNU_strp_alt
:
9070 info_ptr
+= cu
->header
.offset_size
;
9072 case DW_FORM_exprloc
:
9074 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9075 info_ptr
+= bytes_read
;
9077 case DW_FORM_block1
:
9078 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9080 case DW_FORM_block2
:
9081 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9083 case DW_FORM_block4
:
9084 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9090 case DW_FORM_ref_udata
:
9091 case DW_FORM_GNU_addr_index
:
9092 case DW_FORM_GNU_str_index
:
9093 case DW_FORM_rnglistx
:
9094 case DW_FORM_loclistx
:
9095 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9097 case DW_FORM_indirect
:
9098 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9099 info_ptr
+= bytes_read
;
9100 /* We need to continue parsing from here, so just go back to
9102 goto skip_attribute
;
9105 error (_("Dwarf Error: Cannot handle %s "
9106 "in DWARF reader [in module %s]"),
9107 dwarf_form_name (form
),
9108 bfd_get_filename (abfd
));
9112 if (abbrev
->has_children
)
9113 return skip_children (reader
, info_ptr
);
9118 /* Locate ORIG_PDI's sibling.
9119 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9121 static const gdb_byte
*
9122 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9123 struct partial_die_info
*orig_pdi
,
9124 const gdb_byte
*info_ptr
)
9126 /* Do we know the sibling already? */
9128 if (orig_pdi
->sibling
)
9129 return orig_pdi
->sibling
;
9131 /* Are there any children to deal with? */
9133 if (!orig_pdi
->has_children
)
9136 /* Skip the children the long way. */
9138 return skip_children (reader
, info_ptr
);
9141 /* Expand this partial symbol table into a full symbol table. SELF is
9145 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
9147 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9149 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
9151 /* If this psymtab is constructed from a debug-only objfile, the
9152 has_section_at_zero flag will not necessarily be correct. We
9153 can get the correct value for this flag by looking at the data
9154 associated with the (presumably stripped) associated objfile. */
9155 if (objfile
->separate_debug_objfile_backlink
)
9157 dwarf2_per_objfile
*per_objfile_backlink
9158 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9160 per_objfile
->per_bfd
->has_section_at_zero
9161 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
9164 expand_psymtab (objfile
);
9166 process_cu_includes (per_objfile
);
9169 /* Reading in full CUs. */
9171 /* Add PER_CU to the queue. */
9174 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
9175 dwarf2_per_objfile
*per_objfile
,
9176 enum language pretend_language
)
9179 per_cu
->per_bfd
->queue
.emplace (per_cu
, per_objfile
, pretend_language
);
9182 /* If PER_CU is not yet queued, add it to the queue.
9183 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9185 The result is non-zero if PER_CU was queued, otherwise the result is zero
9186 meaning either PER_CU is already queued or it is already loaded.
9188 N.B. There is an invariant here that if a CU is queued then it is loaded.
9189 The caller is required to load PER_CU if we return non-zero. */
9192 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9193 dwarf2_per_cu_data
*per_cu
,
9194 dwarf2_per_objfile
*per_objfile
,
9195 enum language pretend_language
)
9197 /* We may arrive here during partial symbol reading, if we need full
9198 DIEs to process an unusual case (e.g. template arguments). Do
9199 not queue PER_CU, just tell our caller to load its DIEs. */
9200 if (per_cu
->per_bfd
->reading_partial_symbols
)
9202 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9204 if (cu
== NULL
|| cu
->dies
== NULL
)
9209 /* Mark the dependence relation so that we don't flush PER_CU
9211 if (dependent_cu
!= NULL
)
9212 dwarf2_add_dependence (dependent_cu
, per_cu
);
9214 /* If it's already on the queue, we have nothing to do. */
9217 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
9219 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
9223 /* If the compilation unit is already loaded, just mark it as
9225 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9232 /* Add it to the queue. */
9233 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9238 /* Process the queue. */
9241 process_queue (dwarf2_per_objfile
*per_objfile
)
9243 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
9244 objfile_name (per_objfile
->objfile
));
9246 /* The queue starts out with one item, but following a DIE reference
9247 may load a new CU, adding it to the end of the queue. */
9248 while (!per_objfile
->per_bfd
->queue
.empty ())
9250 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
.front ();
9251 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9253 if (!per_objfile
->symtab_set_p (per_cu
))
9255 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9257 /* Skip dummy CUs. */
9260 unsigned int debug_print_threshold
;
9263 if (per_cu
->is_debug_types
)
9265 struct signatured_type
*sig_type
=
9266 (struct signatured_type
*) per_cu
;
9268 sprintf (buf
, "TU %s at offset %s",
9269 hex_string (sig_type
->signature
),
9270 sect_offset_str (per_cu
->sect_off
));
9271 /* There can be 100s of TUs.
9272 Only print them in verbose mode. */
9273 debug_print_threshold
= 2;
9277 sprintf (buf
, "CU at offset %s",
9278 sect_offset_str (per_cu
->sect_off
));
9279 debug_print_threshold
= 1;
9282 if (dwarf_read_debug
>= debug_print_threshold
)
9283 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
9285 if (per_cu
->is_debug_types
)
9286 process_full_type_unit (cu
, item
.pretend_language
);
9288 process_full_comp_unit (cu
, item
.pretend_language
);
9290 if (dwarf_read_debug
>= debug_print_threshold
)
9291 dwarf_read_debug_printf ("Done expanding %s", buf
);
9296 per_objfile
->per_bfd
->queue
.pop ();
9299 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
9300 objfile_name (per_objfile
->objfile
));
9303 /* Read in full symbols for PST, and anything it depends on. */
9306 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9308 gdb_assert (!readin_p (objfile
));
9310 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9311 free_cached_comp_units
freer (per_objfile
);
9312 expand_dependencies (objfile
);
9314 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9315 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9318 /* See psympriv.h. */
9321 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9323 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9324 return per_objfile
->symtab_set_p (per_cu_data
);
9327 /* See psympriv.h. */
9330 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9332 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9333 return per_objfile
->get_symtab (per_cu_data
);
9336 /* Trivial hash function for die_info: the hash value of a DIE
9337 is its offset in .debug_info for this objfile. */
9340 die_hash (const void *item
)
9342 const struct die_info
*die
= (const struct die_info
*) item
;
9344 return to_underlying (die
->sect_off
);
9347 /* Trivial comparison function for die_info structures: two DIEs
9348 are equal if they have the same offset. */
9351 die_eq (const void *item_lhs
, const void *item_rhs
)
9353 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9354 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9356 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9359 /* Load the DIEs associated with PER_CU into memory.
9361 In some cases, the caller, while reading partial symbols, will need to load
9362 the full symbols for the CU for some reason. It will already have a
9363 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
9364 rather than creating a new one. */
9367 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9368 dwarf2_per_objfile
*per_objfile
,
9369 dwarf2_cu
*existing_cu
,
9371 enum language pretend_language
)
9373 gdb_assert (! this_cu
->is_debug_types
);
9375 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9379 struct dwarf2_cu
*cu
= reader
.cu
;
9380 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9382 gdb_assert (cu
->die_hash
== NULL
);
9384 htab_create_alloc_ex (cu
->header
.length
/ 12,
9388 &cu
->comp_unit_obstack
,
9389 hashtab_obstack_allocate
,
9390 dummy_obstack_deallocate
);
9392 if (reader
.comp_unit_die
->has_children
)
9393 reader
.comp_unit_die
->child
9394 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9395 &info_ptr
, reader
.comp_unit_die
);
9396 cu
->dies
= reader
.comp_unit_die
;
9397 /* comp_unit_die is not stored in die_hash, no need. */
9399 /* We try not to read any attributes in this function, because not
9400 all CUs needed for references have been loaded yet, and symbol
9401 table processing isn't initialized. But we have to set the CU language,
9402 or we won't be able to build types correctly.
9403 Similarly, if we do not read the producer, we can not apply
9404 producer-specific interpretation. */
9405 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9410 /* Add a DIE to the delayed physname list. */
9413 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9414 const char *name
, struct die_info
*die
,
9415 struct dwarf2_cu
*cu
)
9417 struct delayed_method_info mi
;
9419 mi
.fnfield_index
= fnfield_index
;
9423 cu
->method_list
.push_back (mi
);
9426 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9427 "const" / "volatile". If so, decrements LEN by the length of the
9428 modifier and return true. Otherwise return false. */
9432 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9434 size_t mod_len
= sizeof (mod
) - 1;
9435 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9443 /* Compute the physnames of any methods on the CU's method list.
9445 The computation of method physnames is delayed in order to avoid the
9446 (bad) condition that one of the method's formal parameters is of an as yet
9450 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9452 /* Only C++ delays computing physnames. */
9453 if (cu
->method_list
.empty ())
9455 gdb_assert (cu
->language
== language_cplus
);
9457 for (const delayed_method_info
&mi
: cu
->method_list
)
9459 const char *physname
;
9460 struct fn_fieldlist
*fn_flp
9461 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9462 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9463 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9464 = physname
? physname
: "";
9466 /* Since there's no tag to indicate whether a method is a
9467 const/volatile overload, extract that information out of the
9469 if (physname
!= NULL
)
9471 size_t len
= strlen (physname
);
9475 if (physname
[len
] == ')') /* shortcut */
9477 else if (check_modifier (physname
, len
, " const"))
9478 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9479 else if (check_modifier (physname
, len
, " volatile"))
9480 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9487 /* The list is no longer needed. */
9488 cu
->method_list
.clear ();
9491 /* Go objects should be embedded in a DW_TAG_module DIE,
9492 and it's not clear if/how imported objects will appear.
9493 To keep Go support simple until that's worked out,
9494 go back through what we've read and create something usable.
9495 We could do this while processing each DIE, and feels kinda cleaner,
9496 but that way is more invasive.
9497 This is to, for example, allow the user to type "p var" or "b main"
9498 without having to specify the package name, and allow lookups
9499 of module.object to work in contexts that use the expression
9503 fixup_go_packaging (struct dwarf2_cu
*cu
)
9505 gdb::unique_xmalloc_ptr
<char> package_name
;
9506 struct pending
*list
;
9509 for (list
= *cu
->get_builder ()->get_global_symbols ();
9513 for (i
= 0; i
< list
->nsyms
; ++i
)
9515 struct symbol
*sym
= list
->symbol
[i
];
9517 if (sym
->language () == language_go
9518 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9520 gdb::unique_xmalloc_ptr
<char> this_package_name
9521 (go_symbol_package_name (sym
));
9523 if (this_package_name
== NULL
)
9525 if (package_name
== NULL
)
9526 package_name
= std::move (this_package_name
);
9529 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9530 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9531 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9532 (symbol_symtab (sym
) != NULL
9533 ? symtab_to_filename_for_display
9534 (symbol_symtab (sym
))
9535 : objfile_name (objfile
)),
9536 this_package_name
.get (), package_name
.get ());
9542 if (package_name
!= NULL
)
9544 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9545 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9546 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9547 saved_package_name
);
9550 sym
= new (&objfile
->objfile_obstack
) symbol
;
9551 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9552 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9553 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9554 e.g., "main" finds the "main" module and not C's main(). */
9555 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9556 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9557 SYMBOL_TYPE (sym
) = type
;
9559 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9563 /* Allocate a fully-qualified name consisting of the two parts on the
9567 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9569 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9572 /* A helper that allocates a variant part to attach to a Rust enum
9573 type. OBSTACK is where the results should be allocated. TYPE is
9574 the type we're processing. DISCRIMINANT_INDEX is the index of the
9575 discriminant. It must be the index of one of the fields of TYPE,
9576 or -1 to mean there is no discriminant (univariant enum).
9577 DEFAULT_INDEX is the index of the default field; or -1 if there is
9578 no default. RANGES is indexed by "effective" field number (the
9579 field index, but omitting the discriminant and default fields) and
9580 must hold the discriminant values used by the variants. Note that
9581 RANGES must have a lifetime at least as long as OBSTACK -- either
9582 already allocated on it, or static. */
9585 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9586 int discriminant_index
, int default_index
,
9587 gdb::array_view
<discriminant_range
> ranges
)
9589 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
9590 gdb_assert (discriminant_index
== -1
9591 || (discriminant_index
>= 0
9592 && discriminant_index
< type
->num_fields ()));
9593 gdb_assert (default_index
== -1
9594 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9596 /* We have one variant for each non-discriminant field. */
9597 int n_variants
= type
->num_fields ();
9598 if (discriminant_index
!= -1)
9601 variant
*variants
= new (obstack
) variant
[n_variants
];
9604 for (int i
= 0; i
< type
->num_fields (); ++i
)
9606 if (i
== discriminant_index
)
9609 variants
[var_idx
].first_field
= i
;
9610 variants
[var_idx
].last_field
= i
+ 1;
9612 /* The default field does not need a range, but other fields do.
9613 We skipped the discriminant above. */
9614 if (i
!= default_index
)
9616 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9623 gdb_assert (range_idx
== ranges
.size ());
9624 gdb_assert (var_idx
== n_variants
);
9626 variant_part
*part
= new (obstack
) variant_part
;
9627 part
->discriminant_index
= discriminant_index
;
9628 /* If there is no discriminant, then whether it is signed is of no
9631 = (discriminant_index
== -1
9633 : type
->field (discriminant_index
).type ()->is_unsigned ());
9634 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9636 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9637 gdb::array_view
<variant_part
> *prop_value
9638 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9640 struct dynamic_prop prop
;
9641 prop
.set_variant_parts (prop_value
);
9643 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9646 /* Some versions of rustc emitted enums in an unusual way.
9648 Ordinary enums were emitted as unions. The first element of each
9649 structure in the union was named "RUST$ENUM$DISR". This element
9650 held the discriminant.
9652 These versions of Rust also implemented the "non-zero"
9653 optimization. When the enum had two values, and one is empty and
9654 the other holds a pointer that cannot be zero, the pointer is used
9655 as the discriminant, with a zero value meaning the empty variant.
9656 Here, the union's first member is of the form
9657 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9658 where the fieldnos are the indices of the fields that should be
9659 traversed in order to find the field (which may be several fields deep)
9660 and the variantname is the name of the variant of the case when the
9663 This function recognizes whether TYPE is of one of these forms,
9664 and, if so, smashes it to be a variant type. */
9667 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9669 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9671 /* We don't need to deal with empty enums. */
9672 if (type
->num_fields () == 0)
9675 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9676 if (type
->num_fields () == 1
9677 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9679 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9681 /* Decode the field name to find the offset of the
9683 ULONGEST bit_offset
= 0;
9684 struct type
*field_type
= type
->field (0).type ();
9685 while (name
[0] >= '0' && name
[0] <= '9')
9688 unsigned long index
= strtoul (name
, &tail
, 10);
9691 || index
>= field_type
->num_fields ()
9692 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9693 != FIELD_LOC_KIND_BITPOS
))
9695 complaint (_("Could not parse Rust enum encoding string \"%s\""
9697 TYPE_FIELD_NAME (type
, 0),
9698 objfile_name (objfile
));
9703 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9704 field_type
= field_type
->field (index
).type ();
9707 /* Smash this type to be a structure type. We have to do this
9708 because the type has already been recorded. */
9709 type
->set_code (TYPE_CODE_STRUCT
);
9710 type
->set_num_fields (3);
9711 /* Save the field we care about. */
9712 struct field saved_field
= type
->field (0);
9714 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9716 /* Put the discriminant at index 0. */
9717 type
->field (0).set_type (field_type
);
9718 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9719 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9720 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9722 /* The order of fields doesn't really matter, so put the real
9723 field at index 1 and the data-less field at index 2. */
9724 type
->field (1) = saved_field
;
9725 TYPE_FIELD_NAME (type
, 1)
9726 = rust_last_path_segment (type
->field (1).type ()->name ());
9727 type
->field (1).type ()->set_name
9728 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9729 TYPE_FIELD_NAME (type
, 1)));
9731 const char *dataless_name
9732 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9734 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9736 type
->field (2).set_type (dataless_type
);
9737 /* NAME points into the original discriminant name, which
9738 already has the correct lifetime. */
9739 TYPE_FIELD_NAME (type
, 2) = name
;
9740 SET_FIELD_BITPOS (type
->field (2), 0);
9742 /* Indicate that this is a variant type. */
9743 static discriminant_range ranges
[1] = { { 0, 0 } };
9744 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9746 /* A union with a single anonymous field is probably an old-style
9748 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9750 /* Smash this type to be a structure type. We have to do this
9751 because the type has already been recorded. */
9752 type
->set_code (TYPE_CODE_STRUCT
);
9754 struct type
*field_type
= type
->field (0).type ();
9755 const char *variant_name
9756 = rust_last_path_segment (field_type
->name ());
9757 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9758 field_type
->set_name
9759 (rust_fully_qualify (&objfile
->objfile_obstack
,
9760 type
->name (), variant_name
));
9762 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9766 struct type
*disr_type
= nullptr;
9767 for (int i
= 0; i
< type
->num_fields (); ++i
)
9769 disr_type
= type
->field (i
).type ();
9771 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9773 /* All fields of a true enum will be structs. */
9776 else if (disr_type
->num_fields () == 0)
9778 /* Could be data-less variant, so keep going. */
9779 disr_type
= nullptr;
9781 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9782 "RUST$ENUM$DISR") != 0)
9784 /* Not a Rust enum. */
9794 /* If we got here without a discriminant, then it's probably
9796 if (disr_type
== nullptr)
9799 /* Smash this type to be a structure type. We have to do this
9800 because the type has already been recorded. */
9801 type
->set_code (TYPE_CODE_STRUCT
);
9803 /* Make space for the discriminant field. */
9804 struct field
*disr_field
= &disr_type
->field (0);
9806 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9807 * sizeof (struct field
)));
9808 memcpy (new_fields
+ 1, type
->fields (),
9809 type
->num_fields () * sizeof (struct field
));
9810 type
->set_fields (new_fields
);
9811 type
->set_num_fields (type
->num_fields () + 1);
9813 /* Install the discriminant at index 0 in the union. */
9814 type
->field (0) = *disr_field
;
9815 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9816 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9818 /* We need a way to find the correct discriminant given a
9819 variant name. For convenience we build a map here. */
9820 struct type
*enum_type
= disr_field
->type ();
9821 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9822 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9824 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9827 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9828 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9832 int n_fields
= type
->num_fields ();
9833 /* We don't need a range entry for the discriminant, but we do
9834 need one for every other field, as there is no default
9836 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9839 /* Skip the discriminant here. */
9840 for (int i
= 1; i
< n_fields
; ++i
)
9842 /* Find the final word in the name of this variant's type.
9843 That name can be used to look up the correct
9845 const char *variant_name
9846 = rust_last_path_segment (type
->field (i
).type ()->name ());
9848 auto iter
= discriminant_map
.find (variant_name
);
9849 if (iter
!= discriminant_map
.end ())
9851 ranges
[i
- 1].low
= iter
->second
;
9852 ranges
[i
- 1].high
= iter
->second
;
9855 /* In Rust, each element should have the size of the
9857 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9859 /* Remove the discriminant field, if it exists. */
9860 struct type
*sub_type
= type
->field (i
).type ();
9861 if (sub_type
->num_fields () > 0)
9863 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9864 sub_type
->set_fields (sub_type
->fields () + 1);
9866 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9868 (rust_fully_qualify (&objfile
->objfile_obstack
,
9869 type
->name (), variant_name
));
9872 /* Indicate that this is a variant type. */
9873 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9874 gdb::array_view
<discriminant_range
> (ranges
,
9879 /* Rewrite some Rust unions to be structures with variants parts. */
9882 rust_union_quirks (struct dwarf2_cu
*cu
)
9884 gdb_assert (cu
->language
== language_rust
);
9885 for (type
*type_
: cu
->rust_unions
)
9886 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9887 /* We don't need this any more. */
9888 cu
->rust_unions
.clear ();
9893 type_unit_group_unshareable
*
9894 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9896 auto iter
= this->m_type_units
.find (tu_group
);
9897 if (iter
!= this->m_type_units
.end ())
9898 return iter
->second
.get ();
9900 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9901 type_unit_group_unshareable
*result
= uniq
.get ();
9902 this->m_type_units
[tu_group
] = std::move (uniq
);
9907 dwarf2_per_objfile::get_type_for_signatured_type
9908 (signatured_type
*sig_type
) const
9910 auto iter
= this->m_type_map
.find (sig_type
);
9911 if (iter
== this->m_type_map
.end ())
9914 return iter
->second
;
9917 void dwarf2_per_objfile::set_type_for_signatured_type
9918 (signatured_type
*sig_type
, struct type
*type
)
9920 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9922 this->m_type_map
[sig_type
] = type
;
9925 /* A helper function for computing the list of all symbol tables
9926 included by PER_CU. */
9929 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9930 htab_t all_children
, htab_t all_type_symtabs
,
9931 dwarf2_per_cu_data
*per_cu
,
9932 dwarf2_per_objfile
*per_objfile
,
9933 struct compunit_symtab
*immediate_parent
)
9935 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9938 /* This inclusion and its children have been processed. */
9944 /* Only add a CU if it has a symbol table. */
9945 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9948 /* If this is a type unit only add its symbol table if we haven't
9949 seen it yet (type unit per_cu's can share symtabs). */
9950 if (per_cu
->is_debug_types
)
9952 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9956 result
->push_back (cust
);
9957 if (cust
->user
== NULL
)
9958 cust
->user
= immediate_parent
;
9963 result
->push_back (cust
);
9964 if (cust
->user
== NULL
)
9965 cust
->user
= immediate_parent
;
9969 if (!per_cu
->imported_symtabs_empty ())
9970 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9972 recursively_compute_inclusions (result
, all_children
,
9973 all_type_symtabs
, ptr
, per_objfile
,
9978 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9982 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9983 dwarf2_per_objfile
*per_objfile
)
9985 gdb_assert (! per_cu
->is_debug_types
);
9987 if (!per_cu
->imported_symtabs_empty ())
9990 std::vector
<compunit_symtab
*> result_symtabs
;
9991 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9993 /* If we don't have a symtab, we can just skip this case. */
9997 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9999 NULL
, xcalloc
, xfree
));
10000 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
10002 NULL
, xcalloc
, xfree
));
10004 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10006 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
10007 all_type_symtabs
.get (), ptr
,
10008 per_objfile
, cust
);
10011 /* Now we have a transitive closure of all the included symtabs. */
10012 len
= result_symtabs
.size ();
10014 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
10015 struct compunit_symtab
*, len
+ 1);
10016 memcpy (cust
->includes
, result_symtabs
.data (),
10017 len
* sizeof (compunit_symtab
*));
10018 cust
->includes
[len
] = NULL
;
10022 /* Compute the 'includes' field for the symtabs of all the CUs we just
10026 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
10028 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
10030 if (! iter
->is_debug_types
)
10031 compute_compunit_symtab_includes (iter
, per_objfile
);
10034 per_objfile
->per_bfd
->just_read_cus
.clear ();
10037 /* Generate full symbol information for CU, whose DIEs have
10038 already been loaded into memory. */
10041 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
10043 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10044 struct objfile
*objfile
= per_objfile
->objfile
;
10045 struct gdbarch
*gdbarch
= objfile
->arch ();
10046 CORE_ADDR lowpc
, highpc
;
10047 struct compunit_symtab
*cust
;
10048 CORE_ADDR baseaddr
;
10049 struct block
*static_block
;
10052 baseaddr
= objfile
->text_section_offset ();
10054 /* Clear the list here in case something was left over. */
10055 cu
->method_list
.clear ();
10057 cu
->language
= pretend_language
;
10058 cu
->language_defn
= language_def (cu
->language
);
10060 dwarf2_find_base_address (cu
->dies
, cu
);
10062 /* Do line number decoding in read_file_scope () */
10063 process_die (cu
->dies
, cu
);
10065 /* For now fudge the Go package. */
10066 if (cu
->language
== language_go
)
10067 fixup_go_packaging (cu
);
10069 /* Now that we have processed all the DIEs in the CU, all the types
10070 should be complete, and it should now be safe to compute all of the
10072 compute_delayed_physnames (cu
);
10074 if (cu
->language
== language_rust
)
10075 rust_union_quirks (cu
);
10077 /* Some compilers don't define a DW_AT_high_pc attribute for the
10078 compilation unit. If the DW_AT_high_pc is missing, synthesize
10079 it, by scanning the DIE's below the compilation unit. */
10080 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10082 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10083 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10085 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10086 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10087 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10088 addrmap to help ensure it has an accurate map of pc values belonging to
10090 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10092 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10093 SECT_OFF_TEXT (objfile
),
10098 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10100 /* Set symtab language to language from DW_AT_language. If the
10101 compilation is from a C file generated by language preprocessors, do
10102 not set the language if it was already deduced by start_subfile. */
10103 if (!(cu
->language
== language_c
10104 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10105 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10107 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10108 produce DW_AT_location with location lists but it can be possibly
10109 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10110 there were bugs in prologue debug info, fixed later in GCC-4.5
10111 by "unwind info for epilogues" patch (which is not directly related).
10113 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10114 needed, it would be wrong due to missing DW_AT_producer there.
10116 Still one can confuse GDB by using non-standard GCC compilation
10117 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10119 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10120 cust
->locations_valid
= 1;
10122 if (gcc_4_minor
>= 5)
10123 cust
->epilogue_unwind_valid
= 1;
10125 cust
->call_site_htab
= cu
->call_site_htab
;
10128 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10130 /* Push it for inclusion processing later. */
10131 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
10133 /* Not needed any more. */
10134 cu
->reset_builder ();
10137 /* Generate full symbol information for type unit CU, whose DIEs have
10138 already been loaded into memory. */
10141 process_full_type_unit (dwarf2_cu
*cu
,
10142 enum language pretend_language
)
10144 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10145 struct objfile
*objfile
= per_objfile
->objfile
;
10146 struct compunit_symtab
*cust
;
10147 struct signatured_type
*sig_type
;
10149 gdb_assert (cu
->per_cu
->is_debug_types
);
10150 sig_type
= (struct signatured_type
*) cu
->per_cu
;
10152 /* Clear the list here in case something was left over. */
10153 cu
->method_list
.clear ();
10155 cu
->language
= pretend_language
;
10156 cu
->language_defn
= language_def (cu
->language
);
10158 /* The symbol tables are set up in read_type_unit_scope. */
10159 process_die (cu
->dies
, cu
);
10161 /* For now fudge the Go package. */
10162 if (cu
->language
== language_go
)
10163 fixup_go_packaging (cu
);
10165 /* Now that we have processed all the DIEs in the CU, all the types
10166 should be complete, and it should now be safe to compute all of the
10168 compute_delayed_physnames (cu
);
10170 if (cu
->language
== language_rust
)
10171 rust_union_quirks (cu
);
10173 /* TUs share symbol tables.
10174 If this is the first TU to use this symtab, complete the construction
10175 of it with end_expandable_symtab. Otherwise, complete the addition of
10176 this TU's symbols to the existing symtab. */
10177 type_unit_group_unshareable
*tug_unshare
=
10178 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
10179 if (tug_unshare
->compunit_symtab
== NULL
)
10181 buildsym_compunit
*builder
= cu
->get_builder ();
10182 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10183 tug_unshare
->compunit_symtab
= cust
;
10187 /* Set symtab language to language from DW_AT_language. If the
10188 compilation is from a C file generated by language preprocessors,
10189 do not set the language if it was already deduced by
10191 if (!(cu
->language
== language_c
10192 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10193 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10198 cu
->get_builder ()->augment_type_symtab ();
10199 cust
= tug_unshare
->compunit_symtab
;
10202 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10204 /* Not needed any more. */
10205 cu
->reset_builder ();
10208 /* Process an imported unit DIE. */
10211 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10213 struct attribute
*attr
;
10215 /* For now we don't handle imported units in type units. */
10216 if (cu
->per_cu
->is_debug_types
)
10218 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10219 " supported in type units [in module %s]"),
10220 objfile_name (cu
->per_objfile
->objfile
));
10223 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10226 sect_offset sect_off
= attr
->get_ref_die_offset ();
10227 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10228 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10229 dwarf2_per_cu_data
*per_cu
10230 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10232 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10233 into another compilation unit, at root level. Regard this as a hint,
10235 if (die
->parent
&& die
->parent
->parent
== NULL
10236 && per_cu
->unit_type
== DW_UT_compile
10237 && per_cu
->lang
== language_cplus
)
10240 /* If necessary, add it to the queue and load its DIEs. */
10241 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10242 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
10243 false, cu
->language
);
10245 cu
->per_cu
->imported_symtabs_push (per_cu
);
10249 /* RAII object that represents a process_die scope: i.e.,
10250 starts/finishes processing a DIE. */
10251 class process_die_scope
10254 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10255 : m_die (die
), m_cu (cu
)
10257 /* We should only be processing DIEs not already in process. */
10258 gdb_assert (!m_die
->in_process
);
10259 m_die
->in_process
= true;
10262 ~process_die_scope ()
10264 m_die
->in_process
= false;
10266 /* If we're done processing the DIE for the CU that owns the line
10267 header, we don't need the line header anymore. */
10268 if (m_cu
->line_header_die_owner
== m_die
)
10270 delete m_cu
->line_header
;
10271 m_cu
->line_header
= NULL
;
10272 m_cu
->line_header_die_owner
= NULL
;
10281 /* Process a die and its children. */
10284 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10286 process_die_scope
scope (die
, cu
);
10290 case DW_TAG_padding
:
10292 case DW_TAG_compile_unit
:
10293 case DW_TAG_partial_unit
:
10294 read_file_scope (die
, cu
);
10296 case DW_TAG_type_unit
:
10297 read_type_unit_scope (die
, cu
);
10299 case DW_TAG_subprogram
:
10300 /* Nested subprograms in Fortran get a prefix. */
10301 if (cu
->language
== language_fortran
10302 && die
->parent
!= NULL
10303 && die
->parent
->tag
== DW_TAG_subprogram
)
10304 cu
->processing_has_namespace_info
= true;
10305 /* Fall through. */
10306 case DW_TAG_inlined_subroutine
:
10307 read_func_scope (die
, cu
);
10309 case DW_TAG_lexical_block
:
10310 case DW_TAG_try_block
:
10311 case DW_TAG_catch_block
:
10312 read_lexical_block_scope (die
, cu
);
10314 case DW_TAG_call_site
:
10315 case DW_TAG_GNU_call_site
:
10316 read_call_site_scope (die
, cu
);
10318 case DW_TAG_class_type
:
10319 case DW_TAG_interface_type
:
10320 case DW_TAG_structure_type
:
10321 case DW_TAG_union_type
:
10322 process_structure_scope (die
, cu
);
10324 case DW_TAG_enumeration_type
:
10325 process_enumeration_scope (die
, cu
);
10328 /* These dies have a type, but processing them does not create
10329 a symbol or recurse to process the children. Therefore we can
10330 read them on-demand through read_type_die. */
10331 case DW_TAG_subroutine_type
:
10332 case DW_TAG_set_type
:
10333 case DW_TAG_pointer_type
:
10334 case DW_TAG_ptr_to_member_type
:
10335 case DW_TAG_reference_type
:
10336 case DW_TAG_rvalue_reference_type
:
10337 case DW_TAG_string_type
:
10340 case DW_TAG_array_type
:
10341 /* We only need to handle this case for Ada -- in other
10342 languages, it's normal for the compiler to emit a typedef
10344 if (cu
->language
!= language_ada
)
10347 case DW_TAG_base_type
:
10348 case DW_TAG_subrange_type
:
10349 case DW_TAG_typedef
:
10350 /* Add a typedef symbol for the type definition, if it has a
10352 new_symbol (die
, read_type_die (die
, cu
), cu
);
10354 case DW_TAG_common_block
:
10355 read_common_block (die
, cu
);
10357 case DW_TAG_common_inclusion
:
10359 case DW_TAG_namespace
:
10360 cu
->processing_has_namespace_info
= true;
10361 read_namespace (die
, cu
);
10363 case DW_TAG_module
:
10364 cu
->processing_has_namespace_info
= true;
10365 read_module (die
, cu
);
10367 case DW_TAG_imported_declaration
:
10368 cu
->processing_has_namespace_info
= true;
10369 if (read_namespace_alias (die
, cu
))
10371 /* The declaration is not a global namespace alias. */
10372 /* Fall through. */
10373 case DW_TAG_imported_module
:
10374 cu
->processing_has_namespace_info
= true;
10375 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10376 || cu
->language
!= language_fortran
))
10377 complaint (_("Tag '%s' has unexpected children"),
10378 dwarf_tag_name (die
->tag
));
10379 read_import_statement (die
, cu
);
10382 case DW_TAG_imported_unit
:
10383 process_imported_unit_die (die
, cu
);
10386 case DW_TAG_variable
:
10387 read_variable (die
, cu
);
10391 new_symbol (die
, NULL
, cu
);
10396 /* DWARF name computation. */
10398 /* A helper function for dwarf2_compute_name which determines whether DIE
10399 needs to have the name of the scope prepended to the name listed in the
10403 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10405 struct attribute
*attr
;
10409 case DW_TAG_namespace
:
10410 case DW_TAG_typedef
:
10411 case DW_TAG_class_type
:
10412 case DW_TAG_interface_type
:
10413 case DW_TAG_structure_type
:
10414 case DW_TAG_union_type
:
10415 case DW_TAG_enumeration_type
:
10416 case DW_TAG_enumerator
:
10417 case DW_TAG_subprogram
:
10418 case DW_TAG_inlined_subroutine
:
10419 case DW_TAG_member
:
10420 case DW_TAG_imported_declaration
:
10423 case DW_TAG_variable
:
10424 case DW_TAG_constant
:
10425 /* We only need to prefix "globally" visible variables. These include
10426 any variable marked with DW_AT_external or any variable that
10427 lives in a namespace. [Variables in anonymous namespaces
10428 require prefixing, but they are not DW_AT_external.] */
10430 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10432 struct dwarf2_cu
*spec_cu
= cu
;
10434 return die_needs_namespace (die_specification (die
, &spec_cu
),
10438 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10439 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10440 && die
->parent
->tag
!= DW_TAG_module
)
10442 /* A variable in a lexical block of some kind does not need a
10443 namespace, even though in C++ such variables may be external
10444 and have a mangled name. */
10445 if (die
->parent
->tag
== DW_TAG_lexical_block
10446 || die
->parent
->tag
== DW_TAG_try_block
10447 || die
->parent
->tag
== DW_TAG_catch_block
10448 || die
->parent
->tag
== DW_TAG_subprogram
)
10457 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10458 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10459 defined for the given DIE. */
10461 static struct attribute
*
10462 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10464 struct attribute
*attr
;
10466 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10468 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10473 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10474 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10475 defined for the given DIE. */
10477 static const char *
10478 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10480 const char *linkage_name
;
10482 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10483 if (linkage_name
== NULL
)
10484 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10486 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10487 See https://github.com/rust-lang/rust/issues/32925. */
10488 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10489 && strchr (linkage_name
, '{') != NULL
)
10490 linkage_name
= NULL
;
10492 return linkage_name
;
10495 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10496 compute the physname for the object, which include a method's:
10497 - formal parameters (C++),
10498 - receiver type (Go),
10500 The term "physname" is a bit confusing.
10501 For C++, for example, it is the demangled name.
10502 For Go, for example, it's the mangled name.
10504 For Ada, return the DIE's linkage name rather than the fully qualified
10505 name. PHYSNAME is ignored..
10507 The result is allocated on the objfile->per_bfd's obstack and
10510 static const char *
10511 dwarf2_compute_name (const char *name
,
10512 struct die_info
*die
, struct dwarf2_cu
*cu
,
10515 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10518 name
= dwarf2_name (die
, cu
);
10520 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10521 but otherwise compute it by typename_concat inside GDB.
10522 FIXME: Actually this is not really true, or at least not always true.
10523 It's all very confusing. compute_and_set_names doesn't try to demangle
10524 Fortran names because there is no mangling standard. So new_symbol
10525 will set the demangled name to the result of dwarf2_full_name, and it is
10526 the demangled name that GDB uses if it exists. */
10527 if (cu
->language
== language_ada
10528 || (cu
->language
== language_fortran
&& physname
))
10530 /* For Ada unit, we prefer the linkage name over the name, as
10531 the former contains the exported name, which the user expects
10532 to be able to reference. Ideally, we want the user to be able
10533 to reference this entity using either natural or linkage name,
10534 but we haven't started looking at this enhancement yet. */
10535 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10537 if (linkage_name
!= NULL
)
10538 return linkage_name
;
10541 /* These are the only languages we know how to qualify names in. */
10543 && (cu
->language
== language_cplus
10544 || cu
->language
== language_fortran
|| cu
->language
== language_d
10545 || cu
->language
== language_rust
))
10547 if (die_needs_namespace (die
, cu
))
10549 const char *prefix
;
10550 const char *canonical_name
= NULL
;
10554 prefix
= determine_prefix (die
, cu
);
10555 if (*prefix
!= '\0')
10557 gdb::unique_xmalloc_ptr
<char> prefixed_name
10558 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10560 buf
.puts (prefixed_name
.get ());
10565 /* Template parameters may be specified in the DIE's DW_AT_name, or
10566 as children with DW_TAG_template_type_param or
10567 DW_TAG_value_type_param. If the latter, add them to the name
10568 here. If the name already has template parameters, then
10569 skip this step; some versions of GCC emit both, and
10570 it is more efficient to use the pre-computed name.
10572 Something to keep in mind about this process: it is very
10573 unlikely, or in some cases downright impossible, to produce
10574 something that will match the mangled name of a function.
10575 If the definition of the function has the same debug info,
10576 we should be able to match up with it anyway. But fallbacks
10577 using the minimal symbol, for instance to find a method
10578 implemented in a stripped copy of libstdc++, will not work.
10579 If we do not have debug info for the definition, we will have to
10580 match them up some other way.
10582 When we do name matching there is a related problem with function
10583 templates; two instantiated function templates are allowed to
10584 differ only by their return types, which we do not add here. */
10586 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10588 struct attribute
*attr
;
10589 struct die_info
*child
;
10591 const language_defn
*cplus_lang
= language_def (cu
->language
);
10593 die
->building_fullname
= 1;
10595 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10599 const gdb_byte
*bytes
;
10600 struct dwarf2_locexpr_baton
*baton
;
10603 if (child
->tag
!= DW_TAG_template_type_param
10604 && child
->tag
!= DW_TAG_template_value_param
)
10615 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10618 complaint (_("template parameter missing DW_AT_type"));
10619 buf
.puts ("UNKNOWN_TYPE");
10622 type
= die_type (child
, cu
);
10624 if (child
->tag
== DW_TAG_template_type_param
)
10626 cplus_lang
->print_type (type
, "", &buf
, -1, 0,
10627 &type_print_raw_options
);
10631 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10634 complaint (_("template parameter missing "
10635 "DW_AT_const_value"));
10636 buf
.puts ("UNKNOWN_VALUE");
10640 dwarf2_const_value_attr (attr
, type
, name
,
10641 &cu
->comp_unit_obstack
, cu
,
10642 &value
, &bytes
, &baton
);
10644 if (type
->has_no_signedness ())
10645 /* GDB prints characters as NUMBER 'CHAR'. If that's
10646 changed, this can use value_print instead. */
10647 cplus_lang
->printchar (value
, type
, &buf
);
10650 struct value_print_options opts
;
10653 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10657 baton
->per_objfile
);
10658 else if (bytes
!= NULL
)
10660 v
= allocate_value (type
);
10661 memcpy (value_contents_writeable (v
), bytes
,
10662 TYPE_LENGTH (type
));
10665 v
= value_from_longest (type
, value
);
10667 /* Specify decimal so that we do not depend on
10669 get_formatted_print_options (&opts
, 'd');
10671 value_print (v
, &buf
, &opts
);
10676 die
->building_fullname
= 0;
10680 /* Close the argument list, with a space if necessary
10681 (nested templates). */
10682 if (!buf
.empty () && buf
.string ().back () == '>')
10689 /* For C++ methods, append formal parameter type
10690 information, if PHYSNAME. */
10692 if (physname
&& die
->tag
== DW_TAG_subprogram
10693 && cu
->language
== language_cplus
)
10695 struct type
*type
= read_type_die (die
, cu
);
10697 c_type_print_args (type
, &buf
, 1, cu
->language
,
10698 &type_print_raw_options
);
10700 if (cu
->language
== language_cplus
)
10702 /* Assume that an artificial first parameter is
10703 "this", but do not crash if it is not. RealView
10704 marks unnamed (and thus unused) parameters as
10705 artificial; there is no way to differentiate
10707 if (type
->num_fields () > 0
10708 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10709 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10710 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10711 buf
.puts (" const");
10715 const std::string
&intermediate_name
= buf
.string ();
10717 if (cu
->language
== language_cplus
)
10719 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10722 /* If we only computed INTERMEDIATE_NAME, or if
10723 INTERMEDIATE_NAME is already canonical, then we need to
10725 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10726 name
= objfile
->intern (intermediate_name
);
10728 name
= canonical_name
;
10735 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10736 If scope qualifiers are appropriate they will be added. The result
10737 will be allocated on the storage_obstack, or NULL if the DIE does
10738 not have a name. NAME may either be from a previous call to
10739 dwarf2_name or NULL.
10741 The output string will be canonicalized (if C++). */
10743 static const char *
10744 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10746 return dwarf2_compute_name (name
, die
, cu
, 0);
10749 /* Construct a physname for the given DIE in CU. NAME may either be
10750 from a previous call to dwarf2_name or NULL. The result will be
10751 allocated on the objfile_objstack or NULL if the DIE does not have a
10754 The output string will be canonicalized (if C++). */
10756 static const char *
10757 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10759 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10760 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10763 /* In this case dwarf2_compute_name is just a shortcut not building anything
10765 if (!die_needs_namespace (die
, cu
))
10766 return dwarf2_compute_name (name
, die
, cu
, 1);
10768 if (cu
->language
!= language_rust
)
10769 mangled
= dw2_linkage_name (die
, cu
);
10771 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10773 gdb::unique_xmalloc_ptr
<char> demangled
;
10774 if (mangled
!= NULL
)
10777 if (language_def (cu
->language
)->store_sym_names_in_linkage_form_p ())
10779 /* Do nothing (do not demangle the symbol name). */
10783 /* Use DMGL_RET_DROP for C++ template functions to suppress
10784 their return type. It is easier for GDB users to search
10785 for such functions as `name(params)' than `long name(params)'.
10786 In such case the minimal symbol names do not match the full
10787 symbol names but for template functions there is never a need
10788 to look up their definition from their declaration so
10789 the only disadvantage remains the minimal symbol variant
10790 `long name(params)' does not have the proper inferior type. */
10791 demangled
.reset (gdb_demangle (mangled
,
10792 (DMGL_PARAMS
| DMGL_ANSI
10793 | DMGL_RET_DROP
)));
10796 canon
= demangled
.get ();
10804 if (canon
== NULL
|| check_physname
)
10806 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10808 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10810 /* It may not mean a bug in GDB. The compiler could also
10811 compute DW_AT_linkage_name incorrectly. But in such case
10812 GDB would need to be bug-to-bug compatible. */
10814 complaint (_("Computed physname <%s> does not match demangled <%s> "
10815 "(from linkage <%s>) - DIE at %s [in module %s]"),
10816 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10817 objfile_name (objfile
));
10819 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10820 is available here - over computed PHYSNAME. It is safer
10821 against both buggy GDB and buggy compilers. */
10835 retval
= objfile
->intern (retval
);
10840 /* Inspect DIE in CU for a namespace alias. If one exists, record
10841 a new symbol for it.
10843 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10846 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10848 struct attribute
*attr
;
10850 /* If the die does not have a name, this is not a namespace
10852 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10856 struct die_info
*d
= die
;
10857 struct dwarf2_cu
*imported_cu
= cu
;
10859 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10860 keep inspecting DIEs until we hit the underlying import. */
10861 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10862 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10864 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10868 d
= follow_die_ref (d
, attr
, &imported_cu
);
10869 if (d
->tag
!= DW_TAG_imported_declaration
)
10873 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10875 complaint (_("DIE at %s has too many recursively imported "
10876 "declarations"), sect_offset_str (d
->sect_off
));
10883 sect_offset sect_off
= attr
->get_ref_die_offset ();
10885 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10886 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10888 /* This declaration is a global namespace alias. Add
10889 a symbol for it whose type is the aliased namespace. */
10890 new_symbol (die
, type
, cu
);
10899 /* Return the using directives repository (global or local?) to use in the
10900 current context for CU.
10902 For Ada, imported declarations can materialize renamings, which *may* be
10903 global. However it is impossible (for now?) in DWARF to distinguish
10904 "external" imported declarations and "static" ones. As all imported
10905 declarations seem to be static in all other languages, make them all CU-wide
10906 global only in Ada. */
10908 static struct using_direct
**
10909 using_directives (struct dwarf2_cu
*cu
)
10911 if (cu
->language
== language_ada
10912 && cu
->get_builder ()->outermost_context_p ())
10913 return cu
->get_builder ()->get_global_using_directives ();
10915 return cu
->get_builder ()->get_local_using_directives ();
10918 /* Read the import statement specified by the given die and record it. */
10921 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10923 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10924 struct attribute
*import_attr
;
10925 struct die_info
*imported_die
, *child_die
;
10926 struct dwarf2_cu
*imported_cu
;
10927 const char *imported_name
;
10928 const char *imported_name_prefix
;
10929 const char *canonical_name
;
10930 const char *import_alias
;
10931 const char *imported_declaration
= NULL
;
10932 const char *import_prefix
;
10933 std::vector
<const char *> excludes
;
10935 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10936 if (import_attr
== NULL
)
10938 complaint (_("Tag '%s' has no DW_AT_import"),
10939 dwarf_tag_name (die
->tag
));
10944 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10945 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10946 if (imported_name
== NULL
)
10948 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10950 The import in the following code:
10964 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10965 <52> DW_AT_decl_file : 1
10966 <53> DW_AT_decl_line : 6
10967 <54> DW_AT_import : <0x75>
10968 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10969 <59> DW_AT_name : B
10970 <5b> DW_AT_decl_file : 1
10971 <5c> DW_AT_decl_line : 2
10972 <5d> DW_AT_type : <0x6e>
10974 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10975 <76> DW_AT_byte_size : 4
10976 <77> DW_AT_encoding : 5 (signed)
10978 imports the wrong die ( 0x75 instead of 0x58 ).
10979 This case will be ignored until the gcc bug is fixed. */
10983 /* Figure out the local name after import. */
10984 import_alias
= dwarf2_name (die
, cu
);
10986 /* Figure out where the statement is being imported to. */
10987 import_prefix
= determine_prefix (die
, cu
);
10989 /* Figure out what the scope of the imported die is and prepend it
10990 to the name of the imported die. */
10991 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10993 if (imported_die
->tag
!= DW_TAG_namespace
10994 && imported_die
->tag
!= DW_TAG_module
)
10996 imported_declaration
= imported_name
;
10997 canonical_name
= imported_name_prefix
;
10999 else if (strlen (imported_name_prefix
) > 0)
11000 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11001 imported_name_prefix
,
11002 (cu
->language
== language_d
? "." : "::"),
11003 imported_name
, (char *) NULL
);
11005 canonical_name
= imported_name
;
11007 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11008 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11009 child_die
= child_die
->sibling
)
11011 /* DWARF-4: A Fortran use statement with a “rename list” may be
11012 represented by an imported module entry with an import attribute
11013 referring to the module and owned entries corresponding to those
11014 entities that are renamed as part of being imported. */
11016 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11018 complaint (_("child DW_TAG_imported_declaration expected "
11019 "- DIE at %s [in module %s]"),
11020 sect_offset_str (child_die
->sect_off
),
11021 objfile_name (objfile
));
11025 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11026 if (import_attr
== NULL
)
11028 complaint (_("Tag '%s' has no DW_AT_import"),
11029 dwarf_tag_name (child_die
->tag
));
11034 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11036 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11037 if (imported_name
== NULL
)
11039 complaint (_("child DW_TAG_imported_declaration has unknown "
11040 "imported name - DIE at %s [in module %s]"),
11041 sect_offset_str (child_die
->sect_off
),
11042 objfile_name (objfile
));
11046 excludes
.push_back (imported_name
);
11048 process_die (child_die
, cu
);
11051 add_using_directive (using_directives (cu
),
11055 imported_declaration
,
11058 &objfile
->objfile_obstack
);
11061 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11062 types, but gives them a size of zero. Starting with version 14,
11063 ICC is compatible with GCC. */
11066 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11068 if (!cu
->checked_producer
)
11069 check_producer (cu
);
11071 return cu
->producer_is_icc_lt_14
;
11074 /* ICC generates a DW_AT_type for C void functions. This was observed on
11075 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11076 which says that void functions should not have a DW_AT_type. */
11079 producer_is_icc (struct dwarf2_cu
*cu
)
11081 if (!cu
->checked_producer
)
11082 check_producer (cu
);
11084 return cu
->producer_is_icc
;
11087 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11088 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11089 this, it was first present in GCC release 4.3.0. */
11092 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11094 if (!cu
->checked_producer
)
11095 check_producer (cu
);
11097 return cu
->producer_is_gcc_lt_4_3
;
11100 static file_and_directory
11101 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11103 file_and_directory res
;
11105 /* Find the filename. Do not use dwarf2_name here, since the filename
11106 is not a source language identifier. */
11107 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11108 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11110 if (res
.comp_dir
== NULL
11111 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11112 && IS_ABSOLUTE_PATH (res
.name
))
11114 res
.comp_dir_storage
= ldirname (res
.name
);
11115 if (!res
.comp_dir_storage
.empty ())
11116 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11118 if (res
.comp_dir
!= NULL
)
11120 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11121 directory, get rid of it. */
11122 const char *cp
= strchr (res
.comp_dir
, ':');
11124 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11125 res
.comp_dir
= cp
+ 1;
11128 if (res
.name
== NULL
)
11129 res
.name
= "<unknown>";
11134 /* Handle DW_AT_stmt_list for a compilation unit.
11135 DIE is the DW_TAG_compile_unit die for CU.
11136 COMP_DIR is the compilation directory. LOWPC is passed to
11137 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11140 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11141 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11143 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11144 struct attribute
*attr
;
11145 struct line_header line_header_local
;
11146 hashval_t line_header_local_hash
;
11148 int decode_mapping
;
11150 gdb_assert (! cu
->per_cu
->is_debug_types
);
11152 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11153 if (attr
== NULL
|| !attr
->form_is_unsigned ())
11156 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11158 /* The line header hash table is only created if needed (it exists to
11159 prevent redundant reading of the line table for partial_units).
11160 If we're given a partial_unit, we'll need it. If we're given a
11161 compile_unit, then use the line header hash table if it's already
11162 created, but don't create one just yet. */
11164 if (per_objfile
->line_header_hash
== NULL
11165 && die
->tag
== DW_TAG_partial_unit
)
11167 per_objfile
->line_header_hash
11168 .reset (htab_create_alloc (127, line_header_hash_voidp
,
11169 line_header_eq_voidp
,
11170 free_line_header_voidp
,
11174 line_header_local
.sect_off
= line_offset
;
11175 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11176 line_header_local_hash
= line_header_hash (&line_header_local
);
11177 if (per_objfile
->line_header_hash
!= NULL
)
11179 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11180 &line_header_local
,
11181 line_header_local_hash
, NO_INSERT
);
11183 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11184 is not present in *SLOT (since if there is something in *SLOT then
11185 it will be for a partial_unit). */
11186 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11188 gdb_assert (*slot
!= NULL
);
11189 cu
->line_header
= (struct line_header
*) *slot
;
11194 /* dwarf_decode_line_header does not yet provide sufficient information.
11195 We always have to call also dwarf_decode_lines for it. */
11196 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11200 cu
->line_header
= lh
.release ();
11201 cu
->line_header_die_owner
= die
;
11203 if (per_objfile
->line_header_hash
== NULL
)
11207 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11208 &line_header_local
,
11209 line_header_local_hash
, INSERT
);
11210 gdb_assert (slot
!= NULL
);
11212 if (slot
!= NULL
&& *slot
== NULL
)
11214 /* This newly decoded line number information unit will be owned
11215 by line_header_hash hash table. */
11216 *slot
= cu
->line_header
;
11217 cu
->line_header_die_owner
= NULL
;
11221 /* We cannot free any current entry in (*slot) as that struct line_header
11222 may be already used by multiple CUs. Create only temporary decoded
11223 line_header for this CU - it may happen at most once for each line
11224 number information unit. And if we're not using line_header_hash
11225 then this is what we want as well. */
11226 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11228 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11229 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11234 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11237 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11239 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11240 struct objfile
*objfile
= per_objfile
->objfile
;
11241 struct gdbarch
*gdbarch
= objfile
->arch ();
11242 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11243 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11244 struct attribute
*attr
;
11245 struct die_info
*child_die
;
11246 CORE_ADDR baseaddr
;
11248 prepare_one_comp_unit (cu
, die
, cu
->language
);
11249 baseaddr
= objfile
->text_section_offset ();
11251 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11253 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11254 from finish_block. */
11255 if (lowpc
== ((CORE_ADDR
) -1))
11257 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11259 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11261 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11262 standardised yet. As a workaround for the language detection we fall
11263 back to the DW_AT_producer string. */
11264 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11265 cu
->language
= language_opencl
;
11267 /* Similar hack for Go. */
11268 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11269 set_cu_language (DW_LANG_Go
, cu
);
11271 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11273 /* Decode line number information if present. We do this before
11274 processing child DIEs, so that the line header table is available
11275 for DW_AT_decl_file. */
11276 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11278 /* Process all dies in compilation unit. */
11279 if (die
->child
!= NULL
)
11281 child_die
= die
->child
;
11282 while (child_die
&& child_die
->tag
)
11284 process_die (child_die
, cu
);
11285 child_die
= child_die
->sibling
;
11289 /* Decode macro information, if present. Dwarf 2 macro information
11290 refers to information in the line number info statement program
11291 header, so we can only read it if we've read the header
11293 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11295 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11296 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11298 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11299 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11301 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
11305 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11306 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11308 unsigned int macro_offset
= attr
->as_unsigned ();
11310 dwarf_decode_macros (cu
, macro_offset
, 0);
11316 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11318 struct type_unit_group
*tu_group
;
11320 struct attribute
*attr
;
11322 struct signatured_type
*sig_type
;
11324 gdb_assert (per_cu
->is_debug_types
);
11325 sig_type
= (struct signatured_type
*) per_cu
;
11327 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11329 /* If we're using .gdb_index (includes -readnow) then
11330 per_cu->type_unit_group may not have been set up yet. */
11331 if (sig_type
->type_unit_group
== NULL
)
11332 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11333 tu_group
= sig_type
->type_unit_group
;
11335 /* If we've already processed this stmt_list there's no real need to
11336 do it again, we could fake it and just recreate the part we need
11337 (file name,index -> symtab mapping). If data shows this optimization
11338 is useful we can do it then. */
11339 type_unit_group_unshareable
*tug_unshare
11340 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11341 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11343 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11346 if (attr
!= NULL
&& attr
->form_is_unsigned ())
11348 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11349 lh
= dwarf_decode_line_header (line_offset
, this);
11354 start_symtab ("", NULL
, 0);
11357 gdb_assert (tug_unshare
->symtabs
== NULL
);
11358 gdb_assert (m_builder
== nullptr);
11359 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11360 m_builder
.reset (new struct buildsym_compunit
11361 (COMPUNIT_OBJFILE (cust
), "",
11362 COMPUNIT_DIRNAME (cust
),
11363 compunit_language (cust
),
11365 list_in_scope
= get_builder ()->get_file_symbols ();
11370 line_header
= lh
.release ();
11371 line_header_die_owner
= die
;
11375 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11377 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11378 still initializing it, and our caller (a few levels up)
11379 process_full_type_unit still needs to know if this is the first
11382 tug_unshare
->symtabs
11383 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11384 struct symtab
*, line_header
->file_names_size ());
11386 auto &file_names
= line_header
->file_names ();
11387 for (i
= 0; i
< file_names
.size (); ++i
)
11389 file_entry
&fe
= file_names
[i
];
11390 dwarf2_start_subfile (this, fe
.name
,
11391 fe
.include_dir (line_header
));
11392 buildsym_compunit
*b
= get_builder ();
11393 if (b
->get_current_subfile ()->symtab
== NULL
)
11395 /* NOTE: start_subfile will recognize when it's been
11396 passed a file it has already seen. So we can't
11397 assume there's a simple mapping from
11398 cu->line_header->file_names to subfiles, plus
11399 cu->line_header->file_names may contain dups. */
11400 b
->get_current_subfile ()->symtab
11401 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11404 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11405 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11410 gdb_assert (m_builder
== nullptr);
11411 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11412 m_builder
.reset (new struct buildsym_compunit
11413 (COMPUNIT_OBJFILE (cust
), "",
11414 COMPUNIT_DIRNAME (cust
),
11415 compunit_language (cust
),
11417 list_in_scope
= get_builder ()->get_file_symbols ();
11419 auto &file_names
= line_header
->file_names ();
11420 for (i
= 0; i
< file_names
.size (); ++i
)
11422 file_entry
&fe
= file_names
[i
];
11423 fe
.symtab
= tug_unshare
->symtabs
[i
];
11427 /* The main symtab is allocated last. Type units don't have DW_AT_name
11428 so they don't have a "real" (so to speak) symtab anyway.
11429 There is later code that will assign the main symtab to all symbols
11430 that don't have one. We need to handle the case of a symbol with a
11431 missing symtab (DW_AT_decl_file) anyway. */
11434 /* Process DW_TAG_type_unit.
11435 For TUs we want to skip the first top level sibling if it's not the
11436 actual type being defined by this TU. In this case the first top
11437 level sibling is there to provide context only. */
11440 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11442 struct die_info
*child_die
;
11444 prepare_one_comp_unit (cu
, die
, language_minimal
);
11446 /* Initialize (or reinitialize) the machinery for building symtabs.
11447 We do this before processing child DIEs, so that the line header table
11448 is available for DW_AT_decl_file. */
11449 cu
->setup_type_unit_groups (die
);
11451 if (die
->child
!= NULL
)
11453 child_die
= die
->child
;
11454 while (child_die
&& child_die
->tag
)
11456 process_die (child_die
, cu
);
11457 child_die
= child_die
->sibling
;
11464 http://gcc.gnu.org/wiki/DebugFission
11465 http://gcc.gnu.org/wiki/DebugFissionDWP
11467 To simplify handling of both DWO files ("object" files with the DWARF info)
11468 and DWP files (a file with the DWOs packaged up into one file), we treat
11469 DWP files as having a collection of virtual DWO files. */
11472 hash_dwo_file (const void *item
)
11474 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11477 hash
= htab_hash_string (dwo_file
->dwo_name
);
11478 if (dwo_file
->comp_dir
!= NULL
)
11479 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11484 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11486 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11487 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11489 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11491 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11492 return lhs
->comp_dir
== rhs
->comp_dir
;
11493 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11496 /* Allocate a hash table for DWO files. */
11499 allocate_dwo_file_hash_table ()
11501 auto delete_dwo_file
= [] (void *item
)
11503 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11508 return htab_up (htab_create_alloc (41,
11515 /* Lookup DWO file DWO_NAME. */
11518 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11519 const char *dwo_name
,
11520 const char *comp_dir
)
11522 struct dwo_file find_entry
;
11525 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11526 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11528 find_entry
.dwo_name
= dwo_name
;
11529 find_entry
.comp_dir
= comp_dir
;
11530 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11537 hash_dwo_unit (const void *item
)
11539 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11541 /* This drops the top 32 bits of the id, but is ok for a hash. */
11542 return dwo_unit
->signature
;
11546 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11548 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11549 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11551 /* The signature is assumed to be unique within the DWO file.
11552 So while object file CU dwo_id's always have the value zero,
11553 that's OK, assuming each object file DWO file has only one CU,
11554 and that's the rule for now. */
11555 return lhs
->signature
== rhs
->signature
;
11558 /* Allocate a hash table for DWO CUs,TUs.
11559 There is one of these tables for each of CUs,TUs for each DWO file. */
11562 allocate_dwo_unit_table ()
11564 /* Start out with a pretty small number.
11565 Generally DWO files contain only one CU and maybe some TUs. */
11566 return htab_up (htab_create_alloc (3,
11569 NULL
, xcalloc
, xfree
));
11572 /* die_reader_func for create_dwo_cu. */
11575 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11576 const gdb_byte
*info_ptr
,
11577 struct die_info
*comp_unit_die
,
11578 struct dwo_file
*dwo_file
,
11579 struct dwo_unit
*dwo_unit
)
11581 struct dwarf2_cu
*cu
= reader
->cu
;
11582 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11583 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11585 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11586 if (!signature
.has_value ())
11588 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11589 " its dwo_id [in module %s]"),
11590 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11594 dwo_unit
->dwo_file
= dwo_file
;
11595 dwo_unit
->signature
= *signature
;
11596 dwo_unit
->section
= section
;
11597 dwo_unit
->sect_off
= sect_off
;
11598 dwo_unit
->length
= cu
->per_cu
->length
;
11600 dwarf_read_debug_printf (" offset %s, dwo_id %s",
11601 sect_offset_str (sect_off
),
11602 hex_string (dwo_unit
->signature
));
11605 /* Create the dwo_units for the CUs in a DWO_FILE.
11606 Note: This function processes DWO files only, not DWP files. */
11609 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11610 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11611 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11613 struct objfile
*objfile
= per_objfile
->objfile
;
11614 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11615 const gdb_byte
*info_ptr
, *end_ptr
;
11617 section
.read (objfile
);
11618 info_ptr
= section
.buffer
;
11620 if (info_ptr
== NULL
)
11623 dwarf_read_debug_printf ("Reading %s for %s:",
11624 section
.get_name (),
11625 section
.get_file_name ());
11627 end_ptr
= info_ptr
+ section
.size
;
11628 while (info_ptr
< end_ptr
)
11630 struct dwarf2_per_cu_data per_cu
;
11631 struct dwo_unit read_unit
{};
11632 struct dwo_unit
*dwo_unit
;
11634 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11636 memset (&per_cu
, 0, sizeof (per_cu
));
11637 per_cu
.per_bfd
= per_bfd
;
11638 per_cu
.is_debug_types
= 0;
11639 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11640 per_cu
.section
= §ion
;
11642 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11643 if (!reader
.dummy_p
)
11644 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11645 &dwo_file
, &read_unit
);
11646 info_ptr
+= per_cu
.length
;
11648 // If the unit could not be parsed, skip it.
11649 if (read_unit
.dwo_file
== NULL
)
11652 if (cus_htab
== NULL
)
11653 cus_htab
= allocate_dwo_unit_table ();
11655 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11657 *dwo_unit
= read_unit
;
11658 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11659 gdb_assert (slot
!= NULL
);
11662 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11663 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11665 complaint (_("debug cu entry at offset %s is duplicate to"
11666 " the entry at offset %s, signature %s"),
11667 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11668 hex_string (dwo_unit
->signature
));
11670 *slot
= (void *)dwo_unit
;
11674 /* DWP file .debug_{cu,tu}_index section format:
11675 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11676 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11678 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11679 officially standard DWP format was published with DWARF v5 and is called
11680 Version 5. There are no versions 3 or 4.
11684 Both index sections have the same format, and serve to map a 64-bit
11685 signature to a set of section numbers. Each section begins with a header,
11686 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11687 indexes, and a pool of 32-bit section numbers. The index sections will be
11688 aligned at 8-byte boundaries in the file.
11690 The index section header consists of:
11692 V, 32 bit version number
11694 N, 32 bit number of compilation units or type units in the index
11695 M, 32 bit number of slots in the hash table
11697 Numbers are recorded using the byte order of the application binary.
11699 The hash table begins at offset 16 in the section, and consists of an array
11700 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11701 order of the application binary). Unused slots in the hash table are 0.
11702 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11704 The parallel table begins immediately after the hash table
11705 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11706 array of 32-bit indexes (using the byte order of the application binary),
11707 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11708 table contains a 32-bit index into the pool of section numbers. For unused
11709 hash table slots, the corresponding entry in the parallel table will be 0.
11711 The pool of section numbers begins immediately following the hash table
11712 (at offset 16 + 12 * M from the beginning of the section). The pool of
11713 section numbers consists of an array of 32-bit words (using the byte order
11714 of the application binary). Each item in the array is indexed starting
11715 from 0. The hash table entry provides the index of the first section
11716 number in the set. Additional section numbers in the set follow, and the
11717 set is terminated by a 0 entry (section number 0 is not used in ELF).
11719 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11720 section must be the first entry in the set, and the .debug_abbrev.dwo must
11721 be the second entry. Other members of the set may follow in any order.
11725 DWP Versions 2 and 5:
11727 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11728 and the entries in the index tables are now offsets into these sections.
11729 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11732 Index Section Contents:
11734 Hash Table of Signatures dwp_hash_table.hash_table
11735 Parallel Table of Indices dwp_hash_table.unit_table
11736 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11737 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11739 The index section header consists of:
11741 V, 32 bit version number
11742 L, 32 bit number of columns in the table of section offsets
11743 N, 32 bit number of compilation units or type units in the index
11744 M, 32 bit number of slots in the hash table
11746 Numbers are recorded using the byte order of the application binary.
11748 The hash table has the same format as version 1.
11749 The parallel table of indices has the same format as version 1,
11750 except that the entries are origin-1 indices into the table of sections
11751 offsets and the table of section sizes.
11753 The table of offsets begins immediately following the parallel table
11754 (at offset 16 + 12 * M from the beginning of the section). The table is
11755 a two-dimensional array of 32-bit words (using the byte order of the
11756 application binary), with L columns and N+1 rows, in row-major order.
11757 Each row in the array is indexed starting from 0. The first row provides
11758 a key to the remaining rows: each column in this row provides an identifier
11759 for a debug section, and the offsets in the same column of subsequent rows
11760 refer to that section. The section identifiers for Version 2 are:
11762 DW_SECT_INFO 1 .debug_info.dwo
11763 DW_SECT_TYPES 2 .debug_types.dwo
11764 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11765 DW_SECT_LINE 4 .debug_line.dwo
11766 DW_SECT_LOC 5 .debug_loc.dwo
11767 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11768 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11769 DW_SECT_MACRO 8 .debug_macro.dwo
11771 The section identifiers for Version 5 are:
11773 DW_SECT_INFO_V5 1 .debug_info.dwo
11774 DW_SECT_RESERVED_V5 2 --
11775 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11776 DW_SECT_LINE_V5 4 .debug_line.dwo
11777 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11778 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11779 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11780 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11782 The offsets provided by the CU and TU index sections are the base offsets
11783 for the contributions made by each CU or TU to the corresponding section
11784 in the package file. Each CU and TU header contains an abbrev_offset
11785 field, used to find the abbreviations table for that CU or TU within the
11786 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11787 be interpreted as relative to the base offset given in the index section.
11788 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11789 should be interpreted as relative to the base offset for .debug_line.dwo,
11790 and offsets into other debug sections obtained from DWARF attributes should
11791 also be interpreted as relative to the corresponding base offset.
11793 The table of sizes begins immediately following the table of offsets.
11794 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11795 with L columns and N rows, in row-major order. Each row in the array is
11796 indexed starting from 1 (row 0 is shared by the two tables).
11800 Hash table lookup is handled the same in version 1 and 2:
11802 We assume that N and M will not exceed 2^32 - 1.
11803 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11805 Given a 64-bit compilation unit signature or a type signature S, an entry
11806 in the hash table is located as follows:
11808 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11809 the low-order k bits all set to 1.
11811 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11813 3) If the hash table entry at index H matches the signature, use that
11814 entry. If the hash table entry at index H is unused (all zeroes),
11815 terminate the search: the signature is not present in the table.
11817 4) Let H = (H + H') modulo M. Repeat at Step 3.
11819 Because M > N and H' and M are relatively prime, the search is guaranteed
11820 to stop at an unused slot or find the match. */
11822 /* Create a hash table to map DWO IDs to their CU/TU entry in
11823 .debug_{info,types}.dwo in DWP_FILE.
11824 Returns NULL if there isn't one.
11825 Note: This function processes DWP files only, not DWO files. */
11827 static struct dwp_hash_table
*
11828 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11829 struct dwp_file
*dwp_file
, int is_debug_types
)
11831 struct objfile
*objfile
= per_objfile
->objfile
;
11832 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11833 const gdb_byte
*index_ptr
, *index_end
;
11834 struct dwarf2_section_info
*index
;
11835 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11836 struct dwp_hash_table
*htab
;
11838 if (is_debug_types
)
11839 index
= &dwp_file
->sections
.tu_index
;
11841 index
= &dwp_file
->sections
.cu_index
;
11843 if (index
->empty ())
11845 index
->read (objfile
);
11847 index_ptr
= index
->buffer
;
11848 index_end
= index_ptr
+ index
->size
;
11850 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11851 For now it's safe to just read 4 bytes (particularly as it's difficult to
11852 tell if you're dealing with Version 5 before you've read the version). */
11853 version
= read_4_bytes (dbfd
, index_ptr
);
11855 if (version
== 2 || version
== 5)
11856 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11860 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11862 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11865 if (version
!= 1 && version
!= 2 && version
!= 5)
11867 error (_("Dwarf Error: unsupported DWP file version (%s)"
11868 " [in module %s]"),
11869 pulongest (version
), dwp_file
->name
);
11871 if (nr_slots
!= (nr_slots
& -nr_slots
))
11873 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11874 " is not power of 2 [in module %s]"),
11875 pulongest (nr_slots
), dwp_file
->name
);
11878 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11879 htab
->version
= version
;
11880 htab
->nr_columns
= nr_columns
;
11881 htab
->nr_units
= nr_units
;
11882 htab
->nr_slots
= nr_slots
;
11883 htab
->hash_table
= index_ptr
;
11884 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11886 /* Exit early if the table is empty. */
11887 if (nr_slots
== 0 || nr_units
== 0
11888 || (version
== 2 && nr_columns
== 0)
11889 || (version
== 5 && nr_columns
== 0))
11891 /* All must be zero. */
11892 if (nr_slots
!= 0 || nr_units
!= 0
11893 || (version
== 2 && nr_columns
!= 0)
11894 || (version
== 5 && nr_columns
!= 0))
11896 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11897 " all zero [in modules %s]"),
11905 htab
->section_pool
.v1
.indices
=
11906 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11907 /* It's harder to decide whether the section is too small in v1.
11908 V1 is deprecated anyway so we punt. */
11910 else if (version
== 2)
11912 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11913 int *ids
= htab
->section_pool
.v2
.section_ids
;
11914 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11915 /* Reverse map for error checking. */
11916 int ids_seen
[DW_SECT_MAX
+ 1];
11919 if (nr_columns
< 2)
11921 error (_("Dwarf Error: bad DWP hash table, too few columns"
11922 " in section table [in module %s]"),
11925 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11927 error (_("Dwarf Error: bad DWP hash table, too many columns"
11928 " in section table [in module %s]"),
11931 memset (ids
, 255, sizeof_ids
);
11932 memset (ids_seen
, 255, sizeof (ids_seen
));
11933 for (i
= 0; i
< nr_columns
; ++i
)
11935 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11937 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11939 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11940 " in section table [in module %s]"),
11941 id
, dwp_file
->name
);
11943 if (ids_seen
[id
] != -1)
11945 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11946 " id %d in section table [in module %s]"),
11947 id
, dwp_file
->name
);
11952 /* Must have exactly one info or types section. */
11953 if (((ids_seen
[DW_SECT_INFO
] != -1)
11954 + (ids_seen
[DW_SECT_TYPES
] != -1))
11957 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11958 " DWO info/types section [in module %s]"),
11961 /* Must have an abbrev section. */
11962 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11964 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11965 " section [in module %s]"),
11968 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11969 htab
->section_pool
.v2
.sizes
=
11970 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11971 * nr_units
* nr_columns
);
11972 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11973 * nr_units
* nr_columns
))
11976 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11977 " [in module %s]"),
11981 else /* version == 5 */
11983 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11984 int *ids
= htab
->section_pool
.v5
.section_ids
;
11985 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11986 /* Reverse map for error checking. */
11987 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11989 if (nr_columns
< 2)
11991 error (_("Dwarf Error: bad DWP hash table, too few columns"
11992 " in section table [in module %s]"),
11995 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11997 error (_("Dwarf Error: bad DWP hash table, too many columns"
11998 " in section table [in module %s]"),
12001 memset (ids
, 255, sizeof_ids
);
12002 memset (ids_seen
, 255, sizeof (ids_seen
));
12003 for (int i
= 0; i
< nr_columns
; ++i
)
12005 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12007 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
12009 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12010 " in section table [in module %s]"),
12011 id
, dwp_file
->name
);
12013 if (ids_seen
[id
] != -1)
12015 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12016 " id %d in section table [in module %s]"),
12017 id
, dwp_file
->name
);
12022 /* Must have seen an info section. */
12023 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
12025 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12026 " DWO info/types section [in module %s]"),
12029 /* Must have an abbrev section. */
12030 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
12032 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12033 " section [in module %s]"),
12036 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12037 htab
->section_pool
.v5
.sizes
12038 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
12039 * nr_units
* nr_columns
);
12040 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
12041 * nr_units
* nr_columns
))
12044 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12045 " [in module %s]"),
12053 /* Update SECTIONS with the data from SECTP.
12055 This function is like the other "locate" section routines, but in
12056 this context the sections to read comes from the DWP V1 hash table,
12057 not the full ELF section table.
12059 The result is non-zero for success, or zero if an error was found. */
12062 locate_v1_virtual_dwo_sections (asection
*sectp
,
12063 struct virtual_v1_dwo_sections
*sections
)
12065 const struct dwop_section_names
*names
= &dwop_section_names
;
12067 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12069 /* There can be only one. */
12070 if (sections
->abbrev
.s
.section
!= NULL
)
12072 sections
->abbrev
.s
.section
= sectp
;
12073 sections
->abbrev
.size
= bfd_section_size (sectp
);
12075 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12076 || section_is_p (sectp
->name
, &names
->types_dwo
))
12078 /* There can be only one. */
12079 if (sections
->info_or_types
.s
.section
!= NULL
)
12081 sections
->info_or_types
.s
.section
= sectp
;
12082 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12084 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12086 /* There can be only one. */
12087 if (sections
->line
.s
.section
!= NULL
)
12089 sections
->line
.s
.section
= sectp
;
12090 sections
->line
.size
= bfd_section_size (sectp
);
12092 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12094 /* There can be only one. */
12095 if (sections
->loc
.s
.section
!= NULL
)
12097 sections
->loc
.s
.section
= sectp
;
12098 sections
->loc
.size
= bfd_section_size (sectp
);
12100 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12102 /* There can be only one. */
12103 if (sections
->macinfo
.s
.section
!= NULL
)
12105 sections
->macinfo
.s
.section
= sectp
;
12106 sections
->macinfo
.size
= bfd_section_size (sectp
);
12108 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12110 /* There can be only one. */
12111 if (sections
->macro
.s
.section
!= NULL
)
12113 sections
->macro
.s
.section
= sectp
;
12114 sections
->macro
.size
= bfd_section_size (sectp
);
12116 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12118 /* There can be only one. */
12119 if (sections
->str_offsets
.s
.section
!= NULL
)
12121 sections
->str_offsets
.s
.section
= sectp
;
12122 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12126 /* No other kind of section is valid. */
12133 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12134 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12135 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12136 This is for DWP version 1 files. */
12138 static struct dwo_unit
*
12139 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
12140 struct dwp_file
*dwp_file
,
12141 uint32_t unit_index
,
12142 const char *comp_dir
,
12143 ULONGEST signature
, int is_debug_types
)
12145 const struct dwp_hash_table
*dwp_htab
=
12146 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12147 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12148 const char *kind
= is_debug_types
? "TU" : "CU";
12149 struct dwo_file
*dwo_file
;
12150 struct dwo_unit
*dwo_unit
;
12151 struct virtual_v1_dwo_sections sections
;
12152 void **dwo_file_slot
;
12155 gdb_assert (dwp_file
->version
== 1);
12157 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
12158 kind
, pulongest (unit_index
), hex_string (signature
),
12161 /* Fetch the sections of this DWO unit.
12162 Put a limit on the number of sections we look for so that bad data
12163 doesn't cause us to loop forever. */
12165 #define MAX_NR_V1_DWO_SECTIONS \
12166 (1 /* .debug_info or .debug_types */ \
12167 + 1 /* .debug_abbrev */ \
12168 + 1 /* .debug_line */ \
12169 + 1 /* .debug_loc */ \
12170 + 1 /* .debug_str_offsets */ \
12171 + 1 /* .debug_macro or .debug_macinfo */ \
12172 + 1 /* trailing zero */)
12174 memset (§ions
, 0, sizeof (sections
));
12176 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12179 uint32_t section_nr
=
12180 read_4_bytes (dbfd
,
12181 dwp_htab
->section_pool
.v1
.indices
12182 + (unit_index
+ i
) * sizeof (uint32_t));
12184 if (section_nr
== 0)
12186 if (section_nr
>= dwp_file
->num_sections
)
12188 error (_("Dwarf Error: bad DWP hash table, section number too large"
12189 " [in module %s]"),
12193 sectp
= dwp_file
->elf_sections
[section_nr
];
12194 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12196 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12197 " [in module %s]"),
12203 || sections
.info_or_types
.empty ()
12204 || sections
.abbrev
.empty ())
12206 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12207 " [in module %s]"),
12210 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12212 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12213 " [in module %s]"),
12217 /* It's easier for the rest of the code if we fake a struct dwo_file and
12218 have dwo_unit "live" in that. At least for now.
12220 The DWP file can be made up of a random collection of CUs and TUs.
12221 However, for each CU + set of TUs that came from the same original DWO
12222 file, we can combine them back into a virtual DWO file to save space
12223 (fewer struct dwo_file objects to allocate). Remember that for really
12224 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12226 std::string virtual_dwo_name
=
12227 string_printf ("virtual-dwo/%d-%d-%d-%d",
12228 sections
.abbrev
.get_id (),
12229 sections
.line
.get_id (),
12230 sections
.loc
.get_id (),
12231 sections
.str_offsets
.get_id ());
12232 /* Can we use an existing virtual DWO file? */
12233 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12235 /* Create one if necessary. */
12236 if (*dwo_file_slot
== NULL
)
12238 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12239 virtual_dwo_name
.c_str ());
12241 dwo_file
= new struct dwo_file
;
12242 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12243 dwo_file
->comp_dir
= comp_dir
;
12244 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12245 dwo_file
->sections
.line
= sections
.line
;
12246 dwo_file
->sections
.loc
= sections
.loc
;
12247 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12248 dwo_file
->sections
.macro
= sections
.macro
;
12249 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12250 /* The "str" section is global to the entire DWP file. */
12251 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12252 /* The info or types section is assigned below to dwo_unit,
12253 there's no need to record it in dwo_file.
12254 Also, we can't simply record type sections in dwo_file because
12255 we record a pointer into the vector in dwo_unit. As we collect more
12256 types we'll grow the vector and eventually have to reallocate space
12257 for it, invalidating all copies of pointers into the previous
12259 *dwo_file_slot
= dwo_file
;
12263 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12264 virtual_dwo_name
.c_str ());
12266 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12269 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12270 dwo_unit
->dwo_file
= dwo_file
;
12271 dwo_unit
->signature
= signature
;
12272 dwo_unit
->section
=
12273 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12274 *dwo_unit
->section
= sections
.info_or_types
;
12275 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12280 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
12281 simplify them. Given a pointer to the containing section SECTION, and
12282 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
12283 virtual section of just that piece. */
12285 static struct dwarf2_section_info
12286 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
12287 struct dwarf2_section_info
*section
,
12288 bfd_size_type offset
, bfd_size_type size
)
12290 struct dwarf2_section_info result
;
12293 gdb_assert (section
!= NULL
);
12294 gdb_assert (!section
->is_virtual
);
12296 memset (&result
, 0, sizeof (result
));
12297 result
.s
.containing_section
= section
;
12298 result
.is_virtual
= true;
12303 sectp
= section
->get_bfd_section ();
12305 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12306 bounds of the real section. This is a pretty-rare event, so just
12307 flag an error (easier) instead of a warning and trying to cope. */
12309 || offset
+ size
> bfd_section_size (sectp
))
12311 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
12312 " in section %s [in module %s]"),
12313 sectp
? bfd_section_name (sectp
) : "<unknown>",
12314 objfile_name (per_objfile
->objfile
));
12317 result
.virtual_offset
= offset
;
12318 result
.size
= size
;
12322 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12323 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12324 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12325 This is for DWP version 2 files. */
12327 static struct dwo_unit
*
12328 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
12329 struct dwp_file
*dwp_file
,
12330 uint32_t unit_index
,
12331 const char *comp_dir
,
12332 ULONGEST signature
, int is_debug_types
)
12334 const struct dwp_hash_table
*dwp_htab
=
12335 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12336 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12337 const char *kind
= is_debug_types
? "TU" : "CU";
12338 struct dwo_file
*dwo_file
;
12339 struct dwo_unit
*dwo_unit
;
12340 struct virtual_v2_or_v5_dwo_sections sections
;
12341 void **dwo_file_slot
;
12344 gdb_assert (dwp_file
->version
== 2);
12346 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
12347 kind
, pulongest (unit_index
), hex_string (signature
),
12350 /* Fetch the section offsets of this DWO unit. */
12352 memset (§ions
, 0, sizeof (sections
));
12354 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12356 uint32_t offset
= read_4_bytes (dbfd
,
12357 dwp_htab
->section_pool
.v2
.offsets
12358 + (((unit_index
- 1) * dwp_htab
->nr_columns
12360 * sizeof (uint32_t)));
12361 uint32_t size
= read_4_bytes (dbfd
,
12362 dwp_htab
->section_pool
.v2
.sizes
12363 + (((unit_index
- 1) * dwp_htab
->nr_columns
12365 * sizeof (uint32_t)));
12367 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12370 case DW_SECT_TYPES
:
12371 sections
.info_or_types_offset
= offset
;
12372 sections
.info_or_types_size
= size
;
12374 case DW_SECT_ABBREV
:
12375 sections
.abbrev_offset
= offset
;
12376 sections
.abbrev_size
= size
;
12379 sections
.line_offset
= offset
;
12380 sections
.line_size
= size
;
12383 sections
.loc_offset
= offset
;
12384 sections
.loc_size
= size
;
12386 case DW_SECT_STR_OFFSETS
:
12387 sections
.str_offsets_offset
= offset
;
12388 sections
.str_offsets_size
= size
;
12390 case DW_SECT_MACINFO
:
12391 sections
.macinfo_offset
= offset
;
12392 sections
.macinfo_size
= size
;
12394 case DW_SECT_MACRO
:
12395 sections
.macro_offset
= offset
;
12396 sections
.macro_size
= size
;
12401 /* It's easier for the rest of the code if we fake a struct dwo_file and
12402 have dwo_unit "live" in that. At least for now.
12404 The DWP file can be made up of a random collection of CUs and TUs.
12405 However, for each CU + set of TUs that came from the same original DWO
12406 file, we can combine them back into a virtual DWO file to save space
12407 (fewer struct dwo_file objects to allocate). Remember that for really
12408 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12410 std::string virtual_dwo_name
=
12411 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12412 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12413 (long) (sections
.line_size
? sections
.line_offset
: 0),
12414 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12415 (long) (sections
.str_offsets_size
12416 ? sections
.str_offsets_offset
: 0));
12417 /* Can we use an existing virtual DWO file? */
12418 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12420 /* Create one if necessary. */
12421 if (*dwo_file_slot
== NULL
)
12423 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12424 virtual_dwo_name
.c_str ());
12426 dwo_file
= new struct dwo_file
;
12427 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12428 dwo_file
->comp_dir
= comp_dir
;
12429 dwo_file
->sections
.abbrev
=
12430 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12431 sections
.abbrev_offset
,
12432 sections
.abbrev_size
);
12433 dwo_file
->sections
.line
=
12434 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
12435 sections
.line_offset
,
12436 sections
.line_size
);
12437 dwo_file
->sections
.loc
=
12438 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
12439 sections
.loc_offset
, sections
.loc_size
);
12440 dwo_file
->sections
.macinfo
=
12441 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12442 sections
.macinfo_offset
,
12443 sections
.macinfo_size
);
12444 dwo_file
->sections
.macro
=
12445 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
12446 sections
.macro_offset
,
12447 sections
.macro_size
);
12448 dwo_file
->sections
.str_offsets
=
12449 create_dwp_v2_or_v5_section (per_objfile
,
12450 &dwp_file
->sections
.str_offsets
,
12451 sections
.str_offsets_offset
,
12452 sections
.str_offsets_size
);
12453 /* The "str" section is global to the entire DWP file. */
12454 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12455 /* The info or types section is assigned below to dwo_unit,
12456 there's no need to record it in dwo_file.
12457 Also, we can't simply record type sections in dwo_file because
12458 we record a pointer into the vector in dwo_unit. As we collect more
12459 types we'll grow the vector and eventually have to reallocate space
12460 for it, invalidating all copies of pointers into the previous
12462 *dwo_file_slot
= dwo_file
;
12466 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12467 virtual_dwo_name
.c_str ());
12469 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12472 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12473 dwo_unit
->dwo_file
= dwo_file
;
12474 dwo_unit
->signature
= signature
;
12475 dwo_unit
->section
=
12476 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12477 *dwo_unit
->section
= create_dwp_v2_or_v5_section
12480 ? &dwp_file
->sections
.types
12481 : &dwp_file
->sections
.info
,
12482 sections
.info_or_types_offset
,
12483 sections
.info_or_types_size
);
12484 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12489 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12490 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12491 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12492 This is for DWP version 5 files. */
12494 static struct dwo_unit
*
12495 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
12496 struct dwp_file
*dwp_file
,
12497 uint32_t unit_index
,
12498 const char *comp_dir
,
12499 ULONGEST signature
, int is_debug_types
)
12501 const struct dwp_hash_table
*dwp_htab
12502 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12503 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12504 const char *kind
= is_debug_types
? "TU" : "CU";
12505 struct dwo_file
*dwo_file
;
12506 struct dwo_unit
*dwo_unit
;
12507 struct virtual_v2_or_v5_dwo_sections sections
{};
12508 void **dwo_file_slot
;
12510 gdb_assert (dwp_file
->version
== 5);
12512 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
12513 kind
, pulongest (unit_index
), hex_string (signature
),
12516 /* Fetch the section offsets of this DWO unit. */
12518 /* memset (§ions, 0, sizeof (sections)); */
12520 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12522 uint32_t offset
= read_4_bytes (dbfd
,
12523 dwp_htab
->section_pool
.v5
.offsets
12524 + (((unit_index
- 1)
12525 * dwp_htab
->nr_columns
12527 * sizeof (uint32_t)));
12528 uint32_t size
= read_4_bytes (dbfd
,
12529 dwp_htab
->section_pool
.v5
.sizes
12530 + (((unit_index
- 1) * dwp_htab
->nr_columns
12532 * sizeof (uint32_t)));
12534 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
12536 case DW_SECT_ABBREV_V5
:
12537 sections
.abbrev_offset
= offset
;
12538 sections
.abbrev_size
= size
;
12540 case DW_SECT_INFO_V5
:
12541 sections
.info_or_types_offset
= offset
;
12542 sections
.info_or_types_size
= size
;
12544 case DW_SECT_LINE_V5
:
12545 sections
.line_offset
= offset
;
12546 sections
.line_size
= size
;
12548 case DW_SECT_LOCLISTS_V5
:
12549 sections
.loclists_offset
= offset
;
12550 sections
.loclists_size
= size
;
12552 case DW_SECT_MACRO_V5
:
12553 sections
.macro_offset
= offset
;
12554 sections
.macro_size
= size
;
12556 case DW_SECT_RNGLISTS_V5
:
12557 sections
.rnglists_offset
= offset
;
12558 sections
.rnglists_size
= size
;
12560 case DW_SECT_STR_OFFSETS_V5
:
12561 sections
.str_offsets_offset
= offset
;
12562 sections
.str_offsets_size
= size
;
12564 case DW_SECT_RESERVED_V5
:
12570 /* It's easier for the rest of the code if we fake a struct dwo_file and
12571 have dwo_unit "live" in that. At least for now.
12573 The DWP file can be made up of a random collection of CUs and TUs.
12574 However, for each CU + set of TUs that came from the same original DWO
12575 file, we can combine them back into a virtual DWO file to save space
12576 (fewer struct dwo_file objects to allocate). Remember that for really
12577 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12579 std::string virtual_dwo_name
=
12580 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
12581 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12582 (long) (sections
.line_size
? sections
.line_offset
: 0),
12583 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
12584 (long) (sections
.str_offsets_size
12585 ? sections
.str_offsets_offset
: 0),
12586 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
12587 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
12588 /* Can we use an existing virtual DWO file? */
12589 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
12590 virtual_dwo_name
.c_str (),
12592 /* Create one if necessary. */
12593 if (*dwo_file_slot
== NULL
)
12595 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12596 virtual_dwo_name
.c_str ());
12598 dwo_file
= new struct dwo_file
;
12599 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12600 dwo_file
->comp_dir
= comp_dir
;
12601 dwo_file
->sections
.abbrev
=
12602 create_dwp_v2_or_v5_section (per_objfile
,
12603 &dwp_file
->sections
.abbrev
,
12604 sections
.abbrev_offset
,
12605 sections
.abbrev_size
);
12606 dwo_file
->sections
.line
=
12607 create_dwp_v2_or_v5_section (per_objfile
,
12608 &dwp_file
->sections
.line
,
12609 sections
.line_offset
, sections
.line_size
);
12610 dwo_file
->sections
.macro
=
12611 create_dwp_v2_or_v5_section (per_objfile
,
12612 &dwp_file
->sections
.macro
,
12613 sections
.macro_offset
,
12614 sections
.macro_size
);
12615 dwo_file
->sections
.loclists
=
12616 create_dwp_v2_or_v5_section (per_objfile
,
12617 &dwp_file
->sections
.loclists
,
12618 sections
.loclists_offset
,
12619 sections
.loclists_size
);
12620 dwo_file
->sections
.rnglists
=
12621 create_dwp_v2_or_v5_section (per_objfile
,
12622 &dwp_file
->sections
.rnglists
,
12623 sections
.rnglists_offset
,
12624 sections
.rnglists_size
);
12625 dwo_file
->sections
.str_offsets
=
12626 create_dwp_v2_or_v5_section (per_objfile
,
12627 &dwp_file
->sections
.str_offsets
,
12628 sections
.str_offsets_offset
,
12629 sections
.str_offsets_size
);
12630 /* The "str" section is global to the entire DWP file. */
12631 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12632 /* The info or types section is assigned below to dwo_unit,
12633 there's no need to record it in dwo_file.
12634 Also, we can't simply record type sections in dwo_file because
12635 we record a pointer into the vector in dwo_unit. As we collect more
12636 types we'll grow the vector and eventually have to reallocate space
12637 for it, invalidating all copies of pointers into the previous
12639 *dwo_file_slot
= dwo_file
;
12643 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12644 virtual_dwo_name
.c_str ());
12646 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12649 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12650 dwo_unit
->dwo_file
= dwo_file
;
12651 dwo_unit
->signature
= signature
;
12653 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12654 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12655 &dwp_file
->sections
.info
,
12656 sections
.info_or_types_offset
,
12657 sections
.info_or_types_size
);
12658 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12663 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12664 Returns NULL if the signature isn't found. */
12666 static struct dwo_unit
*
12667 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12668 struct dwp_file
*dwp_file
, const char *comp_dir
,
12669 ULONGEST signature
, int is_debug_types
)
12671 const struct dwp_hash_table
*dwp_htab
=
12672 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12673 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12674 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12675 uint32_t hash
= signature
& mask
;
12676 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12679 struct dwo_unit find_dwo_cu
;
12681 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12682 find_dwo_cu
.signature
= signature
;
12683 slot
= htab_find_slot (is_debug_types
12684 ? dwp_file
->loaded_tus
.get ()
12685 : dwp_file
->loaded_cus
.get (),
12686 &find_dwo_cu
, INSERT
);
12689 return (struct dwo_unit
*) *slot
;
12691 /* Use a for loop so that we don't loop forever on bad debug info. */
12692 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12694 ULONGEST signature_in_table
;
12696 signature_in_table
=
12697 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12698 if (signature_in_table
== signature
)
12700 uint32_t unit_index
=
12701 read_4_bytes (dbfd
,
12702 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12704 if (dwp_file
->version
== 1)
12706 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12707 unit_index
, comp_dir
,
12708 signature
, is_debug_types
);
12710 else if (dwp_file
->version
== 2)
12712 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12713 unit_index
, comp_dir
,
12714 signature
, is_debug_types
);
12716 else /* version == 5 */
12718 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12719 unit_index
, comp_dir
,
12720 signature
, is_debug_types
);
12722 return (struct dwo_unit
*) *slot
;
12724 if (signature_in_table
== 0)
12726 hash
= (hash
+ hash2
) & mask
;
12729 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12730 " [in module %s]"),
12734 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12735 Open the file specified by FILE_NAME and hand it off to BFD for
12736 preliminary analysis. Return a newly initialized bfd *, which
12737 includes a canonicalized copy of FILE_NAME.
12738 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12739 SEARCH_CWD is true if the current directory is to be searched.
12740 It will be searched before debug-file-directory.
12741 If successful, the file is added to the bfd include table of the
12742 objfile's bfd (see gdb_bfd_record_inclusion).
12743 If unable to find/open the file, return NULL.
12744 NOTE: This function is derived from symfile_bfd_open. */
12746 static gdb_bfd_ref_ptr
12747 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12748 const char *file_name
, int is_dwp
, int search_cwd
)
12751 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12752 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12753 to debug_file_directory. */
12754 const char *search_path
;
12755 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12757 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12760 if (*debug_file_directory
!= '\0')
12762 search_path_holder
.reset (concat (".", dirname_separator_string
,
12763 debug_file_directory
,
12765 search_path
= search_path_holder
.get ();
12771 search_path
= debug_file_directory
;
12773 openp_flags flags
= OPF_RETURN_REALPATH
;
12775 flags
|= OPF_SEARCH_IN_PATH
;
12777 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12778 desc
= openp (search_path
, flags
, file_name
,
12779 O_RDONLY
| O_BINARY
, &absolute_name
);
12783 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12785 if (sym_bfd
== NULL
)
12787 bfd_set_cacheable (sym_bfd
.get (), 1);
12789 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12792 /* Success. Record the bfd as having been included by the objfile's bfd.
12793 This is important because things like demangled_names_hash lives in the
12794 objfile's per_bfd space and may have references to things like symbol
12795 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12796 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12801 /* Try to open DWO file FILE_NAME.
12802 COMP_DIR is the DW_AT_comp_dir attribute.
12803 The result is the bfd handle of the file.
12804 If there is a problem finding or opening the file, return NULL.
12805 Upon success, the canonicalized path of the file is stored in the bfd,
12806 same as symfile_bfd_open. */
12808 static gdb_bfd_ref_ptr
12809 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12810 const char *file_name
, const char *comp_dir
)
12812 if (IS_ABSOLUTE_PATH (file_name
))
12813 return try_open_dwop_file (per_objfile
, file_name
,
12814 0 /*is_dwp*/, 0 /*search_cwd*/);
12816 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12818 if (comp_dir
!= NULL
)
12820 gdb::unique_xmalloc_ptr
<char> path_to_try
12821 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12823 /* NOTE: If comp_dir is a relative path, this will also try the
12824 search path, which seems useful. */
12825 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12827 1 /*search_cwd*/));
12832 /* That didn't work, try debug-file-directory, which, despite its name,
12833 is a list of paths. */
12835 if (*debug_file_directory
== '\0')
12838 return try_open_dwop_file (per_objfile
, file_name
,
12839 0 /*is_dwp*/, 1 /*search_cwd*/);
12842 /* This function is mapped across the sections and remembers the offset and
12843 size of each of the DWO debugging sections we are interested in. */
12846 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12847 dwo_sections
*dwo_sections
)
12849 const struct dwop_section_names
*names
= &dwop_section_names
;
12851 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12853 dwo_sections
->abbrev
.s
.section
= sectp
;
12854 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12856 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12858 dwo_sections
->info
.s
.section
= sectp
;
12859 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12861 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12863 dwo_sections
->line
.s
.section
= sectp
;
12864 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12866 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12868 dwo_sections
->loc
.s
.section
= sectp
;
12869 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12871 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
12873 dwo_sections
->loclists
.s
.section
= sectp
;
12874 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12876 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12878 dwo_sections
->macinfo
.s
.section
= sectp
;
12879 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12881 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12883 dwo_sections
->macro
.s
.section
= sectp
;
12884 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12886 else if (section_is_p (sectp
->name
, &names
->rnglists_dwo
))
12888 dwo_sections
->rnglists
.s
.section
= sectp
;
12889 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12891 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12893 dwo_sections
->str
.s
.section
= sectp
;
12894 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12896 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12898 dwo_sections
->str_offsets
.s
.section
= sectp
;
12899 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12901 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12903 struct dwarf2_section_info type_section
;
12905 memset (&type_section
, 0, sizeof (type_section
));
12906 type_section
.s
.section
= sectp
;
12907 type_section
.size
= bfd_section_size (sectp
);
12908 dwo_sections
->types
.push_back (type_section
);
12912 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12913 by PER_CU. This is for the non-DWP case.
12914 The result is NULL if DWO_NAME can't be found. */
12916 static struct dwo_file
*
12917 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12918 const char *comp_dir
)
12920 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12922 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12925 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12930 dwo_file_up
dwo_file (new struct dwo_file
);
12931 dwo_file
->dwo_name
= dwo_name
;
12932 dwo_file
->comp_dir
= comp_dir
;
12933 dwo_file
->dbfd
= std::move (dbfd
);
12935 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12936 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12937 &dwo_file
->sections
);
12939 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12942 if (cu
->per_cu
->dwarf_version
< 5)
12944 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12945 dwo_file
->sections
.types
, dwo_file
->tus
);
12949 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12950 &dwo_file
->sections
.info
, dwo_file
->tus
,
12954 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12956 return dwo_file
.release ();
12959 /* This function is mapped across the sections and remembers the offset and
12960 size of each of the DWP debugging sections common to version 1 and 2 that
12961 we are interested in. */
12964 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12965 dwp_file
*dwp_file
)
12967 const struct dwop_section_names
*names
= &dwop_section_names
;
12968 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12970 /* Record the ELF section number for later lookup: this is what the
12971 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12972 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12973 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12975 /* Look for specific sections that we need. */
12976 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12978 dwp_file
->sections
.str
.s
.section
= sectp
;
12979 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12981 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12983 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12984 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12986 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12988 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12989 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12993 /* This function is mapped across the sections and remembers the offset and
12994 size of each of the DWP version 2 debugging sections that we are interested
12995 in. This is split into a separate function because we don't know if we
12996 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12999 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13001 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13002 const struct dwop_section_names
*names
= &dwop_section_names
;
13003 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13005 /* Record the ELF section number for later lookup: this is what the
13006 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13007 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13008 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13010 /* Look for specific sections that we need. */
13011 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13013 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13014 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13016 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13018 dwp_file
->sections
.info
.s
.section
= sectp
;
13019 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13021 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13023 dwp_file
->sections
.line
.s
.section
= sectp
;
13024 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13026 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13028 dwp_file
->sections
.loc
.s
.section
= sectp
;
13029 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
13031 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13033 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13034 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
13036 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13038 dwp_file
->sections
.macro
.s
.section
= sectp
;
13039 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13041 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13043 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13044 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13046 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13048 dwp_file
->sections
.types
.s
.section
= sectp
;
13049 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13053 /* This function is mapped across the sections and remembers the offset and
13054 size of each of the DWP version 5 debugging sections that we are interested
13055 in. This is split into a separate function because we don't know if we
13056 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
13059 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13061 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13062 const struct dwop_section_names
*names
= &dwop_section_names
;
13063 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13065 /* Record the ELF section number for later lookup: this is what the
13066 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13067 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13068 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13070 /* Look for specific sections that we need. */
13071 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13073 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13074 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13076 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13078 dwp_file
->sections
.info
.s
.section
= sectp
;
13079 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13081 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13083 dwp_file
->sections
.line
.s
.section
= sectp
;
13084 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13086 else if (section_is_p (sectp
->name
, &names
->loclists_dwo
))
13088 dwp_file
->sections
.loclists
.s
.section
= sectp
;
13089 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
13091 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13093 dwp_file
->sections
.macro
.s
.section
= sectp
;
13094 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13096 else if (section_is_p (sectp
->name
, &names
->rnglists_dwo
))
13098 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
13099 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
13101 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13103 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13104 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13108 /* Hash function for dwp_file loaded CUs/TUs. */
13111 hash_dwp_loaded_cutus (const void *item
)
13113 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13115 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13116 return dwo_unit
->signature
;
13119 /* Equality function for dwp_file loaded CUs/TUs. */
13122 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13124 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13125 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13127 return dua
->signature
== dub
->signature
;
13130 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13133 allocate_dwp_loaded_cutus_table ()
13135 return htab_up (htab_create_alloc (3,
13136 hash_dwp_loaded_cutus
,
13137 eq_dwp_loaded_cutus
,
13138 NULL
, xcalloc
, xfree
));
13141 /* Try to open DWP file FILE_NAME.
13142 The result is the bfd handle of the file.
13143 If there is a problem finding or opening the file, return NULL.
13144 Upon success, the canonicalized path of the file is stored in the bfd,
13145 same as symfile_bfd_open. */
13147 static gdb_bfd_ref_ptr
13148 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
13150 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
13152 1 /*search_cwd*/));
13156 /* Work around upstream bug 15652.
13157 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13158 [Whether that's a "bug" is debatable, but it is getting in our way.]
13159 We have no real idea where the dwp file is, because gdb's realpath-ing
13160 of the executable's path may have discarded the needed info.
13161 [IWBN if the dwp file name was recorded in the executable, akin to
13162 .gnu_debuglink, but that doesn't exist yet.]
13163 Strip the directory from FILE_NAME and search again. */
13164 if (*debug_file_directory
!= '\0')
13166 /* Don't implicitly search the current directory here.
13167 If the user wants to search "." to handle this case,
13168 it must be added to debug-file-directory. */
13169 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
13177 /* Initialize the use of the DWP file for the current objfile.
13178 By convention the name of the DWP file is ${objfile}.dwp.
13179 The result is NULL if it can't be found. */
13181 static std::unique_ptr
<struct dwp_file
>
13182 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
13184 struct objfile
*objfile
= per_objfile
->objfile
;
13186 /* Try to find first .dwp for the binary file before any symbolic links
13189 /* If the objfile is a debug file, find the name of the real binary
13190 file and get the name of dwp file from there. */
13191 std::string dwp_name
;
13192 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13194 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13195 const char *backlink_basename
= lbasename (backlink
->original_name
);
13197 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13200 dwp_name
= objfile
->original_name
;
13202 dwp_name
+= ".dwp";
13204 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
13206 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13208 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13209 dwp_name
= objfile_name (objfile
);
13210 dwp_name
+= ".dwp";
13211 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
13216 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
13218 return std::unique_ptr
<dwp_file
> ();
13221 const char *name
= bfd_get_filename (dbfd
.get ());
13222 std::unique_ptr
<struct dwp_file
> dwp_file
13223 (new struct dwp_file (name
, std::move (dbfd
)));
13225 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13226 dwp_file
->elf_sections
=
13227 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
13228 dwp_file
->num_sections
, asection
*);
13230 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13231 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13234 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
13236 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
13238 /* The DWP file version is stored in the hash table. Oh well. */
13239 if (dwp_file
->cus
&& dwp_file
->tus
13240 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13242 /* Technically speaking, we should try to limp along, but this is
13243 pretty bizarre. We use pulongest here because that's the established
13244 portability solution (e.g, we cannot use %u for uint32_t). */
13245 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13246 " TU version %s [in DWP file %s]"),
13247 pulongest (dwp_file
->cus
->version
),
13248 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13252 dwp_file
->version
= dwp_file
->cus
->version
;
13253 else if (dwp_file
->tus
)
13254 dwp_file
->version
= dwp_file
->tus
->version
;
13256 dwp_file
->version
= 2;
13258 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13260 if (dwp_file
->version
== 2)
13261 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13264 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13268 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
13269 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
13271 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
13272 dwarf_read_debug_printf (" %s CUs, %s TUs",
13273 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13274 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13279 /* Wrapper around open_and_init_dwp_file, only open it once. */
13281 static struct dwp_file
*
13282 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
13284 if (!per_objfile
->per_bfd
->dwp_checked
)
13286 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
13287 per_objfile
->per_bfd
->dwp_checked
= 1;
13289 return per_objfile
->per_bfd
->dwp_file
.get ();
13292 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13293 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13294 or in the DWP file for the objfile, referenced by THIS_UNIT.
13295 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13296 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13298 This is called, for example, when wanting to read a variable with a
13299 complex location. Therefore we don't want to do file i/o for every call.
13300 Therefore we don't want to look for a DWO file on every call.
13301 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13302 then we check if we've already seen DWO_NAME, and only THEN do we check
13305 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13306 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13308 static struct dwo_unit
*
13309 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13310 ULONGEST signature
, int is_debug_types
)
13312 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13313 struct objfile
*objfile
= per_objfile
->objfile
;
13314 const char *kind
= is_debug_types
? "TU" : "CU";
13315 void **dwo_file_slot
;
13316 struct dwo_file
*dwo_file
;
13317 struct dwp_file
*dwp_file
;
13319 /* First see if there's a DWP file.
13320 If we have a DWP file but didn't find the DWO inside it, don't
13321 look for the original DWO file. It makes gdb behave differently
13322 depending on whether one is debugging in the build tree. */
13324 dwp_file
= get_dwp_file (per_objfile
);
13325 if (dwp_file
!= NULL
)
13327 const struct dwp_hash_table
*dwp_htab
=
13328 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13330 if (dwp_htab
!= NULL
)
13332 struct dwo_unit
*dwo_cutu
=
13333 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
13336 if (dwo_cutu
!= NULL
)
13338 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
13339 kind
, hex_string (signature
),
13340 host_address_to_string (dwo_cutu
));
13348 /* No DWP file, look for the DWO file. */
13350 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
13351 if (*dwo_file_slot
== NULL
)
13353 /* Read in the file and build a table of the CUs/TUs it contains. */
13354 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
13356 /* NOTE: This will be NULL if unable to open the file. */
13357 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13359 if (dwo_file
!= NULL
)
13361 struct dwo_unit
*dwo_cutu
= NULL
;
13363 if (is_debug_types
&& dwo_file
->tus
)
13365 struct dwo_unit find_dwo_cutu
;
13367 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13368 find_dwo_cutu
.signature
= signature
;
13370 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
13373 else if (!is_debug_types
&& dwo_file
->cus
)
13375 struct dwo_unit find_dwo_cutu
;
13377 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13378 find_dwo_cutu
.signature
= signature
;
13379 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
13383 if (dwo_cutu
!= NULL
)
13385 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
13386 kind
, dwo_name
, hex_string (signature
),
13387 host_address_to_string (dwo_cutu
));
13394 /* We didn't find it. This could mean a dwo_id mismatch, or
13395 someone deleted the DWO/DWP file, or the search path isn't set up
13396 correctly to find the file. */
13398 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
13399 kind
, dwo_name
, hex_string (signature
));
13401 /* This is a warning and not a complaint because it can be caused by
13402 pilot error (e.g., user accidentally deleting the DWO). */
13404 /* Print the name of the DWP file if we looked there, helps the user
13405 better diagnose the problem. */
13406 std::string dwp_text
;
13408 if (dwp_file
!= NULL
)
13409 dwp_text
= string_printf (" [in DWP file %s]",
13410 lbasename (dwp_file
->name
));
13412 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13413 " [in module %s]"),
13414 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
13415 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
13420 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13421 See lookup_dwo_cutu_unit for details. */
13423 static struct dwo_unit
*
13424 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13425 ULONGEST signature
)
13427 gdb_assert (!cu
->per_cu
->is_debug_types
);
13429 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
13432 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13433 See lookup_dwo_cutu_unit for details. */
13435 static struct dwo_unit
*
13436 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
13438 gdb_assert (cu
->per_cu
->is_debug_types
);
13440 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
13442 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
13445 /* Traversal function for queue_and_load_all_dwo_tus. */
13448 queue_and_load_dwo_tu (void **slot
, void *info
)
13450 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13451 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
13452 ULONGEST signature
= dwo_unit
->signature
;
13453 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
13455 if (sig_type
!= NULL
)
13457 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13459 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13460 a real dependency of PER_CU on SIG_TYPE. That is detected later
13461 while processing PER_CU. */
13462 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
13463 load_full_type_unit (sig_cu
, cu
->per_objfile
);
13464 cu
->per_cu
->imported_symtabs_push (sig_cu
);
13470 /* Queue all TUs contained in the DWO of CU to be read in.
13471 The DWO may have the only definition of the type, though it may not be
13472 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13473 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13476 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
13478 struct dwo_unit
*dwo_unit
;
13479 struct dwo_file
*dwo_file
;
13481 gdb_assert (cu
!= nullptr);
13482 gdb_assert (!cu
->per_cu
->is_debug_types
);
13483 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
13485 dwo_unit
= cu
->dwo_unit
;
13486 gdb_assert (dwo_unit
!= NULL
);
13488 dwo_file
= dwo_unit
->dwo_file
;
13489 if (dwo_file
->tus
!= NULL
)
13490 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
13493 /* Read in various DIEs. */
13495 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13496 Inherit only the children of the DW_AT_abstract_origin DIE not being
13497 already referenced by DW_AT_abstract_origin from the children of the
13501 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13503 struct die_info
*child_die
;
13504 sect_offset
*offsetp
;
13505 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13506 struct die_info
*origin_die
;
13507 /* Iterator of the ORIGIN_DIE children. */
13508 struct die_info
*origin_child_die
;
13509 struct attribute
*attr
;
13510 struct dwarf2_cu
*origin_cu
;
13511 struct pending
**origin_previous_list_in_scope
;
13513 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13517 /* Note that following die references may follow to a die in a
13521 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13523 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13525 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13526 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13528 if (die
->tag
!= origin_die
->tag
13529 && !(die
->tag
== DW_TAG_inlined_subroutine
13530 && origin_die
->tag
== DW_TAG_subprogram
))
13531 complaint (_("DIE %s and its abstract origin %s have different tags"),
13532 sect_offset_str (die
->sect_off
),
13533 sect_offset_str (origin_die
->sect_off
));
13535 std::vector
<sect_offset
> offsets
;
13537 for (child_die
= die
->child
;
13538 child_die
&& child_die
->tag
;
13539 child_die
= child_die
->sibling
)
13541 struct die_info
*child_origin_die
;
13542 struct dwarf2_cu
*child_origin_cu
;
13544 /* We are trying to process concrete instance entries:
13545 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13546 it's not relevant to our analysis here. i.e. detecting DIEs that are
13547 present in the abstract instance but not referenced in the concrete
13549 if (child_die
->tag
== DW_TAG_call_site
13550 || child_die
->tag
== DW_TAG_GNU_call_site
)
13553 /* For each CHILD_DIE, find the corresponding child of
13554 ORIGIN_DIE. If there is more than one layer of
13555 DW_AT_abstract_origin, follow them all; there shouldn't be,
13556 but GCC versions at least through 4.4 generate this (GCC PR
13558 child_origin_die
= child_die
;
13559 child_origin_cu
= cu
;
13562 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13566 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13570 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13571 counterpart may exist. */
13572 if (child_origin_die
!= child_die
)
13574 if (child_die
->tag
!= child_origin_die
->tag
13575 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13576 && child_origin_die
->tag
== DW_TAG_subprogram
))
13577 complaint (_("Child DIE %s and its abstract origin %s have "
13579 sect_offset_str (child_die
->sect_off
),
13580 sect_offset_str (child_origin_die
->sect_off
));
13581 if (child_origin_die
->parent
!= origin_die
)
13582 complaint (_("Child DIE %s and its abstract origin %s have "
13583 "different parents"),
13584 sect_offset_str (child_die
->sect_off
),
13585 sect_offset_str (child_origin_die
->sect_off
));
13587 offsets
.push_back (child_origin_die
->sect_off
);
13590 std::sort (offsets
.begin (), offsets
.end ());
13591 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13592 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13593 if (offsetp
[-1] == *offsetp
)
13594 complaint (_("Multiple children of DIE %s refer "
13595 "to DIE %s as their abstract origin"),
13596 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13598 offsetp
= offsets
.data ();
13599 origin_child_die
= origin_die
->child
;
13600 while (origin_child_die
&& origin_child_die
->tag
)
13602 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13603 while (offsetp
< offsets_end
13604 && *offsetp
< origin_child_die
->sect_off
)
13606 if (offsetp
>= offsets_end
13607 || *offsetp
> origin_child_die
->sect_off
)
13609 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13610 Check whether we're already processing ORIGIN_CHILD_DIE.
13611 This can happen with mutually referenced abstract_origins.
13613 if (!origin_child_die
->in_process
)
13614 process_die (origin_child_die
, origin_cu
);
13616 origin_child_die
= origin_child_die
->sibling
;
13618 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13620 if (cu
!= origin_cu
)
13621 compute_delayed_physnames (origin_cu
);
13625 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13627 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13628 struct gdbarch
*gdbarch
= objfile
->arch ();
13629 struct context_stack
*newobj
;
13632 struct die_info
*child_die
;
13633 struct attribute
*attr
, *call_line
, *call_file
;
13635 CORE_ADDR baseaddr
;
13636 struct block
*block
;
13637 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13638 std::vector
<struct symbol
*> template_args
;
13639 struct template_symbol
*templ_func
= NULL
;
13643 /* If we do not have call site information, we can't show the
13644 caller of this inlined function. That's too confusing, so
13645 only use the scope for local variables. */
13646 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13647 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13648 if (call_line
== NULL
|| call_file
== NULL
)
13650 read_lexical_block_scope (die
, cu
);
13655 baseaddr
= objfile
->text_section_offset ();
13657 name
= dwarf2_name (die
, cu
);
13659 /* Ignore functions with missing or empty names. These are actually
13660 illegal according to the DWARF standard. */
13663 complaint (_("missing name for subprogram DIE at %s"),
13664 sect_offset_str (die
->sect_off
));
13668 /* Ignore functions with missing or invalid low and high pc attributes. */
13669 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13670 <= PC_BOUNDS_INVALID
)
13672 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13673 if (attr
== nullptr || !attr
->as_boolean ())
13674 complaint (_("cannot get low and high bounds "
13675 "for subprogram DIE at %s"),
13676 sect_offset_str (die
->sect_off
));
13680 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13681 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13683 /* If we have any template arguments, then we must allocate a
13684 different sort of symbol. */
13685 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13687 if (child_die
->tag
== DW_TAG_template_type_param
13688 || child_die
->tag
== DW_TAG_template_value_param
)
13690 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13691 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13696 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13697 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13698 (struct symbol
*) templ_func
);
13700 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13701 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13704 /* If there is a location expression for DW_AT_frame_base, record
13706 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13707 if (attr
!= nullptr)
13708 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13710 /* If there is a location for the static link, record it. */
13711 newobj
->static_link
= NULL
;
13712 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13713 if (attr
!= nullptr)
13715 newobj
->static_link
13716 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13717 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13721 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13723 if (die
->child
!= NULL
)
13725 child_die
= die
->child
;
13726 while (child_die
&& child_die
->tag
)
13728 if (child_die
->tag
== DW_TAG_template_type_param
13729 || child_die
->tag
== DW_TAG_template_value_param
)
13731 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13734 template_args
.push_back (arg
);
13737 process_die (child_die
, cu
);
13738 child_die
= child_die
->sibling
;
13742 inherit_abstract_dies (die
, cu
);
13744 /* If we have a DW_AT_specification, we might need to import using
13745 directives from the context of the specification DIE. See the
13746 comment in determine_prefix. */
13747 if (cu
->language
== language_cplus
13748 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13750 struct dwarf2_cu
*spec_cu
= cu
;
13751 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13755 child_die
= spec_die
->child
;
13756 while (child_die
&& child_die
->tag
)
13758 if (child_die
->tag
== DW_TAG_imported_module
)
13759 process_die (child_die
, spec_cu
);
13760 child_die
= child_die
->sibling
;
13763 /* In some cases, GCC generates specification DIEs that
13764 themselves contain DW_AT_specification attributes. */
13765 spec_die
= die_specification (spec_die
, &spec_cu
);
13769 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13770 /* Make a block for the local symbols within. */
13771 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13772 cstk
.static_link
, lowpc
, highpc
);
13774 /* For C++, set the block's scope. */
13775 if ((cu
->language
== language_cplus
13776 || cu
->language
== language_fortran
13777 || cu
->language
== language_d
13778 || cu
->language
== language_rust
)
13779 && cu
->processing_has_namespace_info
)
13780 block_set_scope (block
, determine_prefix (die
, cu
),
13781 &objfile
->objfile_obstack
);
13783 /* If we have address ranges, record them. */
13784 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13786 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13788 /* Attach template arguments to function. */
13789 if (!template_args
.empty ())
13791 gdb_assert (templ_func
!= NULL
);
13793 templ_func
->n_template_arguments
= template_args
.size ();
13794 templ_func
->template_arguments
13795 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13796 templ_func
->n_template_arguments
);
13797 memcpy (templ_func
->template_arguments
,
13798 template_args
.data (),
13799 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13801 /* Make sure that the symtab is set on the new symbols. Even
13802 though they don't appear in this symtab directly, other parts
13803 of gdb assume that symbols do, and this is reasonably
13805 for (symbol
*sym
: template_args
)
13806 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13809 /* In C++, we can have functions nested inside functions (e.g., when
13810 a function declares a class that has methods). This means that
13811 when we finish processing a function scope, we may need to go
13812 back to building a containing block's symbol lists. */
13813 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13814 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13816 /* If we've finished processing a top-level function, subsequent
13817 symbols go in the file symbol list. */
13818 if (cu
->get_builder ()->outermost_context_p ())
13819 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13822 /* Process all the DIES contained within a lexical block scope. Start
13823 a new scope, process the dies, and then close the scope. */
13826 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13828 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13829 struct gdbarch
*gdbarch
= objfile
->arch ();
13830 CORE_ADDR lowpc
, highpc
;
13831 struct die_info
*child_die
;
13832 CORE_ADDR baseaddr
;
13834 baseaddr
= objfile
->text_section_offset ();
13836 /* Ignore blocks with missing or invalid low and high pc attributes. */
13837 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13838 as multiple lexical blocks? Handling children in a sane way would
13839 be nasty. Might be easier to properly extend generic blocks to
13840 describe ranges. */
13841 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13843 case PC_BOUNDS_NOT_PRESENT
:
13844 /* DW_TAG_lexical_block has no attributes, process its children as if
13845 there was no wrapping by that DW_TAG_lexical_block.
13846 GCC does no longer produces such DWARF since GCC r224161. */
13847 for (child_die
= die
->child
;
13848 child_die
!= NULL
&& child_die
->tag
;
13849 child_die
= child_die
->sibling
)
13851 /* We might already be processing this DIE. This can happen
13852 in an unusual circumstance -- where a subroutine A
13853 appears lexically in another subroutine B, but A actually
13854 inlines B. The recursion is broken here, rather than in
13855 inherit_abstract_dies, because it seems better to simply
13856 drop concrete children here. */
13857 if (!child_die
->in_process
)
13858 process_die (child_die
, cu
);
13861 case PC_BOUNDS_INVALID
:
13864 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13865 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13867 cu
->get_builder ()->push_context (0, lowpc
);
13868 if (die
->child
!= NULL
)
13870 child_die
= die
->child
;
13871 while (child_die
&& child_die
->tag
)
13873 process_die (child_die
, cu
);
13874 child_die
= child_die
->sibling
;
13877 inherit_abstract_dies (die
, cu
);
13878 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13880 if (*cu
->get_builder ()->get_local_symbols () != NULL
13881 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13883 struct block
*block
13884 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13885 cstk
.start_addr
, highpc
);
13887 /* Note that recording ranges after traversing children, as we
13888 do here, means that recording a parent's ranges entails
13889 walking across all its children's ranges as they appear in
13890 the address map, which is quadratic behavior.
13892 It would be nicer to record the parent's ranges before
13893 traversing its children, simply overriding whatever you find
13894 there. But since we don't even decide whether to create a
13895 block until after we've traversed its children, that's hard
13897 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13899 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13900 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13903 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13906 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13908 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13909 struct objfile
*objfile
= per_objfile
->objfile
;
13910 struct gdbarch
*gdbarch
= objfile
->arch ();
13911 CORE_ADDR pc
, baseaddr
;
13912 struct attribute
*attr
;
13913 struct call_site
*call_site
, call_site_local
;
13916 struct die_info
*child_die
;
13918 baseaddr
= objfile
->text_section_offset ();
13920 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13923 /* This was a pre-DWARF-5 GNU extension alias
13924 for DW_AT_call_return_pc. */
13925 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13929 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13930 "DIE %s [in module %s]"),
13931 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13934 pc
= attr
->as_address () + baseaddr
;
13935 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13937 if (cu
->call_site_htab
== NULL
)
13938 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13939 NULL
, &objfile
->objfile_obstack
,
13940 hashtab_obstack_allocate
, NULL
);
13941 call_site_local
.pc
= pc
;
13942 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13945 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13946 "DIE %s [in module %s]"),
13947 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13948 objfile_name (objfile
));
13952 /* Count parameters at the caller. */
13955 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13956 child_die
= child_die
->sibling
)
13958 if (child_die
->tag
!= DW_TAG_call_site_parameter
13959 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13961 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13962 "DW_TAG_call_site child DIE %s [in module %s]"),
13963 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13964 objfile_name (objfile
));
13972 = ((struct call_site
*)
13973 obstack_alloc (&objfile
->objfile_obstack
,
13974 sizeof (*call_site
)
13975 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13977 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13978 call_site
->pc
= pc
;
13980 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13981 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13983 struct die_info
*func_die
;
13985 /* Skip also over DW_TAG_inlined_subroutine. */
13986 for (func_die
= die
->parent
;
13987 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13988 && func_die
->tag
!= DW_TAG_subroutine_type
;
13989 func_die
= func_die
->parent
);
13991 /* DW_AT_call_all_calls is a superset
13992 of DW_AT_call_all_tail_calls. */
13994 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13995 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13996 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13997 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13999 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14000 not complete. But keep CALL_SITE for look ups via call_site_htab,
14001 both the initial caller containing the real return address PC and
14002 the final callee containing the current PC of a chain of tail
14003 calls do not need to have the tail call list complete. But any
14004 function candidate for a virtual tail call frame searched via
14005 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14006 determined unambiguously. */
14010 struct type
*func_type
= NULL
;
14013 func_type
= get_die_type (func_die
, cu
);
14014 if (func_type
!= NULL
)
14016 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
14018 /* Enlist this call site to the function. */
14019 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14020 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14023 complaint (_("Cannot find function owning DW_TAG_call_site "
14024 "DIE %s [in module %s]"),
14025 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14029 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14031 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14033 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14036 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14037 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14039 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14040 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
14041 /* Keep NULL DWARF_BLOCK. */;
14042 else if (attr
->form_is_block ())
14044 struct dwarf2_locexpr_baton
*dlbaton
;
14045 struct dwarf_block
*block
= attr
->as_block ();
14047 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14048 dlbaton
->data
= block
->data
;
14049 dlbaton
->size
= block
->size
;
14050 dlbaton
->per_objfile
= per_objfile
;
14051 dlbaton
->per_cu
= cu
->per_cu
;
14053 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14055 else if (attr
->form_is_ref ())
14057 struct dwarf2_cu
*target_cu
= cu
;
14058 struct die_info
*target_die
;
14060 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14061 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
14062 if (die_is_declaration (target_die
, target_cu
))
14064 const char *target_physname
;
14066 /* Prefer the mangled name; otherwise compute the demangled one. */
14067 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14068 if (target_physname
== NULL
)
14069 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14070 if (target_physname
== NULL
)
14071 complaint (_("DW_AT_call_target target DIE has invalid "
14072 "physname, for referencing DIE %s [in module %s]"),
14073 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14075 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14081 /* DW_AT_entry_pc should be preferred. */
14082 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14083 <= PC_BOUNDS_INVALID
)
14084 complaint (_("DW_AT_call_target target DIE has invalid "
14085 "low pc, for referencing DIE %s [in module %s]"),
14086 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14089 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14090 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14095 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14096 "block nor reference, for DIE %s [in module %s]"),
14097 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14099 call_site
->per_cu
= cu
->per_cu
;
14100 call_site
->per_objfile
= per_objfile
;
14102 for (child_die
= die
->child
;
14103 child_die
&& child_die
->tag
;
14104 child_die
= child_die
->sibling
)
14106 struct call_site_parameter
*parameter
;
14107 struct attribute
*loc
, *origin
;
14109 if (child_die
->tag
!= DW_TAG_call_site_parameter
14110 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14112 /* Already printed the complaint above. */
14116 gdb_assert (call_site
->parameter_count
< nparams
);
14117 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14119 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14120 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14121 register is contained in DW_AT_call_value. */
14123 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14124 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14125 if (origin
== NULL
)
14127 /* This was a pre-DWARF-5 GNU extension alias
14128 for DW_AT_call_parameter. */
14129 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14131 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
14133 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14135 sect_offset sect_off
= origin
->get_ref_die_offset ();
14136 if (!cu
->header
.offset_in_cu_p (sect_off
))
14138 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14139 binding can be done only inside one CU. Such referenced DIE
14140 therefore cannot be even moved to DW_TAG_partial_unit. */
14141 complaint (_("DW_AT_call_parameter offset is not in CU for "
14142 "DW_TAG_call_site child DIE %s [in module %s]"),
14143 sect_offset_str (child_die
->sect_off
),
14144 objfile_name (objfile
));
14147 parameter
->u
.param_cu_off
14148 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14150 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
14152 complaint (_("No DW_FORM_block* DW_AT_location for "
14153 "DW_TAG_call_site child DIE %s [in module %s]"),
14154 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14159 struct dwarf_block
*block
= loc
->as_block ();
14161 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14162 (block
->data
, &block
->data
[block
->size
]);
14163 if (parameter
->u
.dwarf_reg
!= -1)
14164 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14165 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
14166 &block
->data
[block
->size
],
14167 ¶meter
->u
.fb_offset
))
14168 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14171 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14172 "for DW_FORM_block* DW_AT_location is supported for "
14173 "DW_TAG_call_site child DIE %s "
14175 sect_offset_str (child_die
->sect_off
),
14176 objfile_name (objfile
));
14181 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14183 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14184 if (attr
== NULL
|| !attr
->form_is_block ())
14186 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14187 "DW_TAG_call_site child DIE %s [in module %s]"),
14188 sect_offset_str (child_die
->sect_off
),
14189 objfile_name (objfile
));
14193 struct dwarf_block
*block
= attr
->as_block ();
14194 parameter
->value
= block
->data
;
14195 parameter
->value_size
= block
->size
;
14197 /* Parameters are not pre-cleared by memset above. */
14198 parameter
->data_value
= NULL
;
14199 parameter
->data_value_size
= 0;
14200 call_site
->parameter_count
++;
14202 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14204 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14205 if (attr
!= nullptr)
14207 if (!attr
->form_is_block ())
14208 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14209 "DW_TAG_call_site child DIE %s [in module %s]"),
14210 sect_offset_str (child_die
->sect_off
),
14211 objfile_name (objfile
));
14214 block
= attr
->as_block ();
14215 parameter
->data_value
= block
->data
;
14216 parameter
->data_value_size
= block
->size
;
14222 /* Helper function for read_variable. If DIE represents a virtual
14223 table, then return the type of the concrete object that is
14224 associated with the virtual table. Otherwise, return NULL. */
14226 static struct type
*
14227 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14229 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14233 /* Find the type DIE. */
14234 struct die_info
*type_die
= NULL
;
14235 struct dwarf2_cu
*type_cu
= cu
;
14237 if (attr
->form_is_ref ())
14238 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14239 if (type_die
== NULL
)
14242 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14244 return die_containing_type (type_die
, type_cu
);
14247 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14250 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14252 struct rust_vtable_symbol
*storage
= NULL
;
14254 if (cu
->language
== language_rust
)
14256 struct type
*containing_type
= rust_containing_type (die
, cu
);
14258 if (containing_type
!= NULL
)
14260 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14262 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
14263 storage
->concrete_type
= containing_type
;
14264 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14268 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14269 struct attribute
*abstract_origin
14270 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14271 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14272 if (res
== NULL
&& loc
&& abstract_origin
)
14274 /* We have a variable without a name, but with a location and an abstract
14275 origin. This may be a concrete instance of an abstract variable
14276 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14278 struct dwarf2_cu
*origin_cu
= cu
;
14279 struct die_info
*origin_die
14280 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14281 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14282 per_objfile
->per_bfd
->abstract_to_concrete
14283 [origin_die
->sect_off
].push_back (die
->sect_off
);
14287 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14288 reading .debug_rnglists.
14289 Callback's type should be:
14290 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14291 Return true if the attributes are present and valid, otherwise,
14294 template <typename Callback
>
14296 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14297 dwarf_tag tag
, Callback
&&callback
)
14299 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14300 struct objfile
*objfile
= per_objfile
->objfile
;
14301 bfd
*obfd
= objfile
->obfd
;
14302 /* Base address selection entry. */
14303 gdb::optional
<CORE_ADDR
> base
;
14304 const gdb_byte
*buffer
;
14305 CORE_ADDR baseaddr
;
14306 bool overflow
= false;
14307 ULONGEST addr_index
;
14308 struct dwarf2_section_info
*rnglists_section
;
14310 base
= cu
->base_address
;
14311 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
14312 rnglists_section
->read (objfile
);
14314 if (offset
>= rnglists_section
->size
)
14316 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14320 buffer
= rnglists_section
->buffer
+ offset
;
14322 baseaddr
= objfile
->text_section_offset ();
14326 /* Initialize it due to a false compiler warning. */
14327 CORE_ADDR range_beginning
= 0, range_end
= 0;
14328 const gdb_byte
*buf_end
= (rnglists_section
->buffer
14329 + rnglists_section
->size
);
14330 unsigned int bytes_read
;
14332 if (buffer
== buf_end
)
14337 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14340 case DW_RLE_end_of_list
:
14342 case DW_RLE_base_address
:
14343 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14348 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14349 buffer
+= bytes_read
;
14351 case DW_RLE_base_addressx
:
14352 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14353 buffer
+= bytes_read
;
14354 base
= read_addr_index (cu
, addr_index
);
14356 case DW_RLE_start_length
:
14357 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14362 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14364 buffer
+= bytes_read
;
14365 range_end
= (range_beginning
14366 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14367 buffer
+= bytes_read
;
14368 if (buffer
> buf_end
)
14374 case DW_RLE_startx_length
:
14375 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14376 buffer
+= bytes_read
;
14377 range_beginning
= read_addr_index (cu
, addr_index
);
14378 if (buffer
> buf_end
)
14383 range_end
= (range_beginning
14384 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14385 buffer
+= bytes_read
;
14387 case DW_RLE_offset_pair
:
14388 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14389 buffer
+= bytes_read
;
14390 if (buffer
> buf_end
)
14395 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14396 buffer
+= bytes_read
;
14397 if (buffer
> buf_end
)
14403 case DW_RLE_start_end
:
14404 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14409 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14411 buffer
+= bytes_read
;
14412 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14413 buffer
+= bytes_read
;
14415 case DW_RLE_startx_endx
:
14416 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14417 buffer
+= bytes_read
;
14418 range_beginning
= read_addr_index (cu
, addr_index
);
14419 if (buffer
> buf_end
)
14424 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14425 buffer
+= bytes_read
;
14426 range_end
= read_addr_index (cu
, addr_index
);
14429 complaint (_("Invalid .debug_rnglists data (no base address)"));
14432 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14434 if (rlet
== DW_RLE_base_address
)
14437 if (range_beginning
> range_end
)
14439 /* Inverted range entries are invalid. */
14440 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14444 /* Empty range entries have no effect. */
14445 if (range_beginning
== range_end
)
14448 /* Only DW_RLE_offset_pair needs the base address added. */
14449 if (rlet
== DW_RLE_offset_pair
)
14451 if (!base
.has_value ())
14453 /* We have no valid base address for the DW_RLE_offset_pair. */
14454 complaint (_("Invalid .debug_rnglists data (no base address for "
14455 "DW_RLE_offset_pair)"));
14459 range_beginning
+= *base
;
14460 range_end
+= *base
;
14463 /* A not-uncommon case of bad debug info.
14464 Don't pollute the addrmap with bad data. */
14465 if (range_beginning
+ baseaddr
== 0
14466 && !per_objfile
->per_bfd
->has_section_at_zero
)
14468 complaint (_(".debug_rnglists entry has start address of zero"
14469 " [in module %s]"), objfile_name (objfile
));
14473 callback (range_beginning
, range_end
);
14478 complaint (_("Offset %d is not terminated "
14479 "for DW_AT_ranges attribute"),
14487 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14488 Callback's type should be:
14489 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14490 Return 1 if the attributes are present and valid, otherwise, return 0. */
14492 template <typename Callback
>
14494 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
14495 Callback
&&callback
)
14497 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14498 struct objfile
*objfile
= per_objfile
->objfile
;
14499 struct comp_unit_head
*cu_header
= &cu
->header
;
14500 bfd
*obfd
= objfile
->obfd
;
14501 unsigned int addr_size
= cu_header
->addr_size
;
14502 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14503 /* Base address selection entry. */
14504 gdb::optional
<CORE_ADDR
> base
;
14505 unsigned int dummy
;
14506 const gdb_byte
*buffer
;
14507 CORE_ADDR baseaddr
;
14509 if (cu_header
->version
>= 5)
14510 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
14512 base
= cu
->base_address
;
14514 per_objfile
->per_bfd
->ranges
.read (objfile
);
14515 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
14517 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14521 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
14523 baseaddr
= objfile
->text_section_offset ();
14527 CORE_ADDR range_beginning
, range_end
;
14529 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14530 buffer
+= addr_size
;
14531 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14532 buffer
+= addr_size
;
14533 offset
+= 2 * addr_size
;
14535 /* An end of list marker is a pair of zero addresses. */
14536 if (range_beginning
== 0 && range_end
== 0)
14537 /* Found the end of list entry. */
14540 /* Each base address selection entry is a pair of 2 values.
14541 The first is the largest possible address, the second is
14542 the base address. Check for a base address here. */
14543 if ((range_beginning
& mask
) == mask
)
14545 /* If we found the largest possible address, then we already
14546 have the base address in range_end. */
14551 if (!base
.has_value ())
14553 /* We have no valid base address for the ranges
14555 complaint (_("Invalid .debug_ranges data (no base address)"));
14559 if (range_beginning
> range_end
)
14561 /* Inverted range entries are invalid. */
14562 complaint (_("Invalid .debug_ranges data (inverted range)"));
14566 /* Empty range entries have no effect. */
14567 if (range_beginning
== range_end
)
14570 range_beginning
+= *base
;
14571 range_end
+= *base
;
14573 /* A not-uncommon case of bad debug info.
14574 Don't pollute the addrmap with bad data. */
14575 if (range_beginning
+ baseaddr
== 0
14576 && !per_objfile
->per_bfd
->has_section_at_zero
)
14578 complaint (_(".debug_ranges entry has start address of zero"
14579 " [in module %s]"), objfile_name (objfile
));
14583 callback (range_beginning
, range_end
);
14589 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14590 Return 1 if the attributes are present and valid, otherwise, return 0.
14591 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14594 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14595 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14596 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
14598 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14599 struct gdbarch
*gdbarch
= objfile
->arch ();
14600 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14603 CORE_ADDR high
= 0;
14606 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14607 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14609 if (ranges_pst
!= NULL
)
14614 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14615 range_beginning
+ baseaddr
)
14617 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14618 range_end
+ baseaddr
)
14620 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14621 lowpc
, highpc
- 1, ranges_pst
);
14624 /* FIXME: This is recording everything as a low-high
14625 segment of consecutive addresses. We should have a
14626 data structure for discontiguous block ranges
14630 low
= range_beginning
;
14636 if (range_beginning
< low
)
14637 low
= range_beginning
;
14638 if (range_end
> high
)
14646 /* If the first entry is an end-of-list marker, the range
14647 describes an empty scope, i.e. no instructions. */
14653 *high_return
= high
;
14657 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14658 definition for the return value. *LOWPC and *HIGHPC are set iff
14659 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14661 static enum pc_bounds_kind
14662 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14663 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14664 dwarf2_psymtab
*pst
)
14666 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14667 struct attribute
*attr
;
14668 struct attribute
*attr_high
;
14670 CORE_ADDR high
= 0;
14671 enum pc_bounds_kind ret
;
14673 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14676 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14677 if (attr
!= nullptr)
14679 low
= attr
->as_address ();
14680 high
= attr_high
->as_address ();
14681 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14685 /* Found high w/o low attribute. */
14686 return PC_BOUNDS_INVALID
;
14688 /* Found consecutive range of addresses. */
14689 ret
= PC_BOUNDS_HIGH_LOW
;
14693 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14694 if (attr
!= nullptr && attr
->form_is_unsigned ())
14696 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14697 on DWARF version). */
14698 ULONGEST ranges_offset
= attr
->as_unsigned ();
14700 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14702 if (die
->tag
!= DW_TAG_compile_unit
)
14703 ranges_offset
+= cu
->gnu_ranges_base
;
14705 /* Value of the DW_AT_ranges attribute is the offset in the
14706 .debug_ranges section. */
14707 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14709 return PC_BOUNDS_INVALID
;
14710 /* Found discontinuous range of addresses. */
14711 ret
= PC_BOUNDS_RANGES
;
14714 return PC_BOUNDS_NOT_PRESENT
;
14717 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14719 return PC_BOUNDS_INVALID
;
14721 /* When using the GNU linker, .gnu.linkonce. sections are used to
14722 eliminate duplicate copies of functions and vtables and such.
14723 The linker will arbitrarily choose one and discard the others.
14724 The AT_*_pc values for such functions refer to local labels in
14725 these sections. If the section from that file was discarded, the
14726 labels are not in the output, so the relocs get a value of 0.
14727 If this is a discarded function, mark the pc bounds as invalid,
14728 so that GDB will ignore it. */
14729 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14730 return PC_BOUNDS_INVALID
;
14738 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14739 its low and high PC addresses. Do nothing if these addresses could not
14740 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14741 and HIGHPC to the high address if greater than HIGHPC. */
14744 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14745 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14746 struct dwarf2_cu
*cu
)
14748 CORE_ADDR low
, high
;
14749 struct die_info
*child
= die
->child
;
14751 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14753 *lowpc
= std::min (*lowpc
, low
);
14754 *highpc
= std::max (*highpc
, high
);
14757 /* If the language does not allow nested subprograms (either inside
14758 subprograms or lexical blocks), we're done. */
14759 if (cu
->language
!= language_ada
)
14762 /* Check all the children of the given DIE. If it contains nested
14763 subprograms, then check their pc bounds. Likewise, we need to
14764 check lexical blocks as well, as they may also contain subprogram
14766 while (child
&& child
->tag
)
14768 if (child
->tag
== DW_TAG_subprogram
14769 || child
->tag
== DW_TAG_lexical_block
)
14770 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14771 child
= child
->sibling
;
14775 /* Get the low and high pc's represented by the scope DIE, and store
14776 them in *LOWPC and *HIGHPC. If the correct values can't be
14777 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14780 get_scope_pc_bounds (struct die_info
*die
,
14781 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14782 struct dwarf2_cu
*cu
)
14784 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14785 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14786 CORE_ADDR current_low
, current_high
;
14788 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14789 >= PC_BOUNDS_RANGES
)
14791 best_low
= current_low
;
14792 best_high
= current_high
;
14796 struct die_info
*child
= die
->child
;
14798 while (child
&& child
->tag
)
14800 switch (child
->tag
) {
14801 case DW_TAG_subprogram
:
14802 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14804 case DW_TAG_namespace
:
14805 case DW_TAG_module
:
14806 /* FIXME: carlton/2004-01-16: Should we do this for
14807 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14808 that current GCC's always emit the DIEs corresponding
14809 to definitions of methods of classes as children of a
14810 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14811 the DIEs giving the declarations, which could be
14812 anywhere). But I don't see any reason why the
14813 standards says that they have to be there. */
14814 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14816 if (current_low
!= ((CORE_ADDR
) -1))
14818 best_low
= std::min (best_low
, current_low
);
14819 best_high
= std::max (best_high
, current_high
);
14827 child
= child
->sibling
;
14832 *highpc
= best_high
;
14835 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14839 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14840 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14842 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14843 struct gdbarch
*gdbarch
= objfile
->arch ();
14844 struct attribute
*attr
;
14845 struct attribute
*attr_high
;
14847 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14850 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14851 if (attr
!= nullptr)
14853 CORE_ADDR low
= attr
->as_address ();
14854 CORE_ADDR high
= attr_high
->as_address ();
14856 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14859 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14860 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14861 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14865 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14866 if (attr
!= nullptr && attr
->form_is_unsigned ())
14868 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14869 on DWARF version). */
14870 ULONGEST ranges_offset
= attr
->as_unsigned ();
14872 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14874 if (die
->tag
!= DW_TAG_compile_unit
)
14875 ranges_offset
+= cu
->gnu_ranges_base
;
14877 std::vector
<blockrange
> blockvec
;
14878 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14879 [&] (CORE_ADDR start
, CORE_ADDR end
)
14883 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14884 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14885 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14886 blockvec
.emplace_back (start
, end
);
14889 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14893 /* Check whether the producer field indicates either of GCC < 4.6, or the
14894 Intel C/C++ compiler, and cache the result in CU. */
14897 check_producer (struct dwarf2_cu
*cu
)
14901 if (cu
->producer
== NULL
)
14903 /* For unknown compilers expect their behavior is DWARF version
14906 GCC started to support .debug_types sections by -gdwarf-4 since
14907 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14908 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14909 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14910 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14912 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14914 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14915 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14917 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14919 cu
->producer_is_icc
= true;
14920 cu
->producer_is_icc_lt_14
= major
< 14;
14922 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14923 cu
->producer_is_codewarrior
= true;
14926 /* For other non-GCC compilers, expect their behavior is DWARF version
14930 cu
->checked_producer
= true;
14933 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14934 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14935 during 4.6.0 experimental. */
14938 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14940 if (!cu
->checked_producer
)
14941 check_producer (cu
);
14943 return cu
->producer_is_gxx_lt_4_6
;
14947 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14948 with incorrect is_stmt attributes. */
14951 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14953 if (!cu
->checked_producer
)
14954 check_producer (cu
);
14956 return cu
->producer_is_codewarrior
;
14959 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14960 If that attribute is not available, return the appropriate
14963 static enum dwarf_access_attribute
14964 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14966 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14967 if (attr
!= nullptr)
14969 LONGEST value
= attr
->constant_value (-1);
14970 if (value
== DW_ACCESS_public
14971 || value
== DW_ACCESS_protected
14972 || value
== DW_ACCESS_private
)
14973 return (dwarf_access_attribute
) value
;
14974 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14978 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14980 /* The default DWARF 2 accessibility for members is public, the default
14981 accessibility for inheritance is private. */
14983 if (die
->tag
!= DW_TAG_inheritance
)
14984 return DW_ACCESS_public
;
14986 return DW_ACCESS_private
;
14990 /* DWARF 3+ defines the default accessibility a different way. The same
14991 rules apply now for DW_TAG_inheritance as for the members and it only
14992 depends on the container kind. */
14994 if (die
->parent
->tag
== DW_TAG_class_type
)
14995 return DW_ACCESS_private
;
14997 return DW_ACCESS_public
;
15001 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
15002 offset. If the attribute was not found return 0, otherwise return
15003 1. If it was found but could not properly be handled, set *OFFSET
15007 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15010 struct attribute
*attr
;
15012 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15017 /* Note that we do not check for a section offset first here.
15018 This is because DW_AT_data_member_location is new in DWARF 4,
15019 so if we see it, we can assume that a constant form is really
15020 a constant and not a section offset. */
15021 if (attr
->form_is_constant ())
15022 *offset
= attr
->constant_value (0);
15023 else if (attr
->form_is_section_offset ())
15024 dwarf2_complex_location_expr_complaint ();
15025 else if (attr
->form_is_block ())
15026 *offset
= decode_locdesc (attr
->as_block (), cu
);
15028 dwarf2_complex_location_expr_complaint ();
15036 /* Look for DW_AT_data_member_location and store the results in FIELD. */
15039 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15040 struct field
*field
)
15042 struct attribute
*attr
;
15044 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15047 if (attr
->form_is_constant ())
15049 LONGEST offset
= attr
->constant_value (0);
15050 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
15052 else if (attr
->form_is_section_offset ())
15053 dwarf2_complex_location_expr_complaint ();
15054 else if (attr
->form_is_block ())
15057 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
15059 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
15062 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
15063 struct objfile
*objfile
= per_objfile
->objfile
;
15064 struct dwarf2_locexpr_baton
*dlbaton
15065 = XOBNEW (&objfile
->objfile_obstack
,
15066 struct dwarf2_locexpr_baton
);
15067 dlbaton
->data
= attr
->as_block ()->data
;
15068 dlbaton
->size
= attr
->as_block ()->size
;
15069 /* When using this baton, we want to compute the address
15070 of the field, not the value. This is why
15071 is_reference is set to false here. */
15072 dlbaton
->is_reference
= false;
15073 dlbaton
->per_objfile
= per_objfile
;
15074 dlbaton
->per_cu
= cu
->per_cu
;
15076 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
15080 dwarf2_complex_location_expr_complaint ();
15084 /* Add an aggregate field to the field list. */
15087 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15088 struct dwarf2_cu
*cu
)
15090 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15091 struct gdbarch
*gdbarch
= objfile
->arch ();
15092 struct nextfield
*new_field
;
15093 struct attribute
*attr
;
15095 const char *fieldname
= "";
15097 if (die
->tag
== DW_TAG_inheritance
)
15099 fip
->baseclasses
.emplace_back ();
15100 new_field
= &fip
->baseclasses
.back ();
15104 fip
->fields
.emplace_back ();
15105 new_field
= &fip
->fields
.back ();
15108 new_field
->offset
= die
->sect_off
;
15110 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
15111 if (new_field
->accessibility
!= DW_ACCESS_public
)
15112 fip
->non_public_fields
= true;
15114 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15115 if (attr
!= nullptr)
15116 new_field
->virtuality
= attr
->as_virtuality ();
15118 new_field
->virtuality
= DW_VIRTUALITY_none
;
15120 fp
= &new_field
->field
;
15122 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15124 /* Data member other than a C++ static data member. */
15126 /* Get type of field. */
15127 fp
->set_type (die_type (die
, cu
));
15129 SET_FIELD_BITPOS (*fp
, 0);
15131 /* Get bit size of field (zero if none). */
15132 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15133 if (attr
!= nullptr)
15135 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
15139 FIELD_BITSIZE (*fp
) = 0;
15142 /* Get bit offset of field. */
15143 handle_data_member_location (die
, cu
, fp
);
15144 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15145 if (attr
!= nullptr && attr
->form_is_constant ())
15147 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15149 /* For big endian bits, the DW_AT_bit_offset gives the
15150 additional bit offset from the MSB of the containing
15151 anonymous object to the MSB of the field. We don't
15152 have to do anything special since we don't need to
15153 know the size of the anonymous object. */
15154 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15155 + attr
->constant_value (0)));
15159 /* For little endian bits, compute the bit offset to the
15160 MSB of the anonymous object, subtract off the number of
15161 bits from the MSB of the field to the MSB of the
15162 object, and then subtract off the number of bits of
15163 the field itself. The result is the bit offset of
15164 the LSB of the field. */
15165 int anonymous_size
;
15166 int bit_offset
= attr
->constant_value (0);
15168 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15169 if (attr
!= nullptr && attr
->form_is_constant ())
15171 /* The size of the anonymous object containing
15172 the bit field is explicit, so use the
15173 indicated size (in bytes). */
15174 anonymous_size
= attr
->constant_value (0);
15178 /* The size of the anonymous object containing
15179 the bit field must be inferred from the type
15180 attribute of the data member containing the
15182 anonymous_size
= TYPE_LENGTH (fp
->type ());
15184 SET_FIELD_BITPOS (*fp
,
15185 (FIELD_BITPOS (*fp
)
15186 + anonymous_size
* bits_per_byte
15187 - bit_offset
- FIELD_BITSIZE (*fp
)));
15190 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15192 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15193 + attr
->constant_value (0)));
15195 /* Get name of field. */
15196 fieldname
= dwarf2_name (die
, cu
);
15197 if (fieldname
== NULL
)
15200 /* The name is already allocated along with this objfile, so we don't
15201 need to duplicate it for the type. */
15202 fp
->name
= fieldname
;
15204 /* Change accessibility for artificial fields (e.g. virtual table
15205 pointer or virtual base class pointer) to private. */
15206 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15208 FIELD_ARTIFICIAL (*fp
) = 1;
15209 new_field
->accessibility
= DW_ACCESS_private
;
15210 fip
->non_public_fields
= true;
15213 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15215 /* C++ static member. */
15217 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15218 is a declaration, but all versions of G++ as of this writing
15219 (so through at least 3.2.1) incorrectly generate
15220 DW_TAG_variable tags. */
15222 const char *physname
;
15224 /* Get name of field. */
15225 fieldname
= dwarf2_name (die
, cu
);
15226 if (fieldname
== NULL
)
15229 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15231 /* Only create a symbol if this is an external value.
15232 new_symbol checks this and puts the value in the global symbol
15233 table, which we want. If it is not external, new_symbol
15234 will try to put the value in cu->list_in_scope which is wrong. */
15235 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15237 /* A static const member, not much different than an enum as far as
15238 we're concerned, except that we can support more types. */
15239 new_symbol (die
, NULL
, cu
);
15242 /* Get physical name. */
15243 physname
= dwarf2_physname (fieldname
, die
, cu
);
15245 /* The name is already allocated along with this objfile, so we don't
15246 need to duplicate it for the type. */
15247 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15248 fp
->set_type (die_type (die
, cu
));
15249 FIELD_NAME (*fp
) = fieldname
;
15251 else if (die
->tag
== DW_TAG_inheritance
)
15253 /* C++ base class field. */
15254 handle_data_member_location (die
, cu
, fp
);
15255 FIELD_BITSIZE (*fp
) = 0;
15256 fp
->set_type (die_type (die
, cu
));
15257 FIELD_NAME (*fp
) = fp
->type ()->name ();
15260 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15263 /* Can the type given by DIE define another type? */
15266 type_can_define_types (const struct die_info
*die
)
15270 case DW_TAG_typedef
:
15271 case DW_TAG_class_type
:
15272 case DW_TAG_structure_type
:
15273 case DW_TAG_union_type
:
15274 case DW_TAG_enumeration_type
:
15282 /* Add a type definition defined in the scope of the FIP's class. */
15285 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15286 struct dwarf2_cu
*cu
)
15288 struct decl_field fp
;
15289 memset (&fp
, 0, sizeof (fp
));
15291 gdb_assert (type_can_define_types (die
));
15293 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15294 fp
.name
= dwarf2_name (die
, cu
);
15295 fp
.type
= read_type_die (die
, cu
);
15297 /* Save accessibility. */
15298 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15299 switch (accessibility
)
15301 case DW_ACCESS_public
:
15302 /* The assumed value if neither private nor protected. */
15304 case DW_ACCESS_private
:
15307 case DW_ACCESS_protected
:
15308 fp
.is_protected
= 1;
15312 if (die
->tag
== DW_TAG_typedef
)
15313 fip
->typedef_field_list
.push_back (fp
);
15315 fip
->nested_types_list
.push_back (fp
);
15318 /* A convenience typedef that's used when finding the discriminant
15319 field for a variant part. */
15320 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
15323 /* Compute the discriminant range for a given variant. OBSTACK is
15324 where the results will be stored. VARIANT is the variant to
15325 process. IS_UNSIGNED indicates whether the discriminant is signed
15328 static const gdb::array_view
<discriminant_range
>
15329 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
15332 std::vector
<discriminant_range
> ranges
;
15334 if (variant
.default_branch
)
15337 if (variant
.discr_list_data
== nullptr)
15339 discriminant_range r
15340 = {variant
.discriminant_value
, variant
.discriminant_value
};
15341 ranges
.push_back (r
);
15345 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
15346 variant
.discr_list_data
->size
);
15347 while (!data
.empty ())
15349 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
15351 complaint (_("invalid discriminant marker: %d"), data
[0]);
15354 bool is_range
= data
[0] == DW_DSC_range
;
15355 data
= data
.slice (1);
15357 ULONGEST low
, high
;
15358 unsigned int bytes_read
;
15362 complaint (_("DW_AT_discr_list missing low value"));
15366 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
15368 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
15370 data
= data
.slice (bytes_read
);
15376 complaint (_("DW_AT_discr_list missing high value"));
15380 high
= read_unsigned_leb128 (nullptr, data
.data (),
15383 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
15385 data
= data
.slice (bytes_read
);
15390 ranges
.push_back ({ low
, high
});
15394 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
15396 std::copy (ranges
.begin (), ranges
.end (), result
);
15397 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
15400 static const gdb::array_view
<variant_part
> create_variant_parts
15401 (struct obstack
*obstack
,
15402 const offset_map_type
&offset_map
,
15403 struct field_info
*fi
,
15404 const std::vector
<variant_part_builder
> &variant_parts
);
15406 /* Fill in a "struct variant" for a given variant field. RESULT is
15407 the variant to fill in. OBSTACK is where any needed allocations
15408 will be done. OFFSET_MAP holds the mapping from section offsets to
15409 fields for the type. FI describes the fields of the type we're
15410 processing. FIELD is the variant field we're converting. */
15413 create_one_variant (variant
&result
, struct obstack
*obstack
,
15414 const offset_map_type
&offset_map
,
15415 struct field_info
*fi
, const variant_field
&field
)
15417 result
.discriminants
= convert_variant_range (obstack
, field
, false);
15418 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
15419 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
15420 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
15421 field
.variant_parts
);
15424 /* Fill in a "struct variant_part" for a given variant part. RESULT
15425 is the variant part to fill in. OBSTACK is where any needed
15426 allocations will be done. OFFSET_MAP holds the mapping from
15427 section offsets to fields for the type. FI describes the fields of
15428 the type we're processing. BUILDER is the variant part to be
15432 create_one_variant_part (variant_part
&result
,
15433 struct obstack
*obstack
,
15434 const offset_map_type
&offset_map
,
15435 struct field_info
*fi
,
15436 const variant_part_builder
&builder
)
15438 auto iter
= offset_map
.find (builder
.discriminant_offset
);
15439 if (iter
== offset_map
.end ())
15441 result
.discriminant_index
= -1;
15442 /* Doesn't matter. */
15443 result
.is_unsigned
= false;
15447 result
.discriminant_index
= iter
->second
;
15449 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
15452 size_t n
= builder
.variants
.size ();
15453 variant
*output
= new (obstack
) variant
[n
];
15454 for (size_t i
= 0; i
< n
; ++i
)
15455 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
15456 builder
.variants
[i
]);
15458 result
.variants
= gdb::array_view
<variant
> (output
, n
);
15461 /* Create a vector of variant parts that can be attached to a type.
15462 OBSTACK is where any needed allocations will be done. OFFSET_MAP
15463 holds the mapping from section offsets to fields for the type. FI
15464 describes the fields of the type we're processing. VARIANT_PARTS
15465 is the vector to convert. */
15467 static const gdb::array_view
<variant_part
>
15468 create_variant_parts (struct obstack
*obstack
,
15469 const offset_map_type
&offset_map
,
15470 struct field_info
*fi
,
15471 const std::vector
<variant_part_builder
> &variant_parts
)
15473 if (variant_parts
.empty ())
15476 size_t n
= variant_parts
.size ();
15477 variant_part
*result
= new (obstack
) variant_part
[n
];
15478 for (size_t i
= 0; i
< n
; ++i
)
15479 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
15482 return gdb::array_view
<variant_part
> (result
, n
);
15485 /* Compute the variant part vector for FIP, attaching it to TYPE when
15489 add_variant_property (struct field_info
*fip
, struct type
*type
,
15490 struct dwarf2_cu
*cu
)
15492 /* Map section offsets of fields to their field index. Note the
15493 field index here does not take the number of baseclasses into
15495 offset_map_type offset_map
;
15496 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
15497 offset_map
[fip
->fields
[i
].offset
] = i
;
15499 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15500 gdb::array_view
<variant_part
> parts
15501 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
15502 fip
->variant_parts
);
15504 struct dynamic_prop prop
;
15505 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
15506 obstack_copy (&objfile
->objfile_obstack
, &parts
,
15509 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
15512 /* Create the vector of fields, and attach it to the type. */
15515 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15516 struct dwarf2_cu
*cu
)
15518 int nfields
= fip
->nfields ();
15520 /* Record the field count, allocate space for the array of fields,
15521 and create blank accessibility bitfields if necessary. */
15522 type
->set_num_fields (nfields
);
15524 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
15526 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15528 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15530 TYPE_FIELD_PRIVATE_BITS (type
) =
15531 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15532 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15534 TYPE_FIELD_PROTECTED_BITS (type
) =
15535 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15536 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15538 TYPE_FIELD_IGNORE_BITS (type
) =
15539 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15540 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15543 /* If the type has baseclasses, allocate and clear a bit vector for
15544 TYPE_FIELD_VIRTUAL_BITS. */
15545 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15547 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15548 unsigned char *pointer
;
15550 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15551 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15552 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15553 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15554 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15557 if (!fip
->variant_parts
.empty ())
15558 add_variant_property (fip
, type
, cu
);
15560 /* Copy the saved-up fields into the field vector. */
15561 for (int i
= 0; i
< nfields
; ++i
)
15563 struct nextfield
&field
15564 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15565 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15567 type
->field (i
) = field
.field
;
15568 switch (field
.accessibility
)
15570 case DW_ACCESS_private
:
15571 if (cu
->language
!= language_ada
)
15572 SET_TYPE_FIELD_PRIVATE (type
, i
);
15575 case DW_ACCESS_protected
:
15576 if (cu
->language
!= language_ada
)
15577 SET_TYPE_FIELD_PROTECTED (type
, i
);
15580 case DW_ACCESS_public
:
15584 /* Unknown accessibility. Complain and treat it as public. */
15586 complaint (_("unsupported accessibility %d"),
15587 field
.accessibility
);
15591 if (i
< fip
->baseclasses
.size ())
15593 switch (field
.virtuality
)
15595 case DW_VIRTUALITY_virtual
:
15596 case DW_VIRTUALITY_pure_virtual
:
15597 if (cu
->language
== language_ada
)
15598 error (_("unexpected virtuality in component of Ada type"));
15599 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15606 /* Return true if this member function is a constructor, false
15610 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15612 const char *fieldname
;
15613 const char *type_name
;
15616 if (die
->parent
== NULL
)
15619 if (die
->parent
->tag
!= DW_TAG_structure_type
15620 && die
->parent
->tag
!= DW_TAG_union_type
15621 && die
->parent
->tag
!= DW_TAG_class_type
)
15624 fieldname
= dwarf2_name (die
, cu
);
15625 type_name
= dwarf2_name (die
->parent
, cu
);
15626 if (fieldname
== NULL
|| type_name
== NULL
)
15629 len
= strlen (fieldname
);
15630 return (strncmp (fieldname
, type_name
, len
) == 0
15631 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15634 /* Add a member function to the proper fieldlist. */
15637 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15638 struct type
*type
, struct dwarf2_cu
*cu
)
15640 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15641 struct attribute
*attr
;
15643 struct fnfieldlist
*flp
= nullptr;
15644 struct fn_field
*fnp
;
15645 const char *fieldname
;
15646 struct type
*this_type
;
15648 if (cu
->language
== language_ada
)
15649 error (_("unexpected member function in Ada type"));
15651 /* Get name of member function. */
15652 fieldname
= dwarf2_name (die
, cu
);
15653 if (fieldname
== NULL
)
15656 /* Look up member function name in fieldlist. */
15657 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15659 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15661 flp
= &fip
->fnfieldlists
[i
];
15666 /* Create a new fnfieldlist if necessary. */
15667 if (flp
== nullptr)
15669 fip
->fnfieldlists
.emplace_back ();
15670 flp
= &fip
->fnfieldlists
.back ();
15671 flp
->name
= fieldname
;
15672 i
= fip
->fnfieldlists
.size () - 1;
15675 /* Create a new member function field and add it to the vector of
15677 flp
->fnfields
.emplace_back ();
15678 fnp
= &flp
->fnfields
.back ();
15680 /* Delay processing of the physname until later. */
15681 if (cu
->language
== language_cplus
)
15682 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15686 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15687 fnp
->physname
= physname
? physname
: "";
15690 fnp
->type
= alloc_type (objfile
);
15691 this_type
= read_type_die (die
, cu
);
15692 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15694 int nparams
= this_type
->num_fields ();
15696 /* TYPE is the domain of this method, and THIS_TYPE is the type
15697 of the method itself (TYPE_CODE_METHOD). */
15698 smash_to_method_type (fnp
->type
, type
,
15699 TYPE_TARGET_TYPE (this_type
),
15700 this_type
->fields (),
15701 this_type
->num_fields (),
15702 this_type
->has_varargs ());
15704 /* Handle static member functions.
15705 Dwarf2 has no clean way to discern C++ static and non-static
15706 member functions. G++ helps GDB by marking the first
15707 parameter for non-static member functions (which is the this
15708 pointer) as artificial. We obtain this information from
15709 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15710 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15711 fnp
->voffset
= VOFFSET_STATIC
;
15714 complaint (_("member function type missing for '%s'"),
15715 dwarf2_full_name (fieldname
, die
, cu
));
15717 /* Get fcontext from DW_AT_containing_type if present. */
15718 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15719 fnp
->fcontext
= die_containing_type (die
, cu
);
15721 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15722 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15724 /* Get accessibility. */
15725 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15726 switch (accessibility
)
15728 case DW_ACCESS_private
:
15729 fnp
->is_private
= 1;
15731 case DW_ACCESS_protected
:
15732 fnp
->is_protected
= 1;
15736 /* Check for artificial methods. */
15737 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15738 if (attr
&& attr
->as_boolean ())
15739 fnp
->is_artificial
= 1;
15741 /* Check for defaulted methods. */
15742 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15743 if (attr
!= nullptr)
15744 fnp
->defaulted
= attr
->defaulted ();
15746 /* Check for deleted methods. */
15747 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15748 if (attr
!= nullptr && attr
->as_boolean ())
15749 fnp
->is_deleted
= 1;
15751 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15753 /* Get index in virtual function table if it is a virtual member
15754 function. For older versions of GCC, this is an offset in the
15755 appropriate virtual table, as specified by DW_AT_containing_type.
15756 For everyone else, it is an expression to be evaluated relative
15757 to the object address. */
15759 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15760 if (attr
!= nullptr)
15762 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15764 struct dwarf_block
*block
= attr
->as_block ();
15766 if (block
->data
[0] == DW_OP_constu
)
15768 /* Old-style GCC. */
15769 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15771 else if (block
->data
[0] == DW_OP_deref
15772 || (block
->size
> 1
15773 && block
->data
[0] == DW_OP_deref_size
15774 && block
->data
[1] == cu
->header
.addr_size
))
15776 fnp
->voffset
= decode_locdesc (block
, cu
);
15777 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15778 dwarf2_complex_location_expr_complaint ();
15780 fnp
->voffset
/= cu
->header
.addr_size
;
15784 dwarf2_complex_location_expr_complaint ();
15786 if (!fnp
->fcontext
)
15788 /* If there is no `this' field and no DW_AT_containing_type,
15789 we cannot actually find a base class context for the
15791 if (this_type
->num_fields () == 0
15792 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15794 complaint (_("cannot determine context for virtual member "
15795 "function \"%s\" (offset %s)"),
15796 fieldname
, sect_offset_str (die
->sect_off
));
15801 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15805 else if (attr
->form_is_section_offset ())
15807 dwarf2_complex_location_expr_complaint ();
15811 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15817 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15818 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15820 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15821 complaint (_("Member function \"%s\" (offset %s) is virtual "
15822 "but the vtable offset is not specified"),
15823 fieldname
, sect_offset_str (die
->sect_off
));
15824 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15825 TYPE_CPLUS_DYNAMIC (type
) = 1;
15830 /* Create the vector of member function fields, and attach it to the type. */
15833 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15834 struct dwarf2_cu
*cu
)
15836 if (cu
->language
== language_ada
)
15837 error (_("unexpected member functions in Ada type"));
15839 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15840 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15842 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15844 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15846 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15847 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15849 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15850 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15851 fn_flp
->fn_fields
= (struct fn_field
*)
15852 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15854 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15855 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15858 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15861 /* Returns non-zero if NAME is the name of a vtable member in CU's
15862 language, zero otherwise. */
15864 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15866 static const char vptr
[] = "_vptr";
15868 /* Look for the C++ form of the vtable. */
15869 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15875 /* GCC outputs unnamed structures that are really pointers to member
15876 functions, with the ABI-specified layout. If TYPE describes
15877 such a structure, smash it into a member function type.
15879 GCC shouldn't do this; it should just output pointer to member DIEs.
15880 This is GCC PR debug/28767. */
15883 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15885 struct type
*pfn_type
, *self_type
, *new_type
;
15887 /* Check for a structure with no name and two children. */
15888 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15891 /* Check for __pfn and __delta members. */
15892 if (TYPE_FIELD_NAME (type
, 0) == NULL
15893 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15894 || TYPE_FIELD_NAME (type
, 1) == NULL
15895 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15898 /* Find the type of the method. */
15899 pfn_type
= type
->field (0).type ();
15900 if (pfn_type
== NULL
15901 || pfn_type
->code () != TYPE_CODE_PTR
15902 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15905 /* Look for the "this" argument. */
15906 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15907 if (pfn_type
->num_fields () == 0
15908 /* || pfn_type->field (0).type () == NULL */
15909 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15912 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15913 new_type
= alloc_type (objfile
);
15914 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15915 pfn_type
->fields (), pfn_type
->num_fields (),
15916 pfn_type
->has_varargs ());
15917 smash_to_methodptr_type (type
, new_type
);
15920 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15921 requires rewriting, then copy it and return the updated copy.
15922 Otherwise return nullptr. */
15924 static struct type
*
15925 rewrite_array_type (struct type
*type
)
15927 if (type
->code () != TYPE_CODE_ARRAY
)
15930 struct type
*index_type
= type
->index_type ();
15931 range_bounds
*current_bounds
= index_type
->bounds ();
15933 /* Handle multi-dimensional arrays. */
15934 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15935 if (new_target
== nullptr)
15937 /* Maybe we don't need to rewrite this array. */
15938 if (current_bounds
->low
.kind () == PROP_CONST
15939 && current_bounds
->high
.kind () == PROP_CONST
)
15943 /* Either the target type was rewritten, or the bounds have to be
15944 updated. Either way we want to copy the type and update
15946 struct type
*copy
= copy_type (type
);
15947 int nfields
= copy
->num_fields ();
15949 = ((struct field
*) TYPE_ZALLOC (copy
,
15950 nfields
* sizeof (struct field
)));
15951 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15952 copy
->set_fields (new_fields
);
15953 if (new_target
!= nullptr)
15954 TYPE_TARGET_TYPE (copy
) = new_target
;
15956 struct type
*index_copy
= copy_type (index_type
);
15957 range_bounds
*bounds
15958 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15959 sizeof (range_bounds
));
15960 *bounds
= *current_bounds
;
15961 bounds
->low
.set_const_val (1);
15962 bounds
->high
.set_const_val (0);
15963 index_copy
->set_bounds (bounds
);
15964 copy
->set_index_type (index_copy
);
15969 /* While some versions of GCC will generate complicated DWARF for an
15970 array (see quirk_ada_thick_pointer), more recent versions were
15971 modified to emit an explicit thick pointer structure. However, in
15972 this case, the array still has DWARF expressions for its ranges,
15973 and these must be ignored. */
15976 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15979 gdb_assert (cu
->language
== language_ada
);
15981 /* Check for a structure with two children. */
15982 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15985 /* Check for P_ARRAY and P_BOUNDS members. */
15986 if (TYPE_FIELD_NAME (type
, 0) == NULL
15987 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
15988 || TYPE_FIELD_NAME (type
, 1) == NULL
15989 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
15992 /* Make sure we're looking at a pointer to an array. */
15993 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15996 /* The Ada code already knows how to handle these types, so all that
15997 we need to do is turn the bounds into static bounds. However, we
15998 don't want to rewrite existing array or index types in-place,
15999 because those may be referenced in other contexts where this
16000 rewriting is undesirable. */
16001 struct type
*new_ary_type
16002 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
16003 if (new_ary_type
!= nullptr)
16004 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
16007 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
16008 appropriate error checking and issuing complaints if there is a
16012 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
16014 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
16016 if (attr
== nullptr)
16019 if (!attr
->form_is_constant ())
16021 complaint (_("DW_AT_alignment must have constant form"
16022 " - DIE at %s [in module %s]"),
16023 sect_offset_str (die
->sect_off
),
16024 objfile_name (cu
->per_objfile
->objfile
));
16028 LONGEST val
= attr
->constant_value (0);
16031 complaint (_("DW_AT_alignment value must not be negative"
16032 " - DIE at %s [in module %s]"),
16033 sect_offset_str (die
->sect_off
),
16034 objfile_name (cu
->per_objfile
->objfile
));
16037 ULONGEST align
= val
;
16041 complaint (_("DW_AT_alignment value must not be zero"
16042 " - DIE at %s [in module %s]"),
16043 sect_offset_str (die
->sect_off
),
16044 objfile_name (cu
->per_objfile
->objfile
));
16047 if ((align
& (align
- 1)) != 0)
16049 complaint (_("DW_AT_alignment value must be a power of 2"
16050 " - DIE at %s [in module %s]"),
16051 sect_offset_str (die
->sect_off
),
16052 objfile_name (cu
->per_objfile
->objfile
));
16059 /* If the DIE has a DW_AT_alignment attribute, use its value to set
16060 the alignment for TYPE. */
16063 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
16066 if (!set_type_align (type
, get_alignment (cu
, die
)))
16067 complaint (_("DW_AT_alignment value too large"
16068 " - DIE at %s [in module %s]"),
16069 sect_offset_str (die
->sect_off
),
16070 objfile_name (cu
->per_objfile
->objfile
));
16073 /* Check if the given VALUE is a valid enum dwarf_calling_convention
16074 constant for a type, according to DWARF5 spec, Table 5.5. */
16077 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
16082 case DW_CC_pass_by_reference
:
16083 case DW_CC_pass_by_value
:
16087 complaint (_("unrecognized DW_AT_calling_convention value "
16088 "(%s) for a type"), pulongest (value
));
16093 /* Check if the given VALUE is a valid enum dwarf_calling_convention
16094 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
16095 also according to GNU-specific values (see include/dwarf2.h). */
16098 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
16103 case DW_CC_program
:
16107 case DW_CC_GNU_renesas_sh
:
16108 case DW_CC_GNU_borland_fastcall_i386
:
16109 case DW_CC_GDB_IBM_OpenCL
:
16113 complaint (_("unrecognized DW_AT_calling_convention value "
16114 "(%s) for a subroutine"), pulongest (value
));
16119 /* Called when we find the DIE that starts a structure or union scope
16120 (definition) to create a type for the structure or union. Fill in
16121 the type's name and general properties; the members will not be
16122 processed until process_structure_scope. A symbol table entry for
16123 the type will also not be done until process_structure_scope (assuming
16124 the type has a name).
16126 NOTE: we need to call these functions regardless of whether or not the
16127 DIE has a DW_AT_name attribute, since it might be an anonymous
16128 structure or union. This gets the type entered into our set of
16129 user defined types. */
16131 static struct type
*
16132 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16134 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16136 struct attribute
*attr
;
16139 /* If the definition of this type lives in .debug_types, read that type.
16140 Don't follow DW_AT_specification though, that will take us back up
16141 the chain and we want to go down. */
16142 attr
= die
->attr (DW_AT_signature
);
16143 if (attr
!= nullptr)
16145 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16147 /* The type's CU may not be the same as CU.
16148 Ensure TYPE is recorded with CU in die_type_hash. */
16149 return set_die_type (die
, type
, cu
);
16152 type
= alloc_type (objfile
);
16153 INIT_CPLUS_SPECIFIC (type
);
16155 name
= dwarf2_name (die
, cu
);
16158 if (cu
->language
== language_cplus
16159 || cu
->language
== language_d
16160 || cu
->language
== language_rust
)
16162 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
16164 /* dwarf2_full_name might have already finished building the DIE's
16165 type. If so, there is no need to continue. */
16166 if (get_die_type (die
, cu
) != NULL
)
16167 return get_die_type (die
, cu
);
16169 type
->set_name (full_name
);
16173 /* The name is already allocated along with this objfile, so
16174 we don't need to duplicate it for the type. */
16175 type
->set_name (name
);
16179 if (die
->tag
== DW_TAG_structure_type
)
16181 type
->set_code (TYPE_CODE_STRUCT
);
16183 else if (die
->tag
== DW_TAG_union_type
)
16185 type
->set_code (TYPE_CODE_UNION
);
16189 type
->set_code (TYPE_CODE_STRUCT
);
16192 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
16193 TYPE_DECLARED_CLASS (type
) = 1;
16195 /* Store the calling convention in the type if it's available in
16196 the die. Otherwise the calling convention remains set to
16197 the default value DW_CC_normal. */
16198 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16199 if (attr
!= nullptr
16200 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
16202 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16203 TYPE_CPLUS_CALLING_CONVENTION (type
)
16204 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
16207 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16208 if (attr
!= nullptr)
16210 if (attr
->form_is_constant ())
16211 TYPE_LENGTH (type
) = attr
->constant_value (0);
16214 struct dynamic_prop prop
;
16215 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
16216 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
16217 TYPE_LENGTH (type
) = 0;
16222 TYPE_LENGTH (type
) = 0;
16225 maybe_set_alignment (cu
, die
, type
);
16227 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16229 /* ICC<14 does not output the required DW_AT_declaration on
16230 incomplete types, but gives them a size of zero. */
16231 type
->set_is_stub (true);
16234 type
->set_stub_is_supported (true);
16236 if (die_is_declaration (die
, cu
))
16237 type
->set_is_stub (true);
16238 else if (attr
== NULL
&& die
->child
== NULL
16239 && producer_is_realview (cu
->producer
))
16240 /* RealView does not output the required DW_AT_declaration
16241 on incomplete types. */
16242 type
->set_is_stub (true);
16244 /* We need to add the type field to the die immediately so we don't
16245 infinitely recurse when dealing with pointers to the structure
16246 type within the structure itself. */
16247 set_die_type (die
, type
, cu
);
16249 /* set_die_type should be already done. */
16250 set_descriptive_type (type
, die
, cu
);
16255 static void handle_struct_member_die
16256 (struct die_info
*child_die
,
16258 struct field_info
*fi
,
16259 std::vector
<struct symbol
*> *template_args
,
16260 struct dwarf2_cu
*cu
);
16262 /* A helper for handle_struct_member_die that handles
16263 DW_TAG_variant_part. */
16266 handle_variant_part (struct die_info
*die
, struct type
*type
,
16267 struct field_info
*fi
,
16268 std::vector
<struct symbol
*> *template_args
,
16269 struct dwarf2_cu
*cu
)
16271 variant_part_builder
*new_part
;
16272 if (fi
->current_variant_part
== nullptr)
16274 fi
->variant_parts
.emplace_back ();
16275 new_part
= &fi
->variant_parts
.back ();
16277 else if (!fi
->current_variant_part
->processing_variant
)
16279 complaint (_("nested DW_TAG_variant_part seen "
16280 "- DIE at %s [in module %s]"),
16281 sect_offset_str (die
->sect_off
),
16282 objfile_name (cu
->per_objfile
->objfile
));
16287 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
16288 current
.variant_parts
.emplace_back ();
16289 new_part
= ¤t
.variant_parts
.back ();
16292 /* When we recurse, we want callees to add to this new variant
16294 scoped_restore save_current_variant_part
16295 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
16297 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16300 /* It's a univariant form, an extension we support. */
16302 else if (discr
->form_is_ref ())
16304 struct dwarf2_cu
*target_cu
= cu
;
16305 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16307 new_part
->discriminant_offset
= target_die
->sect_off
;
16311 complaint (_("DW_AT_discr does not have DIE reference form"
16312 " - DIE at %s [in module %s]"),
16313 sect_offset_str (die
->sect_off
),
16314 objfile_name (cu
->per_objfile
->objfile
));
16317 for (die_info
*child_die
= die
->child
;
16319 child_die
= child_die
->sibling
)
16320 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
16323 /* A helper for handle_struct_member_die that handles
16327 handle_variant (struct die_info
*die
, struct type
*type
,
16328 struct field_info
*fi
,
16329 std::vector
<struct symbol
*> *template_args
,
16330 struct dwarf2_cu
*cu
)
16332 if (fi
->current_variant_part
== nullptr)
16334 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
16335 "- DIE at %s [in module %s]"),
16336 sect_offset_str (die
->sect_off
),
16337 objfile_name (cu
->per_objfile
->objfile
));
16340 if (fi
->current_variant_part
->processing_variant
)
16342 complaint (_("nested DW_TAG_variant seen "
16343 "- DIE at %s [in module %s]"),
16344 sect_offset_str (die
->sect_off
),
16345 objfile_name (cu
->per_objfile
->objfile
));
16349 scoped_restore save_processing_variant
16350 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
16353 fi
->current_variant_part
->variants
.emplace_back ();
16354 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
16355 variant
.first_field
= fi
->fields
.size ();
16357 /* In a variant we want to get the discriminant and also add a
16358 field for our sole member child. */
16359 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
16360 if (discr
== nullptr || !discr
->form_is_constant ())
16362 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
16363 if (discr
== nullptr || discr
->as_block ()->size
== 0)
16364 variant
.default_branch
= true;
16366 variant
.discr_list_data
= discr
->as_block ();
16369 variant
.discriminant_value
= discr
->constant_value (0);
16371 for (die_info
*variant_child
= die
->child
;
16372 variant_child
!= NULL
;
16373 variant_child
= variant_child
->sibling
)
16374 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
16376 variant
.last_field
= fi
->fields
.size ();
16379 /* A helper for process_structure_scope that handles a single member
16383 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16384 struct field_info
*fi
,
16385 std::vector
<struct symbol
*> *template_args
,
16386 struct dwarf2_cu
*cu
)
16388 if (child_die
->tag
== DW_TAG_member
16389 || child_die
->tag
== DW_TAG_variable
)
16391 /* NOTE: carlton/2002-11-05: A C++ static data member
16392 should be a DW_TAG_member that is a declaration, but
16393 all versions of G++ as of this writing (so through at
16394 least 3.2.1) incorrectly generate DW_TAG_variable
16395 tags for them instead. */
16396 dwarf2_add_field (fi
, child_die
, cu
);
16398 else if (child_die
->tag
== DW_TAG_subprogram
)
16400 /* Rust doesn't have member functions in the C++ sense.
16401 However, it does emit ordinary functions as children
16402 of a struct DIE. */
16403 if (cu
->language
== language_rust
)
16404 read_func_scope (child_die
, cu
);
16407 /* C++ member function. */
16408 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16411 else if (child_die
->tag
== DW_TAG_inheritance
)
16413 /* C++ base class field. */
16414 dwarf2_add_field (fi
, child_die
, cu
);
16416 else if (type_can_define_types (child_die
))
16417 dwarf2_add_type_defn (fi
, child_die
, cu
);
16418 else if (child_die
->tag
== DW_TAG_template_type_param
16419 || child_die
->tag
== DW_TAG_template_value_param
)
16421 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16424 template_args
->push_back (arg
);
16426 else if (child_die
->tag
== DW_TAG_variant_part
)
16427 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
16428 else if (child_die
->tag
== DW_TAG_variant
)
16429 handle_variant (child_die
, type
, fi
, template_args
, cu
);
16432 /* Finish creating a structure or union type, including filling in
16433 its members and creating a symbol for it. */
16436 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16438 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16439 struct die_info
*child_die
;
16442 type
= get_die_type (die
, cu
);
16444 type
= read_structure_type (die
, cu
);
16446 bool has_template_parameters
= false;
16447 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16449 struct field_info fi
;
16450 std::vector
<struct symbol
*> template_args
;
16452 child_die
= die
->child
;
16454 while (child_die
&& child_die
->tag
)
16456 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16457 child_die
= child_die
->sibling
;
16460 /* Attach template arguments to type. */
16461 if (!template_args
.empty ())
16463 has_template_parameters
= true;
16464 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16465 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16466 TYPE_TEMPLATE_ARGUMENTS (type
)
16467 = XOBNEWVEC (&objfile
->objfile_obstack
,
16469 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16470 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16471 template_args
.data (),
16472 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16473 * sizeof (struct symbol
*)));
16476 /* Attach fields and member functions to the type. */
16477 if (fi
.nfields () > 0)
16478 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16479 if (!fi
.fnfieldlists
.empty ())
16481 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16483 /* Get the type which refers to the base class (possibly this
16484 class itself) which contains the vtable pointer for the current
16485 class from the DW_AT_containing_type attribute. This use of
16486 DW_AT_containing_type is a GNU extension. */
16488 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16490 struct type
*t
= die_containing_type (die
, cu
);
16492 set_type_vptr_basetype (type
, t
);
16497 /* Our own class provides vtbl ptr. */
16498 for (i
= t
->num_fields () - 1;
16499 i
>= TYPE_N_BASECLASSES (t
);
16502 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16504 if (is_vtable_name (fieldname
, cu
))
16506 set_type_vptr_fieldno (type
, i
);
16511 /* Complain if virtual function table field not found. */
16512 if (i
< TYPE_N_BASECLASSES (t
))
16513 complaint (_("virtual function table pointer "
16514 "not found when defining class '%s'"),
16515 type
->name () ? type
->name () : "");
16519 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16522 else if (cu
->producer
16523 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16525 /* The IBM XLC compiler does not provide direct indication
16526 of the containing type, but the vtable pointer is
16527 always named __vfp. */
16531 for (i
= type
->num_fields () - 1;
16532 i
>= TYPE_N_BASECLASSES (type
);
16535 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16537 set_type_vptr_fieldno (type
, i
);
16538 set_type_vptr_basetype (type
, type
);
16545 /* Copy fi.typedef_field_list linked list elements content into the
16546 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16547 if (!fi
.typedef_field_list
.empty ())
16549 int count
= fi
.typedef_field_list
.size ();
16551 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16552 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16553 = ((struct decl_field
*)
16555 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16556 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16558 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16559 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16562 /* Copy fi.nested_types_list linked list elements content into the
16563 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16564 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16566 int count
= fi
.nested_types_list
.size ();
16568 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16569 TYPE_NESTED_TYPES_ARRAY (type
)
16570 = ((struct decl_field
*)
16571 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16572 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16574 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16575 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16579 quirk_gcc_member_function_pointer (type
, objfile
);
16580 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16581 cu
->rust_unions
.push_back (type
);
16582 else if (cu
->language
== language_ada
)
16583 quirk_ada_thick_pointer_struct (die
, cu
, type
);
16585 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16586 snapshots) has been known to create a die giving a declaration
16587 for a class that has, as a child, a die giving a definition for a
16588 nested class. So we have to process our children even if the
16589 current die is a declaration. Normally, of course, a declaration
16590 won't have any children at all. */
16592 child_die
= die
->child
;
16594 while (child_die
!= NULL
&& child_die
->tag
)
16596 if (child_die
->tag
== DW_TAG_member
16597 || child_die
->tag
== DW_TAG_variable
16598 || child_die
->tag
== DW_TAG_inheritance
16599 || child_die
->tag
== DW_TAG_template_value_param
16600 || child_die
->tag
== DW_TAG_template_type_param
)
16605 process_die (child_die
, cu
);
16607 child_die
= child_die
->sibling
;
16610 /* Do not consider external references. According to the DWARF standard,
16611 these DIEs are identified by the fact that they have no byte_size
16612 attribute, and a declaration attribute. */
16613 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16614 || !die_is_declaration (die
, cu
)
16615 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16617 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16619 if (has_template_parameters
)
16621 struct symtab
*symtab
;
16622 if (sym
!= nullptr)
16623 symtab
= symbol_symtab (sym
);
16624 else if (cu
->line_header
!= nullptr)
16626 /* Any related symtab will do. */
16628 = cu
->line_header
->file_names ()[0].symtab
;
16633 complaint (_("could not find suitable "
16634 "symtab for template parameter"
16635 " - DIE at %s [in module %s]"),
16636 sect_offset_str (die
->sect_off
),
16637 objfile_name (objfile
));
16640 if (symtab
!= nullptr)
16642 /* Make sure that the symtab is set on the new symbols.
16643 Even though they don't appear in this symtab directly,
16644 other parts of gdb assume that symbols do, and this is
16645 reasonably true. */
16646 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16647 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16653 /* Assuming DIE is an enumeration type, and TYPE is its associated
16654 type, update TYPE using some information only available in DIE's
16655 children. In particular, the fields are computed. */
16658 update_enumeration_type_from_children (struct die_info
*die
,
16660 struct dwarf2_cu
*cu
)
16662 struct die_info
*child_die
;
16663 int unsigned_enum
= 1;
16666 auto_obstack obstack
;
16667 std::vector
<struct field
> fields
;
16669 for (child_die
= die
->child
;
16670 child_die
!= NULL
&& child_die
->tag
;
16671 child_die
= child_die
->sibling
)
16673 struct attribute
*attr
;
16675 const gdb_byte
*bytes
;
16676 struct dwarf2_locexpr_baton
*baton
;
16679 if (child_die
->tag
!= DW_TAG_enumerator
)
16682 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16686 name
= dwarf2_name (child_die
, cu
);
16688 name
= "<anonymous enumerator>";
16690 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16691 &value
, &bytes
, &baton
);
16699 if (count_one_bits_ll (value
) >= 2)
16703 fields
.emplace_back ();
16704 struct field
&field
= fields
.back ();
16705 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16706 SET_FIELD_ENUMVAL (field
, value
);
16709 if (!fields
.empty ())
16711 type
->set_num_fields (fields
.size ());
16714 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16715 memcpy (type
->fields (), fields
.data (),
16716 sizeof (struct field
) * fields
.size ());
16720 type
->set_is_unsigned (true);
16723 TYPE_FLAG_ENUM (type
) = 1;
16726 /* Given a DW_AT_enumeration_type die, set its type. We do not
16727 complete the type's fields yet, or create any symbols. */
16729 static struct type
*
16730 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16732 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16734 struct attribute
*attr
;
16737 /* If the definition of this type lives in .debug_types, read that type.
16738 Don't follow DW_AT_specification though, that will take us back up
16739 the chain and we want to go down. */
16740 attr
= die
->attr (DW_AT_signature
);
16741 if (attr
!= nullptr)
16743 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16745 /* The type's CU may not be the same as CU.
16746 Ensure TYPE is recorded with CU in die_type_hash. */
16747 return set_die_type (die
, type
, cu
);
16750 type
= alloc_type (objfile
);
16752 type
->set_code (TYPE_CODE_ENUM
);
16753 name
= dwarf2_full_name (NULL
, die
, cu
);
16755 type
->set_name (name
);
16757 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16760 struct type
*underlying_type
= die_type (die
, cu
);
16762 TYPE_TARGET_TYPE (type
) = underlying_type
;
16765 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16766 if (attr
!= nullptr)
16768 TYPE_LENGTH (type
) = attr
->constant_value (0);
16772 TYPE_LENGTH (type
) = 0;
16775 maybe_set_alignment (cu
, die
, type
);
16777 /* The enumeration DIE can be incomplete. In Ada, any type can be
16778 declared as private in the package spec, and then defined only
16779 inside the package body. Such types are known as Taft Amendment
16780 Types. When another package uses such a type, an incomplete DIE
16781 may be generated by the compiler. */
16782 if (die_is_declaration (die
, cu
))
16783 type
->set_is_stub (true);
16785 /* If this type has an underlying type that is not a stub, then we
16786 may use its attributes. We always use the "unsigned" attribute
16787 in this situation, because ordinarily we guess whether the type
16788 is unsigned -- but the guess can be wrong and the underlying type
16789 can tell us the reality. However, we defer to a local size
16790 attribute if one exists, because this lets the compiler override
16791 the underlying type if needed. */
16792 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16794 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16795 underlying_type
= check_typedef (underlying_type
);
16797 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16799 if (TYPE_LENGTH (type
) == 0)
16800 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16802 if (TYPE_RAW_ALIGN (type
) == 0
16803 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16804 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16807 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16809 set_die_type (die
, type
, cu
);
16811 /* Finish the creation of this type by using the enum's children.
16812 Note that, as usual, this must come after set_die_type to avoid
16813 infinite recursion when trying to compute the names of the
16815 update_enumeration_type_from_children (die
, type
, cu
);
16820 /* Given a pointer to a die which begins an enumeration, process all
16821 the dies that define the members of the enumeration, and create the
16822 symbol for the enumeration type.
16824 NOTE: We reverse the order of the element list. */
16827 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16829 struct type
*this_type
;
16831 this_type
= get_die_type (die
, cu
);
16832 if (this_type
== NULL
)
16833 this_type
= read_enumeration_type (die
, cu
);
16835 if (die
->child
!= NULL
)
16837 struct die_info
*child_die
;
16840 child_die
= die
->child
;
16841 while (child_die
&& child_die
->tag
)
16843 if (child_die
->tag
!= DW_TAG_enumerator
)
16845 process_die (child_die
, cu
);
16849 name
= dwarf2_name (child_die
, cu
);
16851 new_symbol (child_die
, this_type
, cu
);
16854 child_die
= child_die
->sibling
;
16858 /* If we are reading an enum from a .debug_types unit, and the enum
16859 is a declaration, and the enum is not the signatured type in the
16860 unit, then we do not want to add a symbol for it. Adding a
16861 symbol would in some cases obscure the true definition of the
16862 enum, giving users an incomplete type when the definition is
16863 actually available. Note that we do not want to do this for all
16864 enums which are just declarations, because C++0x allows forward
16865 enum declarations. */
16866 if (cu
->per_cu
->is_debug_types
16867 && die_is_declaration (die
, cu
))
16869 struct signatured_type
*sig_type
;
16871 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16872 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16873 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16877 new_symbol (die
, this_type
, cu
);
16880 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16881 expression for an index type and finds the corresponding field
16882 offset in the hidden "P_BOUNDS" structure. Returns true on success
16883 and updates *FIELD, false if it fails to recognize an
16887 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16888 int *bounds_offset
, struct field
*field
,
16889 struct dwarf2_cu
*cu
)
16891 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16892 if (attr
== nullptr || !attr
->form_is_block ())
16895 const struct dwarf_block
*block
= attr
->as_block ();
16896 const gdb_byte
*start
= block
->data
;
16897 const gdb_byte
*end
= block
->data
+ block
->size
;
16899 /* The expression to recognize generally looks like:
16901 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16902 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16904 However, the second "plus_uconst" may be missing:
16906 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16907 DW_OP_deref_size: 4)
16909 This happens when the field is at the start of the structure.
16911 Also, the final deref may not be sized:
16913 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16916 This happens when the size of the index type happens to be the
16917 same as the architecture's word size. This can occur with or
16918 without the second plus_uconst. */
16920 if (end
- start
< 2)
16922 if (*start
++ != DW_OP_push_object_address
)
16924 if (*start
++ != DW_OP_plus_uconst
)
16927 uint64_t this_bound_off
;
16928 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16929 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16931 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16932 is consistent among all bounds. */
16933 if (*bounds_offset
== -1)
16934 *bounds_offset
= this_bound_off
;
16935 else if (*bounds_offset
!= this_bound_off
)
16938 if (start
== end
|| *start
++ != DW_OP_deref
)
16944 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16946 /* This means an offset of 0. */
16948 else if (*start
++ != DW_OP_plus_uconst
)
16952 /* The size is the parameter to DW_OP_plus_uconst. */
16954 start
= gdb_read_uleb128 (start
, end
, &val
);
16955 if (start
== nullptr)
16957 if ((int) val
!= val
)
16966 if (*start
== DW_OP_deref_size
)
16968 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16969 if (start
== nullptr)
16972 else if (*start
== DW_OP_deref
)
16974 size
= cu
->header
.addr_size
;
16980 SET_FIELD_BITPOS (*field
, 8 * offset
);
16981 if (size
!= TYPE_LENGTH (field
->type ()))
16982 FIELD_BITSIZE (*field
) = 8 * size
;
16987 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16988 some kinds of Ada arrays:
16990 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16991 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16992 <11e0> DW_AT_data_location: 2 byte block: 97 6
16993 (DW_OP_push_object_address; DW_OP_deref)
16994 <11e3> DW_AT_type : <0x1173>
16995 <11e7> DW_AT_sibling : <0x1201>
16996 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16997 <11ec> DW_AT_type : <0x1206>
16998 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16999 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
17000 DW_OP_deref_size: 4)
17001 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
17002 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
17003 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
17005 This actually represents a "thick pointer", which is a structure
17006 with two elements: one that is a pointer to the array data, and one
17007 that is a pointer to another structure; this second structure holds
17010 This returns a new type on success, or nullptr if this didn't
17011 recognize the type. */
17013 static struct type
*
17014 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
17017 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
17018 /* So far we've only seen this with block form. */
17019 if (attr
== nullptr || !attr
->form_is_block ())
17022 /* Note that this will fail if the structure layout is changed by
17023 the compiler. However, we have no good way to recognize some
17024 other layout, because we don't know what expression the compiler
17025 might choose to emit should this happen. */
17026 struct dwarf_block
*blk
= attr
->as_block ();
17028 || blk
->data
[0] != DW_OP_push_object_address
17029 || blk
->data
[1] != DW_OP_deref
)
17032 int bounds_offset
= -1;
17033 int max_align
= -1;
17034 std::vector
<struct field
> range_fields
;
17035 for (struct die_info
*child_die
= die
->child
;
17037 child_die
= child_die
->sibling
)
17039 if (child_die
->tag
== DW_TAG_subrange_type
)
17041 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
17043 int this_align
= type_align (underlying
);
17044 if (this_align
> max_align
)
17045 max_align
= this_align
;
17047 range_fields
.emplace_back ();
17048 range_fields
.emplace_back ();
17050 struct field
&lower
= range_fields
[range_fields
.size () - 2];
17051 struct field
&upper
= range_fields
[range_fields
.size () - 1];
17053 lower
.set_type (underlying
);
17054 FIELD_ARTIFICIAL (lower
) = 1;
17056 upper
.set_type (underlying
);
17057 FIELD_ARTIFICIAL (upper
) = 1;
17059 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
17060 &bounds_offset
, &lower
, cu
)
17061 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
17062 &bounds_offset
, &upper
, cu
))
17067 /* This shouldn't really happen, but double-check that we found
17068 where the bounds are stored. */
17069 if (bounds_offset
== -1)
17072 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17073 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
17077 /* Set the name of each field in the bounds. */
17078 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
17079 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
17080 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
17081 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
17084 struct type
*bounds
= alloc_type (objfile
);
17085 bounds
->set_code (TYPE_CODE_STRUCT
);
17087 bounds
->set_num_fields (range_fields
.size ());
17089 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
17090 * sizeof (struct field
))));
17091 memcpy (bounds
->fields (), range_fields
.data (),
17092 bounds
->num_fields () * sizeof (struct field
));
17094 int last_fieldno
= range_fields
.size () - 1;
17095 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
17096 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
17097 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
17099 /* Rewrite the existing array type in place. Specifically, we
17100 remove any dynamic properties we might have read, and we replace
17101 the index types. */
17102 struct type
*iter
= type
;
17103 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
17105 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
17106 iter
->main_type
->dyn_prop_list
= nullptr;
17107 iter
->set_index_type
17108 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
17109 iter
= TYPE_TARGET_TYPE (iter
);
17112 struct type
*result
= alloc_type (objfile
);
17113 result
->set_code (TYPE_CODE_STRUCT
);
17115 result
->set_num_fields (2);
17117 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
17118 * sizeof (struct field
))));
17120 /* The names are chosen to coincide with what the compiler does with
17121 -fgnat-encodings=all, which the Ada code in gdb already
17123 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
17124 result
->field (0).set_type (lookup_pointer_type (type
));
17126 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
17127 result
->field (1).set_type (lookup_pointer_type (bounds
));
17128 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
17130 result
->set_name (type
->name ());
17131 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
17132 + TYPE_LENGTH (result
->field (1).type ()));
17137 /* Extract all information from a DW_TAG_array_type DIE and put it in
17138 the DIE's type field. For now, this only handles one dimensional
17141 static struct type
*
17142 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17144 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17145 struct die_info
*child_die
;
17147 struct type
*element_type
, *range_type
, *index_type
;
17148 struct attribute
*attr
;
17150 struct dynamic_prop
*byte_stride_prop
= NULL
;
17151 unsigned int bit_stride
= 0;
17153 element_type
= die_type (die
, cu
);
17155 /* The die_type call above may have already set the type for this DIE. */
17156 type
= get_die_type (die
, cu
);
17160 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17164 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17167 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
17168 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
17172 complaint (_("unable to read array DW_AT_byte_stride "
17173 " - DIE at %s [in module %s]"),
17174 sect_offset_str (die
->sect_off
),
17175 objfile_name (cu
->per_objfile
->objfile
));
17176 /* Ignore this attribute. We will likely not be able to print
17177 arrays of this type correctly, but there is little we can do
17178 to help if we cannot read the attribute's value. */
17179 byte_stride_prop
= NULL
;
17183 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17185 bit_stride
= attr
->constant_value (0);
17187 /* Irix 6.2 native cc creates array types without children for
17188 arrays with unspecified length. */
17189 if (die
->child
== NULL
)
17191 index_type
= objfile_type (objfile
)->builtin_int
;
17192 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
17193 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
17194 byte_stride_prop
, bit_stride
);
17195 return set_die_type (die
, type
, cu
);
17198 std::vector
<struct type
*> range_types
;
17199 child_die
= die
->child
;
17200 while (child_die
&& child_die
->tag
)
17202 if (child_die
->tag
== DW_TAG_subrange_type
)
17204 struct type
*child_type
= read_type_die (child_die
, cu
);
17206 if (child_type
!= NULL
)
17208 /* The range type was succesfully read. Save it for the
17209 array type creation. */
17210 range_types
.push_back (child_type
);
17213 child_die
= child_die
->sibling
;
17216 /* Dwarf2 dimensions are output from left to right, create the
17217 necessary array types in backwards order. */
17219 type
= element_type
;
17221 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
17225 while (i
< range_types
.size ())
17227 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
17228 byte_stride_prop
, bit_stride
);
17230 byte_stride_prop
= nullptr;
17235 size_t ndim
= range_types
.size ();
17238 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
17239 byte_stride_prop
, bit_stride
);
17241 byte_stride_prop
= nullptr;
17245 /* Understand Dwarf2 support for vector types (like they occur on
17246 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
17247 array type. This is not part of the Dwarf2/3 standard yet, but a
17248 custom vendor extension. The main difference between a regular
17249 array and the vector variant is that vectors are passed by value
17251 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
17252 if (attr
!= nullptr)
17253 make_vector_type (type
);
17255 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
17256 implementation may choose to implement triple vectors using this
17258 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17259 if (attr
!= nullptr && attr
->form_is_unsigned ())
17261 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
17262 TYPE_LENGTH (type
) = attr
->as_unsigned ();
17264 complaint (_("DW_AT_byte_size for array type smaller "
17265 "than the total size of elements"));
17268 name
= dwarf2_name (die
, cu
);
17270 type
->set_name (name
);
17272 maybe_set_alignment (cu
, die
, type
);
17274 struct type
*replacement_type
= nullptr;
17275 if (cu
->language
== language_ada
)
17277 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
17278 if (replacement_type
!= nullptr)
17279 type
= replacement_type
;
17282 /* Install the type in the die. */
17283 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
17285 /* set_die_type should be already done. */
17286 set_descriptive_type (type
, die
, cu
);
17291 static enum dwarf_array_dim_ordering
17292 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
17294 struct attribute
*attr
;
17296 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
17298 if (attr
!= nullptr)
17300 LONGEST val
= attr
->constant_value (-1);
17301 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
17302 return (enum dwarf_array_dim_ordering
) val
;
17305 /* GNU F77 is a special case, as at 08/2004 array type info is the
17306 opposite order to the dwarf2 specification, but data is still
17307 laid out as per normal fortran.
17309 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
17310 version checking. */
17312 if (cu
->language
== language_fortran
17313 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
17315 return DW_ORD_row_major
;
17318 switch (cu
->language_defn
->array_ordering ())
17320 case array_column_major
:
17321 return DW_ORD_col_major
;
17322 case array_row_major
:
17324 return DW_ORD_row_major
;
17328 /* Extract all information from a DW_TAG_set_type DIE and put it in
17329 the DIE's type field. */
17331 static struct type
*
17332 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17334 struct type
*domain_type
, *set_type
;
17335 struct attribute
*attr
;
17337 domain_type
= die_type (die
, cu
);
17339 /* The die_type call above may have already set the type for this DIE. */
17340 set_type
= get_die_type (die
, cu
);
17344 set_type
= create_set_type (NULL
, domain_type
);
17346 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17347 if (attr
!= nullptr && attr
->form_is_unsigned ())
17348 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
17350 maybe_set_alignment (cu
, die
, set_type
);
17352 return set_die_type (die
, set_type
, cu
);
17355 /* A helper for read_common_block that creates a locexpr baton.
17356 SYM is the symbol which we are marking as computed.
17357 COMMON_DIE is the DIE for the common block.
17358 COMMON_LOC is the location expression attribute for the common
17360 MEMBER_LOC is the location expression attribute for the particular
17361 member of the common block that we are processing.
17362 CU is the CU from which the above come. */
17365 mark_common_block_symbol_computed (struct symbol
*sym
,
17366 struct die_info
*common_die
,
17367 struct attribute
*common_loc
,
17368 struct attribute
*member_loc
,
17369 struct dwarf2_cu
*cu
)
17371 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17372 struct objfile
*objfile
= per_objfile
->objfile
;
17373 struct dwarf2_locexpr_baton
*baton
;
17375 unsigned int cu_off
;
17376 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
17377 LONGEST offset
= 0;
17379 gdb_assert (common_loc
&& member_loc
);
17380 gdb_assert (common_loc
->form_is_block ());
17381 gdb_assert (member_loc
->form_is_block ()
17382 || member_loc
->form_is_constant ());
17384 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
17385 baton
->per_objfile
= per_objfile
;
17386 baton
->per_cu
= cu
->per_cu
;
17387 gdb_assert (baton
->per_cu
);
17389 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
17391 if (member_loc
->form_is_constant ())
17393 offset
= member_loc
->constant_value (0);
17394 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
17397 baton
->size
+= member_loc
->as_block ()->size
;
17399 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
17402 *ptr
++ = DW_OP_call4
;
17403 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
17404 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
17407 if (member_loc
->form_is_constant ())
17409 *ptr
++ = DW_OP_addr
;
17410 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
17411 ptr
+= cu
->header
.addr_size
;
17415 /* We have to copy the data here, because DW_OP_call4 will only
17416 use a DW_AT_location attribute. */
17417 struct dwarf_block
*block
= member_loc
->as_block ();
17418 memcpy (ptr
, block
->data
, block
->size
);
17419 ptr
+= block
->size
;
17422 *ptr
++ = DW_OP_plus
;
17423 gdb_assert (ptr
- baton
->data
== baton
->size
);
17425 SYMBOL_LOCATION_BATON (sym
) = baton
;
17426 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
17429 /* Create appropriate locally-scoped variables for all the
17430 DW_TAG_common_block entries. Also create a struct common_block
17431 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
17432 is used to separate the common blocks name namespace from regular
17436 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
17438 struct attribute
*attr
;
17440 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17441 if (attr
!= nullptr)
17443 /* Support the .debug_loc offsets. */
17444 if (attr
->form_is_block ())
17448 else if (attr
->form_is_section_offset ())
17450 dwarf2_complex_location_expr_complaint ();
17455 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17456 "common block member");
17461 if (die
->child
!= NULL
)
17463 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17464 struct die_info
*child_die
;
17465 size_t n_entries
= 0, size
;
17466 struct common_block
*common_block
;
17467 struct symbol
*sym
;
17469 for (child_die
= die
->child
;
17470 child_die
&& child_die
->tag
;
17471 child_die
= child_die
->sibling
)
17474 size
= (sizeof (struct common_block
)
17475 + (n_entries
- 1) * sizeof (struct symbol
*));
17477 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17479 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17480 common_block
->n_entries
= 0;
17482 for (child_die
= die
->child
;
17483 child_die
&& child_die
->tag
;
17484 child_die
= child_die
->sibling
)
17486 /* Create the symbol in the DW_TAG_common_block block in the current
17488 sym
= new_symbol (child_die
, NULL
, cu
);
17491 struct attribute
*member_loc
;
17493 common_block
->contents
[common_block
->n_entries
++] = sym
;
17495 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17499 /* GDB has handled this for a long time, but it is
17500 not specified by DWARF. It seems to have been
17501 emitted by gfortran at least as recently as:
17502 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17503 complaint (_("Variable in common block has "
17504 "DW_AT_data_member_location "
17505 "- DIE at %s [in module %s]"),
17506 sect_offset_str (child_die
->sect_off
),
17507 objfile_name (objfile
));
17509 if (member_loc
->form_is_section_offset ())
17510 dwarf2_complex_location_expr_complaint ();
17511 else if (member_loc
->form_is_constant ()
17512 || member_loc
->form_is_block ())
17514 if (attr
!= nullptr)
17515 mark_common_block_symbol_computed (sym
, die
, attr
,
17519 dwarf2_complex_location_expr_complaint ();
17524 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17525 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17529 /* Create a type for a C++ namespace. */
17531 static struct type
*
17532 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17534 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17535 const char *previous_prefix
, *name
;
17539 /* For extensions, reuse the type of the original namespace. */
17540 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17542 struct die_info
*ext_die
;
17543 struct dwarf2_cu
*ext_cu
= cu
;
17545 ext_die
= dwarf2_extension (die
, &ext_cu
);
17546 type
= read_type_die (ext_die
, ext_cu
);
17548 /* EXT_CU may not be the same as CU.
17549 Ensure TYPE is recorded with CU in die_type_hash. */
17550 return set_die_type (die
, type
, cu
);
17553 name
= namespace_name (die
, &is_anonymous
, cu
);
17555 /* Now build the name of the current namespace. */
17557 previous_prefix
= determine_prefix (die
, cu
);
17558 if (previous_prefix
[0] != '\0')
17559 name
= typename_concat (&objfile
->objfile_obstack
,
17560 previous_prefix
, name
, 0, cu
);
17562 /* Create the type. */
17563 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17565 return set_die_type (die
, type
, cu
);
17568 /* Read a namespace scope. */
17571 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17573 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17576 /* Add a symbol associated to this if we haven't seen the namespace
17577 before. Also, add a using directive if it's an anonymous
17580 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17584 type
= read_type_die (die
, cu
);
17585 new_symbol (die
, type
, cu
);
17587 namespace_name (die
, &is_anonymous
, cu
);
17590 const char *previous_prefix
= determine_prefix (die
, cu
);
17592 std::vector
<const char *> excludes
;
17593 add_using_directive (using_directives (cu
),
17594 previous_prefix
, type
->name (), NULL
,
17595 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17599 if (die
->child
!= NULL
)
17601 struct die_info
*child_die
= die
->child
;
17603 while (child_die
&& child_die
->tag
)
17605 process_die (child_die
, cu
);
17606 child_die
= child_die
->sibling
;
17611 /* Read a Fortran module as type. This DIE can be only a declaration used for
17612 imported module. Still we need that type as local Fortran "use ... only"
17613 declaration imports depend on the created type in determine_prefix. */
17615 static struct type
*
17616 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17618 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17619 const char *module_name
;
17622 module_name
= dwarf2_name (die
, cu
);
17623 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17625 return set_die_type (die
, type
, cu
);
17628 /* Read a Fortran module. */
17631 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17633 struct die_info
*child_die
= die
->child
;
17636 type
= read_type_die (die
, cu
);
17637 new_symbol (die
, type
, cu
);
17639 while (child_die
&& child_die
->tag
)
17641 process_die (child_die
, cu
);
17642 child_die
= child_die
->sibling
;
17646 /* Return the name of the namespace represented by DIE. Set
17647 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17650 static const char *
17651 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17653 struct die_info
*current_die
;
17654 const char *name
= NULL
;
17656 /* Loop through the extensions until we find a name. */
17658 for (current_die
= die
;
17659 current_die
!= NULL
;
17660 current_die
= dwarf2_extension (die
, &cu
))
17662 /* We don't use dwarf2_name here so that we can detect the absence
17663 of a name -> anonymous namespace. */
17664 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17670 /* Is it an anonymous namespace? */
17672 *is_anonymous
= (name
== NULL
);
17674 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17679 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17680 the user defined type vector. */
17682 static struct type
*
17683 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17685 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17686 struct comp_unit_head
*cu_header
= &cu
->header
;
17688 struct attribute
*attr_byte_size
;
17689 struct attribute
*attr_address_class
;
17690 int byte_size
, addr_class
;
17691 struct type
*target_type
;
17693 target_type
= die_type (die
, cu
);
17695 /* The die_type call above may have already set the type for this DIE. */
17696 type
= get_die_type (die
, cu
);
17700 type
= lookup_pointer_type (target_type
);
17702 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17703 if (attr_byte_size
)
17704 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17706 byte_size
= cu_header
->addr_size
;
17708 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17709 if (attr_address_class
)
17710 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17712 addr_class
= DW_ADDR_none
;
17714 ULONGEST alignment
= get_alignment (cu
, die
);
17716 /* If the pointer size, alignment, or address class is different
17717 than the default, create a type variant marked as such and set
17718 the length accordingly. */
17719 if (TYPE_LENGTH (type
) != byte_size
17720 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17721 && alignment
!= TYPE_RAW_ALIGN (type
))
17722 || addr_class
!= DW_ADDR_none
)
17724 if (gdbarch_address_class_type_flags_p (gdbarch
))
17726 type_instance_flags type_flags
17727 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17729 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17731 type
= make_type_with_address_space (type
, type_flags
);
17733 else if (TYPE_LENGTH (type
) != byte_size
)
17735 complaint (_("invalid pointer size %d"), byte_size
);
17737 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17739 complaint (_("Invalid DW_AT_alignment"
17740 " - DIE at %s [in module %s]"),
17741 sect_offset_str (die
->sect_off
),
17742 objfile_name (cu
->per_objfile
->objfile
));
17746 /* Should we also complain about unhandled address classes? */
17750 TYPE_LENGTH (type
) = byte_size
;
17751 set_type_align (type
, alignment
);
17752 return set_die_type (die
, type
, cu
);
17755 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17756 the user defined type vector. */
17758 static struct type
*
17759 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17762 struct type
*to_type
;
17763 struct type
*domain
;
17765 to_type
= die_type (die
, cu
);
17766 domain
= die_containing_type (die
, cu
);
17768 /* The calls above may have already set the type for this DIE. */
17769 type
= get_die_type (die
, cu
);
17773 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17774 type
= lookup_methodptr_type (to_type
);
17775 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17777 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17779 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17780 to_type
->fields (), to_type
->num_fields (),
17781 to_type
->has_varargs ());
17782 type
= lookup_methodptr_type (new_type
);
17785 type
= lookup_memberptr_type (to_type
, domain
);
17787 return set_die_type (die
, type
, cu
);
17790 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17791 the user defined type vector. */
17793 static struct type
*
17794 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17795 enum type_code refcode
)
17797 struct comp_unit_head
*cu_header
= &cu
->header
;
17798 struct type
*type
, *target_type
;
17799 struct attribute
*attr
;
17801 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17803 target_type
= die_type (die
, cu
);
17805 /* The die_type call above may have already set the type for this DIE. */
17806 type
= get_die_type (die
, cu
);
17810 type
= lookup_reference_type (target_type
, refcode
);
17811 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17812 if (attr
!= nullptr)
17814 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17818 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17820 maybe_set_alignment (cu
, die
, type
);
17821 return set_die_type (die
, type
, cu
);
17824 /* Add the given cv-qualifiers to the element type of the array. GCC
17825 outputs DWARF type qualifiers that apply to an array, not the
17826 element type. But GDB relies on the array element type to carry
17827 the cv-qualifiers. This mimics section 6.7.3 of the C99
17830 static struct type
*
17831 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17832 struct type
*base_type
, int cnst
, int voltl
)
17834 struct type
*el_type
, *inner_array
;
17836 base_type
= copy_type (base_type
);
17837 inner_array
= base_type
;
17839 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17841 TYPE_TARGET_TYPE (inner_array
) =
17842 copy_type (TYPE_TARGET_TYPE (inner_array
));
17843 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17846 el_type
= TYPE_TARGET_TYPE (inner_array
);
17847 cnst
|= TYPE_CONST (el_type
);
17848 voltl
|= TYPE_VOLATILE (el_type
);
17849 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17851 return set_die_type (die
, base_type
, cu
);
17854 static struct type
*
17855 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17857 struct type
*base_type
, *cv_type
;
17859 base_type
= die_type (die
, cu
);
17861 /* The die_type call above may have already set the type for this DIE. */
17862 cv_type
= get_die_type (die
, cu
);
17866 /* In case the const qualifier is applied to an array type, the element type
17867 is so qualified, not the array type (section 6.7.3 of C99). */
17868 if (base_type
->code () == TYPE_CODE_ARRAY
)
17869 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17871 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17872 return set_die_type (die
, cv_type
, cu
);
17875 static struct type
*
17876 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17878 struct type
*base_type
, *cv_type
;
17880 base_type
= die_type (die
, cu
);
17882 /* The die_type call above may have already set the type for this DIE. */
17883 cv_type
= get_die_type (die
, cu
);
17887 /* In case the volatile qualifier is applied to an array type, the
17888 element type is so qualified, not the array type (section 6.7.3
17890 if (base_type
->code () == TYPE_CODE_ARRAY
)
17891 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17893 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17894 return set_die_type (die
, cv_type
, cu
);
17897 /* Handle DW_TAG_restrict_type. */
17899 static struct type
*
17900 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17902 struct type
*base_type
, *cv_type
;
17904 base_type
= die_type (die
, cu
);
17906 /* The die_type call above may have already set the type for this DIE. */
17907 cv_type
= get_die_type (die
, cu
);
17911 cv_type
= make_restrict_type (base_type
);
17912 return set_die_type (die
, cv_type
, cu
);
17915 /* Handle DW_TAG_atomic_type. */
17917 static struct type
*
17918 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17920 struct type
*base_type
, *cv_type
;
17922 base_type
= die_type (die
, cu
);
17924 /* The die_type call above may have already set the type for this DIE. */
17925 cv_type
= get_die_type (die
, cu
);
17929 cv_type
= make_atomic_type (base_type
);
17930 return set_die_type (die
, cv_type
, cu
);
17933 /* Extract all information from a DW_TAG_string_type DIE and add to
17934 the user defined type vector. It isn't really a user defined type,
17935 but it behaves like one, with other DIE's using an AT_user_def_type
17936 attribute to reference it. */
17938 static struct type
*
17939 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17941 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17942 struct gdbarch
*gdbarch
= objfile
->arch ();
17943 struct type
*type
, *range_type
, *index_type
, *char_type
;
17944 struct attribute
*attr
;
17945 struct dynamic_prop prop
;
17946 bool length_is_constant
= true;
17949 /* There are a couple of places where bit sizes might be made use of
17950 when parsing a DW_TAG_string_type, however, no producer that we know
17951 of make use of these. Handling bit sizes that are a multiple of the
17952 byte size is easy enough, but what about other bit sizes? Lets deal
17953 with that problem when we have to. Warn about these attributes being
17954 unsupported, then parse the type and ignore them like we always
17956 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17957 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17959 static bool warning_printed
= false;
17960 if (!warning_printed
)
17962 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17963 "currently supported on DW_TAG_string_type."));
17964 warning_printed
= true;
17968 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17969 if (attr
!= nullptr && !attr
->form_is_constant ())
17971 /* The string length describes the location at which the length of
17972 the string can be found. The size of the length field can be
17973 specified with one of the attributes below. */
17974 struct type
*prop_type
;
17975 struct attribute
*len
17976 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17977 if (len
== nullptr)
17978 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17979 if (len
!= nullptr && len
->form_is_constant ())
17981 /* Pass 0 as the default as we know this attribute is constant
17982 and the default value will not be returned. */
17983 LONGEST sz
= len
->constant_value (0);
17984 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17988 /* If the size is not specified then we assume it is the size of
17989 an address on this target. */
17990 prop_type
= cu
->addr_sized_int_type (true);
17993 /* Convert the attribute into a dynamic property. */
17994 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17997 length_is_constant
= false;
17999 else if (attr
!= nullptr)
18001 /* This DW_AT_string_length just contains the length with no
18002 indirection. There's no need to create a dynamic property in this
18003 case. Pass 0 for the default value as we know it will not be
18004 returned in this case. */
18005 length
= attr
->constant_value (0);
18007 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
18009 /* We don't currently support non-constant byte sizes for strings. */
18010 length
= attr
->constant_value (1);
18014 /* Use 1 as a fallback length if we have nothing else. */
18018 index_type
= objfile_type (objfile
)->builtin_int
;
18019 if (length_is_constant
)
18020 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
18023 struct dynamic_prop low_bound
;
18025 low_bound
.set_const_val (1);
18026 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
18028 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
18029 type
= create_string_type (NULL
, char_type
, range_type
);
18031 return set_die_type (die
, type
, cu
);
18034 /* Assuming that DIE corresponds to a function, returns nonzero
18035 if the function is prototyped. */
18038 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
18040 struct attribute
*attr
;
18042 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
18043 if (attr
&& attr
->as_boolean ())
18046 /* The DWARF standard implies that the DW_AT_prototyped attribute
18047 is only meaningful for C, but the concept also extends to other
18048 languages that allow unprototyped functions (Eg: Objective C).
18049 For all other languages, assume that functions are always
18051 if (cu
->language
!= language_c
18052 && cu
->language
!= language_objc
18053 && cu
->language
!= language_opencl
)
18056 /* RealView does not emit DW_AT_prototyped. We can not distinguish
18057 prototyped and unprototyped functions; default to prototyped,
18058 since that is more common in modern code (and RealView warns
18059 about unprototyped functions). */
18060 if (producer_is_realview (cu
->producer
))
18066 /* Handle DIES due to C code like:
18070 int (*funcp)(int a, long l);
18074 ('funcp' generates a DW_TAG_subroutine_type DIE). */
18076 static struct type
*
18077 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18079 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18080 struct type
*type
; /* Type that this function returns. */
18081 struct type
*ftype
; /* Function that returns above type. */
18082 struct attribute
*attr
;
18084 type
= die_type (die
, cu
);
18086 /* The die_type call above may have already set the type for this DIE. */
18087 ftype
= get_die_type (die
, cu
);
18091 ftype
= lookup_function_type (type
);
18093 if (prototyped_function_p (die
, cu
))
18094 ftype
->set_is_prototyped (true);
18096 /* Store the calling convention in the type if it's available in
18097 the subroutine die. Otherwise set the calling convention to
18098 the default value DW_CC_normal. */
18099 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
18100 if (attr
!= nullptr
18101 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
18102 TYPE_CALLING_CONVENTION (ftype
)
18103 = (enum dwarf_calling_convention
) attr
->constant_value (0);
18104 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
18105 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
18107 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
18109 /* Record whether the function returns normally to its caller or not
18110 if the DWARF producer set that information. */
18111 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
18112 if (attr
&& attr
->as_boolean ())
18113 TYPE_NO_RETURN (ftype
) = 1;
18115 /* We need to add the subroutine type to the die immediately so
18116 we don't infinitely recurse when dealing with parameters
18117 declared as the same subroutine type. */
18118 set_die_type (die
, ftype
, cu
);
18120 if (die
->child
!= NULL
)
18122 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
18123 struct die_info
*child_die
;
18124 int nparams
, iparams
;
18126 /* Count the number of parameters.
18127 FIXME: GDB currently ignores vararg functions, but knows about
18128 vararg member functions. */
18130 child_die
= die
->child
;
18131 while (child_die
&& child_die
->tag
)
18133 if (child_die
->tag
== DW_TAG_formal_parameter
)
18135 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
18136 ftype
->set_has_varargs (true);
18138 child_die
= child_die
->sibling
;
18141 /* Allocate storage for parameters and fill them in. */
18142 ftype
->set_num_fields (nparams
);
18144 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
18146 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
18147 even if we error out during the parameters reading below. */
18148 for (iparams
= 0; iparams
< nparams
; iparams
++)
18149 ftype
->field (iparams
).set_type (void_type
);
18152 child_die
= die
->child
;
18153 while (child_die
&& child_die
->tag
)
18155 if (child_die
->tag
== DW_TAG_formal_parameter
)
18157 struct type
*arg_type
;
18159 /* DWARF version 2 has no clean way to discern C++
18160 static and non-static member functions. G++ helps
18161 GDB by marking the first parameter for non-static
18162 member functions (which is the this pointer) as
18163 artificial. We pass this information to
18164 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
18166 DWARF version 3 added DW_AT_object_pointer, which GCC
18167 4.5 does not yet generate. */
18168 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
18169 if (attr
!= nullptr)
18170 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
18172 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
18173 arg_type
= die_type (child_die
, cu
);
18175 /* RealView does not mark THIS as const, which the testsuite
18176 expects. GCC marks THIS as const in method definitions,
18177 but not in the class specifications (GCC PR 43053). */
18178 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
18179 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
18182 struct dwarf2_cu
*arg_cu
= cu
;
18183 const char *name
= dwarf2_name (child_die
, cu
);
18185 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
18186 if (attr
!= nullptr)
18188 /* If the compiler emits this, use it. */
18189 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
18192 else if (name
&& strcmp (name
, "this") == 0)
18193 /* Function definitions will have the argument names. */
18195 else if (name
== NULL
&& iparams
== 0)
18196 /* Declarations may not have the names, so like
18197 elsewhere in GDB, assume an artificial first
18198 argument is "this". */
18202 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
18206 ftype
->field (iparams
).set_type (arg_type
);
18209 child_die
= child_die
->sibling
;
18216 static struct type
*
18217 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
18219 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18220 const char *name
= NULL
;
18221 struct type
*this_type
, *target_type
;
18223 name
= dwarf2_full_name (NULL
, die
, cu
);
18224 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
18225 this_type
->set_target_is_stub (true);
18226 set_die_type (die
, this_type
, cu
);
18227 target_type
= die_type (die
, cu
);
18228 if (target_type
!= this_type
)
18229 TYPE_TARGET_TYPE (this_type
) = target_type
;
18232 /* Self-referential typedefs are, it seems, not allowed by the DWARF
18233 spec and cause infinite loops in GDB. */
18234 complaint (_("Self-referential DW_TAG_typedef "
18235 "- DIE at %s [in module %s]"),
18236 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
18237 TYPE_TARGET_TYPE (this_type
) = NULL
;
18241 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
18242 anonymous typedefs, which is, strictly speaking, invalid DWARF.
18243 Handle these by just returning the target type, rather than
18244 constructing an anonymous typedef type and trying to handle this
18246 set_die_type (die
, target_type
, cu
);
18247 return target_type
;
18252 /* Helper for get_dwarf2_rational_constant that computes the value of
18253 a given gmp_mpz given an attribute. */
18256 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
18258 /* GCC will sometimes emit a 16-byte constant value as a DWARF
18259 location expression that pushes an implicit value. */
18260 if (attr
->form
== DW_FORM_exprloc
)
18262 dwarf_block
*blk
= attr
->as_block ();
18263 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
18266 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
18267 blk
->data
+ blk
->size
,
18269 if (ptr
- blk
->data
+ len
<= blk
->size
)
18271 mpz_import (value
->val
, len
,
18272 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
18278 /* On failure set it to 1. */
18279 *value
= gdb_mpz (1);
18281 else if (attr
->form_is_block ())
18283 dwarf_block
*blk
= attr
->as_block ();
18284 mpz_import (value
->val
, blk
->size
,
18285 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
18286 1, 0, 0, blk
->data
);
18289 *value
= gdb_mpz (attr
->constant_value (1));
18292 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
18293 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
18295 If the numerator and/or numerator attribute is missing,
18296 a complaint is filed, and NUMERATOR and DENOMINATOR are left
18300 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
18301 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
18303 struct attribute
*num_attr
, *denom_attr
;
18305 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
18306 if (num_attr
== nullptr)
18307 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
18308 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18310 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
18311 if (denom_attr
== nullptr)
18312 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
18313 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18315 if (num_attr
== nullptr || denom_attr
== nullptr)
18318 get_mpz (cu
, numerator
, num_attr
);
18319 get_mpz (cu
, denominator
, denom_attr
);
18322 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
18323 rational constant, rather than a signed one.
18325 If the rational constant has a negative value, a complaint
18326 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
18329 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
18330 struct dwarf2_cu
*cu
,
18331 gdb_mpz
*numerator
,
18332 gdb_mpz
*denominator
)
18337 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
18338 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
18340 mpz_neg (num
.val
, num
.val
);
18341 mpz_neg (denom
.val
, denom
.val
);
18343 else if (mpz_sgn (num
.val
) == -1)
18345 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
18347 sect_offset_str (die
->sect_off
));
18350 else if (mpz_sgn (denom
.val
) == -1)
18352 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
18354 sect_offset_str (die
->sect_off
));
18358 *numerator
= std::move (num
);
18359 *denominator
= std::move (denom
);
18362 /* Assuming DIE corresponds to a fixed point type, finish the creation
18363 of the corresponding TYPE by setting its type-specific data.
18364 CU is the DIE's CU. */
18367 finish_fixed_point_type (struct type
*type
, struct die_info
*die
,
18368 struct dwarf2_cu
*cu
)
18370 struct attribute
*attr
;
18372 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
18373 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
18375 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
18377 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
18379 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18381 /* Numerator and denominator of our fixed-point type's scaling factor.
18382 The default is a scaling factor of 1, which we use as a fallback
18383 when we are not able to decode it (problem with the debugging info,
18384 unsupported forms, bug in GDB, etc...). Using that as the default
18385 allows us to at least print the unscaled value, which might still
18386 be useful to a user. */
18387 gdb_mpz
scale_num (1);
18388 gdb_mpz
scale_denom (1);
18390 if (attr
== nullptr)
18392 /* Scaling factor not found. Assume a scaling factor of 1,
18393 and hope for the best. At least the user will be able to see
18394 the encoded value. */
18395 complaint (_("no scale found for fixed-point type (DIE at %s)"),
18396 sect_offset_str (die
->sect_off
));
18398 else if (attr
->name
== DW_AT_binary_scale
)
18400 LONGEST scale_exp
= attr
->constant_value (0);
18401 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18403 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
18405 else if (attr
->name
== DW_AT_decimal_scale
)
18407 LONGEST scale_exp
= attr
->constant_value (0);
18408 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18410 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
18412 else if (attr
->name
== DW_AT_small
)
18414 struct die_info
*scale_die
;
18415 struct dwarf2_cu
*scale_cu
= cu
;
18417 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
18418 if (scale_die
->tag
== DW_TAG_constant
)
18419 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
18420 &scale_num
, &scale_denom
);
18422 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
18424 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18428 complaint (_("unsupported scale attribute %s for fixed-point type"
18430 dwarf_attr_name (attr
->name
),
18431 sect_offset_str (die
->sect_off
));
18434 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
18435 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
18436 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
18437 mpq_canonicalize (scaling_factor
.val
);
18440 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
18441 (which may be different from NAME) to the architecture back-end to allow
18442 it to guess the correct format if necessary. */
18444 static struct type
*
18445 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
18446 const char *name_hint
, enum bfd_endian byte_order
)
18448 struct gdbarch
*gdbarch
= objfile
->arch ();
18449 const struct floatformat
**format
;
18452 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
18454 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
18456 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18461 /* Allocate an integer type of size BITS and name NAME. */
18463 static struct type
*
18464 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
18465 int bits
, int unsigned_p
, const char *name
)
18469 /* Versions of Intel's C Compiler generate an integer type called "void"
18470 instead of using DW_TAG_unspecified_type. This has been seen on
18471 at least versions 14, 17, and 18. */
18472 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18473 && strcmp (name
, "void") == 0)
18474 type
= objfile_type (objfile
)->builtin_void
;
18476 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18481 /* Return true if DIE has a DW_AT_small attribute whose value is
18482 a constant rational, where both the numerator and denominator
18485 CU is the DIE's Compilation Unit. */
18488 has_zero_over_zero_small_attribute (struct die_info
*die
,
18489 struct dwarf2_cu
*cu
)
18491 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18492 if (attr
== nullptr)
18495 struct dwarf2_cu
*scale_cu
= cu
;
18496 struct die_info
*scale_die
18497 = follow_die_ref (die
, attr
, &scale_cu
);
18499 if (scale_die
->tag
!= DW_TAG_constant
)
18502 gdb_mpz
num (1), denom (1);
18503 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18504 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
18507 /* Initialise and return a floating point type of size BITS suitable for
18508 use as a component of a complex number. The NAME_HINT is passed through
18509 when initialising the floating point type and is the name of the complex
18512 As DWARF doesn't currently provide an explicit name for the components
18513 of a complex number, but it can be helpful to have these components
18514 named, we try to select a suitable name based on the size of the
18516 static struct type
*
18517 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18518 struct objfile
*objfile
,
18519 int bits
, const char *name_hint
,
18520 enum bfd_endian byte_order
)
18522 gdbarch
*gdbarch
= objfile
->arch ();
18523 struct type
*tt
= nullptr;
18525 /* Try to find a suitable floating point builtin type of size BITS.
18526 We're going to use the name of this type as the name for the complex
18527 target type that we are about to create. */
18528 switch (cu
->language
)
18530 case language_fortran
:
18534 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18537 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18539 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18541 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18549 tt
= builtin_type (gdbarch
)->builtin_float
;
18552 tt
= builtin_type (gdbarch
)->builtin_double
;
18554 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18556 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18562 /* If the type we found doesn't match the size we were looking for, then
18563 pretend we didn't find a type at all, the complex target type we
18564 create will then be nameless. */
18565 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18568 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18569 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18572 /* Find a representation of a given base type and install
18573 it in the TYPE field of the die. */
18575 static struct type
*
18576 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18578 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18580 struct attribute
*attr
;
18581 int encoding
= 0, bits
= 0;
18585 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18586 if (attr
!= nullptr && attr
->form_is_constant ())
18587 encoding
= attr
->constant_value (0);
18588 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18589 if (attr
!= nullptr)
18590 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18591 name
= dwarf2_name (die
, cu
);
18593 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18595 arch
= objfile
->arch ();
18596 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18598 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18599 if (attr
!= nullptr && attr
->form_is_constant ())
18601 int endianity
= attr
->constant_value (0);
18606 byte_order
= BFD_ENDIAN_BIG
;
18608 case DW_END_little
:
18609 byte_order
= BFD_ENDIAN_LITTLE
;
18612 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18617 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18618 && cu
->language
== language_ada
18619 && has_zero_over_zero_small_attribute (die
, cu
))
18621 /* brobecker/2018-02-24: This is a fixed point type for which
18622 the scaling factor is represented as fraction whose value
18623 does not make sense (zero divided by zero), so we should
18624 normally never see these. However, there is a small category
18625 of fixed point types for which GNAT is unable to provide
18626 the scaling factor via the standard DWARF mechanisms, and
18627 for which the info is provided via the GNAT encodings instead.
18628 This is likely what this DIE is about.
18630 Ideally, GNAT should be declaring this type the same way
18631 it declares other fixed point types when using the legacy
18632 GNAT encoding, which is to use a simple signed or unsigned
18633 base type. A report to the GNAT team has been created to
18634 look into it. In the meantime, pretend this type is a simple
18635 signed or unsigned integral, rather than a fixed point type,
18636 to avoid any confusion later on as to how to process this type. */
18637 encoding
= (encoding
== DW_ATE_signed_fixed
18639 : DW_ATE_unsigned
);
18644 case DW_ATE_address
:
18645 /* Turn DW_ATE_address into a void * pointer. */
18646 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18647 type
= init_pointer_type (objfile
, bits
, name
, type
);
18649 case DW_ATE_boolean
:
18650 type
= init_boolean_type (objfile
, bits
, 1, name
);
18652 case DW_ATE_complex_float
:
18653 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18655 if (type
->code () == TYPE_CODE_ERROR
)
18657 if (name
== nullptr)
18659 struct obstack
*obstack
18660 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18661 name
= obconcat (obstack
, "_Complex ", type
->name (),
18664 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18667 type
= init_complex_type (name
, type
);
18669 case DW_ATE_decimal_float
:
18670 type
= init_decfloat_type (objfile
, bits
, name
);
18673 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18675 case DW_ATE_signed
:
18676 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18678 case DW_ATE_unsigned
:
18679 if (cu
->language
== language_fortran
18681 && startswith (name
, "character("))
18682 type
= init_character_type (objfile
, bits
, 1, name
);
18684 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18686 case DW_ATE_signed_char
:
18687 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18688 || cu
->language
== language_pascal
18689 || cu
->language
== language_fortran
)
18690 type
= init_character_type (objfile
, bits
, 0, name
);
18692 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18694 case DW_ATE_unsigned_char
:
18695 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18696 || cu
->language
== language_pascal
18697 || cu
->language
== language_fortran
18698 || cu
->language
== language_rust
)
18699 type
= init_character_type (objfile
, bits
, 1, name
);
18701 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18706 type
= builtin_type (arch
)->builtin_char16
;
18707 else if (bits
== 32)
18708 type
= builtin_type (arch
)->builtin_char32
;
18711 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18713 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18715 return set_die_type (die
, type
, cu
);
18718 case DW_ATE_signed_fixed
:
18719 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18720 finish_fixed_point_type (type
, die
, cu
);
18722 case DW_ATE_unsigned_fixed
:
18723 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18724 finish_fixed_point_type (type
, die
, cu
);
18728 complaint (_("unsupported DW_AT_encoding: '%s'"),
18729 dwarf_type_encoding_name (encoding
));
18730 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18734 if (name
&& strcmp (name
, "char") == 0)
18735 type
->set_has_no_signedness (true);
18737 maybe_set_alignment (cu
, die
, type
);
18739 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18741 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18743 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18744 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18746 unsigned real_bit_size
= attr
->as_unsigned ();
18747 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18748 /* Only use the attributes if they make sense together. */
18749 if (attr
== nullptr
18750 || (attr
->as_unsigned () + real_bit_size
18751 <= 8 * TYPE_LENGTH (type
)))
18753 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18755 if (attr
!= nullptr)
18756 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18757 = attr
->as_unsigned ();
18762 return set_die_type (die
, type
, cu
);
18765 /* Parse dwarf attribute if it's a block, reference or constant and put the
18766 resulting value of the attribute into struct bound_prop.
18767 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18770 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18771 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18772 struct type
*default_type
)
18774 struct dwarf2_property_baton
*baton
;
18775 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18776 struct objfile
*objfile
= per_objfile
->objfile
;
18777 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18779 gdb_assert (default_type
!= NULL
);
18781 if (attr
== NULL
|| prop
== NULL
)
18784 if (attr
->form_is_block ())
18786 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18787 baton
->property_type
= default_type
;
18788 baton
->locexpr
.per_cu
= cu
->per_cu
;
18789 baton
->locexpr
.per_objfile
= per_objfile
;
18791 struct dwarf_block
*block
= attr
->as_block ();
18792 baton
->locexpr
.size
= block
->size
;
18793 baton
->locexpr
.data
= block
->data
;
18794 switch (attr
->name
)
18796 case DW_AT_string_length
:
18797 baton
->locexpr
.is_reference
= true;
18800 baton
->locexpr
.is_reference
= false;
18804 prop
->set_locexpr (baton
);
18805 gdb_assert (prop
->baton () != NULL
);
18807 else if (attr
->form_is_ref ())
18809 struct dwarf2_cu
*target_cu
= cu
;
18810 struct die_info
*target_die
;
18811 struct attribute
*target_attr
;
18813 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18814 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18815 if (target_attr
== NULL
)
18816 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18818 if (target_attr
== NULL
)
18821 switch (target_attr
->name
)
18823 case DW_AT_location
:
18824 if (target_attr
->form_is_section_offset ())
18826 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18827 baton
->property_type
= die_type (target_die
, target_cu
);
18828 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18829 prop
->set_loclist (baton
);
18830 gdb_assert (prop
->baton () != NULL
);
18832 else if (target_attr
->form_is_block ())
18834 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18835 baton
->property_type
= die_type (target_die
, target_cu
);
18836 baton
->locexpr
.per_cu
= cu
->per_cu
;
18837 baton
->locexpr
.per_objfile
= per_objfile
;
18838 struct dwarf_block
*block
= target_attr
->as_block ();
18839 baton
->locexpr
.size
= block
->size
;
18840 baton
->locexpr
.data
= block
->data
;
18841 baton
->locexpr
.is_reference
= true;
18842 prop
->set_locexpr (baton
);
18843 gdb_assert (prop
->baton () != NULL
);
18847 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18848 "dynamic property");
18852 case DW_AT_data_member_location
:
18856 if (!handle_data_member_location (target_die
, target_cu
,
18860 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18861 baton
->property_type
= read_type_die (target_die
->parent
,
18863 baton
->offset_info
.offset
= offset
;
18864 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18865 prop
->set_addr_offset (baton
);
18870 else if (attr
->form_is_constant ())
18871 prop
->set_const_val (attr
->constant_value (0));
18874 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18875 dwarf2_name (die
, cu
));
18885 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18887 struct type
*int_type
;
18889 /* Helper macro to examine the various builtin types. */
18890 #define TRY_TYPE(F) \
18891 int_type = (unsigned_p \
18892 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18893 : objfile_type (objfile)->builtin_ ## F); \
18894 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18901 TRY_TYPE (long_long
);
18905 gdb_assert_not_reached ("unable to find suitable integer type");
18911 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
18913 int addr_size
= this->per_cu
->addr_size ();
18914 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
18917 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18918 present (which is valid) then compute the default type based on the
18919 compilation units address size. */
18921 static struct type
*
18922 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18924 struct type
*index_type
= die_type (die
, cu
);
18926 /* Dwarf-2 specifications explicitly allows to create subrange types
18927 without specifying a base type.
18928 In that case, the base type must be set to the type of
18929 the lower bound, upper bound or count, in that order, if any of these
18930 three attributes references an object that has a type.
18931 If no base type is found, the Dwarf-2 specifications say that
18932 a signed integer type of size equal to the size of an address should
18934 For the following C code: `extern char gdb_int [];'
18935 GCC produces an empty range DIE.
18936 FIXME: muller/2010-05-28: Possible references to object for low bound,
18937 high bound or count are not yet handled by this code. */
18938 if (index_type
->code () == TYPE_CODE_VOID
)
18939 index_type
= cu
->addr_sized_int_type (false);
18944 /* Read the given DW_AT_subrange DIE. */
18946 static struct type
*
18947 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18949 struct type
*base_type
, *orig_base_type
;
18950 struct type
*range_type
;
18951 struct attribute
*attr
;
18952 struct dynamic_prop low
, high
;
18953 int low_default_is_valid
;
18954 int high_bound_is_count
= 0;
18956 ULONGEST negative_mask
;
18958 orig_base_type
= read_subrange_index_type (die
, cu
);
18960 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18961 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18962 creating the range type, but we use the result of check_typedef
18963 when examining properties of the type. */
18964 base_type
= check_typedef (orig_base_type
);
18966 /* The die_type call above may have already set the type for this DIE. */
18967 range_type
= get_die_type (die
, cu
);
18971 high
.set_const_val (0);
18973 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18974 omitting DW_AT_lower_bound. */
18975 switch (cu
->language
)
18978 case language_cplus
:
18979 low
.set_const_val (0);
18980 low_default_is_valid
= 1;
18982 case language_fortran
:
18983 low
.set_const_val (1);
18984 low_default_is_valid
= 1;
18987 case language_objc
:
18988 case language_rust
:
18989 low
.set_const_val (0);
18990 low_default_is_valid
= (cu
->header
.version
>= 4);
18994 case language_pascal
:
18995 low
.set_const_val (1);
18996 low_default_is_valid
= (cu
->header
.version
>= 4);
18999 low
.set_const_val (0);
19000 low_default_is_valid
= 0;
19004 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
19005 if (attr
!= nullptr)
19006 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
19007 else if (!low_default_is_valid
)
19008 complaint (_("Missing DW_AT_lower_bound "
19009 "- DIE at %s [in module %s]"),
19010 sect_offset_str (die
->sect_off
),
19011 objfile_name (cu
->per_objfile
->objfile
));
19013 struct attribute
*attr_ub
, *attr_count
;
19014 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
19015 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
19017 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
19018 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
19020 /* If bounds are constant do the final calculation here. */
19021 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
19022 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
19024 high_bound_is_count
= 1;
19028 if (attr_ub
!= NULL
)
19029 complaint (_("Unresolved DW_AT_upper_bound "
19030 "- DIE at %s [in module %s]"),
19031 sect_offset_str (die
->sect_off
),
19032 objfile_name (cu
->per_objfile
->objfile
));
19033 if (attr_count
!= NULL
)
19034 complaint (_("Unresolved DW_AT_count "
19035 "- DIE at %s [in module %s]"),
19036 sect_offset_str (die
->sect_off
),
19037 objfile_name (cu
->per_objfile
->objfile
));
19042 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
19043 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
19044 bias
= bias_attr
->constant_value (0);
19046 /* Normally, the DWARF producers are expected to use a signed
19047 constant form (Eg. DW_FORM_sdata) to express negative bounds.
19048 But this is unfortunately not always the case, as witnessed
19049 with GCC, for instance, where the ambiguous DW_FORM_dataN form
19050 is used instead. To work around that ambiguity, we treat
19051 the bounds as signed, and thus sign-extend their values, when
19052 the base type is signed. */
19054 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
19055 if (low
.kind () == PROP_CONST
19056 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
19057 low
.set_const_val (low
.const_val () | negative_mask
);
19058 if (high
.kind () == PROP_CONST
19059 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
19060 high
.set_const_val (high
.const_val () | negative_mask
);
19062 /* Check for bit and byte strides. */
19063 struct dynamic_prop byte_stride_prop
;
19064 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
19065 if (attr_byte_stride
!= nullptr)
19067 struct type
*prop_type
= cu
->addr_sized_int_type (false);
19068 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
19072 struct dynamic_prop bit_stride_prop
;
19073 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
19074 if (attr_bit_stride
!= nullptr)
19076 /* It only makes sense to have either a bit or byte stride. */
19077 if (attr_byte_stride
!= nullptr)
19079 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
19080 "- DIE at %s [in module %s]"),
19081 sect_offset_str (die
->sect_off
),
19082 objfile_name (cu
->per_objfile
->objfile
));
19083 attr_bit_stride
= nullptr;
19087 struct type
*prop_type
= cu
->addr_sized_int_type (false);
19088 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
19093 if (attr_byte_stride
!= nullptr
19094 || attr_bit_stride
!= nullptr)
19096 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
19097 struct dynamic_prop
*stride
19098 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
19101 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
19102 &high
, bias
, stride
, byte_stride_p
);
19105 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
19107 if (high_bound_is_count
)
19108 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
19110 /* Ada expects an empty array on no boundary attributes. */
19111 if (attr
== NULL
&& cu
->language
!= language_ada
)
19112 range_type
->bounds ()->high
.set_undefined ();
19114 name
= dwarf2_name (die
, cu
);
19116 range_type
->set_name (name
);
19118 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
19119 if (attr
!= nullptr)
19120 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
19122 maybe_set_alignment (cu
, die
, range_type
);
19124 set_die_type (die
, range_type
, cu
);
19126 /* set_die_type should be already done. */
19127 set_descriptive_type (range_type
, die
, cu
);
19132 static struct type
*
19133 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19137 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
19138 type
->set_name (dwarf2_name (die
, cu
));
19140 /* In Ada, an unspecified type is typically used when the description
19141 of the type is deferred to a different unit. When encountering
19142 such a type, we treat it as a stub, and try to resolve it later on,
19144 if (cu
->language
== language_ada
)
19145 type
->set_is_stub (true);
19147 return set_die_type (die
, type
, cu
);
19150 /* Read a single die and all its descendents. Set the die's sibling
19151 field to NULL; set other fields in the die correctly, and set all
19152 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
19153 location of the info_ptr after reading all of those dies. PARENT
19154 is the parent of the die in question. */
19156 static struct die_info
*
19157 read_die_and_children (const struct die_reader_specs
*reader
,
19158 const gdb_byte
*info_ptr
,
19159 const gdb_byte
**new_info_ptr
,
19160 struct die_info
*parent
)
19162 struct die_info
*die
;
19163 const gdb_byte
*cur_ptr
;
19165 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
19168 *new_info_ptr
= cur_ptr
;
19171 store_in_ref_table (die
, reader
->cu
);
19173 if (die
->has_children
)
19174 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
19178 *new_info_ptr
= cur_ptr
;
19181 die
->sibling
= NULL
;
19182 die
->parent
= parent
;
19186 /* Read a die, all of its descendents, and all of its siblings; set
19187 all of the fields of all of the dies correctly. Arguments are as
19188 in read_die_and_children. */
19190 static struct die_info
*
19191 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
19192 const gdb_byte
*info_ptr
,
19193 const gdb_byte
**new_info_ptr
,
19194 struct die_info
*parent
)
19196 struct die_info
*first_die
, *last_sibling
;
19197 const gdb_byte
*cur_ptr
;
19199 cur_ptr
= info_ptr
;
19200 first_die
= last_sibling
= NULL
;
19204 struct die_info
*die
19205 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
19209 *new_info_ptr
= cur_ptr
;
19216 last_sibling
->sibling
= die
;
19218 last_sibling
= die
;
19222 /* Read a die, all of its descendents, and all of its siblings; set
19223 all of the fields of all of the dies correctly. Arguments are as
19224 in read_die_and_children.
19225 This the main entry point for reading a DIE and all its children. */
19227 static struct die_info
*
19228 read_die_and_siblings (const struct die_reader_specs
*reader
,
19229 const gdb_byte
*info_ptr
,
19230 const gdb_byte
**new_info_ptr
,
19231 struct die_info
*parent
)
19233 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
19234 new_info_ptr
, parent
);
19236 if (dwarf_die_debug
)
19238 fprintf_unfiltered (gdb_stdlog
,
19239 "Read die from %s@0x%x of %s:\n",
19240 reader
->die_section
->get_name (),
19241 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19242 bfd_get_filename (reader
->abfd
));
19243 dump_die (die
, dwarf_die_debug
);
19249 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
19251 The caller is responsible for filling in the extra attributes
19252 and updating (*DIEP)->num_attrs.
19253 Set DIEP to point to a newly allocated die with its information,
19254 except for its child, sibling, and parent fields. */
19256 static const gdb_byte
*
19257 read_full_die_1 (const struct die_reader_specs
*reader
,
19258 struct die_info
**diep
, const gdb_byte
*info_ptr
,
19259 int num_extra_attrs
)
19261 unsigned int abbrev_number
, bytes_read
, i
;
19262 struct abbrev_info
*abbrev
;
19263 struct die_info
*die
;
19264 struct dwarf2_cu
*cu
= reader
->cu
;
19265 bfd
*abfd
= reader
->abfd
;
19267 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
19268 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19269 info_ptr
+= bytes_read
;
19270 if (!abbrev_number
)
19276 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
19278 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
19280 bfd_get_filename (abfd
));
19282 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
19283 die
->sect_off
= sect_off
;
19284 die
->tag
= abbrev
->tag
;
19285 die
->abbrev
= abbrev_number
;
19286 die
->has_children
= abbrev
->has_children
;
19288 /* Make the result usable.
19289 The caller needs to update num_attrs after adding the extra
19291 die
->num_attrs
= abbrev
->num_attrs
;
19293 bool any_need_reprocess
= false;
19294 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19296 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
19298 if (die
->attrs
[i
].requires_reprocessing_p ())
19299 any_need_reprocess
= true;
19302 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
19303 if (attr
!= nullptr && attr
->form_is_unsigned ())
19304 cu
->str_offsets_base
= attr
->as_unsigned ();
19306 attr
= die
->attr (DW_AT_loclists_base
);
19307 if (attr
!= nullptr)
19308 cu
->loclist_base
= attr
->as_unsigned ();
19310 auto maybe_addr_base
= die
->addr_base ();
19311 if (maybe_addr_base
.has_value ())
19312 cu
->addr_base
= *maybe_addr_base
;
19314 attr
= die
->attr (DW_AT_rnglists_base
);
19315 if (attr
!= nullptr)
19316 cu
->rnglists_base
= attr
->as_unsigned ();
19318 if (any_need_reprocess
)
19320 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19322 if (die
->attrs
[i
].requires_reprocessing_p ())
19323 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
19330 /* Read a die and all its attributes.
19331 Set DIEP to point to a newly allocated die with its information,
19332 except for its child, sibling, and parent fields. */
19334 static const gdb_byte
*
19335 read_full_die (const struct die_reader_specs
*reader
,
19336 struct die_info
**diep
, const gdb_byte
*info_ptr
)
19338 const gdb_byte
*result
;
19340 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
19342 if (dwarf_die_debug
)
19344 fprintf_unfiltered (gdb_stdlog
,
19345 "Read die from %s@0x%x of %s:\n",
19346 reader
->die_section
->get_name (),
19347 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19348 bfd_get_filename (reader
->abfd
));
19349 dump_die (*diep
, dwarf_die_debug
);
19356 /* Returns nonzero if TAG represents a type that we might generate a partial
19360 is_type_tag_for_partial (int tag
, enum language lang
)
19365 /* Some types that would be reasonable to generate partial symbols for,
19366 that we don't at present. Note that normally this does not
19367 matter, mainly because C compilers don't give names to these
19368 types, but instead emit DW_TAG_typedef. */
19369 case DW_TAG_file_type
:
19370 case DW_TAG_ptr_to_member_type
:
19371 case DW_TAG_set_type
:
19372 case DW_TAG_string_type
:
19373 case DW_TAG_subroutine_type
:
19376 /* GNAT may emit an array with a name, but no typedef, so we
19377 need to make a symbol in this case. */
19378 case DW_TAG_array_type
:
19379 return lang
== language_ada
;
19381 case DW_TAG_base_type
:
19382 case DW_TAG_class_type
:
19383 case DW_TAG_interface_type
:
19384 case DW_TAG_enumeration_type
:
19385 case DW_TAG_structure_type
:
19386 case DW_TAG_subrange_type
:
19387 case DW_TAG_typedef
:
19388 case DW_TAG_union_type
:
19395 /* Load all DIEs that are interesting for partial symbols into memory. */
19397 static struct partial_die_info
*
19398 load_partial_dies (const struct die_reader_specs
*reader
,
19399 const gdb_byte
*info_ptr
, int building_psymtab
)
19401 struct dwarf2_cu
*cu
= reader
->cu
;
19402 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19403 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
19404 unsigned int bytes_read
;
19405 unsigned int load_all
= 0;
19406 int nesting_level
= 1;
19411 gdb_assert (cu
->per_cu
!= NULL
);
19412 if (cu
->per_cu
->load_all_dies
)
19416 = htab_create_alloc_ex (cu
->header
.length
/ 12,
19420 &cu
->comp_unit_obstack
,
19421 hashtab_obstack_allocate
,
19422 dummy_obstack_deallocate
);
19426 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
19428 /* A NULL abbrev means the end of a series of children. */
19429 if (abbrev
== NULL
)
19431 if (--nesting_level
== 0)
19434 info_ptr
+= bytes_read
;
19435 last_die
= parent_die
;
19436 parent_die
= parent_die
->die_parent
;
19440 /* Check for template arguments. We never save these; if
19441 they're seen, we just mark the parent, and go on our way. */
19442 if (parent_die
!= NULL
19443 && cu
->language
== language_cplus
19444 && (abbrev
->tag
== DW_TAG_template_type_param
19445 || abbrev
->tag
== DW_TAG_template_value_param
))
19447 parent_die
->has_template_arguments
= 1;
19451 /* We don't need a partial DIE for the template argument. */
19452 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19457 /* We only recurse into c++ subprograms looking for template arguments.
19458 Skip their other children. */
19460 && cu
->language
== language_cplus
19461 && parent_die
!= NULL
19462 && parent_die
->tag
== DW_TAG_subprogram
19463 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19465 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19469 /* Check whether this DIE is interesting enough to save. Normally
19470 we would not be interested in members here, but there may be
19471 later variables referencing them via DW_AT_specification (for
19472 static members). */
19474 && !is_type_tag_for_partial (abbrev
->tag
, cu
->language
)
19475 && abbrev
->tag
!= DW_TAG_constant
19476 && abbrev
->tag
!= DW_TAG_enumerator
19477 && abbrev
->tag
!= DW_TAG_subprogram
19478 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19479 && abbrev
->tag
!= DW_TAG_lexical_block
19480 && abbrev
->tag
!= DW_TAG_variable
19481 && abbrev
->tag
!= DW_TAG_namespace
19482 && abbrev
->tag
!= DW_TAG_module
19483 && abbrev
->tag
!= DW_TAG_member
19484 && abbrev
->tag
!= DW_TAG_imported_unit
19485 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19487 /* Otherwise we skip to the next sibling, if any. */
19488 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19492 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19495 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19497 /* This two-pass algorithm for processing partial symbols has a
19498 high cost in cache pressure. Thus, handle some simple cases
19499 here which cover the majority of C partial symbols. DIEs
19500 which neither have specification tags in them, nor could have
19501 specification tags elsewhere pointing at them, can simply be
19502 processed and discarded.
19504 This segment is also optional; scan_partial_symbols and
19505 add_partial_symbol will handle these DIEs if we chain
19506 them in normally. When compilers which do not emit large
19507 quantities of duplicate debug information are more common,
19508 this code can probably be removed. */
19510 /* Any complete simple types at the top level (pretty much all
19511 of them, for a language without namespaces), can be processed
19513 if (parent_die
== NULL
19514 && pdi
.has_specification
== 0
19515 && pdi
.is_declaration
== 0
19516 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19517 || pdi
.tag
== DW_TAG_base_type
19518 || pdi
.tag
== DW_TAG_array_type
19519 || pdi
.tag
== DW_TAG_subrange_type
))
19521 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19522 add_partial_symbol (&pdi
, cu
);
19524 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19528 /* The exception for DW_TAG_typedef with has_children above is
19529 a workaround of GCC PR debug/47510. In the case of this complaint
19530 type_name_or_error will error on such types later.
19532 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19533 it could not find the child DIEs referenced later, this is checked
19534 above. In correct DWARF DW_TAG_typedef should have no children. */
19536 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19537 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19538 "- DIE at %s [in module %s]"),
19539 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19541 /* If we're at the second level, and we're an enumerator, and
19542 our parent has no specification (meaning possibly lives in a
19543 namespace elsewhere), then we can add the partial symbol now
19544 instead of queueing it. */
19545 if (pdi
.tag
== DW_TAG_enumerator
19546 && parent_die
!= NULL
19547 && parent_die
->die_parent
== NULL
19548 && parent_die
->tag
== DW_TAG_enumeration_type
19549 && parent_die
->has_specification
== 0)
19551 if (pdi
.raw_name
== NULL
)
19552 complaint (_("malformed enumerator DIE ignored"));
19553 else if (building_psymtab
)
19554 add_partial_symbol (&pdi
, cu
);
19556 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19560 struct partial_die_info
*part_die
19561 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19563 /* We'll save this DIE so link it in. */
19564 part_die
->die_parent
= parent_die
;
19565 part_die
->die_sibling
= NULL
;
19566 part_die
->die_child
= NULL
;
19568 if (last_die
&& last_die
== parent_die
)
19569 last_die
->die_child
= part_die
;
19571 last_die
->die_sibling
= part_die
;
19573 last_die
= part_die
;
19575 if (first_die
== NULL
)
19576 first_die
= part_die
;
19578 /* Maybe add the DIE to the hash table. Not all DIEs that we
19579 find interesting need to be in the hash table, because we
19580 also have the parent/sibling/child chains; only those that we
19581 might refer to by offset later during partial symbol reading.
19583 For now this means things that might have be the target of a
19584 DW_AT_specification, DW_AT_abstract_origin, or
19585 DW_AT_extension. DW_AT_extension will refer only to
19586 namespaces; DW_AT_abstract_origin refers to functions (and
19587 many things under the function DIE, but we do not recurse
19588 into function DIEs during partial symbol reading) and
19589 possibly variables as well; DW_AT_specification refers to
19590 declarations. Declarations ought to have the DW_AT_declaration
19591 flag. It happens that GCC forgets to put it in sometimes, but
19592 only for functions, not for types.
19594 Adding more things than necessary to the hash table is harmless
19595 except for the performance cost. Adding too few will result in
19596 wasted time in find_partial_die, when we reread the compilation
19597 unit with load_all_dies set. */
19600 || abbrev
->tag
== DW_TAG_constant
19601 || abbrev
->tag
== DW_TAG_subprogram
19602 || abbrev
->tag
== DW_TAG_variable
19603 || abbrev
->tag
== DW_TAG_namespace
19604 || part_die
->is_declaration
)
19608 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19609 to_underlying (part_die
->sect_off
),
19614 /* For some DIEs we want to follow their children (if any). For C
19615 we have no reason to follow the children of structures; for other
19616 languages we have to, so that we can get at method physnames
19617 to infer fully qualified class names, for DW_AT_specification,
19618 and for C++ template arguments. For C++, we also look one level
19619 inside functions to find template arguments (if the name of the
19620 function does not already contain the template arguments).
19622 For Ada and Fortran, we need to scan the children of subprograms
19623 and lexical blocks as well because these languages allow the
19624 definition of nested entities that could be interesting for the
19625 debugger, such as nested subprograms for instance. */
19626 if (last_die
->has_children
19628 || last_die
->tag
== DW_TAG_namespace
19629 || last_die
->tag
== DW_TAG_module
19630 || last_die
->tag
== DW_TAG_enumeration_type
19631 || (cu
->language
== language_cplus
19632 && last_die
->tag
== DW_TAG_subprogram
19633 && (last_die
->raw_name
== NULL
19634 || strchr (last_die
->raw_name
, '<') == NULL
))
19635 || (cu
->language
!= language_c
19636 && (last_die
->tag
== DW_TAG_class_type
19637 || last_die
->tag
== DW_TAG_interface_type
19638 || last_die
->tag
== DW_TAG_structure_type
19639 || last_die
->tag
== DW_TAG_union_type
))
19640 || ((cu
->language
== language_ada
19641 || cu
->language
== language_fortran
)
19642 && (last_die
->tag
== DW_TAG_subprogram
19643 || last_die
->tag
== DW_TAG_lexical_block
))))
19646 parent_die
= last_die
;
19650 /* Otherwise we skip to the next sibling, if any. */
19651 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19653 /* Back to the top, do it again. */
19657 partial_die_info::partial_die_info (sect_offset sect_off_
,
19658 struct abbrev_info
*abbrev
)
19659 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19663 /* See class definition. */
19666 partial_die_info::name (dwarf2_cu
*cu
)
19668 if (!canonical_name
&& raw_name
!= nullptr)
19670 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19671 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19672 canonical_name
= 1;
19678 /* Read a minimal amount of information into the minimal die structure.
19679 INFO_PTR should point just after the initial uleb128 of a DIE. */
19682 partial_die_info::read (const struct die_reader_specs
*reader
,
19683 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19685 struct dwarf2_cu
*cu
= reader
->cu
;
19686 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19688 int has_low_pc_attr
= 0;
19689 int has_high_pc_attr
= 0;
19690 int high_pc_relative
= 0;
19692 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19695 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19696 /* String and address offsets that need to do the reprocessing have
19697 already been read at this point, so there is no need to wait until
19698 the loop terminates to do the reprocessing. */
19699 if (attr
.requires_reprocessing_p ())
19700 read_attribute_reprocess (reader
, &attr
, tag
);
19701 /* Store the data if it is of an attribute we want to keep in a
19702 partial symbol table. */
19708 case DW_TAG_compile_unit
:
19709 case DW_TAG_partial_unit
:
19710 case DW_TAG_type_unit
:
19711 /* Compilation units have a DW_AT_name that is a filename, not
19712 a source language identifier. */
19713 case DW_TAG_enumeration_type
:
19714 case DW_TAG_enumerator
:
19715 /* These tags always have simple identifiers already; no need
19716 to canonicalize them. */
19717 canonical_name
= 1;
19718 raw_name
= attr
.as_string ();
19721 canonical_name
= 0;
19722 raw_name
= attr
.as_string ();
19726 case DW_AT_linkage_name
:
19727 case DW_AT_MIPS_linkage_name
:
19728 /* Note that both forms of linkage name might appear. We
19729 assume they will be the same, and we only store the last
19731 linkage_name
= attr
.as_string ();
19734 has_low_pc_attr
= 1;
19735 lowpc
= attr
.as_address ();
19737 case DW_AT_high_pc
:
19738 has_high_pc_attr
= 1;
19739 highpc
= attr
.as_address ();
19740 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19741 high_pc_relative
= 1;
19743 case DW_AT_location
:
19744 /* Support the .debug_loc offsets. */
19745 if (attr
.form_is_block ())
19747 d
.locdesc
= attr
.as_block ();
19749 else if (attr
.form_is_section_offset ())
19751 dwarf2_complex_location_expr_complaint ();
19755 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19756 "partial symbol information");
19759 case DW_AT_external
:
19760 is_external
= attr
.as_boolean ();
19762 case DW_AT_declaration
:
19763 is_declaration
= attr
.as_boolean ();
19768 case DW_AT_abstract_origin
:
19769 case DW_AT_specification
:
19770 case DW_AT_extension
:
19771 has_specification
= 1;
19772 spec_offset
= attr
.get_ref_die_offset ();
19773 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19774 || cu
->per_cu
->is_dwz
);
19776 case DW_AT_sibling
:
19777 /* Ignore absolute siblings, they might point outside of
19778 the current compile unit. */
19779 if (attr
.form
== DW_FORM_ref_addr
)
19780 complaint (_("ignoring absolute DW_AT_sibling"));
19783 const gdb_byte
*buffer
= reader
->buffer
;
19784 sect_offset off
= attr
.get_ref_die_offset ();
19785 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19787 if (sibling_ptr
< info_ptr
)
19788 complaint (_("DW_AT_sibling points backwards"));
19789 else if (sibling_ptr
> reader
->buffer_end
)
19790 reader
->die_section
->overflow_complaint ();
19792 sibling
= sibling_ptr
;
19795 case DW_AT_byte_size
:
19798 case DW_AT_const_value
:
19799 has_const_value
= 1;
19801 case DW_AT_calling_convention
:
19802 /* DWARF doesn't provide a way to identify a program's source-level
19803 entry point. DW_AT_calling_convention attributes are only meant
19804 to describe functions' calling conventions.
19806 However, because it's a necessary piece of information in
19807 Fortran, and before DWARF 4 DW_CC_program was the only
19808 piece of debugging information whose definition refers to
19809 a 'main program' at all, several compilers marked Fortran
19810 main programs with DW_CC_program --- even when those
19811 functions use the standard calling conventions.
19813 Although DWARF now specifies a way to provide this
19814 information, we support this practice for backward
19816 if (attr
.constant_value (0) == DW_CC_program
19817 && cu
->language
== language_fortran
)
19818 main_subprogram
= 1;
19822 LONGEST value
= attr
.constant_value (-1);
19823 if (value
== DW_INL_inlined
19824 || value
== DW_INL_declared_inlined
)
19825 may_be_inlined
= 1;
19830 if (tag
== DW_TAG_imported_unit
)
19832 d
.sect_off
= attr
.get_ref_die_offset ();
19833 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19834 || cu
->per_cu
->is_dwz
);
19838 case DW_AT_main_subprogram
:
19839 main_subprogram
= attr
.as_boolean ();
19844 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19845 on DWARF version). */
19846 ULONGEST ranges_offset
= attr
.as_unsigned ();
19848 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19850 if (tag
!= DW_TAG_compile_unit
)
19851 ranges_offset
+= cu
->gnu_ranges_base
;
19853 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19864 /* For Ada, if both the name and the linkage name appear, we prefer
19865 the latter. This lets "catch exception" work better, regardless
19866 of the order in which the name and linkage name were emitted.
19867 Really, though, this is just a workaround for the fact that gdb
19868 doesn't store both the name and the linkage name. */
19869 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19870 raw_name
= linkage_name
;
19872 if (high_pc_relative
)
19875 if (has_low_pc_attr
&& has_high_pc_attr
)
19877 /* When using the GNU linker, .gnu.linkonce. sections are used to
19878 eliminate duplicate copies of functions and vtables and such.
19879 The linker will arbitrarily choose one and discard the others.
19880 The AT_*_pc values for such functions refer to local labels in
19881 these sections. If the section from that file was discarded, the
19882 labels are not in the output, so the relocs get a value of 0.
19883 If this is a discarded function, mark the pc bounds as invalid,
19884 so that GDB will ignore it. */
19885 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19887 struct objfile
*objfile
= per_objfile
->objfile
;
19888 struct gdbarch
*gdbarch
= objfile
->arch ();
19890 complaint (_("DW_AT_low_pc %s is zero "
19891 "for DIE at %s [in module %s]"),
19892 paddress (gdbarch
, lowpc
),
19893 sect_offset_str (sect_off
),
19894 objfile_name (objfile
));
19896 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19897 else if (lowpc
>= highpc
)
19899 struct objfile
*objfile
= per_objfile
->objfile
;
19900 struct gdbarch
*gdbarch
= objfile
->arch ();
19902 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19903 "for DIE at %s [in module %s]"),
19904 paddress (gdbarch
, lowpc
),
19905 paddress (gdbarch
, highpc
),
19906 sect_offset_str (sect_off
),
19907 objfile_name (objfile
));
19916 /* Find a cached partial DIE at OFFSET in CU. */
19918 struct partial_die_info
*
19919 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19921 struct partial_die_info
*lookup_die
= NULL
;
19922 struct partial_die_info
part_die (sect_off
);
19924 lookup_die
= ((struct partial_die_info
*)
19925 htab_find_with_hash (partial_dies
, &part_die
,
19926 to_underlying (sect_off
)));
19931 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19932 except in the case of .debug_types DIEs which do not reference
19933 outside their CU (they do however referencing other types via
19934 DW_FORM_ref_sig8). */
19936 static const struct cu_partial_die_info
19937 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19939 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19940 struct objfile
*objfile
= per_objfile
->objfile
;
19941 struct partial_die_info
*pd
= NULL
;
19943 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19944 && cu
->header
.offset_in_cu_p (sect_off
))
19946 pd
= cu
->find_partial_die (sect_off
);
19949 /* We missed recording what we needed.
19950 Load all dies and try again. */
19954 /* TUs don't reference other CUs/TUs (except via type signatures). */
19955 if (cu
->per_cu
->is_debug_types
)
19957 error (_("Dwarf Error: Type Unit at offset %s contains"
19958 " external reference to offset %s [in module %s].\n"),
19959 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19960 bfd_get_filename (objfile
->obfd
));
19962 dwarf2_per_cu_data
*per_cu
19963 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19966 cu
= per_objfile
->get_cu (per_cu
);
19967 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19968 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19970 cu
= per_objfile
->get_cu (per_cu
);
19973 pd
= cu
->find_partial_die (sect_off
);
19976 /* If we didn't find it, and not all dies have been loaded,
19977 load them all and try again. */
19979 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
19981 cu
->per_cu
->load_all_dies
= 1;
19983 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19984 THIS_CU->cu may already be in use. So we can't just free it and
19985 replace its DIEs with the ones we read in. Instead, we leave those
19986 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19987 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19989 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19991 pd
= cu
->find_partial_die (sect_off
);
19995 error (_("Dwarf Error: Cannot not find DIE at %s [from module %s]\n"),
19996 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
20000 /* See if we can figure out if the class lives in a namespace. We do
20001 this by looking for a member function; its demangled name will
20002 contain namespace info, if there is any. */
20005 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
20006 struct dwarf2_cu
*cu
)
20008 /* NOTE: carlton/2003-10-07: Getting the info this way changes
20009 what template types look like, because the demangler
20010 frequently doesn't give the same name as the debug info. We
20011 could fix this by only using the demangled name to get the
20012 prefix (but see comment in read_structure_type). */
20014 struct partial_die_info
*real_pdi
;
20015 struct partial_die_info
*child_pdi
;
20017 /* If this DIE (this DIE's specification, if any) has a parent, then
20018 we should not do this. We'll prepend the parent's fully qualified
20019 name when we create the partial symbol. */
20021 real_pdi
= struct_pdi
;
20022 while (real_pdi
->has_specification
)
20024 auto res
= find_partial_die (real_pdi
->spec_offset
,
20025 real_pdi
->spec_is_dwz
, cu
);
20026 real_pdi
= res
.pdi
;
20030 if (real_pdi
->die_parent
!= NULL
)
20033 for (child_pdi
= struct_pdi
->die_child
;
20035 child_pdi
= child_pdi
->die_sibling
)
20037 if (child_pdi
->tag
== DW_TAG_subprogram
20038 && child_pdi
->linkage_name
!= NULL
)
20040 gdb::unique_xmalloc_ptr
<char> actual_class_name
20041 (cu
->language_defn
->class_name_from_physname
20042 (child_pdi
->linkage_name
));
20043 if (actual_class_name
!= NULL
)
20045 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20046 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
20047 struct_pdi
->canonical_name
= 1;
20054 /* Return true if a DIE with TAG may have the DW_AT_const_value
20058 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
20062 case DW_TAG_constant
:
20063 case DW_TAG_enumerator
:
20064 case DW_TAG_formal_parameter
:
20065 case DW_TAG_template_value_param
:
20066 case DW_TAG_variable
:
20074 partial_die_info::fixup (struct dwarf2_cu
*cu
)
20076 /* Once we've fixed up a die, there's no point in doing so again.
20077 This also avoids a memory leak if we were to call
20078 guess_partial_die_structure_name multiple times. */
20082 /* If we found a reference attribute and the DIE has no name, try
20083 to find a name in the referred to DIE. */
20085 if (raw_name
== NULL
&& has_specification
)
20087 struct partial_die_info
*spec_die
;
20089 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
20090 spec_die
= res
.pdi
;
20093 spec_die
->fixup (cu
);
20095 if (spec_die
->raw_name
)
20097 raw_name
= spec_die
->raw_name
;
20098 canonical_name
= spec_die
->canonical_name
;
20100 /* Copy DW_AT_external attribute if it is set. */
20101 if (spec_die
->is_external
)
20102 is_external
= spec_die
->is_external
;
20106 if (!has_const_value
&& has_specification
20107 && can_have_DW_AT_const_value_p (tag
))
20109 struct partial_die_info
*spec_die
;
20111 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
20112 spec_die
= res
.pdi
;
20115 spec_die
->fixup (cu
);
20117 if (spec_die
->has_const_value
)
20119 /* Copy DW_AT_const_value attribute if it is set. */
20120 has_const_value
= spec_die
->has_const_value
;
20124 /* Set default names for some unnamed DIEs. */
20126 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
20128 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
20129 canonical_name
= 1;
20132 /* If there is no parent die to provide a namespace, and there are
20133 children, see if we can determine the namespace from their linkage
20135 if (cu
->language
== language_cplus
20136 && !cu
->per_objfile
->per_bfd
->types
.empty ()
20137 && die_parent
== NULL
20139 && (tag
== DW_TAG_class_type
20140 || tag
== DW_TAG_structure_type
20141 || tag
== DW_TAG_union_type
))
20142 guess_partial_die_structure_name (this, cu
);
20144 /* GCC might emit a nameless struct or union that has a linkage
20145 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20146 if (raw_name
== NULL
20147 && (tag
== DW_TAG_class_type
20148 || tag
== DW_TAG_interface_type
20149 || tag
== DW_TAG_structure_type
20150 || tag
== DW_TAG_union_type
)
20151 && linkage_name
!= NULL
)
20153 gdb::unique_xmalloc_ptr
<char> demangled
20154 (gdb_demangle (linkage_name
, DMGL_TYPES
));
20155 if (demangled
!= nullptr)
20159 /* Strip any leading namespaces/classes, keep only the base name.
20160 DW_AT_name for named DIEs does not contain the prefixes. */
20161 base
= strrchr (demangled
.get (), ':');
20162 if (base
&& base
> demangled
.get () && base
[-1] == ':')
20165 base
= demangled
.get ();
20167 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20168 raw_name
= objfile
->intern (base
);
20169 canonical_name
= 1;
20176 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
20177 contents from the given SECTION in the HEADER.
20179 HEADER_OFFSET is the offset of the header in the section. */
20181 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
20182 struct dwarf2_section_info
*section
,
20183 sect_offset header_offset
)
20185 unsigned int bytes_read
;
20186 bfd
*abfd
= section
->get_bfd_owner ();
20187 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
20189 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
20190 info_ptr
+= bytes_read
;
20192 header
->version
= read_2_bytes (abfd
, info_ptr
);
20195 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
20198 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
20201 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
20204 /* Return the DW_AT_loclists_base value for the CU. */
20206 lookup_loclist_base (struct dwarf2_cu
*cu
)
20208 /* For the .dwo unit, the loclist_base points to the first offset following
20209 the header. The header consists of the following entities-
20210 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
20212 2. version (2 bytes)
20213 3. address size (1 byte)
20214 4. segment selector size (1 byte)
20215 5. offset entry count (4 bytes)
20216 These sizes are derived as per the DWARFv5 standard. */
20217 if (cu
->dwo_unit
!= nullptr)
20219 if (cu
->header
.initial_length_size
== 4)
20220 return LOCLIST_HEADER_SIZE32
;
20221 return LOCLIST_HEADER_SIZE64
;
20223 return cu
->loclist_base
;
20226 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
20227 array of offsets in the .debug_loclists section. */
20230 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
20232 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20233 struct objfile
*objfile
= per_objfile
->objfile
;
20234 bfd
*abfd
= objfile
->obfd
;
20235 ULONGEST loclist_header_size
=
20236 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
20237 : LOCLIST_HEADER_SIZE64
);
20238 ULONGEST loclist_base
= lookup_loclist_base (cu
);
20240 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
20241 ULONGEST start_offset
=
20242 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
20244 /* Get loclists section. */
20245 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
20247 /* Read the loclists section content. */
20248 section
->read (objfile
);
20249 if (section
->buffer
== NULL
)
20250 error (_("DW_FORM_loclistx used without .debug_loclists "
20251 "section [in module %s]"), objfile_name (objfile
));
20253 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
20254 so if loclist_base is smaller than the header size, we have a problem. */
20255 if (loclist_base
< loclist_header_size
)
20256 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
20257 objfile_name (objfile
));
20259 /* Read the header of the loclists contribution. */
20260 struct loclists_rnglists_header header
;
20261 read_loclists_rnglists_header (&header
, section
,
20262 (sect_offset
) (loclist_base
- loclist_header_size
));
20264 /* Verify the loclist index is valid. */
20265 if (loclist_index
>= header
.offset_entry_count
)
20266 error (_("DW_FORM_loclistx pointing outside of "
20267 ".debug_loclists offset array [in module %s]"),
20268 objfile_name (objfile
));
20270 /* Validate that reading won't go beyond the end of the section. */
20271 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
20272 error (_("Reading DW_FORM_loclistx index beyond end of"
20273 ".debug_loclists section [in module %s]"),
20274 objfile_name (objfile
));
20276 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20278 if (cu
->header
.offset_size
== 4)
20279 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
20281 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
20284 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
20285 array of offsets in the .debug_rnglists section. */
20288 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
20291 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
20292 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20293 bfd
*abfd
= objfile
->obfd
;
20294 ULONGEST rnglist_header_size
=
20295 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
20296 : RNGLIST_HEADER_SIZE64
);
20298 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
20299 .debug_rnglists.dwo section. The rnglists base given in the skeleton
20301 ULONGEST rnglist_base
=
20302 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
20304 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
20305 ULONGEST start_offset
=
20306 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
20308 /* Get rnglists section. */
20309 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
20311 /* Read the rnglists section content. */
20312 section
->read (objfile
);
20313 if (section
->buffer
== nullptr)
20314 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
20316 objfile_name (objfile
));
20318 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
20319 so if rnglist_base is smaller than the header size, we have a problem. */
20320 if (rnglist_base
< rnglist_header_size
)
20321 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
20322 objfile_name (objfile
));
20324 /* Read the header of the rnglists contribution. */
20325 struct loclists_rnglists_header header
;
20326 read_loclists_rnglists_header (&header
, section
,
20327 (sect_offset
) (rnglist_base
- rnglist_header_size
));
20329 /* Verify the rnglist index is valid. */
20330 if (rnglist_index
>= header
.offset_entry_count
)
20331 error (_("DW_FORM_rnglistx index pointing outside of "
20332 ".debug_rnglists offset array [in module %s]"),
20333 objfile_name (objfile
));
20335 /* Validate that reading won't go beyond the end of the section. */
20336 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
20337 error (_("Reading DW_FORM_rnglistx index beyond end of"
20338 ".debug_rnglists section [in module %s]"),
20339 objfile_name (objfile
));
20341 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20343 if (cu
->header
.offset_size
== 4)
20344 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
20346 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
20349 /* Process the attributes that had to be skipped in the first round. These
20350 attributes are the ones that need str_offsets_base or addr_base attributes.
20351 They could not have been processed in the first round, because at the time
20352 the values of str_offsets_base or addr_base may not have been known. */
20354 read_attribute_reprocess (const struct die_reader_specs
*reader
,
20355 struct attribute
*attr
, dwarf_tag tag
)
20357 struct dwarf2_cu
*cu
= reader
->cu
;
20358 switch (attr
->form
)
20360 case DW_FORM_addrx
:
20361 case DW_FORM_GNU_addr_index
:
20362 attr
->set_address (read_addr_index (cu
,
20363 attr
->as_unsigned_reprocess ()));
20365 case DW_FORM_loclistx
:
20367 sect_offset loclists_sect_off
20368 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
20370 attr
->set_unsigned (to_underlying (loclists_sect_off
));
20373 case DW_FORM_rnglistx
:
20375 sect_offset rnglists_sect_off
20376 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
20378 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
20382 case DW_FORM_strx1
:
20383 case DW_FORM_strx2
:
20384 case DW_FORM_strx3
:
20385 case DW_FORM_strx4
:
20386 case DW_FORM_GNU_str_index
:
20388 unsigned int str_index
= attr
->as_unsigned_reprocess ();
20389 gdb_assert (!attr
->canonical_string_p ());
20390 if (reader
->dwo_file
!= NULL
)
20391 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
20394 attr
->set_string_noncanonical (read_stub_str_index (cu
,
20399 gdb_assert_not_reached (_("Unexpected DWARF form."));
20403 /* Read an attribute value described by an attribute form. */
20405 static const gdb_byte
*
20406 read_attribute_value (const struct die_reader_specs
*reader
,
20407 struct attribute
*attr
, unsigned form
,
20408 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
20410 struct dwarf2_cu
*cu
= reader
->cu
;
20411 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20412 struct objfile
*objfile
= per_objfile
->objfile
;
20413 bfd
*abfd
= reader
->abfd
;
20414 struct comp_unit_head
*cu_header
= &cu
->header
;
20415 unsigned int bytes_read
;
20416 struct dwarf_block
*blk
;
20418 attr
->form
= (enum dwarf_form
) form
;
20421 case DW_FORM_ref_addr
:
20422 if (cu
->header
.version
== 2)
20423 attr
->set_unsigned (cu
->header
.read_address (abfd
, info_ptr
,
20426 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
20428 info_ptr
+= bytes_read
;
20430 case DW_FORM_GNU_ref_alt
:
20431 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
20433 info_ptr
+= bytes_read
;
20437 struct gdbarch
*gdbarch
= objfile
->arch ();
20438 CORE_ADDR addr
= cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
20439 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
20440 attr
->set_address (addr
);
20441 info_ptr
+= bytes_read
;
20444 case DW_FORM_block2
:
20445 blk
= dwarf_alloc_block (cu
);
20446 blk
->size
= read_2_bytes (abfd
, info_ptr
);
20448 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20449 info_ptr
+= blk
->size
;
20450 attr
->set_block (blk
);
20452 case DW_FORM_block4
:
20453 blk
= dwarf_alloc_block (cu
);
20454 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20456 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20457 info_ptr
+= blk
->size
;
20458 attr
->set_block (blk
);
20460 case DW_FORM_data2
:
20461 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20464 case DW_FORM_data4
:
20465 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20468 case DW_FORM_data8
:
20469 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20472 case DW_FORM_data16
:
20473 blk
= dwarf_alloc_block (cu
);
20475 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20477 attr
->set_block (blk
);
20479 case DW_FORM_sec_offset
:
20480 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
20482 info_ptr
+= bytes_read
;
20484 case DW_FORM_loclistx
:
20486 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20488 info_ptr
+= bytes_read
;
20491 case DW_FORM_string
:
20492 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20494 info_ptr
+= bytes_read
;
20497 if (!cu
->per_cu
->is_dwz
)
20499 attr
->set_string_noncanonical
20500 (read_indirect_string (per_objfile
,
20501 abfd
, info_ptr
, cu_header
,
20503 info_ptr
+= bytes_read
;
20507 case DW_FORM_line_strp
:
20508 if (!cu
->per_cu
->is_dwz
)
20510 attr
->set_string_noncanonical
20511 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20513 info_ptr
+= bytes_read
;
20517 case DW_FORM_GNU_strp_alt
:
20519 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
20520 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20523 attr
->set_string_noncanonical
20524 (dwz
->read_string (objfile
, str_offset
));
20525 info_ptr
+= bytes_read
;
20528 case DW_FORM_exprloc
:
20529 case DW_FORM_block
:
20530 blk
= dwarf_alloc_block (cu
);
20531 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20532 info_ptr
+= bytes_read
;
20533 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20534 info_ptr
+= blk
->size
;
20535 attr
->set_block (blk
);
20537 case DW_FORM_block1
:
20538 blk
= dwarf_alloc_block (cu
);
20539 blk
->size
= read_1_byte (abfd
, info_ptr
);
20541 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20542 info_ptr
+= blk
->size
;
20543 attr
->set_block (blk
);
20545 case DW_FORM_data1
:
20547 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20550 case DW_FORM_flag_present
:
20551 attr
->set_unsigned (1);
20553 case DW_FORM_sdata
:
20554 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20555 info_ptr
+= bytes_read
;
20557 case DW_FORM_rnglistx
:
20559 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20561 info_ptr
+= bytes_read
;
20564 case DW_FORM_udata
:
20565 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20566 info_ptr
+= bytes_read
;
20569 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20570 + read_1_byte (abfd
, info_ptr
)));
20574 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20575 + read_2_bytes (abfd
, info_ptr
)));
20579 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20580 + read_4_bytes (abfd
, info_ptr
)));
20584 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20585 + read_8_bytes (abfd
, info_ptr
)));
20588 case DW_FORM_ref_sig8
:
20589 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20592 case DW_FORM_ref_udata
:
20593 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20594 + read_unsigned_leb128 (abfd
, info_ptr
,
20596 info_ptr
+= bytes_read
;
20598 case DW_FORM_indirect
:
20599 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20600 info_ptr
+= bytes_read
;
20601 if (form
== DW_FORM_implicit_const
)
20603 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20604 info_ptr
+= bytes_read
;
20606 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20609 case DW_FORM_implicit_const
:
20610 attr
->set_signed (implicit_const
);
20612 case DW_FORM_addrx
:
20613 case DW_FORM_GNU_addr_index
:
20614 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20616 info_ptr
+= bytes_read
;
20619 case DW_FORM_strx1
:
20620 case DW_FORM_strx2
:
20621 case DW_FORM_strx3
:
20622 case DW_FORM_strx4
:
20623 case DW_FORM_GNU_str_index
:
20625 ULONGEST str_index
;
20626 if (form
== DW_FORM_strx1
)
20628 str_index
= read_1_byte (abfd
, info_ptr
);
20631 else if (form
== DW_FORM_strx2
)
20633 str_index
= read_2_bytes (abfd
, info_ptr
);
20636 else if (form
== DW_FORM_strx3
)
20638 str_index
= read_3_bytes (abfd
, info_ptr
);
20641 else if (form
== DW_FORM_strx4
)
20643 str_index
= read_4_bytes (abfd
, info_ptr
);
20648 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20649 info_ptr
+= bytes_read
;
20651 attr
->set_unsigned_reprocess (str_index
);
20655 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20656 dwarf_form_name (form
),
20657 bfd_get_filename (abfd
));
20661 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20662 attr
->form
= DW_FORM_GNU_ref_alt
;
20664 /* We have seen instances where the compiler tried to emit a byte
20665 size attribute of -1 which ended up being encoded as an unsigned
20666 0xffffffff. Although 0xffffffff is technically a valid size value,
20667 an object of this size seems pretty unlikely so we can relatively
20668 safely treat these cases as if the size attribute was invalid and
20669 treat them as zero by default. */
20670 if (attr
->name
== DW_AT_byte_size
20671 && form
== DW_FORM_data4
20672 && attr
->as_unsigned () >= 0xffffffff)
20675 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20676 hex_string (attr
->as_unsigned ()));
20677 attr
->set_unsigned (0);
20683 /* Read an attribute described by an abbreviated attribute. */
20685 static const gdb_byte
*
20686 read_attribute (const struct die_reader_specs
*reader
,
20687 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
20688 const gdb_byte
*info_ptr
)
20690 attr
->name
= abbrev
->name
;
20691 attr
->string_is_canonical
= 0;
20692 attr
->requires_reprocessing
= 0;
20693 return read_attribute_value (reader
, attr
, abbrev
->form
,
20694 abbrev
->implicit_const
, info_ptr
);
20697 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20699 static const char *
20700 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20701 LONGEST str_offset
)
20703 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20704 str_offset
, "DW_FORM_strp");
20707 /* Return pointer to string at .debug_str offset as read from BUF.
20708 BUF is assumed to be in a compilation unit described by CU_HEADER.
20709 Return *BYTES_READ_PTR count of bytes read from BUF. */
20711 static const char *
20712 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20713 const gdb_byte
*buf
,
20714 const struct comp_unit_head
*cu_header
,
20715 unsigned int *bytes_read_ptr
)
20717 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20719 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20725 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20726 const struct comp_unit_head
*cu_header
,
20727 unsigned int *bytes_read_ptr
)
20729 bfd
*abfd
= objfile
->obfd
;
20730 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20732 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20735 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20736 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20737 ADDR_SIZE is the size of addresses from the CU header. */
20740 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20741 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20743 struct objfile
*objfile
= per_objfile
->objfile
;
20744 bfd
*abfd
= objfile
->obfd
;
20745 const gdb_byte
*info_ptr
;
20746 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20748 per_objfile
->per_bfd
->addr
.read (objfile
);
20749 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20750 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20751 objfile_name (objfile
));
20752 if (addr_base_or_zero
+ addr_index
* addr_size
20753 >= per_objfile
->per_bfd
->addr
.size
)
20754 error (_("DW_FORM_addr_index pointing outside of "
20755 ".debug_addr section [in module %s]"),
20756 objfile_name (objfile
));
20757 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20758 + addr_index
* addr_size
);
20759 if (addr_size
== 4)
20760 return bfd_get_32 (abfd
, info_ptr
);
20762 return bfd_get_64 (abfd
, info_ptr
);
20765 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20768 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20770 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20771 cu
->addr_base
, cu
->header
.addr_size
);
20774 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20777 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20778 unsigned int *bytes_read
)
20780 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20781 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20783 return read_addr_index (cu
, addr_index
);
20789 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20790 dwarf2_per_objfile
*per_objfile
,
20791 unsigned int addr_index
)
20793 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20794 gdb::optional
<ULONGEST
> addr_base
;
20797 /* We need addr_base and addr_size.
20798 If we don't have PER_CU->cu, we have to get it.
20799 Nasty, but the alternative is storing the needed info in PER_CU,
20800 which at this point doesn't seem justified: it's not clear how frequently
20801 it would get used and it would increase the size of every PER_CU.
20802 Entry points like dwarf2_per_cu_addr_size do a similar thing
20803 so we're not in uncharted territory here.
20804 Alas we need to be a bit more complicated as addr_base is contained
20807 We don't need to read the entire CU(/TU).
20808 We just need the header and top level die.
20810 IWBN to use the aging mechanism to let us lazily later discard the CU.
20811 For now we skip this optimization. */
20815 addr_base
= cu
->addr_base
;
20816 addr_size
= cu
->header
.addr_size
;
20820 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20821 addr_base
= reader
.cu
->addr_base
;
20822 addr_size
= reader
.cu
->header
.addr_size
;
20825 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20828 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20829 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20832 static const char *
20833 read_str_index (struct dwarf2_cu
*cu
,
20834 struct dwarf2_section_info
*str_section
,
20835 struct dwarf2_section_info
*str_offsets_section
,
20836 ULONGEST str_offsets_base
, ULONGEST str_index
)
20838 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20839 struct objfile
*objfile
= per_objfile
->objfile
;
20840 const char *objf_name
= objfile_name (objfile
);
20841 bfd
*abfd
= objfile
->obfd
;
20842 const gdb_byte
*info_ptr
;
20843 ULONGEST str_offset
;
20844 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20846 str_section
->read (objfile
);
20847 str_offsets_section
->read (objfile
);
20848 if (str_section
->buffer
== NULL
)
20849 error (_("%s used without %s section"
20850 " in CU at offset %s [in module %s]"),
20851 form_name
, str_section
->get_name (),
20852 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20853 if (str_offsets_section
->buffer
== NULL
)
20854 error (_("%s used without %s section"
20855 " in CU at offset %s [in module %s]"),
20856 form_name
, str_section
->get_name (),
20857 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20858 info_ptr
= (str_offsets_section
->buffer
20860 + str_index
* cu
->header
.offset_size
);
20861 if (cu
->header
.offset_size
== 4)
20862 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20864 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20865 if (str_offset
>= str_section
->size
)
20866 error (_("Offset from %s pointing outside of"
20867 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20868 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20869 return (const char *) (str_section
->buffer
+ str_offset
);
20872 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20874 static const char *
20875 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20877 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20878 ? reader
->cu
->header
.addr_size
: 0;
20879 return read_str_index (reader
->cu
,
20880 &reader
->dwo_file
->sections
.str
,
20881 &reader
->dwo_file
->sections
.str_offsets
,
20882 str_offsets_base
, str_index
);
20885 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20887 static const char *
20888 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20890 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20891 const char *objf_name
= objfile_name (objfile
);
20892 static const char form_name
[] = "DW_FORM_GNU_str_index";
20893 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20895 if (!cu
->str_offsets_base
.has_value ())
20896 error (_("%s used in Fission stub without %s"
20897 " in CU at offset 0x%lx [in module %s]"),
20898 form_name
, str_offsets_attr_name
,
20899 (long) cu
->header
.offset_size
, objf_name
);
20901 return read_str_index (cu
,
20902 &cu
->per_objfile
->per_bfd
->str
,
20903 &cu
->per_objfile
->per_bfd
->str_offsets
,
20904 *cu
->str_offsets_base
, str_index
);
20907 /* Return the length of an LEB128 number in BUF. */
20910 leb128_size (const gdb_byte
*buf
)
20912 const gdb_byte
*begin
= buf
;
20918 if ((byte
& 128) == 0)
20919 return buf
- begin
;
20924 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20933 cu
->language
= language_c
;
20936 case DW_LANG_C_plus_plus
:
20937 case DW_LANG_C_plus_plus_11
:
20938 case DW_LANG_C_plus_plus_14
:
20939 cu
->language
= language_cplus
;
20942 cu
->language
= language_d
;
20944 case DW_LANG_Fortran77
:
20945 case DW_LANG_Fortran90
:
20946 case DW_LANG_Fortran95
:
20947 case DW_LANG_Fortran03
:
20948 case DW_LANG_Fortran08
:
20949 cu
->language
= language_fortran
;
20952 cu
->language
= language_go
;
20954 case DW_LANG_Mips_Assembler
:
20955 cu
->language
= language_asm
;
20957 case DW_LANG_Ada83
:
20958 case DW_LANG_Ada95
:
20959 cu
->language
= language_ada
;
20961 case DW_LANG_Modula2
:
20962 cu
->language
= language_m2
;
20964 case DW_LANG_Pascal83
:
20965 cu
->language
= language_pascal
;
20968 cu
->language
= language_objc
;
20971 case DW_LANG_Rust_old
:
20972 cu
->language
= language_rust
;
20974 case DW_LANG_Cobol74
:
20975 case DW_LANG_Cobol85
:
20977 cu
->language
= language_minimal
;
20980 cu
->language_defn
= language_def (cu
->language
);
20983 /* Return the named attribute or NULL if not there. */
20985 static struct attribute
*
20986 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20991 struct attribute
*spec
= NULL
;
20993 for (i
= 0; i
< die
->num_attrs
; ++i
)
20995 if (die
->attrs
[i
].name
== name
)
20996 return &die
->attrs
[i
];
20997 if (die
->attrs
[i
].name
== DW_AT_specification
20998 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20999 spec
= &die
->attrs
[i
];
21005 die
= follow_die_ref (die
, spec
, &cu
);
21011 /* Return the string associated with a string-typed attribute, or NULL if it
21012 is either not found or is of an incorrect type. */
21014 static const char *
21015 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
21017 struct attribute
*attr
;
21018 const char *str
= NULL
;
21020 attr
= dwarf2_attr (die
, name
, cu
);
21024 str
= attr
->as_string ();
21025 if (str
== nullptr)
21026 complaint (_("string type expected for attribute %s for "
21027 "DIE at %s in module %s"),
21028 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
21029 objfile_name (cu
->per_objfile
->objfile
));
21035 /* Return the dwo name or NULL if not present. If present, it is in either
21036 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
21037 static const char *
21038 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21040 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
21041 if (dwo_name
== nullptr)
21042 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
21046 /* Return non-zero iff the attribute NAME is defined for the given DIE,
21047 and holds a non-zero value. This function should only be used for
21048 DW_FORM_flag or DW_FORM_flag_present attributes. */
21051 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
21053 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
21055 return attr
!= nullptr && attr
->as_boolean ();
21059 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
21061 /* A DIE is a declaration if it has a DW_AT_declaration attribute
21062 which value is non-zero. However, we have to be careful with
21063 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
21064 (via dwarf2_flag_true_p) follows this attribute. So we may
21065 end up accidently finding a declaration attribute that belongs
21066 to a different DIE referenced by the specification attribute,
21067 even though the given DIE does not have a declaration attribute. */
21068 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
21069 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
21072 /* Return the die giving the specification for DIE, if there is
21073 one. *SPEC_CU is the CU containing DIE on input, and the CU
21074 containing the return value on output. If there is no
21075 specification, but there is an abstract origin, that is
21078 static struct die_info
*
21079 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
21081 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
21084 if (spec_attr
== NULL
)
21085 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
21087 if (spec_attr
== NULL
)
21090 return follow_die_ref (die
, spec_attr
, spec_cu
);
21093 /* Stub for free_line_header to match void * callback types. */
21096 free_line_header_voidp (void *arg
)
21098 struct line_header
*lh
= (struct line_header
*) arg
;
21103 /* A convenience function to find the proper .debug_line section for a CU. */
21105 static struct dwarf2_section_info
*
21106 get_debug_line_section (struct dwarf2_cu
*cu
)
21108 struct dwarf2_section_info
*section
;
21109 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21111 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
21113 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
21114 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
21115 else if (cu
->per_cu
->is_dwz
)
21117 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
21119 section
= &dwz
->line
;
21122 section
= &per_objfile
->per_bfd
->line
;
21127 /* Read the statement program header starting at OFFSET in
21128 .debug_line, or .debug_line.dwo. Return a pointer
21129 to a struct line_header, allocated using xmalloc.
21130 Returns NULL if there is a problem reading the header, e.g., if it
21131 has a version we don't understand.
21133 NOTE: the strings in the include directory and file name tables of
21134 the returned object point into the dwarf line section buffer,
21135 and must not be freed. */
21137 static line_header_up
21138 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
21140 struct dwarf2_section_info
*section
;
21141 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21143 section
= get_debug_line_section (cu
);
21144 section
->read (per_objfile
->objfile
);
21145 if (section
->buffer
== NULL
)
21147 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
21148 complaint (_("missing .debug_line.dwo section"));
21150 complaint (_("missing .debug_line section"));
21154 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
21155 per_objfile
, section
, &cu
->header
);
21158 /* Subroutine of dwarf_decode_lines to simplify it.
21159 Return the file name of the psymtab for the given file_entry.
21160 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21161 If space for the result is malloc'd, *NAME_HOLDER will be set.
21162 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
21164 static const char *
21165 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
21166 const dwarf2_psymtab
*pst
,
21167 const char *comp_dir
,
21168 gdb::unique_xmalloc_ptr
<char> *name_holder
)
21170 const char *include_name
= fe
.name
;
21171 const char *include_name_to_compare
= include_name
;
21172 const char *pst_filename
;
21175 const char *dir_name
= fe
.include_dir (lh
);
21177 gdb::unique_xmalloc_ptr
<char> hold_compare
;
21178 if (!IS_ABSOLUTE_PATH (include_name
)
21179 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
21181 /* Avoid creating a duplicate psymtab for PST.
21182 We do this by comparing INCLUDE_NAME and PST_FILENAME.
21183 Before we do the comparison, however, we need to account
21184 for DIR_NAME and COMP_DIR.
21185 First prepend dir_name (if non-NULL). If we still don't
21186 have an absolute path prepend comp_dir (if non-NULL).
21187 However, the directory we record in the include-file's
21188 psymtab does not contain COMP_DIR (to match the
21189 corresponding symtab(s)).
21194 bash$ gcc -g ./hello.c
21195 include_name = "hello.c"
21197 DW_AT_comp_dir = comp_dir = "/tmp"
21198 DW_AT_name = "./hello.c"
21202 if (dir_name
!= NULL
)
21204 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
21205 include_name
, (char *) NULL
));
21206 include_name
= name_holder
->get ();
21207 include_name_to_compare
= include_name
;
21209 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
21211 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
21212 include_name
, (char *) NULL
));
21213 include_name_to_compare
= hold_compare
.get ();
21217 pst_filename
= pst
->filename
;
21218 gdb::unique_xmalloc_ptr
<char> copied_name
;
21219 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
21221 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
21222 pst_filename
, (char *) NULL
));
21223 pst_filename
= copied_name
.get ();
21226 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
21230 return include_name
;
21233 /* State machine to track the state of the line number program. */
21235 class lnp_state_machine
21238 /* Initialize a machine state for the start of a line number
21240 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
21241 bool record_lines_p
);
21243 file_entry
*current_file ()
21245 /* lh->file_names is 0-based, but the file name numbers in the
21246 statement program are 1-based. */
21247 return m_line_header
->file_name_at (m_file
);
21250 /* Record the line in the state machine. END_SEQUENCE is true if
21251 we're processing the end of a sequence. */
21252 void record_line (bool end_sequence
);
21254 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
21255 nop-out rest of the lines in this sequence. */
21256 void check_line_address (struct dwarf2_cu
*cu
,
21257 const gdb_byte
*line_ptr
,
21258 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
21260 void handle_set_discriminator (unsigned int discriminator
)
21262 m_discriminator
= discriminator
;
21263 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21266 /* Handle DW_LNE_set_address. */
21267 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21270 address
+= baseaddr
;
21271 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21274 /* Handle DW_LNS_advance_pc. */
21275 void handle_advance_pc (CORE_ADDR adjust
);
21277 /* Handle a special opcode. */
21278 void handle_special_opcode (unsigned char op_code
);
21280 /* Handle DW_LNS_advance_line. */
21281 void handle_advance_line (int line_delta
)
21283 advance_line (line_delta
);
21286 /* Handle DW_LNS_set_file. */
21287 void handle_set_file (file_name_index file
);
21289 /* Handle DW_LNS_negate_stmt. */
21290 void handle_negate_stmt ()
21292 m_is_stmt
= !m_is_stmt
;
21295 /* Handle DW_LNS_const_add_pc. */
21296 void handle_const_add_pc ();
21298 /* Handle DW_LNS_fixed_advance_pc. */
21299 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21301 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21305 /* Handle DW_LNS_copy. */
21306 void handle_copy ()
21308 record_line (false);
21309 m_discriminator
= 0;
21312 /* Handle DW_LNE_end_sequence. */
21313 void handle_end_sequence ()
21315 m_currently_recording_lines
= true;
21319 /* Advance the line by LINE_DELTA. */
21320 void advance_line (int line_delta
)
21322 m_line
+= line_delta
;
21324 if (line_delta
!= 0)
21325 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21328 struct dwarf2_cu
*m_cu
;
21330 gdbarch
*m_gdbarch
;
21332 /* True if we're recording lines.
21333 Otherwise we're building partial symtabs and are just interested in
21334 finding include files mentioned by the line number program. */
21335 bool m_record_lines_p
;
21337 /* The line number header. */
21338 line_header
*m_line_header
;
21340 /* These are part of the standard DWARF line number state machine,
21341 and initialized according to the DWARF spec. */
21343 unsigned char m_op_index
= 0;
21344 /* The line table index of the current file. */
21345 file_name_index m_file
= 1;
21346 unsigned int m_line
= 1;
21348 /* These are initialized in the constructor. */
21350 CORE_ADDR m_address
;
21352 unsigned int m_discriminator
;
21354 /* Additional bits of state we need to track. */
21356 /* The last file that we called dwarf2_start_subfile for.
21357 This is only used for TLLs. */
21358 unsigned int m_last_file
= 0;
21359 /* The last file a line number was recorded for. */
21360 struct subfile
*m_last_subfile
= NULL
;
21362 /* The address of the last line entry. */
21363 CORE_ADDR m_last_address
;
21365 /* Set to true when a previous line at the same address (using
21366 m_last_address) had m_is_stmt true. This is reset to false when a
21367 line entry at a new address (m_address different to m_last_address) is
21369 bool m_stmt_at_address
= false;
21371 /* When true, record the lines we decode. */
21372 bool m_currently_recording_lines
= false;
21374 /* The last line number that was recorded, used to coalesce
21375 consecutive entries for the same line. This can happen, for
21376 example, when discriminators are present. PR 17276. */
21377 unsigned int m_last_line
= 0;
21378 bool m_line_has_non_zero_discriminator
= false;
21382 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21384 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21385 / m_line_header
->maximum_ops_per_instruction
)
21386 * m_line_header
->minimum_instruction_length
);
21387 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21388 m_op_index
= ((m_op_index
+ adjust
)
21389 % m_line_header
->maximum_ops_per_instruction
);
21393 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21395 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21396 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
21397 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
21398 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
21399 / m_line_header
->maximum_ops_per_instruction
)
21400 * m_line_header
->minimum_instruction_length
);
21401 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21402 m_op_index
= ((m_op_index
+ adj_opcode_d
)
21403 % m_line_header
->maximum_ops_per_instruction
);
21405 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
21406 advance_line (line_delta
);
21407 record_line (false);
21408 m_discriminator
= 0;
21412 lnp_state_machine::handle_set_file (file_name_index file
)
21416 const file_entry
*fe
= current_file ();
21418 dwarf2_debug_line_missing_file_complaint ();
21419 else if (m_record_lines_p
)
21421 const char *dir
= fe
->include_dir (m_line_header
);
21423 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21424 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21425 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21430 lnp_state_machine::handle_const_add_pc ()
21433 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21436 = (((m_op_index
+ adjust
)
21437 / m_line_header
->maximum_ops_per_instruction
)
21438 * m_line_header
->minimum_instruction_length
);
21440 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21441 m_op_index
= ((m_op_index
+ adjust
)
21442 % m_line_header
->maximum_ops_per_instruction
);
21445 /* Return non-zero if we should add LINE to the line number table.
21446 LINE is the line to add, LAST_LINE is the last line that was added,
21447 LAST_SUBFILE is the subfile for LAST_LINE.
21448 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21449 had a non-zero discriminator.
21451 We have to be careful in the presence of discriminators.
21452 E.g., for this line:
21454 for (i = 0; i < 100000; i++);
21456 clang can emit four line number entries for that one line,
21457 each with a different discriminator.
21458 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21460 However, we want gdb to coalesce all four entries into one.
21461 Otherwise the user could stepi into the middle of the line and
21462 gdb would get confused about whether the pc really was in the
21463 middle of the line.
21465 Things are further complicated by the fact that two consecutive
21466 line number entries for the same line is a heuristic used by gcc
21467 to denote the end of the prologue. So we can't just discard duplicate
21468 entries, we have to be selective about it. The heuristic we use is
21469 that we only collapse consecutive entries for the same line if at least
21470 one of those entries has a non-zero discriminator. PR 17276.
21472 Note: Addresses in the line number state machine can never go backwards
21473 within one sequence, thus this coalescing is ok. */
21476 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21477 unsigned int line
, unsigned int last_line
,
21478 int line_has_non_zero_discriminator
,
21479 struct subfile
*last_subfile
)
21481 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21483 if (line
!= last_line
)
21485 /* Same line for the same file that we've seen already.
21486 As a last check, for pr 17276, only record the line if the line
21487 has never had a non-zero discriminator. */
21488 if (!line_has_non_zero_discriminator
)
21493 /* Use the CU's builder to record line number LINE beginning at
21494 address ADDRESS in the line table of subfile SUBFILE. */
21497 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21498 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
21499 struct dwarf2_cu
*cu
)
21501 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21503 if (dwarf_line_debug
)
21505 fprintf_unfiltered (gdb_stdlog
,
21506 "Recording line %u, file %s, address %s\n",
21507 line
, lbasename (subfile
->name
),
21508 paddress (gdbarch
, address
));
21512 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21515 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21516 Mark the end of a set of line number records.
21517 The arguments are the same as for dwarf_record_line_1.
21518 If SUBFILE is NULL the request is ignored. */
21521 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21522 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21524 if (subfile
== NULL
)
21527 if (dwarf_line_debug
)
21529 fprintf_unfiltered (gdb_stdlog
,
21530 "Finishing current line, file %s, address %s\n",
21531 lbasename (subfile
->name
),
21532 paddress (gdbarch
, address
));
21535 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21539 lnp_state_machine::record_line (bool end_sequence
)
21541 if (dwarf_line_debug
)
21543 fprintf_unfiltered (gdb_stdlog
,
21544 "Processing actual line %u: file %u,"
21545 " address %s, is_stmt %u, discrim %u%s\n",
21547 paddress (m_gdbarch
, m_address
),
21548 m_is_stmt
, m_discriminator
,
21549 (end_sequence
? "\t(end sequence)" : ""));
21552 file_entry
*fe
= current_file ();
21555 dwarf2_debug_line_missing_file_complaint ();
21556 /* For now we ignore lines not starting on an instruction boundary.
21557 But not when processing end_sequence for compatibility with the
21558 previous version of the code. */
21559 else if (m_op_index
== 0 || end_sequence
)
21561 fe
->included_p
= 1;
21562 if (m_record_lines_p
)
21564 /* When we switch files we insert an end maker in the first file,
21565 switch to the second file and add a new line entry. The
21566 problem is that the end marker inserted in the first file will
21567 discard any previous line entries at the same address. If the
21568 line entries in the first file are marked as is-stmt, while
21569 the new line in the second file is non-stmt, then this means
21570 the end marker will discard is-stmt lines so we can have a
21571 non-stmt line. This means that there are less addresses at
21572 which the user can insert a breakpoint.
21574 To improve this we track the last address in m_last_address,
21575 and whether we have seen an is-stmt at this address. Then
21576 when switching files, if we have seen a stmt at the current
21577 address, and we are switching to create a non-stmt line, then
21578 discard the new line. */
21580 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21581 bool ignore_this_line
21582 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21583 && !m_is_stmt
&& m_stmt_at_address
)
21584 || (!end_sequence
&& m_line
== 0));
21586 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21588 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21589 m_currently_recording_lines
? m_cu
: nullptr);
21592 if (!end_sequence
&& !ignore_this_line
)
21594 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21596 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21597 m_line_has_non_zero_discriminator
,
21600 buildsym_compunit
*builder
= m_cu
->get_builder ();
21601 dwarf_record_line_1 (m_gdbarch
,
21602 builder
->get_current_subfile (),
21603 m_line
, m_address
, is_stmt
,
21604 m_currently_recording_lines
? m_cu
: nullptr);
21606 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21607 m_last_line
= m_line
;
21612 /* Track whether we have seen any m_is_stmt true at m_address in case we
21613 have multiple line table entries all at m_address. */
21614 if (m_last_address
!= m_address
)
21616 m_stmt_at_address
= false;
21617 m_last_address
= m_address
;
21619 m_stmt_at_address
|= m_is_stmt
;
21622 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21623 line_header
*lh
, bool record_lines_p
)
21627 m_record_lines_p
= record_lines_p
;
21628 m_line_header
= lh
;
21630 m_currently_recording_lines
= true;
21632 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21633 was a line entry for it so that the backend has a chance to adjust it
21634 and also record it in case it needs it. This is currently used by MIPS
21635 code, cf. `mips_adjust_dwarf2_line'. */
21636 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21637 m_is_stmt
= lh
->default_is_stmt
;
21638 m_discriminator
= 0;
21640 m_last_address
= m_address
;
21641 m_stmt_at_address
= false;
21645 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21646 const gdb_byte
*line_ptr
,
21647 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21649 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21650 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21651 located at 0x0. In this case, additionally check that if
21652 ADDRESS < UNRELOCATED_LOWPC. */
21654 if ((address
== 0 && address
< unrelocated_lowpc
)
21655 || address
== (CORE_ADDR
) -1)
21657 /* This line table is for a function which has been
21658 GCd by the linker. Ignore it. PR gdb/12528 */
21660 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21661 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21663 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21664 line_offset
, objfile_name (objfile
));
21665 m_currently_recording_lines
= false;
21666 /* Note: m_currently_recording_lines is left as false until we see
21667 DW_LNE_end_sequence. */
21671 /* Subroutine of dwarf_decode_lines to simplify it.
21672 Process the line number information in LH.
21673 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21674 program in order to set included_p for every referenced header. */
21677 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21678 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21680 const gdb_byte
*line_ptr
, *extended_end
;
21681 const gdb_byte
*line_end
;
21682 unsigned int bytes_read
, extended_len
;
21683 unsigned char op_code
, extended_op
;
21684 CORE_ADDR baseaddr
;
21685 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21686 bfd
*abfd
= objfile
->obfd
;
21687 struct gdbarch
*gdbarch
= objfile
->arch ();
21688 /* True if we're recording line info (as opposed to building partial
21689 symtabs and just interested in finding include files mentioned by
21690 the line number program). */
21691 bool record_lines_p
= !decode_for_pst_p
;
21693 baseaddr
= objfile
->text_section_offset ();
21695 line_ptr
= lh
->statement_program_start
;
21696 line_end
= lh
->statement_program_end
;
21698 /* Read the statement sequences until there's nothing left. */
21699 while (line_ptr
< line_end
)
21701 /* The DWARF line number program state machine. Reset the state
21702 machine at the start of each sequence. */
21703 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21704 bool end_sequence
= false;
21706 if (record_lines_p
)
21708 /* Start a subfile for the current file of the state
21710 const file_entry
*fe
= state_machine
.current_file ();
21713 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21716 /* Decode the table. */
21717 while (line_ptr
< line_end
&& !end_sequence
)
21719 op_code
= read_1_byte (abfd
, line_ptr
);
21722 if (op_code
>= lh
->opcode_base
)
21724 /* Special opcode. */
21725 state_machine
.handle_special_opcode (op_code
);
21727 else switch (op_code
)
21729 case DW_LNS_extended_op
:
21730 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21732 line_ptr
+= bytes_read
;
21733 extended_end
= line_ptr
+ extended_len
;
21734 extended_op
= read_1_byte (abfd
, line_ptr
);
21736 if (DW_LNE_lo_user
<= extended_op
21737 && extended_op
<= DW_LNE_hi_user
)
21739 /* Vendor extension, ignore. */
21740 line_ptr
= extended_end
;
21743 switch (extended_op
)
21745 case DW_LNE_end_sequence
:
21746 state_machine
.handle_end_sequence ();
21747 end_sequence
= true;
21749 case DW_LNE_set_address
:
21752 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21753 line_ptr
+= bytes_read
;
21755 state_machine
.check_line_address (cu
, line_ptr
,
21756 lowpc
- baseaddr
, address
);
21757 state_machine
.handle_set_address (baseaddr
, address
);
21760 case DW_LNE_define_file
:
21762 const char *cur_file
;
21763 unsigned int mod_time
, length
;
21766 cur_file
= read_direct_string (abfd
, line_ptr
,
21768 line_ptr
+= bytes_read
;
21769 dindex
= (dir_index
)
21770 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21771 line_ptr
+= bytes_read
;
21773 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21774 line_ptr
+= bytes_read
;
21776 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21777 line_ptr
+= bytes_read
;
21778 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21781 case DW_LNE_set_discriminator
:
21783 /* The discriminator is not interesting to the
21784 debugger; just ignore it. We still need to
21785 check its value though:
21786 if there are consecutive entries for the same
21787 (non-prologue) line we want to coalesce them.
21790 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21791 line_ptr
+= bytes_read
;
21793 state_machine
.handle_set_discriminator (discr
);
21797 complaint (_("mangled .debug_line section"));
21800 /* Make sure that we parsed the extended op correctly. If e.g.
21801 we expected a different address size than the producer used,
21802 we may have read the wrong number of bytes. */
21803 if (line_ptr
!= extended_end
)
21805 complaint (_("mangled .debug_line section"));
21810 state_machine
.handle_copy ();
21812 case DW_LNS_advance_pc
:
21815 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21816 line_ptr
+= bytes_read
;
21818 state_machine
.handle_advance_pc (adjust
);
21821 case DW_LNS_advance_line
:
21824 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21825 line_ptr
+= bytes_read
;
21827 state_machine
.handle_advance_line (line_delta
);
21830 case DW_LNS_set_file
:
21832 file_name_index file
21833 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21835 line_ptr
+= bytes_read
;
21837 state_machine
.handle_set_file (file
);
21840 case DW_LNS_set_column
:
21841 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21842 line_ptr
+= bytes_read
;
21844 case DW_LNS_negate_stmt
:
21845 state_machine
.handle_negate_stmt ();
21847 case DW_LNS_set_basic_block
:
21849 /* Add to the address register of the state machine the
21850 address increment value corresponding to special opcode
21851 255. I.e., this value is scaled by the minimum
21852 instruction length since special opcode 255 would have
21853 scaled the increment. */
21854 case DW_LNS_const_add_pc
:
21855 state_machine
.handle_const_add_pc ();
21857 case DW_LNS_fixed_advance_pc
:
21859 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21862 state_machine
.handle_fixed_advance_pc (addr_adj
);
21867 /* Unknown standard opcode, ignore it. */
21870 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21872 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21873 line_ptr
+= bytes_read
;
21880 dwarf2_debug_line_missing_end_sequence_complaint ();
21882 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21883 in which case we still finish recording the last line). */
21884 state_machine
.record_line (true);
21888 /* Decode the Line Number Program (LNP) for the given line_header
21889 structure and CU. The actual information extracted and the type
21890 of structures created from the LNP depends on the value of PST.
21892 1. If PST is NULL, then this procedure uses the data from the program
21893 to create all necessary symbol tables, and their linetables.
21895 2. If PST is not NULL, this procedure reads the program to determine
21896 the list of files included by the unit represented by PST, and
21897 builds all the associated partial symbol tables.
21899 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21900 It is used for relative paths in the line table.
21901 NOTE: When processing partial symtabs (pst != NULL),
21902 comp_dir == pst->dirname.
21904 NOTE: It is important that psymtabs have the same file name (via strcmp)
21905 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21906 symtab we don't use it in the name of the psymtabs we create.
21907 E.g. expand_line_sal requires this when finding psymtabs to expand.
21908 A good testcase for this is mb-inline.exp.
21910 LOWPC is the lowest address in CU (or 0 if not known).
21912 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21913 for its PC<->lines mapping information. Otherwise only the filename
21914 table is read in. */
21917 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21918 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21919 CORE_ADDR lowpc
, int decode_mapping
)
21921 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21922 const int decode_for_pst_p
= (pst
!= NULL
);
21924 if (decode_mapping
)
21925 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21927 if (decode_for_pst_p
)
21929 /* Now that we're done scanning the Line Header Program, we can
21930 create the psymtab of each included file. */
21931 for (auto &file_entry
: lh
->file_names ())
21932 if (file_entry
.included_p
== 1)
21934 gdb::unique_xmalloc_ptr
<char> name_holder
;
21935 const char *include_name
=
21936 psymtab_include_file_name (lh
, file_entry
, pst
,
21937 comp_dir
, &name_holder
);
21938 if (include_name
!= NULL
)
21939 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21944 /* Make sure a symtab is created for every file, even files
21945 which contain only variables (i.e. no code with associated
21947 buildsym_compunit
*builder
= cu
->get_builder ();
21948 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21950 for (auto &fe
: lh
->file_names ())
21952 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21953 if (builder
->get_current_subfile ()->symtab
== NULL
)
21955 builder
->get_current_subfile ()->symtab
21956 = allocate_symtab (cust
,
21957 builder
->get_current_subfile ()->name
);
21959 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21964 /* Start a subfile for DWARF. FILENAME is the name of the file and
21965 DIRNAME the name of the source directory which contains FILENAME
21966 or NULL if not known.
21967 This routine tries to keep line numbers from identical absolute and
21968 relative file names in a common subfile.
21970 Using the `list' example from the GDB testsuite, which resides in
21971 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21972 of /srcdir/list0.c yields the following debugging information for list0.c:
21974 DW_AT_name: /srcdir/list0.c
21975 DW_AT_comp_dir: /compdir
21976 files.files[0].name: list0.h
21977 files.files[0].dir: /srcdir
21978 files.files[1].name: list0.c
21979 files.files[1].dir: /srcdir
21981 The line number information for list0.c has to end up in a single
21982 subfile, so that `break /srcdir/list0.c:1' works as expected.
21983 start_subfile will ensure that this happens provided that we pass the
21984 concatenation of files.files[1].dir and files.files[1].name as the
21988 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21989 const char *dirname
)
21991 gdb::unique_xmalloc_ptr
<char> copy
;
21993 /* In order not to lose the line information directory,
21994 we concatenate it to the filename when it makes sense.
21995 Note that the Dwarf3 standard says (speaking of filenames in line
21996 information): ``The directory index is ignored for file names
21997 that represent full path names''. Thus ignoring dirname in the
21998 `else' branch below isn't an issue. */
22000 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
22002 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
22003 filename
= copy
.get ();
22006 cu
->get_builder ()->start_subfile (filename
);
22009 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
22010 buildsym_compunit constructor. */
22012 struct compunit_symtab
*
22013 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
22016 gdb_assert (m_builder
== nullptr);
22018 m_builder
.reset (new struct buildsym_compunit
22019 (this->per_objfile
->objfile
,
22020 name
, comp_dir
, language
, low_pc
));
22022 list_in_scope
= get_builder ()->get_file_symbols ();
22024 get_builder ()->record_debugformat ("DWARF 2");
22025 get_builder ()->record_producer (producer
);
22027 processing_has_namespace_info
= false;
22029 return get_builder ()->get_compunit_symtab ();
22033 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
22034 struct dwarf2_cu
*cu
)
22036 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22037 struct comp_unit_head
*cu_header
= &cu
->header
;
22039 /* NOTE drow/2003-01-30: There used to be a comment and some special
22040 code here to turn a symbol with DW_AT_external and a
22041 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
22042 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
22043 with some versions of binutils) where shared libraries could have
22044 relocations against symbols in their debug information - the
22045 minimal symbol would have the right address, but the debug info
22046 would not. It's no longer necessary, because we will explicitly
22047 apply relocations when we read in the debug information now. */
22049 /* A DW_AT_location attribute with no contents indicates that a
22050 variable has been optimized away. */
22051 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
22053 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22057 /* Handle one degenerate form of location expression specially, to
22058 preserve GDB's previous behavior when section offsets are
22059 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
22060 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
22062 if (attr
->form_is_block ())
22064 struct dwarf_block
*block
= attr
->as_block ();
22066 if ((block
->data
[0] == DW_OP_addr
22067 && block
->size
== 1 + cu_header
->addr_size
)
22068 || ((block
->data
[0] == DW_OP_GNU_addr_index
22069 || block
->data
[0] == DW_OP_addrx
)
22071 == 1 + leb128_size (&block
->data
[1]))))
22073 unsigned int dummy
;
22075 if (block
->data
[0] == DW_OP_addr
)
22076 SET_SYMBOL_VALUE_ADDRESS
22077 (sym
, cu
->header
.read_address (objfile
->obfd
,
22081 SET_SYMBOL_VALUE_ADDRESS
22082 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
22084 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
22085 fixup_symbol_section (sym
, objfile
);
22086 SET_SYMBOL_VALUE_ADDRESS
22088 SYMBOL_VALUE_ADDRESS (sym
)
22089 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
22094 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
22095 expression evaluator, and use LOC_COMPUTED only when necessary
22096 (i.e. when the value of a register or memory location is
22097 referenced, or a thread-local block, etc.). Then again, it might
22098 not be worthwhile. I'm assuming that it isn't unless performance
22099 or memory numbers show me otherwise. */
22101 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
22103 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
22104 cu
->has_loclist
= true;
22107 /* Given a pointer to a DWARF information entry, figure out if we need
22108 to make a symbol table entry for it, and if so, create a new entry
22109 and return a pointer to it.
22110 If TYPE is NULL, determine symbol type from the die, otherwise
22111 used the passed type.
22112 If SPACE is not NULL, use it to hold the new symbol. If it is
22113 NULL, allocate a new symbol on the objfile's obstack. */
22115 static struct symbol
*
22116 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
22117 struct symbol
*space
)
22119 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22120 struct objfile
*objfile
= per_objfile
->objfile
;
22121 struct gdbarch
*gdbarch
= objfile
->arch ();
22122 struct symbol
*sym
= NULL
;
22124 struct attribute
*attr
= NULL
;
22125 struct attribute
*attr2
= NULL
;
22126 CORE_ADDR baseaddr
;
22127 struct pending
**list_to_add
= NULL
;
22129 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
22131 baseaddr
= objfile
->text_section_offset ();
22133 name
= dwarf2_name (die
, cu
);
22136 int suppress_add
= 0;
22141 sym
= new (&objfile
->objfile_obstack
) symbol
;
22142 OBJSTAT (objfile
, n_syms
++);
22144 /* Cache this symbol's name and the name's demangled form (if any). */
22145 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
22146 /* Fortran does not have mangling standard and the mangling does differ
22147 between gfortran, iFort etc. */
22148 const char *physname
22149 = (cu
->language
== language_fortran
22150 ? dwarf2_full_name (name
, die
, cu
)
22151 : dwarf2_physname (name
, die
, cu
));
22152 const char *linkagename
= dw2_linkage_name (die
, cu
);
22154 if (linkagename
== nullptr || cu
->language
== language_ada
)
22155 sym
->set_linkage_name (physname
);
22158 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
22159 sym
->set_linkage_name (linkagename
);
22162 /* Default assumptions.
22163 Use the passed type or decode it from the die. */
22164 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22165 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22167 SYMBOL_TYPE (sym
) = type
;
22169 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
22170 attr
= dwarf2_attr (die
,
22171 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
22173 if (attr
!= nullptr)
22174 SYMBOL_LINE (sym
) = attr
->constant_value (0);
22176 attr
= dwarf2_attr (die
,
22177 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
22179 if (attr
!= nullptr && attr
->form_is_unsigned ())
22181 file_name_index file_index
22182 = (file_name_index
) attr
->as_unsigned ();
22183 struct file_entry
*fe
;
22185 if (cu
->line_header
!= NULL
)
22186 fe
= cu
->line_header
->file_name_at (file_index
);
22191 complaint (_("file index out of range"));
22193 symbol_set_symtab (sym
, fe
->symtab
);
22199 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
22200 if (attr
!= nullptr)
22204 addr
= attr
->as_address ();
22205 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
22206 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
22207 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
22210 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22211 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
22212 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
22213 add_symbol_to_list (sym
, cu
->list_in_scope
);
22215 case DW_TAG_subprogram
:
22216 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22218 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22219 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22220 if ((attr2
!= nullptr && attr2
->as_boolean ())
22221 || cu
->language
== language_ada
22222 || cu
->language
== language_fortran
)
22224 /* Subprograms marked external are stored as a global symbol.
22225 Ada and Fortran subprograms, whether marked external or
22226 not, are always stored as a global symbol, because we want
22227 to be able to access them globally. For instance, we want
22228 to be able to break on a nested subprogram without having
22229 to specify the context. */
22230 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22234 list_to_add
= cu
->list_in_scope
;
22237 case DW_TAG_inlined_subroutine
:
22238 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22240 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22241 SYMBOL_INLINED (sym
) = 1;
22242 list_to_add
= cu
->list_in_scope
;
22244 case DW_TAG_template_value_param
:
22246 /* Fall through. */
22247 case DW_TAG_constant
:
22248 case DW_TAG_variable
:
22249 case DW_TAG_member
:
22250 /* Compilation with minimal debug info may result in
22251 variables with missing type entries. Change the
22252 misleading `void' type to something sensible. */
22253 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
22254 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
22256 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22257 /* In the case of DW_TAG_member, we should only be called for
22258 static const members. */
22259 if (die
->tag
== DW_TAG_member
)
22261 /* dwarf2_add_field uses die_is_declaration,
22262 so we do the same. */
22263 gdb_assert (die_is_declaration (die
, cu
));
22266 if (attr
!= nullptr)
22268 dwarf2_const_value (attr
, sym
, cu
);
22269 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22272 if (attr2
!= nullptr && attr2
->as_boolean ())
22273 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22275 list_to_add
= cu
->list_in_scope
;
22279 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22280 if (attr
!= nullptr)
22282 var_decode_location (attr
, sym
, cu
);
22283 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22285 /* Fortran explicitly imports any global symbols to the local
22286 scope by DW_TAG_common_block. */
22287 if (cu
->language
== language_fortran
&& die
->parent
22288 && die
->parent
->tag
== DW_TAG_common_block
)
22291 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22292 && SYMBOL_VALUE_ADDRESS (sym
) == 0
22293 && !per_objfile
->per_bfd
->has_section_at_zero
)
22295 /* When a static variable is eliminated by the linker,
22296 the corresponding debug information is not stripped
22297 out, but the variable address is set to null;
22298 do not add such variables into symbol table. */
22300 else if (attr2
!= nullptr && attr2
->as_boolean ())
22302 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22303 && (objfile
->flags
& OBJF_MAINLINE
) == 0
22304 && per_objfile
->per_bfd
->can_copy
)
22306 /* A global static variable might be subject to
22307 copy relocation. We first check for a local
22308 minsym, though, because maybe the symbol was
22309 marked hidden, in which case this would not
22311 bound_minimal_symbol found
22312 = (lookup_minimal_symbol_linkage
22313 (sym
->linkage_name (), objfile
));
22314 if (found
.minsym
!= nullptr)
22315 sym
->maybe_copied
= 1;
22318 /* A variable with DW_AT_external is never static,
22319 but it may be block-scoped. */
22321 = ((cu
->list_in_scope
22322 == cu
->get_builder ()->get_file_symbols ())
22323 ? cu
->get_builder ()->get_global_symbols ()
22324 : cu
->list_in_scope
);
22327 list_to_add
= cu
->list_in_scope
;
22331 /* We do not know the address of this symbol.
22332 If it is an external symbol and we have type information
22333 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22334 The address of the variable will then be determined from
22335 the minimal symbol table whenever the variable is
22337 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22339 /* Fortran explicitly imports any global symbols to the local
22340 scope by DW_TAG_common_block. */
22341 if (cu
->language
== language_fortran
&& die
->parent
22342 && die
->parent
->tag
== DW_TAG_common_block
)
22344 /* SYMBOL_CLASS doesn't matter here because
22345 read_common_block is going to reset it. */
22347 list_to_add
= cu
->list_in_scope
;
22349 else if (attr2
!= nullptr && attr2
->as_boolean ()
22350 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22352 /* A variable with DW_AT_external is never static, but it
22353 may be block-scoped. */
22355 = ((cu
->list_in_scope
22356 == cu
->get_builder ()->get_file_symbols ())
22357 ? cu
->get_builder ()->get_global_symbols ()
22358 : cu
->list_in_scope
);
22360 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22362 else if (!die_is_declaration (die
, cu
))
22364 /* Use the default LOC_OPTIMIZED_OUT class. */
22365 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22367 list_to_add
= cu
->list_in_scope
;
22371 case DW_TAG_formal_parameter
:
22373 /* If we are inside a function, mark this as an argument. If
22374 not, we might be looking at an argument to an inlined function
22375 when we do not have enough information to show inlined frames;
22376 pretend it's a local variable in that case so that the user can
22378 struct context_stack
*curr
22379 = cu
->get_builder ()->get_current_context_stack ();
22380 if (curr
!= nullptr && curr
->name
!= nullptr)
22381 SYMBOL_IS_ARGUMENT (sym
) = 1;
22382 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22383 if (attr
!= nullptr)
22385 var_decode_location (attr
, sym
, cu
);
22387 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22388 if (attr
!= nullptr)
22390 dwarf2_const_value (attr
, sym
, cu
);
22393 list_to_add
= cu
->list_in_scope
;
22396 case DW_TAG_unspecified_parameters
:
22397 /* From varargs functions; gdb doesn't seem to have any
22398 interest in this information, so just ignore it for now.
22401 case DW_TAG_template_type_param
:
22403 /* Fall through. */
22404 case DW_TAG_class_type
:
22405 case DW_TAG_interface_type
:
22406 case DW_TAG_structure_type
:
22407 case DW_TAG_union_type
:
22408 case DW_TAG_set_type
:
22409 case DW_TAG_enumeration_type
:
22410 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22411 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22414 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22415 really ever be static objects: otherwise, if you try
22416 to, say, break of a class's method and you're in a file
22417 which doesn't mention that class, it won't work unless
22418 the check for all static symbols in lookup_symbol_aux
22419 saves you. See the OtherFileClass tests in
22420 gdb.c++/namespace.exp. */
22424 buildsym_compunit
*builder
= cu
->get_builder ();
22426 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22427 && cu
->language
== language_cplus
22428 ? builder
->get_global_symbols ()
22429 : cu
->list_in_scope
);
22431 /* The semantics of C++ state that "struct foo {
22432 ... }" also defines a typedef for "foo". */
22433 if (cu
->language
== language_cplus
22434 || cu
->language
== language_ada
22435 || cu
->language
== language_d
22436 || cu
->language
== language_rust
)
22438 /* The symbol's name is already allocated along
22439 with this objfile, so we don't need to
22440 duplicate it for the type. */
22441 if (SYMBOL_TYPE (sym
)->name () == 0)
22442 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
22447 case DW_TAG_typedef
:
22448 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22449 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22450 list_to_add
= cu
->list_in_scope
;
22452 case DW_TAG_array_type
:
22453 case DW_TAG_base_type
:
22454 case DW_TAG_subrange_type
:
22455 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22456 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22457 list_to_add
= cu
->list_in_scope
;
22459 case DW_TAG_enumerator
:
22460 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22461 if (attr
!= nullptr)
22463 dwarf2_const_value (attr
, sym
, cu
);
22466 /* NOTE: carlton/2003-11-10: See comment above in the
22467 DW_TAG_class_type, etc. block. */
22470 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22471 && cu
->language
== language_cplus
22472 ? cu
->get_builder ()->get_global_symbols ()
22473 : cu
->list_in_scope
);
22476 case DW_TAG_imported_declaration
:
22477 case DW_TAG_namespace
:
22478 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22479 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22481 case DW_TAG_module
:
22482 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22483 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22484 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22486 case DW_TAG_common_block
:
22487 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22488 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22489 add_symbol_to_list (sym
, cu
->list_in_scope
);
22492 /* Not a tag we recognize. Hopefully we aren't processing
22493 trash data, but since we must specifically ignore things
22494 we don't recognize, there is nothing else we should do at
22496 complaint (_("unsupported tag: '%s'"),
22497 dwarf_tag_name (die
->tag
));
22503 sym
->hash_next
= objfile
->template_symbols
;
22504 objfile
->template_symbols
= sym
;
22505 list_to_add
= NULL
;
22508 if (list_to_add
!= NULL
)
22509 add_symbol_to_list (sym
, list_to_add
);
22511 /* For the benefit of old versions of GCC, check for anonymous
22512 namespaces based on the demangled name. */
22513 if (!cu
->processing_has_namespace_info
22514 && cu
->language
== language_cplus
)
22515 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22520 /* Given an attr with a DW_FORM_dataN value in host byte order,
22521 zero-extend it as appropriate for the symbol's type. The DWARF
22522 standard (v4) is not entirely clear about the meaning of using
22523 DW_FORM_dataN for a constant with a signed type, where the type is
22524 wider than the data. The conclusion of a discussion on the DWARF
22525 list was that this is unspecified. We choose to always zero-extend
22526 because that is the interpretation long in use by GCC. */
22529 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22530 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22532 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22533 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22534 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22535 LONGEST l
= attr
->constant_value (0);
22537 if (bits
< sizeof (*value
) * 8)
22539 l
&= ((LONGEST
) 1 << bits
) - 1;
22542 else if (bits
== sizeof (*value
) * 8)
22546 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22547 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22554 /* Read a constant value from an attribute. Either set *VALUE, or if
22555 the value does not fit in *VALUE, set *BYTES - either already
22556 allocated on the objfile obstack, or newly allocated on OBSTACK,
22557 or, set *BATON, if we translated the constant to a location
22561 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22562 const char *name
, struct obstack
*obstack
,
22563 struct dwarf2_cu
*cu
,
22564 LONGEST
*value
, const gdb_byte
**bytes
,
22565 struct dwarf2_locexpr_baton
**baton
)
22567 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22568 struct objfile
*objfile
= per_objfile
->objfile
;
22569 struct comp_unit_head
*cu_header
= &cu
->header
;
22570 struct dwarf_block
*blk
;
22571 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22572 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22578 switch (attr
->form
)
22581 case DW_FORM_addrx
:
22582 case DW_FORM_GNU_addr_index
:
22586 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22587 dwarf2_const_value_length_mismatch_complaint (name
,
22588 cu_header
->addr_size
,
22589 TYPE_LENGTH (type
));
22590 /* Symbols of this form are reasonably rare, so we just
22591 piggyback on the existing location code rather than writing
22592 a new implementation of symbol_computed_ops. */
22593 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22594 (*baton
)->per_objfile
= per_objfile
;
22595 (*baton
)->per_cu
= cu
->per_cu
;
22596 gdb_assert ((*baton
)->per_cu
);
22598 (*baton
)->size
= 2 + cu_header
->addr_size
;
22599 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22600 (*baton
)->data
= data
;
22602 data
[0] = DW_OP_addr
;
22603 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22604 byte_order
, attr
->as_address ());
22605 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22608 case DW_FORM_string
:
22611 case DW_FORM_GNU_str_index
:
22612 case DW_FORM_GNU_strp_alt
:
22613 /* The string is already allocated on the objfile obstack, point
22615 *bytes
= (const gdb_byte
*) attr
->as_string ();
22617 case DW_FORM_block1
:
22618 case DW_FORM_block2
:
22619 case DW_FORM_block4
:
22620 case DW_FORM_block
:
22621 case DW_FORM_exprloc
:
22622 case DW_FORM_data16
:
22623 blk
= attr
->as_block ();
22624 if (TYPE_LENGTH (type
) != blk
->size
)
22625 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22626 TYPE_LENGTH (type
));
22627 *bytes
= blk
->data
;
22630 /* The DW_AT_const_value attributes are supposed to carry the
22631 symbol's value "represented as it would be on the target
22632 architecture." By the time we get here, it's already been
22633 converted to host endianness, so we just need to sign- or
22634 zero-extend it as appropriate. */
22635 case DW_FORM_data1
:
22636 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22638 case DW_FORM_data2
:
22639 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22641 case DW_FORM_data4
:
22642 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22644 case DW_FORM_data8
:
22645 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22648 case DW_FORM_sdata
:
22649 case DW_FORM_implicit_const
:
22650 *value
= attr
->as_signed ();
22653 case DW_FORM_udata
:
22654 *value
= attr
->as_unsigned ();
22658 complaint (_("unsupported const value attribute form: '%s'"),
22659 dwarf_form_name (attr
->form
));
22666 /* Copy constant value from an attribute to a symbol. */
22669 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22670 struct dwarf2_cu
*cu
)
22672 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22674 const gdb_byte
*bytes
;
22675 struct dwarf2_locexpr_baton
*baton
;
22677 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22678 sym
->print_name (),
22679 &objfile
->objfile_obstack
, cu
,
22680 &value
, &bytes
, &baton
);
22684 SYMBOL_LOCATION_BATON (sym
) = baton
;
22685 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22687 else if (bytes
!= NULL
)
22689 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22690 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22694 SYMBOL_VALUE (sym
) = value
;
22695 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22699 /* Return the type of the die in question using its DW_AT_type attribute. */
22701 static struct type
*
22702 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22704 struct attribute
*type_attr
;
22706 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22709 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22710 /* A missing DW_AT_type represents a void type. */
22711 return objfile_type (objfile
)->builtin_void
;
22714 return lookup_die_type (die
, type_attr
, cu
);
22717 /* True iff CU's producer generates GNAT Ada auxiliary information
22718 that allows to find parallel types through that information instead
22719 of having to do expensive parallel lookups by type name. */
22722 need_gnat_info (struct dwarf2_cu
*cu
)
22724 /* Assume that the Ada compiler was GNAT, which always produces
22725 the auxiliary information. */
22726 return (cu
->language
== language_ada
);
22729 /* Return the auxiliary type of the die in question using its
22730 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22731 attribute is not present. */
22733 static struct type
*
22734 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22736 struct attribute
*type_attr
;
22738 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22742 return lookup_die_type (die
, type_attr
, cu
);
22745 /* If DIE has a descriptive_type attribute, then set the TYPE's
22746 descriptive type accordingly. */
22749 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22750 struct dwarf2_cu
*cu
)
22752 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22754 if (descriptive_type
)
22756 ALLOCATE_GNAT_AUX_TYPE (type
);
22757 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22761 /* Return the containing type of the die in question using its
22762 DW_AT_containing_type attribute. */
22764 static struct type
*
22765 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22767 struct attribute
*type_attr
;
22768 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22770 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22772 error (_("Dwarf Error: Problem turning containing type into gdb type "
22773 "[in module %s]"), objfile_name (objfile
));
22775 return lookup_die_type (die
, type_attr
, cu
);
22778 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22780 static struct type
*
22781 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22783 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22784 struct objfile
*objfile
= per_objfile
->objfile
;
22787 std::string message
22788 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22789 objfile_name (objfile
),
22790 sect_offset_str (cu
->header
.sect_off
),
22791 sect_offset_str (die
->sect_off
));
22792 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22794 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22797 /* Look up the type of DIE in CU using its type attribute ATTR.
22798 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22799 DW_AT_containing_type.
22800 If there is no type substitute an error marker. */
22802 static struct type
*
22803 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22804 struct dwarf2_cu
*cu
)
22806 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22807 struct objfile
*objfile
= per_objfile
->objfile
;
22808 struct type
*this_type
;
22810 gdb_assert (attr
->name
== DW_AT_type
22811 || attr
->name
== DW_AT_GNAT_descriptive_type
22812 || attr
->name
== DW_AT_containing_type
);
22814 /* First see if we have it cached. */
22816 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22818 struct dwarf2_per_cu_data
*per_cu
;
22819 sect_offset sect_off
= attr
->get_ref_die_offset ();
22821 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22822 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22824 else if (attr
->form_is_ref ())
22826 sect_offset sect_off
= attr
->get_ref_die_offset ();
22828 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22830 else if (attr
->form
== DW_FORM_ref_sig8
)
22832 ULONGEST signature
= attr
->as_signature ();
22834 return get_signatured_type (die
, signature
, cu
);
22838 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22839 " at %s [in module %s]"),
22840 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22841 objfile_name (objfile
));
22842 return build_error_marker_type (cu
, die
);
22845 /* If not cached we need to read it in. */
22847 if (this_type
== NULL
)
22849 struct die_info
*type_die
= NULL
;
22850 struct dwarf2_cu
*type_cu
= cu
;
22852 if (attr
->form_is_ref ())
22853 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22854 if (type_die
== NULL
)
22855 return build_error_marker_type (cu
, die
);
22856 /* If we find the type now, it's probably because the type came
22857 from an inter-CU reference and the type's CU got expanded before
22859 this_type
= read_type_die (type_die
, type_cu
);
22862 /* If we still don't have a type use an error marker. */
22864 if (this_type
== NULL
)
22865 return build_error_marker_type (cu
, die
);
22870 /* Return the type in DIE, CU.
22871 Returns NULL for invalid types.
22873 This first does a lookup in die_type_hash,
22874 and only reads the die in if necessary.
22876 NOTE: This can be called when reading in partial or full symbols. */
22878 static struct type
*
22879 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22881 struct type
*this_type
;
22883 this_type
= get_die_type (die
, cu
);
22887 return read_type_die_1 (die
, cu
);
22890 /* Read the type in DIE, CU.
22891 Returns NULL for invalid types. */
22893 static struct type
*
22894 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22896 struct type
*this_type
= NULL
;
22900 case DW_TAG_class_type
:
22901 case DW_TAG_interface_type
:
22902 case DW_TAG_structure_type
:
22903 case DW_TAG_union_type
:
22904 this_type
= read_structure_type (die
, cu
);
22906 case DW_TAG_enumeration_type
:
22907 this_type
= read_enumeration_type (die
, cu
);
22909 case DW_TAG_subprogram
:
22910 case DW_TAG_subroutine_type
:
22911 case DW_TAG_inlined_subroutine
:
22912 this_type
= read_subroutine_type (die
, cu
);
22914 case DW_TAG_array_type
:
22915 this_type
= read_array_type (die
, cu
);
22917 case DW_TAG_set_type
:
22918 this_type
= read_set_type (die
, cu
);
22920 case DW_TAG_pointer_type
:
22921 this_type
= read_tag_pointer_type (die
, cu
);
22923 case DW_TAG_ptr_to_member_type
:
22924 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22926 case DW_TAG_reference_type
:
22927 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22929 case DW_TAG_rvalue_reference_type
:
22930 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22932 case DW_TAG_const_type
:
22933 this_type
= read_tag_const_type (die
, cu
);
22935 case DW_TAG_volatile_type
:
22936 this_type
= read_tag_volatile_type (die
, cu
);
22938 case DW_TAG_restrict_type
:
22939 this_type
= read_tag_restrict_type (die
, cu
);
22941 case DW_TAG_string_type
:
22942 this_type
= read_tag_string_type (die
, cu
);
22944 case DW_TAG_typedef
:
22945 this_type
= read_typedef (die
, cu
);
22947 case DW_TAG_subrange_type
:
22948 this_type
= read_subrange_type (die
, cu
);
22950 case DW_TAG_base_type
:
22951 this_type
= read_base_type (die
, cu
);
22953 case DW_TAG_unspecified_type
:
22954 this_type
= read_unspecified_type (die
, cu
);
22956 case DW_TAG_namespace
:
22957 this_type
= read_namespace_type (die
, cu
);
22959 case DW_TAG_module
:
22960 this_type
= read_module_type (die
, cu
);
22962 case DW_TAG_atomic_type
:
22963 this_type
= read_tag_atomic_type (die
, cu
);
22966 complaint (_("unexpected tag in read_type_die: '%s'"),
22967 dwarf_tag_name (die
->tag
));
22974 /* See if we can figure out if the class lives in a namespace. We do
22975 this by looking for a member function; its demangled name will
22976 contain namespace info, if there is any.
22977 Return the computed name or NULL.
22978 Space for the result is allocated on the objfile's obstack.
22979 This is the full-die version of guess_partial_die_structure_name.
22980 In this case we know DIE has no useful parent. */
22982 static const char *
22983 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22985 struct die_info
*spec_die
;
22986 struct dwarf2_cu
*spec_cu
;
22987 struct die_info
*child
;
22988 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22991 spec_die
= die_specification (die
, &spec_cu
);
22992 if (spec_die
!= NULL
)
22998 for (child
= die
->child
;
23000 child
= child
->sibling
)
23002 if (child
->tag
== DW_TAG_subprogram
)
23004 const char *linkage_name
= dw2_linkage_name (child
, cu
);
23006 if (linkage_name
!= NULL
)
23008 gdb::unique_xmalloc_ptr
<char> actual_name
23009 (cu
->language_defn
->class_name_from_physname (linkage_name
));
23010 const char *name
= NULL
;
23012 if (actual_name
!= NULL
)
23014 const char *die_name
= dwarf2_name (die
, cu
);
23016 if (die_name
!= NULL
23017 && strcmp (die_name
, actual_name
.get ()) != 0)
23019 /* Strip off the class name from the full name.
23020 We want the prefix. */
23021 int die_name_len
= strlen (die_name
);
23022 int actual_name_len
= strlen (actual_name
.get ());
23023 const char *ptr
= actual_name
.get ();
23025 /* Test for '::' as a sanity check. */
23026 if (actual_name_len
> die_name_len
+ 2
23027 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
23028 name
= obstack_strndup (
23029 &objfile
->per_bfd
->storage_obstack
,
23030 ptr
, actual_name_len
- die_name_len
- 2);
23041 /* GCC might emit a nameless typedef that has a linkage name. Determine the
23042 prefix part in such case. See
23043 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23045 static const char *
23046 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
23048 struct attribute
*attr
;
23051 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
23052 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
23055 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
23058 attr
= dw2_linkage_name_attr (die
, cu
);
23059 const char *attr_name
= attr
->as_string ();
23060 if (attr
== NULL
|| attr_name
== NULL
)
23063 /* dwarf2_name had to be already called. */
23064 gdb_assert (attr
->canonical_string_p ());
23066 /* Strip the base name, keep any leading namespaces/classes. */
23067 base
= strrchr (attr_name
, ':');
23068 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
23071 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23072 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
23074 &base
[-1] - attr_name
);
23077 /* Return the name of the namespace/class that DIE is defined within,
23078 or "" if we can't tell. The caller should not xfree the result.
23080 For example, if we're within the method foo() in the following
23090 then determine_prefix on foo's die will return "N::C". */
23092 static const char *
23093 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
23095 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23096 struct die_info
*parent
, *spec_die
;
23097 struct dwarf2_cu
*spec_cu
;
23098 struct type
*parent_type
;
23099 const char *retval
;
23101 if (cu
->language
!= language_cplus
23102 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
23103 && cu
->language
!= language_rust
)
23106 retval
= anonymous_struct_prefix (die
, cu
);
23110 /* We have to be careful in the presence of DW_AT_specification.
23111 For example, with GCC 3.4, given the code
23115 // Definition of N::foo.
23119 then we'll have a tree of DIEs like this:
23121 1: DW_TAG_compile_unit
23122 2: DW_TAG_namespace // N
23123 3: DW_TAG_subprogram // declaration of N::foo
23124 4: DW_TAG_subprogram // definition of N::foo
23125 DW_AT_specification // refers to die #3
23127 Thus, when processing die #4, we have to pretend that we're in
23128 the context of its DW_AT_specification, namely the contex of die
23131 spec_die
= die_specification (die
, &spec_cu
);
23132 if (spec_die
== NULL
)
23133 parent
= die
->parent
;
23136 parent
= spec_die
->parent
;
23140 if (parent
== NULL
)
23142 else if (parent
->building_fullname
)
23145 const char *parent_name
;
23147 /* It has been seen on RealView 2.2 built binaries,
23148 DW_TAG_template_type_param types actually _defined_ as
23149 children of the parent class:
23152 template class <class Enum> Class{};
23153 Class<enum E> class_e;
23155 1: DW_TAG_class_type (Class)
23156 2: DW_TAG_enumeration_type (E)
23157 3: DW_TAG_enumerator (enum1:0)
23158 3: DW_TAG_enumerator (enum2:1)
23160 2: DW_TAG_template_type_param
23161 DW_AT_type DW_FORM_ref_udata (E)
23163 Besides being broken debug info, it can put GDB into an
23164 infinite loop. Consider:
23166 When we're building the full name for Class<E>, we'll start
23167 at Class, and go look over its template type parameters,
23168 finding E. We'll then try to build the full name of E, and
23169 reach here. We're now trying to build the full name of E,
23170 and look over the parent DIE for containing scope. In the
23171 broken case, if we followed the parent DIE of E, we'd again
23172 find Class, and once again go look at its template type
23173 arguments, etc., etc. Simply don't consider such parent die
23174 as source-level parent of this die (it can't be, the language
23175 doesn't allow it), and break the loop here. */
23176 name
= dwarf2_name (die
, cu
);
23177 parent_name
= dwarf2_name (parent
, cu
);
23178 complaint (_("template param type '%s' defined within parent '%s'"),
23179 name
? name
: "<unknown>",
23180 parent_name
? parent_name
: "<unknown>");
23184 switch (parent
->tag
)
23186 case DW_TAG_namespace
:
23187 parent_type
= read_type_die (parent
, cu
);
23188 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
23189 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
23190 Work around this problem here. */
23191 if (cu
->language
== language_cplus
23192 && strcmp (parent_type
->name (), "::") == 0)
23194 /* We give a name to even anonymous namespaces. */
23195 return parent_type
->name ();
23196 case DW_TAG_class_type
:
23197 case DW_TAG_interface_type
:
23198 case DW_TAG_structure_type
:
23199 case DW_TAG_union_type
:
23200 case DW_TAG_module
:
23201 parent_type
= read_type_die (parent
, cu
);
23202 if (parent_type
->name () != NULL
)
23203 return parent_type
->name ();
23205 /* An anonymous structure is only allowed non-static data
23206 members; no typedefs, no member functions, et cetera.
23207 So it does not need a prefix. */
23209 case DW_TAG_compile_unit
:
23210 case DW_TAG_partial_unit
:
23211 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
23212 if (cu
->language
== language_cplus
23213 && !per_objfile
->per_bfd
->types
.empty ()
23214 && die
->child
!= NULL
23215 && (die
->tag
== DW_TAG_class_type
23216 || die
->tag
== DW_TAG_structure_type
23217 || die
->tag
== DW_TAG_union_type
))
23219 const char *name
= guess_full_die_structure_name (die
, cu
);
23224 case DW_TAG_subprogram
:
23225 /* Nested subroutines in Fortran get a prefix with the name
23226 of the parent's subroutine. */
23227 if (cu
->language
== language_fortran
)
23229 if ((die
->tag
== DW_TAG_subprogram
)
23230 && (dwarf2_name (parent
, cu
) != NULL
))
23231 return dwarf2_name (parent
, cu
);
23233 return determine_prefix (parent
, cu
);
23234 case DW_TAG_enumeration_type
:
23235 parent_type
= read_type_die (parent
, cu
);
23236 if (TYPE_DECLARED_CLASS (parent_type
))
23238 if (parent_type
->name () != NULL
)
23239 return parent_type
->name ();
23242 /* Fall through. */
23244 return determine_prefix (parent
, cu
);
23248 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
23249 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
23250 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
23251 an obconcat, otherwise allocate storage for the result. The CU argument is
23252 used to determine the language and hence, the appropriate separator. */
23254 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
23257 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
23258 int physname
, struct dwarf2_cu
*cu
)
23260 const char *lead
= "";
23263 if (suffix
== NULL
|| suffix
[0] == '\0'
23264 || prefix
== NULL
|| prefix
[0] == '\0')
23266 else if (cu
->language
== language_d
)
23268 /* For D, the 'main' function could be defined in any module, but it
23269 should never be prefixed. */
23270 if (strcmp (suffix
, "D main") == 0)
23278 else if (cu
->language
== language_fortran
&& physname
)
23280 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
23281 DW_AT_MIPS_linkage_name is preferred and used instead. */
23289 if (prefix
== NULL
)
23291 if (suffix
== NULL
)
23298 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
23300 strcpy (retval
, lead
);
23301 strcat (retval
, prefix
);
23302 strcat (retval
, sep
);
23303 strcat (retval
, suffix
);
23308 /* We have an obstack. */
23309 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
23313 /* Get name of a die, return NULL if not found. */
23315 static const char *
23316 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
23317 struct objfile
*objfile
)
23319 if (name
&& cu
->language
== language_cplus
)
23321 gdb::unique_xmalloc_ptr
<char> canon_name
23322 = cp_canonicalize_string (name
);
23324 if (canon_name
!= nullptr)
23325 name
= objfile
->intern (canon_name
.get ());
23331 /* Get name of a die, return NULL if not found.
23332 Anonymous namespaces are converted to their magic string. */
23334 static const char *
23335 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23337 struct attribute
*attr
;
23338 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23340 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23341 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23342 if (attr_name
== nullptr
23343 && die
->tag
!= DW_TAG_namespace
23344 && die
->tag
!= DW_TAG_class_type
23345 && die
->tag
!= DW_TAG_interface_type
23346 && die
->tag
!= DW_TAG_structure_type
23347 && die
->tag
!= DW_TAG_union_type
)
23352 case DW_TAG_compile_unit
:
23353 case DW_TAG_partial_unit
:
23354 /* Compilation units have a DW_AT_name that is a filename, not
23355 a source language identifier. */
23356 case DW_TAG_enumeration_type
:
23357 case DW_TAG_enumerator
:
23358 /* These tags always have simple identifiers already; no need
23359 to canonicalize them. */
23362 case DW_TAG_namespace
:
23363 if (attr_name
!= nullptr)
23365 return CP_ANONYMOUS_NAMESPACE_STR
;
23367 case DW_TAG_class_type
:
23368 case DW_TAG_interface_type
:
23369 case DW_TAG_structure_type
:
23370 case DW_TAG_union_type
:
23371 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23372 structures or unions. These were of the form "._%d" in GCC 4.1,
23373 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23374 and GCC 4.4. We work around this problem by ignoring these. */
23375 if (attr_name
!= nullptr
23376 && (startswith (attr_name
, "._")
23377 || startswith (attr_name
, "<anonymous")))
23380 /* GCC might emit a nameless typedef that has a linkage name. See
23381 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23382 if (!attr
|| attr_name
== NULL
)
23384 attr
= dw2_linkage_name_attr (die
, cu
);
23385 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23386 if (attr
== NULL
|| attr_name
== NULL
)
23389 /* Avoid demangling attr_name the second time on a second
23390 call for the same DIE. */
23391 if (!attr
->canonical_string_p ())
23393 gdb::unique_xmalloc_ptr
<char> demangled
23394 (gdb_demangle (attr_name
, DMGL_TYPES
));
23395 if (demangled
== nullptr)
23398 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
23399 attr_name
= attr
->as_string ();
23402 /* Strip any leading namespaces/classes, keep only the
23403 base name. DW_AT_name for named DIEs does not
23404 contain the prefixes. */
23405 const char *base
= strrchr (attr_name
, ':');
23406 if (base
&& base
> attr_name
&& base
[-1] == ':')
23417 if (!attr
->canonical_string_p ())
23418 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
23420 return attr
->as_string ();
23423 /* Return the die that this die in an extension of, or NULL if there
23424 is none. *EXT_CU is the CU containing DIE on input, and the CU
23425 containing the return value on output. */
23427 static struct die_info
*
23428 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23430 struct attribute
*attr
;
23432 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23436 return follow_die_ref (die
, attr
, ext_cu
);
23440 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23444 print_spaces (indent
, f
);
23445 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23446 dwarf_tag_name (die
->tag
), die
->abbrev
,
23447 sect_offset_str (die
->sect_off
));
23449 if (die
->parent
!= NULL
)
23451 print_spaces (indent
, f
);
23452 fprintf_unfiltered (f
, " parent at offset: %s\n",
23453 sect_offset_str (die
->parent
->sect_off
));
23456 print_spaces (indent
, f
);
23457 fprintf_unfiltered (f
, " has children: %s\n",
23458 dwarf_bool_name (die
->child
!= NULL
));
23460 print_spaces (indent
, f
);
23461 fprintf_unfiltered (f
, " attributes:\n");
23463 for (i
= 0; i
< die
->num_attrs
; ++i
)
23465 print_spaces (indent
, f
);
23466 fprintf_unfiltered (f
, " %s (%s) ",
23467 dwarf_attr_name (die
->attrs
[i
].name
),
23468 dwarf_form_name (die
->attrs
[i
].form
));
23470 switch (die
->attrs
[i
].form
)
23473 case DW_FORM_addrx
:
23474 case DW_FORM_GNU_addr_index
:
23475 fprintf_unfiltered (f
, "address: ");
23476 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
23478 case DW_FORM_block2
:
23479 case DW_FORM_block4
:
23480 case DW_FORM_block
:
23481 case DW_FORM_block1
:
23482 fprintf_unfiltered (f
, "block: size %s",
23483 pulongest (die
->attrs
[i
].as_block ()->size
));
23485 case DW_FORM_exprloc
:
23486 fprintf_unfiltered (f
, "expression: size %s",
23487 pulongest (die
->attrs
[i
].as_block ()->size
));
23489 case DW_FORM_data16
:
23490 fprintf_unfiltered (f
, "constant of 16 bytes");
23492 case DW_FORM_ref_addr
:
23493 fprintf_unfiltered (f
, "ref address: ");
23494 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23496 case DW_FORM_GNU_ref_alt
:
23497 fprintf_unfiltered (f
, "alt ref address: ");
23498 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23504 case DW_FORM_ref_udata
:
23505 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23506 (long) (die
->attrs
[i
].as_unsigned ()));
23508 case DW_FORM_data1
:
23509 case DW_FORM_data2
:
23510 case DW_FORM_data4
:
23511 case DW_FORM_data8
:
23512 case DW_FORM_udata
:
23513 fprintf_unfiltered (f
, "constant: %s",
23514 pulongest (die
->attrs
[i
].as_unsigned ()));
23516 case DW_FORM_sec_offset
:
23517 fprintf_unfiltered (f
, "section offset: %s",
23518 pulongest (die
->attrs
[i
].as_unsigned ()));
23520 case DW_FORM_ref_sig8
:
23521 fprintf_unfiltered (f
, "signature: %s",
23522 hex_string (die
->attrs
[i
].as_signature ()));
23524 case DW_FORM_string
:
23526 case DW_FORM_line_strp
:
23528 case DW_FORM_GNU_str_index
:
23529 case DW_FORM_GNU_strp_alt
:
23530 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23531 die
->attrs
[i
].as_string ()
23532 ? die
->attrs
[i
].as_string () : "",
23533 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23536 if (die
->attrs
[i
].as_boolean ())
23537 fprintf_unfiltered (f
, "flag: TRUE");
23539 fprintf_unfiltered (f
, "flag: FALSE");
23541 case DW_FORM_flag_present
:
23542 fprintf_unfiltered (f
, "flag: TRUE");
23544 case DW_FORM_indirect
:
23545 /* The reader will have reduced the indirect form to
23546 the "base form" so this form should not occur. */
23547 fprintf_unfiltered (f
,
23548 "unexpected attribute form: DW_FORM_indirect");
23550 case DW_FORM_sdata
:
23551 case DW_FORM_implicit_const
:
23552 fprintf_unfiltered (f
, "constant: %s",
23553 plongest (die
->attrs
[i
].as_signed ()));
23556 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23557 die
->attrs
[i
].form
);
23560 fprintf_unfiltered (f
, "\n");
23565 dump_die_for_error (struct die_info
*die
)
23567 dump_die_shallow (gdb_stderr
, 0, die
);
23571 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23573 int indent
= level
* 4;
23575 gdb_assert (die
!= NULL
);
23577 if (level
>= max_level
)
23580 dump_die_shallow (f
, indent
, die
);
23582 if (die
->child
!= NULL
)
23584 print_spaces (indent
, f
);
23585 fprintf_unfiltered (f
, " Children:");
23586 if (level
+ 1 < max_level
)
23588 fprintf_unfiltered (f
, "\n");
23589 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23593 fprintf_unfiltered (f
,
23594 " [not printed, max nesting level reached]\n");
23598 if (die
->sibling
!= NULL
&& level
> 0)
23600 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23604 /* This is called from the pdie macro in gdbinit.in.
23605 It's not static so gcc will keep a copy callable from gdb. */
23608 dump_die (struct die_info
*die
, int max_level
)
23610 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23614 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23618 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23619 to_underlying (die
->sect_off
),
23625 /* Follow reference or signature attribute ATTR of SRC_DIE.
23626 On entry *REF_CU is the CU of SRC_DIE.
23627 On exit *REF_CU is the CU of the result. */
23629 static struct die_info
*
23630 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23631 struct dwarf2_cu
**ref_cu
)
23633 struct die_info
*die
;
23635 if (attr
->form_is_ref ())
23636 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23637 else if (attr
->form
== DW_FORM_ref_sig8
)
23638 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23641 dump_die_for_error (src_die
);
23642 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23643 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23649 /* Follow reference OFFSET.
23650 On entry *REF_CU is the CU of the source die referencing OFFSET.
23651 On exit *REF_CU is the CU of the result.
23652 Returns NULL if OFFSET is invalid. */
23654 static struct die_info
*
23655 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23656 struct dwarf2_cu
**ref_cu
)
23658 struct die_info temp_die
;
23659 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23660 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23662 gdb_assert (cu
->per_cu
!= NULL
);
23666 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23667 "source CU contains target offset: %d",
23668 sect_offset_str (cu
->per_cu
->sect_off
),
23669 sect_offset_str (sect_off
),
23670 cu
->header
.offset_in_cu_p (sect_off
));
23672 if (cu
->per_cu
->is_debug_types
)
23674 /* .debug_types CUs cannot reference anything outside their CU.
23675 If they need to, they have to reference a signatured type via
23676 DW_FORM_ref_sig8. */
23677 if (!cu
->header
.offset_in_cu_p (sect_off
))
23680 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23681 || !cu
->header
.offset_in_cu_p (sect_off
))
23683 struct dwarf2_per_cu_data
*per_cu
;
23685 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23688 dwarf_read_debug_printf_v ("target CU offset: %s, "
23689 "target CU DIEs loaded: %d",
23690 sect_offset_str (per_cu
->sect_off
),
23691 per_objfile
->get_cu (per_cu
) != nullptr);
23693 /* If necessary, add it to the queue and load its DIEs. */
23694 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
23695 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23696 false, cu
->language
);
23698 target_cu
= per_objfile
->get_cu (per_cu
);
23700 else if (cu
->dies
== NULL
)
23702 /* We're loading full DIEs during partial symbol reading. */
23703 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23704 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23708 *ref_cu
= target_cu
;
23709 temp_die
.sect_off
= sect_off
;
23711 if (target_cu
!= cu
)
23712 target_cu
->ancestor
= cu
;
23714 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23716 to_underlying (sect_off
));
23719 /* Follow reference attribute ATTR of SRC_DIE.
23720 On entry *REF_CU is the CU of SRC_DIE.
23721 On exit *REF_CU is the CU of the result. */
23723 static struct die_info
*
23724 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23725 struct dwarf2_cu
**ref_cu
)
23727 sect_offset sect_off
= attr
->get_ref_die_offset ();
23728 struct dwarf2_cu
*cu
= *ref_cu
;
23729 struct die_info
*die
;
23731 die
= follow_die_offset (sect_off
,
23732 (attr
->form
== DW_FORM_GNU_ref_alt
23733 || cu
->per_cu
->is_dwz
),
23736 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23737 "at %s [in module %s]"),
23738 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23739 objfile_name (cu
->per_objfile
->objfile
));
23746 struct dwarf2_locexpr_baton
23747 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23748 dwarf2_per_cu_data
*per_cu
,
23749 dwarf2_per_objfile
*per_objfile
,
23750 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23751 bool resolve_abstract_p
)
23753 struct die_info
*die
;
23754 struct attribute
*attr
;
23755 struct dwarf2_locexpr_baton retval
;
23756 struct objfile
*objfile
= per_objfile
->objfile
;
23758 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23760 cu
= load_cu (per_cu
, per_objfile
, false);
23764 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23765 Instead just throw an error, not much else we can do. */
23766 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23767 sect_offset_str (sect_off
), objfile_name (objfile
));
23770 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23772 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23773 sect_offset_str (sect_off
), objfile_name (objfile
));
23775 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23776 if (!attr
&& resolve_abstract_p
23777 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23778 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23780 CORE_ADDR pc
= get_frame_pc ();
23781 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23782 struct gdbarch
*gdbarch
= objfile
->arch ();
23784 for (const auto &cand_off
23785 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23787 struct dwarf2_cu
*cand_cu
= cu
;
23788 struct die_info
*cand
23789 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23792 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23795 CORE_ADDR pc_low
, pc_high
;
23796 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23797 if (pc_low
== ((CORE_ADDR
) -1))
23799 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23800 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23801 if (!(pc_low
<= pc
&& pc
< pc_high
))
23805 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23812 /* DWARF: "If there is no such attribute, then there is no effect.".
23813 DATA is ignored if SIZE is 0. */
23815 retval
.data
= NULL
;
23818 else if (attr
->form_is_section_offset ())
23820 struct dwarf2_loclist_baton loclist_baton
;
23821 CORE_ADDR pc
= get_frame_pc ();
23824 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23826 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23828 retval
.size
= size
;
23832 if (!attr
->form_is_block ())
23833 error (_("Dwarf Error: DIE at %s referenced in module %s "
23834 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23835 sect_offset_str (sect_off
), objfile_name (objfile
));
23837 struct dwarf_block
*block
= attr
->as_block ();
23838 retval
.data
= block
->data
;
23839 retval
.size
= block
->size
;
23841 retval
.per_objfile
= per_objfile
;
23842 retval
.per_cu
= cu
->per_cu
;
23844 per_objfile
->age_comp_units ();
23851 struct dwarf2_locexpr_baton
23852 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23853 dwarf2_per_cu_data
*per_cu
,
23854 dwarf2_per_objfile
*per_objfile
,
23855 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23857 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23859 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23863 /* Write a constant of a given type as target-ordered bytes into
23866 static const gdb_byte
*
23867 write_constant_as_bytes (struct obstack
*obstack
,
23868 enum bfd_endian byte_order
,
23875 *len
= TYPE_LENGTH (type
);
23876 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23877 store_unsigned_integer (result
, *len
, byte_order
, value
);
23885 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23886 dwarf2_per_cu_data
*per_cu
,
23887 dwarf2_per_objfile
*per_objfile
,
23891 struct die_info
*die
;
23892 struct attribute
*attr
;
23893 const gdb_byte
*result
= NULL
;
23896 enum bfd_endian byte_order
;
23897 struct objfile
*objfile
= per_objfile
->objfile
;
23899 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23901 cu
= load_cu (per_cu
, per_objfile
, false);
23905 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23906 Instead just throw an error, not much else we can do. */
23907 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23908 sect_offset_str (sect_off
), objfile_name (objfile
));
23911 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23913 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23914 sect_offset_str (sect_off
), objfile_name (objfile
));
23916 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23920 byte_order
= (bfd_big_endian (objfile
->obfd
)
23921 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23923 switch (attr
->form
)
23926 case DW_FORM_addrx
:
23927 case DW_FORM_GNU_addr_index
:
23931 *len
= cu
->header
.addr_size
;
23932 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23933 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23937 case DW_FORM_string
:
23940 case DW_FORM_GNU_str_index
:
23941 case DW_FORM_GNU_strp_alt
:
23942 /* The string is already allocated on the objfile obstack, point
23945 const char *attr_name
= attr
->as_string ();
23946 result
= (const gdb_byte
*) attr_name
;
23947 *len
= strlen (attr_name
);
23950 case DW_FORM_block1
:
23951 case DW_FORM_block2
:
23952 case DW_FORM_block4
:
23953 case DW_FORM_block
:
23954 case DW_FORM_exprloc
:
23955 case DW_FORM_data16
:
23957 struct dwarf_block
*block
= attr
->as_block ();
23958 result
= block
->data
;
23959 *len
= block
->size
;
23963 /* The DW_AT_const_value attributes are supposed to carry the
23964 symbol's value "represented as it would be on the target
23965 architecture." By the time we get here, it's already been
23966 converted to host endianness, so we just need to sign- or
23967 zero-extend it as appropriate. */
23968 case DW_FORM_data1
:
23969 type
= die_type (die
, cu
);
23970 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23971 if (result
== NULL
)
23972 result
= write_constant_as_bytes (obstack
, byte_order
,
23975 case DW_FORM_data2
:
23976 type
= die_type (die
, cu
);
23977 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23978 if (result
== NULL
)
23979 result
= write_constant_as_bytes (obstack
, byte_order
,
23982 case DW_FORM_data4
:
23983 type
= die_type (die
, cu
);
23984 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23985 if (result
== NULL
)
23986 result
= write_constant_as_bytes (obstack
, byte_order
,
23989 case DW_FORM_data8
:
23990 type
= die_type (die
, cu
);
23991 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23992 if (result
== NULL
)
23993 result
= write_constant_as_bytes (obstack
, byte_order
,
23997 case DW_FORM_sdata
:
23998 case DW_FORM_implicit_const
:
23999 type
= die_type (die
, cu
);
24000 result
= write_constant_as_bytes (obstack
, byte_order
,
24001 type
, attr
->as_signed (), len
);
24004 case DW_FORM_udata
:
24005 type
= die_type (die
, cu
);
24006 result
= write_constant_as_bytes (obstack
, byte_order
,
24007 type
, attr
->as_unsigned (), len
);
24011 complaint (_("unsupported const value attribute form: '%s'"),
24012 dwarf_form_name (attr
->form
));
24022 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
24023 dwarf2_per_cu_data
*per_cu
,
24024 dwarf2_per_objfile
*per_objfile
)
24026 struct die_info
*die
;
24028 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
24030 cu
= load_cu (per_cu
, per_objfile
, false);
24035 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
24039 return die_type (die
, cu
);
24045 dwarf2_get_die_type (cu_offset die_offset
,
24046 dwarf2_per_cu_data
*per_cu
,
24047 dwarf2_per_objfile
*per_objfile
)
24049 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
24050 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
24053 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
24054 On entry *REF_CU is the CU of SRC_DIE.
24055 On exit *REF_CU is the CU of the result.
24056 Returns NULL if the referenced DIE isn't found. */
24058 static struct die_info
*
24059 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
24060 struct dwarf2_cu
**ref_cu
)
24062 struct die_info temp_die
;
24063 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
24064 struct die_info
*die
;
24065 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
24068 /* While it might be nice to assert sig_type->type == NULL here,
24069 we can get here for DW_AT_imported_declaration where we need
24070 the DIE not the type. */
24072 /* If necessary, add it to the queue and load its DIEs. */
24074 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
24076 read_signatured_type (sig_type
, per_objfile
);
24078 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
24079 gdb_assert (sig_cu
!= NULL
);
24080 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
24081 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
24082 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
24083 to_underlying (temp_die
.sect_off
));
24086 /* For .gdb_index version 7 keep track of included TUs.
24087 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
24088 if (per_objfile
->per_bfd
->index_table
!= NULL
24089 && per_objfile
->per_bfd
->index_table
->version
<= 7)
24091 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
24096 sig_cu
->ancestor
= cu
;
24104 /* Follow signatured type referenced by ATTR in SRC_DIE.
24105 On entry *REF_CU is the CU of SRC_DIE.
24106 On exit *REF_CU is the CU of the result.
24107 The result is the DIE of the type.
24108 If the referenced type cannot be found an error is thrown. */
24110 static struct die_info
*
24111 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
24112 struct dwarf2_cu
**ref_cu
)
24114 ULONGEST signature
= attr
->as_signature ();
24115 struct signatured_type
*sig_type
;
24116 struct die_info
*die
;
24118 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
24120 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
24121 /* sig_type will be NULL if the signatured type is missing from
24123 if (sig_type
== NULL
)
24125 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24126 " from DIE at %s [in module %s]"),
24127 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
24128 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
24131 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
24134 dump_die_for_error (src_die
);
24135 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24136 " from DIE at %s [in module %s]"),
24137 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
24138 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
24144 /* Get the type specified by SIGNATURE referenced in DIE/CU,
24145 reading in and processing the type unit if necessary. */
24147 static struct type
*
24148 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
24149 struct dwarf2_cu
*cu
)
24151 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24152 struct signatured_type
*sig_type
;
24153 struct dwarf2_cu
*type_cu
;
24154 struct die_info
*type_die
;
24157 sig_type
= lookup_signatured_type (cu
, signature
);
24158 /* sig_type will be NULL if the signatured type is missing from
24160 if (sig_type
== NULL
)
24162 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24163 " from DIE at %s [in module %s]"),
24164 hex_string (signature
), sect_offset_str (die
->sect_off
),
24165 objfile_name (per_objfile
->objfile
));
24166 return build_error_marker_type (cu
, die
);
24169 /* If we already know the type we're done. */
24170 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
24171 if (type
!= nullptr)
24175 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
24176 if (type_die
!= NULL
)
24178 /* N.B. We need to call get_die_type to ensure only one type for this DIE
24179 is created. This is important, for example, because for c++ classes
24180 we need TYPE_NAME set which is only done by new_symbol. Blech. */
24181 type
= read_type_die (type_die
, type_cu
);
24184 complaint (_("Dwarf Error: Cannot build signatured type %s"
24185 " referenced from DIE at %s [in module %s]"),
24186 hex_string (signature
), sect_offset_str (die
->sect_off
),
24187 objfile_name (per_objfile
->objfile
));
24188 type
= build_error_marker_type (cu
, die
);
24193 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24194 " from DIE at %s [in module %s]"),
24195 hex_string (signature
), sect_offset_str (die
->sect_off
),
24196 objfile_name (per_objfile
->objfile
));
24197 type
= build_error_marker_type (cu
, die
);
24200 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
24205 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
24206 reading in and processing the type unit if necessary. */
24208 static struct type
*
24209 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
24210 struct dwarf2_cu
*cu
) /* ARI: editCase function */
24212 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
24213 if (attr
->form_is_ref ())
24215 struct dwarf2_cu
*type_cu
= cu
;
24216 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24218 return read_type_die (type_die
, type_cu
);
24220 else if (attr
->form
== DW_FORM_ref_sig8
)
24222 return get_signatured_type (die
, attr
->as_signature (), cu
);
24226 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24228 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24229 " at %s [in module %s]"),
24230 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24231 objfile_name (per_objfile
->objfile
));
24232 return build_error_marker_type (cu
, die
);
24236 /* Load the DIEs associated with type unit PER_CU into memory. */
24239 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
24240 dwarf2_per_objfile
*per_objfile
)
24242 struct signatured_type
*sig_type
;
24244 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24245 gdb_assert (! per_cu
->type_unit_group_p ());
24247 /* We have the per_cu, but we need the signatured_type.
24248 Fortunately this is an easy translation. */
24249 gdb_assert (per_cu
->is_debug_types
);
24250 sig_type
= (struct signatured_type
*) per_cu
;
24252 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
24254 read_signatured_type (sig_type
, per_objfile
);
24256 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
24259 /* Read in a signatured type and build its CU and DIEs.
24260 If the type is a stub for the real type in a DWO file,
24261 read in the real type from the DWO file as well. */
24264 read_signatured_type (signatured_type
*sig_type
,
24265 dwarf2_per_objfile
*per_objfile
)
24267 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24269 gdb_assert (per_cu
->is_debug_types
);
24270 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
24272 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
24274 if (!reader
.dummy_p
)
24276 struct dwarf2_cu
*cu
= reader
.cu
;
24277 const gdb_byte
*info_ptr
= reader
.info_ptr
;
24279 gdb_assert (cu
->die_hash
== NULL
);
24281 htab_create_alloc_ex (cu
->header
.length
/ 12,
24285 &cu
->comp_unit_obstack
,
24286 hashtab_obstack_allocate
,
24287 dummy_obstack_deallocate
);
24289 if (reader
.comp_unit_die
->has_children
)
24290 reader
.comp_unit_die
->child
24291 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
24292 reader
.comp_unit_die
);
24293 cu
->dies
= reader
.comp_unit_die
;
24294 /* comp_unit_die is not stored in die_hash, no need. */
24296 /* We try not to read any attributes in this function, because
24297 not all CUs needed for references have been loaded yet, and
24298 symbol table processing isn't initialized. But we have to
24299 set the CU language, or we won't be able to build types
24300 correctly. Similarly, if we do not read the producer, we can
24301 not apply producer-specific interpretation. */
24302 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24307 sig_type
->per_cu
.tu_read
= 1;
24310 /* Decode simple location descriptions.
24311 Given a pointer to a dwarf block that defines a location, compute
24312 the location and return the value. If COMPUTED is non-null, it is
24313 set to true to indicate that decoding was successful, and false
24314 otherwise. If COMPUTED is null, then this function may emit a
24318 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
24320 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
24322 size_t size
= blk
->size
;
24323 const gdb_byte
*data
= blk
->data
;
24324 CORE_ADDR stack
[64];
24326 unsigned int bytes_read
, unsnd
;
24329 if (computed
!= nullptr)
24335 stack
[++stacki
] = 0;
24374 stack
[++stacki
] = op
- DW_OP_lit0
;
24409 stack
[++stacki
] = op
- DW_OP_reg0
;
24412 if (computed
== nullptr)
24413 dwarf2_complex_location_expr_complaint ();
24420 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24422 stack
[++stacki
] = unsnd
;
24425 if (computed
== nullptr)
24426 dwarf2_complex_location_expr_complaint ();
24433 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
24438 case DW_OP_const1u
:
24439 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24443 case DW_OP_const1s
:
24444 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24448 case DW_OP_const2u
:
24449 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24453 case DW_OP_const2s
:
24454 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24458 case DW_OP_const4u
:
24459 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24463 case DW_OP_const4s
:
24464 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24468 case DW_OP_const8u
:
24469 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24474 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24480 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24485 stack
[stacki
+ 1] = stack
[stacki
];
24490 stack
[stacki
- 1] += stack
[stacki
];
24494 case DW_OP_plus_uconst
:
24495 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24501 stack
[stacki
- 1] -= stack
[stacki
];
24506 /* If we're not the last op, then we definitely can't encode
24507 this using GDB's address_class enum. This is valid for partial
24508 global symbols, although the variable's address will be bogus
24512 if (computed
== nullptr)
24513 dwarf2_complex_location_expr_complaint ();
24519 case DW_OP_GNU_push_tls_address
:
24520 case DW_OP_form_tls_address
:
24521 /* The top of the stack has the offset from the beginning
24522 of the thread control block at which the variable is located. */
24523 /* Nothing should follow this operator, so the top of stack would
24525 /* This is valid for partial global symbols, but the variable's
24526 address will be bogus in the psymtab. Make it always at least
24527 non-zero to not look as a variable garbage collected by linker
24528 which have DW_OP_addr 0. */
24531 if (computed
== nullptr)
24532 dwarf2_complex_location_expr_complaint ();
24539 case DW_OP_GNU_uninit
:
24540 if (computed
!= nullptr)
24545 case DW_OP_GNU_addr_index
:
24546 case DW_OP_GNU_const_index
:
24547 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24553 if (computed
== nullptr)
24555 const char *name
= get_DW_OP_name (op
);
24558 complaint (_("unsupported stack op: '%s'"),
24561 complaint (_("unsupported stack op: '%02x'"),
24565 return (stack
[stacki
]);
24568 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24569 outside of the allocated space. Also enforce minimum>0. */
24570 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24572 if (computed
== nullptr)
24573 complaint (_("location description stack overflow"));
24579 if (computed
== nullptr)
24580 complaint (_("location description stack underflow"));
24585 if (computed
!= nullptr)
24587 return (stack
[stacki
]);
24590 /* memory allocation interface */
24592 static struct dwarf_block
*
24593 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24595 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24598 static struct die_info
*
24599 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24601 struct die_info
*die
;
24602 size_t size
= sizeof (struct die_info
);
24605 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24607 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24608 memset (die
, 0, sizeof (struct die_info
));
24614 /* Macro support. */
24616 /* An overload of dwarf_decode_macros that finds the correct section
24617 and ensures it is read in before calling the other overload. */
24620 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24621 int section_is_gnu
)
24623 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24624 struct objfile
*objfile
= per_objfile
->objfile
;
24625 const struct line_header
*lh
= cu
->line_header
;
24626 unsigned int offset_size
= cu
->header
.offset_size
;
24627 struct dwarf2_section_info
*section
;
24628 const char *section_name
;
24630 if (cu
->dwo_unit
!= nullptr)
24632 if (section_is_gnu
)
24634 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24635 section_name
= ".debug_macro.dwo";
24639 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24640 section_name
= ".debug_macinfo.dwo";
24645 if (section_is_gnu
)
24647 section
= &per_objfile
->per_bfd
->macro
;
24648 section_name
= ".debug_macro";
24652 section
= &per_objfile
->per_bfd
->macinfo
;
24653 section_name
= ".debug_macinfo";
24657 section
->read (objfile
);
24658 if (section
->buffer
== nullptr)
24660 complaint (_("missing %s section"), section_name
);
24664 buildsym_compunit
*builder
= cu
->get_builder ();
24666 struct dwarf2_section_info
*str_offsets_section
;
24667 struct dwarf2_section_info
*str_section
;
24668 ULONGEST str_offsets_base
;
24670 if (cu
->dwo_unit
!= nullptr)
24672 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24673 ->sections
.str_offsets
;
24674 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24675 str_offsets_base
= cu
->header
.addr_size
;
24679 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24680 str_section
= &per_objfile
->per_bfd
->str
;
24681 str_offsets_base
= *cu
->str_offsets_base
;
24684 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24685 offset_size
, offset
, str_section
, str_offsets_section
,
24686 str_offsets_base
, section_is_gnu
);
24689 /* Return the .debug_loc section to use for CU.
24690 For DWO files use .debug_loc.dwo. */
24692 static struct dwarf2_section_info
*
24693 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24695 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24699 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24701 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24703 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24704 : &per_objfile
->per_bfd
->loc
);
24707 /* Return the .debug_rnglists section to use for CU. */
24708 static struct dwarf2_section_info
*
24709 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24711 if (cu
->header
.version
< 5)
24712 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24713 cu
->header
.version
);
24714 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24716 /* Make sure we read the .debug_rnglists section from the file that
24717 contains the DW_AT_ranges attribute we are reading. Normally that
24718 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24719 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24721 if (cu
->dwo_unit
!= nullptr
24722 && tag
!= DW_TAG_compile_unit
24723 && tag
!= DW_TAG_skeleton_unit
)
24725 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24727 if (sections
->rnglists
.size
> 0)
24728 return §ions
->rnglists
;
24730 error (_(".debug_rnglists section is missing from .dwo file."));
24732 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24735 /* A helper function that fills in a dwarf2_loclist_baton. */
24738 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24739 struct dwarf2_loclist_baton
*baton
,
24740 const struct attribute
*attr
)
24742 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24743 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24745 section
->read (per_objfile
->objfile
);
24747 baton
->per_objfile
= per_objfile
;
24748 baton
->per_cu
= cu
->per_cu
;
24749 gdb_assert (baton
->per_cu
);
24750 /* We don't know how long the location list is, but make sure we
24751 don't run off the edge of the section. */
24752 baton
->size
= section
->size
- attr
->as_unsigned ();
24753 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24754 if (cu
->base_address
.has_value ())
24755 baton
->base_address
= *cu
->base_address
;
24757 baton
->base_address
= 0;
24758 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24762 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24763 struct dwarf2_cu
*cu
, int is_block
)
24765 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24766 struct objfile
*objfile
= per_objfile
->objfile
;
24767 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24769 if (attr
->form_is_section_offset ()
24770 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24771 the section. If so, fall through to the complaint in the
24773 && attr
->as_unsigned () < section
->get_size (objfile
))
24775 struct dwarf2_loclist_baton
*baton
;
24777 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24779 fill_in_loclist_baton (cu
, baton
, attr
);
24781 if (!cu
->base_address
.has_value ())
24782 complaint (_("Location list used without "
24783 "specifying the CU base address."));
24785 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24786 ? dwarf2_loclist_block_index
24787 : dwarf2_loclist_index
);
24788 SYMBOL_LOCATION_BATON (sym
) = baton
;
24792 struct dwarf2_locexpr_baton
*baton
;
24794 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24795 baton
->per_objfile
= per_objfile
;
24796 baton
->per_cu
= cu
->per_cu
;
24797 gdb_assert (baton
->per_cu
);
24799 if (attr
->form_is_block ())
24801 /* Note that we're just copying the block's data pointer
24802 here, not the actual data. We're still pointing into the
24803 info_buffer for SYM's objfile; right now we never release
24804 that buffer, but when we do clean up properly this may
24806 struct dwarf_block
*block
= attr
->as_block ();
24807 baton
->size
= block
->size
;
24808 baton
->data
= block
->data
;
24812 dwarf2_invalid_attrib_class_complaint ("location description",
24813 sym
->natural_name ());
24817 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24818 ? dwarf2_locexpr_block_index
24819 : dwarf2_locexpr_index
);
24820 SYMBOL_LOCATION_BATON (sym
) = baton
;
24826 const comp_unit_head
*
24827 dwarf2_per_cu_data::get_header () const
24829 if (!m_header_read_in
)
24831 const gdb_byte
*info_ptr
24832 = this->section
->buffer
+ to_underlying (this->sect_off
);
24834 memset (&m_header
, 0, sizeof (m_header
));
24836 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24837 rcuh_kind::COMPILE
);
24846 dwarf2_per_cu_data::addr_size () const
24848 return this->get_header ()->addr_size
;
24854 dwarf2_per_cu_data::offset_size () const
24856 return this->get_header ()->offset_size
;
24862 dwarf2_per_cu_data::ref_addr_size () const
24864 const comp_unit_head
*header
= this->get_header ();
24866 if (header
->version
== 2)
24867 return header
->addr_size
;
24869 return header
->offset_size
;
24875 dwarf2_cu::addr_type () const
24877 struct objfile
*objfile
= this->per_objfile
->objfile
;
24878 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24879 struct type
*addr_type
= lookup_pointer_type (void_type
);
24880 int addr_size
= this->per_cu
->addr_size ();
24882 if (TYPE_LENGTH (addr_type
) == addr_size
)
24885 addr_type
= addr_sized_int_type (addr_type
->is_unsigned ());
24889 /* A helper function for dwarf2_find_containing_comp_unit that returns
24890 the index of the result, and that searches a vector. It will
24891 return a result even if the offset in question does not actually
24892 occur in any CU. This is separate so that it can be unit
24896 dwarf2_find_containing_comp_unit
24897 (sect_offset sect_off
,
24898 unsigned int offset_in_dwz
,
24899 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
24904 high
= all_comp_units
.size () - 1;
24907 struct dwarf2_per_cu_data
*mid_cu
;
24908 int mid
= low
+ (high
- low
) / 2;
24910 mid_cu
= all_comp_units
[mid
];
24911 if (mid_cu
->is_dwz
> offset_in_dwz
24912 || (mid_cu
->is_dwz
== offset_in_dwz
24913 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24918 gdb_assert (low
== high
);
24922 /* Locate the .debug_info compilation unit from CU's objfile which contains
24923 the DIE at OFFSET. Raises an error on failure. */
24925 static struct dwarf2_per_cu_data
*
24926 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24927 unsigned int offset_in_dwz
,
24928 dwarf2_per_objfile
*per_objfile
)
24930 int low
= dwarf2_find_containing_comp_unit
24931 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24932 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
24934 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24936 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24937 error (_("Dwarf Error: could not find partial DIE containing "
24938 "offset %s [in module %s]"),
24939 sect_offset_str (sect_off
),
24940 bfd_get_filename (per_objfile
->objfile
->obfd
));
24942 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24944 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
24948 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24949 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24950 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24951 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24958 namespace selftests
{
24959 namespace find_containing_comp_unit
{
24964 struct dwarf2_per_cu_data one
{};
24965 struct dwarf2_per_cu_data two
{};
24966 struct dwarf2_per_cu_data three
{};
24967 struct dwarf2_per_cu_data four
{};
24970 two
.sect_off
= sect_offset (one
.length
);
24975 four
.sect_off
= sect_offset (three
.length
);
24979 std::vector
<dwarf2_per_cu_data
*> units
;
24980 units
.push_back (&one
);
24981 units
.push_back (&two
);
24982 units
.push_back (&three
);
24983 units
.push_back (&four
);
24987 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24988 SELF_CHECK (units
[result
] == &one
);
24989 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24990 SELF_CHECK (units
[result
] == &one
);
24991 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24992 SELF_CHECK (units
[result
] == &two
);
24994 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24995 SELF_CHECK (units
[result
] == &three
);
24996 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24997 SELF_CHECK (units
[result
] == &three
);
24998 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24999 SELF_CHECK (units
[result
] == &four
);
25005 #endif /* GDB_SELF_TEST */
25007 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
25009 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
25010 dwarf2_per_objfile
*per_objfile
)
25012 per_objfile (per_objfile
),
25014 has_loclist (false),
25015 checked_producer (false),
25016 producer_is_gxx_lt_4_6 (false),
25017 producer_is_gcc_lt_4_3 (false),
25018 producer_is_icc (false),
25019 producer_is_icc_lt_14 (false),
25020 producer_is_codewarrior (false),
25021 processing_has_namespace_info (false)
25025 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25028 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25029 enum language pretend_language
)
25031 struct attribute
*attr
;
25033 /* Set the language we're debugging. */
25034 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25035 if (attr
!= nullptr)
25036 set_cu_language (attr
->constant_value (0), cu
);
25039 cu
->language
= pretend_language
;
25040 cu
->language_defn
= language_def (cu
->language
);
25043 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25049 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
25051 auto it
= m_dwarf2_cus
.find (per_cu
);
25052 if (it
== m_dwarf2_cus
.end ())
25061 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
25063 gdb_assert (this->get_cu (per_cu
) == nullptr);
25065 m_dwarf2_cus
[per_cu
] = cu
;
25071 dwarf2_per_objfile::age_comp_units ()
25073 dwarf_read_debug_printf_v ("running");
25075 /* Start by clearing all marks. */
25076 for (auto pair
: m_dwarf2_cus
)
25077 pair
.second
->mark
= false;
25079 /* Traverse all CUs, mark them and their dependencies if used recently
25081 for (auto pair
: m_dwarf2_cus
)
25083 dwarf2_cu
*cu
= pair
.second
;
25086 if (cu
->last_used
<= dwarf_max_cache_age
)
25090 /* Delete all CUs still not marked. */
25091 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
25093 dwarf2_cu
*cu
= it
->second
;
25097 dwarf_read_debug_printf_v ("deleting old CU %s",
25098 sect_offset_str (cu
->per_cu
->sect_off
));
25100 it
= m_dwarf2_cus
.erase (it
);
25110 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
25112 auto it
= m_dwarf2_cus
.find (per_cu
);
25113 if (it
== m_dwarf2_cus
.end ())
25118 m_dwarf2_cus
.erase (it
);
25121 dwarf2_per_objfile::~dwarf2_per_objfile ()
25126 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25127 We store these in a hash table separate from the DIEs, and preserve them
25128 when the DIEs are flushed out of cache.
25130 The CU "per_cu" pointer is needed because offset alone is not enough to
25131 uniquely identify the type. A file may have multiple .debug_types sections,
25132 or the type may come from a DWO file. Furthermore, while it's more logical
25133 to use per_cu->section+offset, with Fission the section with the data is in
25134 the DWO file but we don't know that section at the point we need it.
25135 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25136 because we can enter the lookup routine, get_die_type_at_offset, from
25137 outside this file, and thus won't necessarily have PER_CU->cu.
25138 Fortunately, PER_CU is stable for the life of the objfile. */
25140 struct dwarf2_per_cu_offset_and_type
25142 const struct dwarf2_per_cu_data
*per_cu
;
25143 sect_offset sect_off
;
25147 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25150 per_cu_offset_and_type_hash (const void *item
)
25152 const struct dwarf2_per_cu_offset_and_type
*ofs
25153 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25155 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25158 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25161 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25163 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25164 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25165 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25166 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25168 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25169 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25172 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25173 table if necessary. For convenience, return TYPE.
25175 The DIEs reading must have careful ordering to:
25176 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25177 reading current DIE.
25178 * Not trying to dereference contents of still incompletely read in types
25179 while reading in other DIEs.
25180 * Enable referencing still incompletely read in types just by a pointer to
25181 the type without accessing its fields.
25183 Therefore caller should follow these rules:
25184 * Try to fetch any prerequisite types we may need to build this DIE type
25185 before building the type and calling set_die_type.
25186 * After building type call set_die_type for current DIE as soon as
25187 possible before fetching more types to complete the current type.
25188 * Make the type as complete as possible before fetching more types. */
25190 static struct type
*
25191 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
25192 bool skip_data_location
)
25194 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
25195 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25196 struct objfile
*objfile
= per_objfile
->objfile
;
25197 struct attribute
*attr
;
25198 struct dynamic_prop prop
;
25200 /* For Ada types, make sure that the gnat-specific data is always
25201 initialized (if not already set). There are a few types where
25202 we should not be doing so, because the type-specific area is
25203 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25204 where the type-specific area is used to store the floatformat).
25205 But this is not a problem, because the gnat-specific information
25206 is actually not needed for these types. */
25207 if (need_gnat_info (cu
)
25208 && type
->code () != TYPE_CODE_FUNC
25209 && type
->code () != TYPE_CODE_FLT
25210 && type
->code () != TYPE_CODE_METHODPTR
25211 && type
->code () != TYPE_CODE_MEMBERPTR
25212 && type
->code () != TYPE_CODE_METHOD
25213 && type
->code () != TYPE_CODE_FIXED_POINT
25214 && !HAVE_GNAT_AUX_INFO (type
))
25215 INIT_GNAT_SPECIFIC (type
);
25217 /* Read DW_AT_allocated and set in type. */
25218 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25221 struct type
*prop_type
= cu
->addr_sized_int_type (false);
25222 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25223 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
25226 /* Read DW_AT_associated and set in type. */
25227 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25230 struct type
*prop_type
= cu
->addr_sized_int_type (false);
25231 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25232 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
25235 /* Read DW_AT_data_location and set in type. */
25236 if (!skip_data_location
)
25238 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25239 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
25240 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
25243 if (per_objfile
->die_type_hash
== NULL
)
25244 per_objfile
->die_type_hash
25245 = htab_up (htab_create_alloc (127,
25246 per_cu_offset_and_type_hash
,
25247 per_cu_offset_and_type_eq
,
25248 NULL
, xcalloc
, xfree
));
25250 ofs
.per_cu
= cu
->per_cu
;
25251 ofs
.sect_off
= die
->sect_off
;
25253 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25254 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
25256 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25257 sect_offset_str (die
->sect_off
));
25258 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25259 struct dwarf2_per_cu_offset_and_type
);
25264 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25265 or return NULL if the die does not have a saved type. */
25267 static struct type
*
25268 get_die_type_at_offset (sect_offset sect_off
,
25269 dwarf2_per_cu_data
*per_cu
,
25270 dwarf2_per_objfile
*per_objfile
)
25272 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25274 if (per_objfile
->die_type_hash
== NULL
)
25277 ofs
.per_cu
= per_cu
;
25278 ofs
.sect_off
= sect_off
;
25279 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25280 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
25287 /* Look up the type for DIE in CU in die_type_hash,
25288 or return NULL if DIE does not have a saved type. */
25290 static struct type
*
25291 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25293 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
25296 /* Add a dependence relationship from CU to REF_PER_CU. */
25299 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25300 struct dwarf2_per_cu_data
*ref_per_cu
)
25304 if (cu
->dependencies
== NULL
)
25306 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25307 NULL
, &cu
->comp_unit_obstack
,
25308 hashtab_obstack_allocate
,
25309 dummy_obstack_deallocate
);
25311 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25313 *slot
= ref_per_cu
;
25316 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25317 Set the mark field in every compilation unit in the
25318 cache that we must keep because we are keeping CU.
25320 DATA is the dwarf2_per_objfile object in which to look up CUs. */
25323 dwarf2_mark_helper (void **slot
, void *data
)
25325 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
25326 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
25327 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
25329 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25330 reading of the chain. As such dependencies remain valid it is not much
25331 useful to track and undo them during QUIT cleanups. */
25340 if (cu
->dependencies
!= nullptr)
25341 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
25346 /* Set the mark field in CU and in every other compilation unit in the
25347 cache that we must keep because we are keeping CU. */
25350 dwarf2_mark (struct dwarf2_cu
*cu
)
25357 if (cu
->dependencies
!= nullptr)
25358 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
25361 /* Trivial hash function for partial_die_info: the hash value of a DIE
25362 is its offset in .debug_info for this objfile. */
25365 partial_die_hash (const void *item
)
25367 const struct partial_die_info
*part_die
25368 = (const struct partial_die_info
*) item
;
25370 return to_underlying (part_die
->sect_off
);
25373 /* Trivial comparison function for partial_die_info structures: two DIEs
25374 are equal if they have the same offset. */
25377 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25379 const struct partial_die_info
*part_die_lhs
25380 = (const struct partial_die_info
*) item_lhs
;
25381 const struct partial_die_info
*part_die_rhs
25382 = (const struct partial_die_info
*) item_rhs
;
25384 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25387 struct cmd_list_element
*set_dwarf_cmdlist
;
25388 struct cmd_list_element
*show_dwarf_cmdlist
;
25391 show_check_physname (struct ui_file
*file
, int from_tty
,
25392 struct cmd_list_element
*c
, const char *value
)
25394 fprintf_filtered (file
,
25395 _("Whether to check \"physname\" is %s.\n"),
25399 void _initialize_dwarf2_read ();
25401 _initialize_dwarf2_read ()
25403 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
25404 Set DWARF specific variables.\n\
25405 Configure DWARF variables such as the cache size."),
25406 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25407 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25409 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
25410 Show DWARF specific variables.\n\
25411 Show DWARF variables such as the cache size."),
25412 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25413 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25415 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25416 &dwarf_max_cache_age
, _("\
25417 Set the upper bound on the age of cached DWARF compilation units."), _("\
25418 Show the upper bound on the age of cached DWARF compilation units."), _("\
25419 A higher limit means that cached compilation units will be stored\n\
25420 in memory longer, and more total memory will be used. Zero disables\n\
25421 caching, which can slow down startup."),
25423 show_dwarf_max_cache_age
,
25424 &set_dwarf_cmdlist
,
25425 &show_dwarf_cmdlist
);
25427 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25428 Set debugging of the DWARF reader."), _("\
25429 Show debugging of the DWARF reader."), _("\
25430 When enabled (non-zero), debugging messages are printed during DWARF\n\
25431 reading and symtab expansion. A value of 1 (one) provides basic\n\
25432 information. A value greater than 1 provides more verbose information."),
25435 &setdebuglist
, &showdebuglist
);
25437 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25438 Set debugging of the DWARF DIE reader."), _("\
25439 Show debugging of the DWARF DIE reader."), _("\
25440 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25441 The value is the maximum depth to print."),
25444 &setdebuglist
, &showdebuglist
);
25446 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25447 Set debugging of the dwarf line reader."), _("\
25448 Show debugging of the dwarf line reader."), _("\
25449 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25450 A value of 1 (one) provides basic information.\n\
25451 A value greater than 1 provides more verbose information."),
25454 &setdebuglist
, &showdebuglist
);
25456 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25457 Set cross-checking of \"physname\" code against demangler."), _("\
25458 Show cross-checking of \"physname\" code against demangler."), _("\
25459 When enabled, GDB's internal \"physname\" code is checked against\n\
25461 NULL
, show_check_physname
,
25462 &setdebuglist
, &showdebuglist
);
25464 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25465 no_class
, &use_deprecated_index_sections
, _("\
25466 Set whether to use deprecated gdb_index sections."), _("\
25467 Show whether to use deprecated gdb_index sections."), _("\
25468 When enabled, deprecated .gdb_index sections are used anyway.\n\
25469 Normally they are ignored either because of a missing feature or\n\
25470 performance issue.\n\
25471 Warning: This option must be enabled before gdb reads the file."),
25474 &setlist
, &showlist
);
25476 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25477 &dwarf2_locexpr_funcs
);
25478 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25479 &dwarf2_loclist_funcs
);
25481 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25482 &dwarf2_block_frame_base_locexpr_funcs
);
25483 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25484 &dwarf2_block_frame_base_loclist_funcs
);
25487 selftests::register_test ("dw2_expand_symtabs_matching",
25488 selftests::dw2_expand_symtabs_matching::run_test
);
25489 selftests::register_test ("dwarf2_find_containing_comp_unit",
25490 selftests::find_containing_comp_unit::run_test
);