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/sect-names.h"
44 #include "dwarf2/stringify.h"
45 #include "dwarf2/public.h"
54 #include "gdb-demangle.h"
55 #include "filenames.h" /* for DOSish file names */
57 #include "complaints.h"
58 #include "dwarf2/expr.h"
59 #include "dwarf2/loc.h"
60 #include "cp-support.h"
66 #include "typeprint.h"
71 #include "gdbcore.h" /* for gnutarget */
72 #include "gdb/gdb-index.h"
77 #include "namespace.h"
78 #include "gdbsupport/function-view.h"
79 #include "gdbsupport/gdb_optional.h"
80 #include "gdbsupport/underlying.h"
81 #include "gdbsupport/hash_enum.h"
82 #include "filename-seen-cache.h"
86 #include <unordered_map>
87 #include "gdbsupport/selftest.h"
88 #include "rust-lang.h"
89 #include "gdbsupport/pathstuff.h"
90 #include "count-one-bits.h"
92 /* When == 1, print basic high level tracing messages.
93 When > 1, be more verbose.
94 This is in contrast to the low level DIE reading of dwarf_die_debug. */
95 static unsigned int dwarf_read_debug
= 0;
97 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
99 #define dwarf_read_debug_printf(fmt, ...) \
100 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
103 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
105 #define dwarf_read_debug_printf_v(fmt, ...) \
106 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
109 /* When non-zero, dump DIEs after they are read in. */
110 static unsigned int dwarf_die_debug
= 0;
112 /* When non-zero, dump line number entries as they are read in. */
113 unsigned int dwarf_line_debug
= 0;
115 /* When true, cross-check physname against demangler. */
116 static bool check_physname
= false;
118 /* When true, do not reject deprecated .gdb_index sections. */
119 static bool use_deprecated_index_sections
= false;
121 /* This is used to store the data that is always per objfile. */
122 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
124 /* These are used to store the dwarf2_per_bfd objects.
126 objfiles having the same BFD, which doesn't require relocations, are going to
127 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
129 Other objfiles are not going to share a dwarf2_per_bfd with any other
130 objfiles, so they'll have their own version kept in the _objfile_data_key
132 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
133 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
135 /* The "aclass" indices for various kinds of computed DWARF symbols. */
137 static int dwarf2_locexpr_index
;
138 static int dwarf2_loclist_index
;
139 static int dwarf2_locexpr_block_index
;
140 static int dwarf2_loclist_block_index
;
142 /* Size of .debug_loclists section header for 32-bit DWARF format. */
143 #define LOCLIST_HEADER_SIZE32 12
145 /* Size of .debug_loclists section header for 64-bit DWARF format. */
146 #define LOCLIST_HEADER_SIZE64 20
148 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
149 #define RNGLIST_HEADER_SIZE32 12
151 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
152 #define RNGLIST_HEADER_SIZE64 20
154 /* An index into a (C++) symbol name component in a symbol name as
155 recorded in the mapped_index's symbol table. For each C++ symbol
156 in the symbol table, we record one entry for the start of each
157 component in the symbol in a table of name components, and then
158 sort the table, in order to be able to binary search symbol names,
159 ignoring leading namespaces, both completion and regular look up.
160 For example, for symbol "A::B::C", we'll have an entry that points
161 to "A::B::C", another that points to "B::C", and another for "C".
162 Note that function symbols in GDB index have no parameter
163 information, just the function/method names. You can convert a
164 name_component to a "const char *" using the
165 'mapped_index::symbol_name_at(offset_type)' method. */
167 struct name_component
169 /* Offset in the symbol name where the component starts. Stored as
170 a (32-bit) offset instead of a pointer to save memory and improve
171 locality on 64-bit architectures. */
172 offset_type name_offset
;
174 /* The symbol's index in the symbol and constant pool tables of a
179 /* Base class containing bits shared by both .gdb_index and
180 .debug_name indexes. */
182 struct mapped_index_base
184 mapped_index_base () = default;
185 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
187 /* The name_component table (a sorted vector). See name_component's
188 description above. */
189 std::vector
<name_component
> name_components
;
191 /* How NAME_COMPONENTS is sorted. */
192 enum case_sensitivity name_components_casing
;
194 /* Return the number of names in the symbol table. */
195 virtual size_t symbol_name_count () const = 0;
197 /* Get the name of the symbol at IDX in the symbol table. */
198 virtual const char *symbol_name_at
199 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
201 /* Return whether the name at IDX in the symbol table should be
203 virtual bool symbol_name_slot_invalid (offset_type idx
) const
208 /* Build the symbol name component sorted vector, if we haven't
210 void build_name_components (dwarf2_per_objfile
*per_objfile
);
212 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
213 possible matches for LN_NO_PARAMS in the name component
215 std::pair
<std::vector
<name_component
>::const_iterator
,
216 std::vector
<name_component
>::const_iterator
>
217 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
219 dwarf2_per_objfile
*per_objfile
) const;
221 /* Prevent deleting/destroying via a base class pointer. */
223 ~mapped_index_base() = default;
226 /* This is a view into the index that converts from bytes to an
227 offset_type, and allows indexing. Unaligned bytes are specifically
228 allowed here, and handled via unpacking. */
233 offset_view () = default;
235 explicit offset_view (gdb::array_view
<const gdb_byte
> bytes
)
240 /* Extract the INDEXth offset_type from the array. */
241 offset_type
operator[] (size_t index
) const
243 const gdb_byte
*bytes
= &m_bytes
[index
* sizeof (offset_type
)];
244 return (offset_type
) extract_unsigned_integer (bytes
,
245 sizeof (offset_type
),
249 /* Return the number of offset_types in this array. */
252 return m_bytes
.size () / sizeof (offset_type
);
255 /* Return true if this view is empty. */
258 return m_bytes
.empty ();
262 /* The underlying bytes. */
263 gdb::array_view
<const gdb_byte
> m_bytes
;
266 /* A description of the mapped index. The file format is described in
267 a comment by the code that writes the index. */
268 struct mapped_index final
: public mapped_index_base
270 /* Index data format version. */
273 /* The address table data. */
274 gdb::array_view
<const gdb_byte
> address_table
;
276 /* The symbol table, implemented as a hash table. */
277 offset_view symbol_table
;
279 /* A pointer to the constant pool. */
280 gdb::array_view
<const gdb_byte
> constant_pool
;
282 /* Return the index into the constant pool of the name of the IDXth
283 symbol in the symbol table. */
284 offset_type
symbol_name_index (offset_type idx
) const
286 return symbol_table
[2 * idx
];
289 /* Return the index into the constant pool of the CU vector of the
290 IDXth symbol in the symbol table. */
291 offset_type
symbol_vec_index (offset_type idx
) const
293 return symbol_table
[2 * idx
+ 1];
296 bool symbol_name_slot_invalid (offset_type idx
) const override
298 return (symbol_name_index (idx
) == 0
299 && symbol_vec_index (idx
) == 0);
302 /* Convenience method to get at the name of the symbol at IDX in the
304 const char *symbol_name_at
305 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
307 return (const char *) (this->constant_pool
.data ()
308 + symbol_name_index (idx
));
311 size_t symbol_name_count () const override
312 { return this->symbol_table
.size () / 2; }
315 /* A description of the mapped .debug_names.
316 Uninitialized map has CU_COUNT 0. */
317 struct mapped_debug_names final
: public mapped_index_base
319 bfd_endian dwarf5_byte_order
;
320 bool dwarf5_is_dwarf64
;
321 bool augmentation_is_gdb
;
323 uint32_t cu_count
= 0;
324 uint32_t tu_count
, bucket_count
, name_count
;
325 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
326 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
327 const gdb_byte
*name_table_string_offs_reordered
;
328 const gdb_byte
*name_table_entry_offs_reordered
;
329 const gdb_byte
*entry_pool
;
336 /* Attribute name DW_IDX_*. */
339 /* Attribute form DW_FORM_*. */
342 /* Value if FORM is DW_FORM_implicit_const. */
343 LONGEST implicit_const
;
345 std::vector
<attr
> attr_vec
;
348 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
350 const char *namei_to_name
351 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
353 /* Implementation of the mapped_index_base virtual interface, for
354 the name_components cache. */
356 const char *symbol_name_at
357 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
358 { return namei_to_name (idx
, per_objfile
); }
360 size_t symbol_name_count () const override
361 { return this->name_count
; }
364 /* See dwarf2read.h. */
367 get_dwarf2_per_objfile (struct objfile
*objfile
)
369 return dwarf2_objfile_data_key
.get (objfile
);
372 /* Default names of the debugging sections. */
374 /* Note that if the debugging section has been compressed, it might
375 have a name like .zdebug_info. */
377 const struct dwarf2_debug_sections dwarf2_elf_names
=
379 { ".debug_info", ".zdebug_info" },
380 { ".debug_abbrev", ".zdebug_abbrev" },
381 { ".debug_line", ".zdebug_line" },
382 { ".debug_loc", ".zdebug_loc" },
383 { ".debug_loclists", ".zdebug_loclists" },
384 { ".debug_macinfo", ".zdebug_macinfo" },
385 { ".debug_macro", ".zdebug_macro" },
386 { ".debug_str", ".zdebug_str" },
387 { ".debug_str_offsets", ".zdebug_str_offsets" },
388 { ".debug_line_str", ".zdebug_line_str" },
389 { ".debug_ranges", ".zdebug_ranges" },
390 { ".debug_rnglists", ".zdebug_rnglists" },
391 { ".debug_types", ".zdebug_types" },
392 { ".debug_addr", ".zdebug_addr" },
393 { ".debug_frame", ".zdebug_frame" },
394 { ".eh_frame", NULL
},
395 { ".gdb_index", ".zgdb_index" },
396 { ".debug_names", ".zdebug_names" },
397 { ".debug_aranges", ".zdebug_aranges" },
401 /* List of DWO/DWP sections. */
403 static const struct dwop_section_names
405 struct dwarf2_section_names abbrev_dwo
;
406 struct dwarf2_section_names info_dwo
;
407 struct dwarf2_section_names line_dwo
;
408 struct dwarf2_section_names loc_dwo
;
409 struct dwarf2_section_names loclists_dwo
;
410 struct dwarf2_section_names macinfo_dwo
;
411 struct dwarf2_section_names macro_dwo
;
412 struct dwarf2_section_names rnglists_dwo
;
413 struct dwarf2_section_names str_dwo
;
414 struct dwarf2_section_names str_offsets_dwo
;
415 struct dwarf2_section_names types_dwo
;
416 struct dwarf2_section_names cu_index
;
417 struct dwarf2_section_names tu_index
;
421 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
422 { ".debug_info.dwo", ".zdebug_info.dwo" },
423 { ".debug_line.dwo", ".zdebug_line.dwo" },
424 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
425 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
426 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
427 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
428 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
429 { ".debug_str.dwo", ".zdebug_str.dwo" },
430 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
431 { ".debug_types.dwo", ".zdebug_types.dwo" },
432 { ".debug_cu_index", ".zdebug_cu_index" },
433 { ".debug_tu_index", ".zdebug_tu_index" },
436 /* local data types */
438 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
439 begin with a header, which contains the following information. */
440 struct loclists_rnglists_header
442 /* A 4-byte or 12-byte length containing the length of the
443 set of entries for this compilation unit, not including the
444 length field itself. */
447 /* A 2-byte version identifier. */
450 /* A 1-byte unsigned integer containing the size in bytes of an address on
451 the target system. */
452 unsigned char addr_size
;
454 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
455 on the target system. */
456 unsigned char segment_collector_size
;
458 /* A 4-byte count of the number of offsets that follow the header. */
459 unsigned int offset_entry_count
;
462 /* Type used for delaying computation of method physnames.
463 See comments for compute_delayed_physnames. */
464 struct delayed_method_info
466 /* The type to which the method is attached, i.e., its parent class. */
469 /* The index of the method in the type's function fieldlists. */
472 /* The index of the method in the fieldlist. */
475 /* The name of the DIE. */
478 /* The DIE associated with this method. */
479 struct die_info
*die
;
482 /* Internal state when decoding a particular compilation unit. */
485 explicit dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
486 dwarf2_per_objfile
*per_objfile
);
488 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
490 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
491 Create the set of symtabs used by this TU, or if this TU is sharing
492 symtabs with another TU and the symtabs have already been created
493 then restore those symtabs in the line header.
494 We don't need the pc/line-number mapping for type units. */
495 void setup_type_unit_groups (struct die_info
*die
);
497 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
498 buildsym_compunit constructor. */
499 struct compunit_symtab
*start_symtab (const char *name
,
500 const char *comp_dir
,
503 /* Reset the builder. */
504 void reset_builder () { m_builder
.reset (); }
506 /* Return a type that is a generic pointer type, the size of which
507 matches the address size given in the compilation unit header for
509 struct type
*addr_type () const;
511 /* Find an integer type the same size as the address size given in
512 the compilation unit header for this CU. UNSIGNED_P controls if
513 the integer is unsigned or not. */
514 struct type
*addr_sized_int_type (bool unsigned_p
) const;
516 /* The header of the compilation unit. */
517 struct comp_unit_head header
{};
519 /* Base address of this compilation unit. */
520 gdb::optional
<CORE_ADDR
> base_address
;
522 /* The language we are debugging. */
523 enum language language
= language_unknown
;
524 const struct language_defn
*language_defn
= nullptr;
526 const char *producer
= nullptr;
529 /* The symtab builder for this CU. This is only non-NULL when full
530 symbols are being read. */
531 std::unique_ptr
<buildsym_compunit
> m_builder
;
534 /* The generic symbol table building routines have separate lists for
535 file scope symbols and all all other scopes (local scopes). So
536 we need to select the right one to pass to add_symbol_to_list().
537 We do it by keeping a pointer to the correct list in list_in_scope.
539 FIXME: The original dwarf code just treated the file scope as the
540 first local scope, and all other local scopes as nested local
541 scopes, and worked fine. Check to see if we really need to
542 distinguish these in buildsym.c. */
543 struct pending
**list_in_scope
= nullptr;
545 /* Hash table holding all the loaded partial DIEs
546 with partial_die->offset.SECT_OFF as hash. */
547 htab_t partial_dies
= nullptr;
549 /* Storage for things with the same lifetime as this read-in compilation
550 unit, including partial DIEs. */
551 auto_obstack comp_unit_obstack
;
553 /* Backlink to our per_cu entry. */
554 struct dwarf2_per_cu_data
*per_cu
;
556 /* The dwarf2_per_objfile that owns this. */
557 dwarf2_per_objfile
*per_objfile
;
559 /* How many compilation units ago was this CU last referenced? */
562 /* A hash table of DIE cu_offset for following references with
563 die_info->offset.sect_off as hash. */
564 htab_t die_hash
= nullptr;
566 /* Full DIEs if read in. */
567 struct die_info
*dies
= nullptr;
569 /* A set of pointers to dwarf2_per_cu_data objects for compilation
570 units referenced by this one. Only set during full symbol processing;
571 partial symbol tables do not have dependencies. */
572 htab_t dependencies
= nullptr;
574 /* Header data from the line table, during full symbol processing. */
575 struct line_header
*line_header
= nullptr;
576 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
577 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
578 this is the DW_TAG_compile_unit die for this CU. We'll hold on
579 to the line header as long as this DIE is being processed. See
580 process_die_scope. */
581 die_info
*line_header_die_owner
= nullptr;
583 /* A list of methods which need to have physnames computed
584 after all type information has been read. */
585 std::vector
<delayed_method_info
> method_list
;
587 /* To be copied to symtab->call_site_htab. */
588 htab_t call_site_htab
= nullptr;
590 /* Non-NULL if this CU came from a DWO file.
591 There is an invariant here that is important to remember:
592 Except for attributes copied from the top level DIE in the "main"
593 (or "stub") file in preparation for reading the DWO file
594 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
595 Either there isn't a DWO file (in which case this is NULL and the point
596 is moot), or there is and either we're not going to read it (in which
597 case this is NULL) or there is and we are reading it (in which case this
599 struct dwo_unit
*dwo_unit
= nullptr;
601 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
602 Note this value comes from the Fission stub CU/TU's DIE. */
603 gdb::optional
<ULONGEST
> addr_base
;
605 /* The DW_AT_GNU_ranges_base attribute, if present.
607 This is only relevant in the context of pre-DWARF 5 split units. In this
608 context, there is a .debug_ranges section in the linked executable,
609 containing all the ranges data for all the compilation units. Each
610 skeleton/stub unit has (if needed) a DW_AT_GNU_ranges_base attribute that
611 indicates the base of its contribution to that section. The DW_AT_ranges
612 attributes in the split-unit are of the form DW_FORM_sec_offset and point
613 into the .debug_ranges section of the linked file. However, they are not
614 "true" DW_FORM_sec_offset, because they are relative to the base of their
615 compilation unit's contribution, rather than relative to the beginning of
616 the section. The DW_AT_GNU_ranges_base value must be added to it to make
617 it relative to the beginning of the section.
619 Note that the value is zero when we are not in a pre-DWARF 5 split-unit
620 case, so this value can be added without needing to know whether we are in
623 N.B. If a DW_AT_ranges attribute is found on the DW_TAG_compile_unit in the
624 skeleton/stub, it must not have the base added, as it already points to the
625 right place. And since the DW_TAG_compile_unit DIE in the split-unit can't
626 have a DW_AT_ranges attribute, we can use the
628 die->tag != DW_AT_compile_unit
630 to determine whether the base should be added or not. */
631 ULONGEST gnu_ranges_base
= 0;
633 /* The DW_AT_rnglists_base attribute, if present.
635 This is used when processing attributes of form DW_FORM_rnglistx in
636 non-split units. Attributes of this form found in a split unit don't
637 use it, as split-unit files have their own non-shared .debug_rnglists.dwo
639 ULONGEST rnglists_base
= 0;
641 /* The DW_AT_loclists_base attribute if present. */
642 ULONGEST loclist_base
= 0;
644 /* When reading debug info generated by older versions of rustc, we
645 have to rewrite some union types to be struct types with a
646 variant part. This rewriting must be done after the CU is fully
647 read in, because otherwise at the point of rewriting some struct
648 type might not have been fully processed. So, we keep a list of
649 all such types here and process them after expansion. */
650 std::vector
<struct type
*> rust_unions
;
652 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
653 files, the value is implicitly zero. For DWARF 5 version DWO files, the
654 value is often implicit and is the size of the header of
655 .debug_str_offsets section (8 or 4, depending on the address size). */
656 gdb::optional
<ULONGEST
> str_offsets_base
;
658 /* Mark used when releasing cached dies. */
661 /* This CU references .debug_loc. See the symtab->locations_valid field.
662 This test is imperfect as there may exist optimized debug code not using
663 any location list and still facing inlining issues if handled as
664 unoptimized code. For a future better test see GCC PR other/32998. */
665 bool has_loclist
: 1;
667 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
668 if all the producer_is_* fields are valid. This information is cached
669 because profiling CU expansion showed excessive time spent in
670 producer_is_gxx_lt_4_6. */
671 bool checked_producer
: 1;
672 bool producer_is_gxx_lt_4_6
: 1;
673 bool producer_is_gcc_lt_4_3
: 1;
674 bool producer_is_icc
: 1;
675 bool producer_is_icc_lt_14
: 1;
676 bool producer_is_codewarrior
: 1;
678 /* When true, the file that we're processing is known to have
679 debugging info for C++ namespaces. GCC 3.3.x did not produce
680 this information, but later versions do. */
682 bool processing_has_namespace_info
: 1;
684 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
686 /* If this CU was inherited by another CU (via specification,
687 abstract_origin, etc), this is the ancestor CU. */
690 /* Get the buildsym_compunit for this CU. */
691 buildsym_compunit
*get_builder ()
693 /* If this CU has a builder associated with it, use that. */
694 if (m_builder
!= nullptr)
695 return m_builder
.get ();
697 /* Otherwise, search ancestors for a valid builder. */
698 if (ancestor
!= nullptr)
699 return ancestor
->get_builder ();
705 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
706 This includes type_unit_group and quick_file_names. */
708 struct stmt_list_hash
710 /* The DWO unit this table is from or NULL if there is none. */
711 struct dwo_unit
*dwo_unit
;
713 /* Offset in .debug_line or .debug_line.dwo. */
714 sect_offset line_sect_off
;
717 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
718 an object of this type. This contains elements of type unit groups
719 that can be shared across objfiles. The non-shareable parts are in
720 type_unit_group_unshareable. */
722 struct type_unit_group
724 /* dwarf2read.c's main "handle" on a TU symtab.
725 To simplify things we create an artificial CU that "includes" all the
726 type units using this stmt_list so that the rest of the code still has
727 a "per_cu" handle on the symtab. */
728 struct dwarf2_per_cu_data per_cu
;
730 /* The TUs that share this DW_AT_stmt_list entry.
731 This is added to while parsing type units to build partial symtabs,
732 and is deleted afterwards and not used again. */
733 std::vector
<signatured_type
*> *tus
;
735 /* The data used to construct the hash key. */
736 struct stmt_list_hash hash
;
739 /* These sections are what may appear in a (real or virtual) DWO file. */
743 struct dwarf2_section_info abbrev
;
744 struct dwarf2_section_info line
;
745 struct dwarf2_section_info loc
;
746 struct dwarf2_section_info loclists
;
747 struct dwarf2_section_info macinfo
;
748 struct dwarf2_section_info macro
;
749 struct dwarf2_section_info rnglists
;
750 struct dwarf2_section_info str
;
751 struct dwarf2_section_info str_offsets
;
752 /* In the case of a virtual DWO file, these two are unused. */
753 struct dwarf2_section_info info
;
754 std::vector
<dwarf2_section_info
> types
;
757 /* CUs/TUs in DWP/DWO files. */
761 /* Backlink to the containing struct dwo_file. */
762 struct dwo_file
*dwo_file
;
764 /* The "id" that distinguishes this CU/TU.
765 .debug_info calls this "dwo_id", .debug_types calls this "signature".
766 Since signatures came first, we stick with it for consistency. */
769 /* The section this CU/TU lives in, in the DWO file. */
770 struct dwarf2_section_info
*section
;
772 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
773 sect_offset sect_off
;
776 /* For types, offset in the type's DIE of the type defined by this TU. */
777 cu_offset type_offset_in_tu
;
780 /* include/dwarf2.h defines the DWP section codes.
781 It defines a max value but it doesn't define a min value, which we
782 use for error checking, so provide one. */
784 enum dwp_v2_section_ids
789 /* Data for one DWO file.
791 This includes virtual DWO files (a virtual DWO file is a DWO file as it
792 appears in a DWP file). DWP files don't really have DWO files per se -
793 comdat folding of types "loses" the DWO file they came from, and from
794 a high level view DWP files appear to contain a mass of random types.
795 However, to maintain consistency with the non-DWP case we pretend DWP
796 files contain virtual DWO files, and we assign each TU with one virtual
797 DWO file (generally based on the line and abbrev section offsets -
798 a heuristic that seems to work in practice). */
802 dwo_file () = default;
803 DISABLE_COPY_AND_ASSIGN (dwo_file
);
805 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
806 For virtual DWO files the name is constructed from the section offsets
807 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
808 from related CU+TUs. */
809 const char *dwo_name
= nullptr;
811 /* The DW_AT_comp_dir attribute. */
812 const char *comp_dir
= nullptr;
814 /* The bfd, when the file is open. Otherwise this is NULL.
815 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
816 gdb_bfd_ref_ptr dbfd
;
818 /* The sections that make up this DWO file.
819 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
820 sections (for lack of a better name). */
821 struct dwo_sections sections
{};
823 /* The CUs in the file.
824 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
825 an extension to handle LLVM's Link Time Optimization output (where
826 multiple source files may be compiled into a single object/dwo pair). */
829 /* Table of TUs in the file.
830 Each element is a struct dwo_unit. */
834 /* These sections are what may appear in a DWP file. */
838 /* These are used by all DWP versions (1, 2 and 5). */
839 struct dwarf2_section_info str
;
840 struct dwarf2_section_info cu_index
;
841 struct dwarf2_section_info tu_index
;
843 /* These are only used by DWP version 2 and version 5 files.
844 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
845 sections are referenced by section number, and are not recorded here.
846 In DWP version 2 or 5 there is at most one copy of all these sections,
847 each section being (effectively) comprised of the concatenation of all of
848 the individual sections that exist in the version 1 format.
849 To keep the code simple we treat each of these concatenated pieces as a
850 section itself (a virtual section?). */
851 struct dwarf2_section_info abbrev
;
852 struct dwarf2_section_info info
;
853 struct dwarf2_section_info line
;
854 struct dwarf2_section_info loc
;
855 struct dwarf2_section_info loclists
;
856 struct dwarf2_section_info macinfo
;
857 struct dwarf2_section_info macro
;
858 struct dwarf2_section_info rnglists
;
859 struct dwarf2_section_info str_offsets
;
860 struct dwarf2_section_info types
;
863 /* These sections are what may appear in a virtual DWO file in DWP version 1.
864 A virtual DWO file is a DWO file as it appears in a DWP file. */
866 struct virtual_v1_dwo_sections
868 struct dwarf2_section_info abbrev
;
869 struct dwarf2_section_info line
;
870 struct dwarf2_section_info loc
;
871 struct dwarf2_section_info macinfo
;
872 struct dwarf2_section_info macro
;
873 struct dwarf2_section_info str_offsets
;
874 /* Each DWP hash table entry records one CU or one TU.
875 That is recorded here, and copied to dwo_unit.section. */
876 struct dwarf2_section_info info_or_types
;
879 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
880 In version 2, the sections of the DWO files are concatenated together
881 and stored in one section of that name. Thus each ELF section contains
882 several "virtual" sections. */
884 struct virtual_v2_or_v5_dwo_sections
886 bfd_size_type abbrev_offset
;
887 bfd_size_type abbrev_size
;
889 bfd_size_type line_offset
;
890 bfd_size_type line_size
;
892 bfd_size_type loc_offset
;
893 bfd_size_type loc_size
;
895 bfd_size_type loclists_offset
;
896 bfd_size_type loclists_size
;
898 bfd_size_type macinfo_offset
;
899 bfd_size_type macinfo_size
;
901 bfd_size_type macro_offset
;
902 bfd_size_type macro_size
;
904 bfd_size_type rnglists_offset
;
905 bfd_size_type rnglists_size
;
907 bfd_size_type str_offsets_offset
;
908 bfd_size_type str_offsets_size
;
910 /* Each DWP hash table entry records one CU or one TU.
911 That is recorded here, and copied to dwo_unit.section. */
912 bfd_size_type info_or_types_offset
;
913 bfd_size_type info_or_types_size
;
916 /* Contents of DWP hash tables. */
918 struct dwp_hash_table
920 uint32_t version
, nr_columns
;
921 uint32_t nr_units
, nr_slots
;
922 const gdb_byte
*hash_table
, *unit_table
;
927 const gdb_byte
*indices
;
931 /* This is indexed by column number and gives the id of the section
933 #define MAX_NR_V2_DWO_SECTIONS \
934 (1 /* .debug_info or .debug_types */ \
935 + 1 /* .debug_abbrev */ \
936 + 1 /* .debug_line */ \
937 + 1 /* .debug_loc */ \
938 + 1 /* .debug_str_offsets */ \
939 + 1 /* .debug_macro or .debug_macinfo */)
940 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
941 const gdb_byte
*offsets
;
942 const gdb_byte
*sizes
;
946 /* This is indexed by column number and gives the id of the section
948 #define MAX_NR_V5_DWO_SECTIONS \
949 (1 /* .debug_info */ \
950 + 1 /* .debug_abbrev */ \
951 + 1 /* .debug_line */ \
952 + 1 /* .debug_loclists */ \
953 + 1 /* .debug_str_offsets */ \
954 + 1 /* .debug_macro */ \
955 + 1 /* .debug_rnglists */)
956 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
957 const gdb_byte
*offsets
;
958 const gdb_byte
*sizes
;
963 /* Data for one DWP file. */
967 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
969 dbfd (std::move (abfd
))
973 /* Name of the file. */
976 /* File format version. */
980 gdb_bfd_ref_ptr dbfd
;
982 /* Section info for this file. */
983 struct dwp_sections sections
{};
985 /* Table of CUs in the file. */
986 const struct dwp_hash_table
*cus
= nullptr;
988 /* Table of TUs in the file. */
989 const struct dwp_hash_table
*tus
= nullptr;
991 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
995 /* Table to map ELF section numbers to their sections.
996 This is only needed for the DWP V1 file format. */
997 unsigned int num_sections
= 0;
998 asection
**elf_sections
= nullptr;
1001 /* Struct used to pass misc. parameters to read_die_and_children, et
1002 al. which are used for both .debug_info and .debug_types dies.
1003 All parameters here are unchanging for the life of the call. This
1004 struct exists to abstract away the constant parameters of die reading. */
1006 struct die_reader_specs
1008 /* The bfd of die_section. */
1011 /* The CU of the DIE we are parsing. */
1012 struct dwarf2_cu
*cu
;
1014 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1015 struct dwo_file
*dwo_file
;
1017 /* The section the die comes from.
1018 This is either .debug_info or .debug_types, or the .dwo variants. */
1019 struct dwarf2_section_info
*die_section
;
1021 /* die_section->buffer. */
1022 const gdb_byte
*buffer
;
1024 /* The end of the buffer. */
1025 const gdb_byte
*buffer_end
;
1027 /* The abbreviation table to use when reading the DIEs. */
1028 struct abbrev_table
*abbrev_table
;
1031 /* A subclass of die_reader_specs that holds storage and has complex
1032 constructor and destructor behavior. */
1034 class cutu_reader
: public die_reader_specs
1038 cutu_reader (dwarf2_per_cu_data
*this_cu
,
1039 dwarf2_per_objfile
*per_objfile
,
1040 struct abbrev_table
*abbrev_table
,
1041 dwarf2_cu
*existing_cu
,
1044 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
1045 dwarf2_per_objfile
*per_objfile
,
1046 struct dwarf2_cu
*parent_cu
= nullptr,
1047 struct dwo_file
*dwo_file
= nullptr);
1049 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
1051 const gdb_byte
*info_ptr
= nullptr;
1052 struct die_info
*comp_unit_die
= nullptr;
1053 bool dummy_p
= false;
1055 /* Release the new CU, putting it on the chain. This cannot be done
1060 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
1061 dwarf2_per_objfile
*per_objfile
,
1062 dwarf2_cu
*existing_cu
);
1064 struct dwarf2_per_cu_data
*m_this_cu
;
1065 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
1067 /* The ordinary abbreviation table. */
1068 abbrev_table_up m_abbrev_table_holder
;
1070 /* The DWO abbreviation table. */
1071 abbrev_table_up m_dwo_abbrev_table
;
1074 /* When we construct a partial symbol table entry we only
1075 need this much information. */
1076 struct partial_die_info
: public allocate_on_obstack
1078 partial_die_info (sect_offset sect_off
, const struct abbrev_info
*abbrev
);
1080 /* Disable assign but still keep copy ctor, which is needed
1081 load_partial_dies. */
1082 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1084 /* Adjust the partial die before generating a symbol for it. This
1085 function may set the is_external flag or change the DIE's
1087 void fixup (struct dwarf2_cu
*cu
);
1089 /* Read a minimal amount of information into the minimal die
1091 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1092 const struct abbrev_info
&abbrev
,
1093 const gdb_byte
*info_ptr
);
1095 /* Compute the name of this partial DIE. This memoizes the
1096 result, so it is safe to call multiple times. */
1097 const char *name (dwarf2_cu
*cu
);
1099 /* Offset of this DIE. */
1100 const sect_offset sect_off
;
1102 /* DWARF-2 tag for this DIE. */
1103 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1105 /* Assorted flags describing the data found in this DIE. */
1106 const unsigned int has_children
: 1;
1108 unsigned int is_external
: 1;
1109 unsigned int is_declaration
: 1;
1110 unsigned int has_type
: 1;
1111 unsigned int has_specification
: 1;
1112 unsigned int has_pc_info
: 1;
1113 unsigned int may_be_inlined
: 1;
1115 /* This DIE has been marked DW_AT_main_subprogram. */
1116 unsigned int main_subprogram
: 1;
1118 /* Flag set if the SCOPE field of this structure has been
1120 unsigned int scope_set
: 1;
1122 /* Flag set if the DIE has a byte_size attribute. */
1123 unsigned int has_byte_size
: 1;
1125 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1126 unsigned int has_const_value
: 1;
1128 /* Flag set if any of the DIE's children are template arguments. */
1129 unsigned int has_template_arguments
: 1;
1131 /* Flag set if fixup has been called on this die. */
1132 unsigned int fixup_called
: 1;
1134 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1135 unsigned int is_dwz
: 1;
1137 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1138 unsigned int spec_is_dwz
: 1;
1140 unsigned int canonical_name
: 1;
1142 /* The name of this DIE. Normally the value of DW_AT_name, but
1143 sometimes a default name for unnamed DIEs. */
1144 const char *raw_name
= nullptr;
1146 /* The linkage name, if present. */
1147 const char *linkage_name
= nullptr;
1149 /* The scope to prepend to our children. This is generally
1150 allocated on the comp_unit_obstack, so will disappear
1151 when this compilation unit leaves the cache. */
1152 const char *scope
= nullptr;
1154 /* Some data associated with the partial DIE. The tag determines
1155 which field is live. */
1158 /* The location description associated with this DIE, if any. */
1159 struct dwarf_block
*locdesc
;
1160 /* The offset of an import, for DW_TAG_imported_unit. */
1161 sect_offset sect_off
;
1164 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1165 CORE_ADDR lowpc
= 0;
1166 CORE_ADDR highpc
= 0;
1168 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1169 DW_AT_sibling, if any. */
1170 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1171 could return DW_AT_sibling values to its caller load_partial_dies. */
1172 const gdb_byte
*sibling
= nullptr;
1174 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1175 DW_AT_specification (or DW_AT_abstract_origin or
1176 DW_AT_extension). */
1177 sect_offset spec_offset
{};
1179 /* Pointers to this DIE's parent, first child, and next sibling,
1181 struct partial_die_info
*die_parent
= nullptr;
1182 struct partial_die_info
*die_child
= nullptr;
1183 struct partial_die_info
*die_sibling
= nullptr;
1185 friend struct partial_die_info
*
1186 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1189 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1190 partial_die_info (sect_offset sect_off
)
1191 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1195 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1197 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1202 has_specification
= 0;
1205 main_subprogram
= 0;
1208 has_const_value
= 0;
1209 has_template_arguments
= 0;
1217 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1218 but this would require a corresponding change in unpack_field_as_long
1220 static int bits_per_byte
= 8;
1222 struct variant_part_builder
;
1224 /* When reading a variant, we track a bit more information about the
1225 field, and store it in an object of this type. */
1227 struct variant_field
1229 int first_field
= -1;
1230 int last_field
= -1;
1232 /* A variant can contain other variant parts. */
1233 std::vector
<variant_part_builder
> variant_parts
;
1235 /* If we see a DW_TAG_variant, then this will be set if this is the
1237 bool default_branch
= false;
1238 /* If we see a DW_AT_discr_value, then this will be the discriminant
1240 ULONGEST discriminant_value
= 0;
1241 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1243 struct dwarf_block
*discr_list_data
= nullptr;
1246 /* This represents a DW_TAG_variant_part. */
1248 struct variant_part_builder
1250 /* The offset of the discriminant field. */
1251 sect_offset discriminant_offset
{};
1253 /* Variants that are direct children of this variant part. */
1254 std::vector
<variant_field
> variants
;
1256 /* True if we're currently reading a variant. */
1257 bool processing_variant
= false;
1262 int accessibility
= 0;
1264 /* Variant parts need to find the discriminant, which is a DIE
1265 reference. We track the section offset of each field to make
1268 struct field field
{};
1273 const char *name
= nullptr;
1274 std::vector
<struct fn_field
> fnfields
;
1277 /* The routines that read and process dies for a C struct or C++ class
1278 pass lists of data member fields and lists of member function fields
1279 in an instance of a field_info structure, as defined below. */
1282 /* List of data member and baseclasses fields. */
1283 std::vector
<struct nextfield
> fields
;
1284 std::vector
<struct nextfield
> baseclasses
;
1286 /* Set if the accessibility of one of the fields is not public. */
1287 bool non_public_fields
= false;
1289 /* Member function fieldlist array, contains name of possibly overloaded
1290 member function, number of overloaded member functions and a pointer
1291 to the head of the member function field chain. */
1292 std::vector
<struct fnfieldlist
> fnfieldlists
;
1294 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1295 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1296 std::vector
<struct decl_field
> typedef_field_list
;
1298 /* Nested types defined by this class and the number of elements in this
1300 std::vector
<struct decl_field
> nested_types_list
;
1302 /* If non-null, this is the variant part we are currently
1304 variant_part_builder
*current_variant_part
= nullptr;
1305 /* This holds all the top-level variant parts attached to the type
1307 std::vector
<variant_part_builder
> variant_parts
;
1309 /* Return the total number of fields (including baseclasses). */
1310 int nfields () const
1312 return fields
.size () + baseclasses
.size ();
1316 /* Loaded secondary compilation units are kept in memory until they
1317 have not been referenced for the processing of this many
1318 compilation units. Set this to zero to disable caching. Cache
1319 sizes of up to at least twenty will improve startup time for
1320 typical inter-CU-reference binaries, at an obvious memory cost. */
1321 static int dwarf_max_cache_age
= 5;
1323 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1324 struct cmd_list_element
*c
, const char *value
)
1326 fprintf_filtered (file
, _("The upper bound on the age of cached "
1327 "DWARF compilation units is %s.\n"),
1331 /* local function prototypes */
1333 static void dwarf2_find_base_address (struct die_info
*die
,
1334 struct dwarf2_cu
*cu
);
1336 static dwarf2_psymtab
*create_partial_symtab
1337 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1340 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1341 const gdb_byte
*info_ptr
,
1342 struct die_info
*type_unit_die
);
1344 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1346 static void scan_partial_symbols (struct partial_die_info
*,
1347 CORE_ADDR
*, CORE_ADDR
*,
1348 int, struct dwarf2_cu
*);
1350 static void add_partial_symbol (struct partial_die_info
*,
1351 struct dwarf2_cu
*);
1353 static void add_partial_namespace (struct partial_die_info
*pdi
,
1354 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1355 int set_addrmap
, struct dwarf2_cu
*cu
);
1357 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1358 CORE_ADDR
*highpc
, int set_addrmap
,
1359 struct dwarf2_cu
*cu
);
1361 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1362 struct dwarf2_cu
*cu
);
1364 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1365 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1366 int need_pc
, struct dwarf2_cu
*cu
);
1368 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1370 static struct partial_die_info
*load_partial_dies
1371 (const struct die_reader_specs
*, const gdb_byte
*, int);
1373 /* A pair of partial_die_info and compilation unit. */
1374 struct cu_partial_die_info
1376 /* The compilation unit of the partial_die_info. */
1377 struct dwarf2_cu
*cu
;
1378 /* A partial_die_info. */
1379 struct partial_die_info
*pdi
;
1381 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1387 cu_partial_die_info () = delete;
1390 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1391 struct dwarf2_cu
*);
1393 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1395 const struct attr_abbrev
*,
1398 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1399 struct attribute
*attr
, dwarf_tag tag
);
1401 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1403 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1404 dwarf2_section_info
*, sect_offset
);
1406 static const char *read_indirect_string
1407 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1408 const struct comp_unit_head
*, unsigned int *);
1410 static const char *read_indirect_string_at_offset
1411 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1413 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1417 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1418 ULONGEST str_index
);
1420 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1421 ULONGEST str_index
);
1423 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1425 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1426 struct dwarf2_cu
*);
1428 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1429 struct dwarf2_cu
*cu
);
1431 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1433 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1434 struct dwarf2_cu
*cu
);
1436 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1438 static struct die_info
*die_specification (struct die_info
*die
,
1439 struct dwarf2_cu
**);
1441 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1442 struct dwarf2_cu
*cu
);
1444 static void dwarf_decode_lines (struct line_header
*, const char *,
1445 struct dwarf2_cu
*, dwarf2_psymtab
*,
1446 CORE_ADDR
, int decode_mapping
);
1448 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1451 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1452 struct dwarf2_cu
*, struct symbol
* = NULL
);
1454 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1455 struct dwarf2_cu
*);
1457 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1460 struct obstack
*obstack
,
1461 struct dwarf2_cu
*cu
, LONGEST
*value
,
1462 const gdb_byte
**bytes
,
1463 struct dwarf2_locexpr_baton
**baton
);
1465 static struct type
*read_subrange_index_type (struct die_info
*die
,
1466 struct dwarf2_cu
*cu
);
1468 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1470 static int need_gnat_info (struct dwarf2_cu
*);
1472 static struct type
*die_descriptive_type (struct die_info
*,
1473 struct dwarf2_cu
*);
1475 static void set_descriptive_type (struct type
*, struct die_info
*,
1476 struct dwarf2_cu
*);
1478 static struct type
*die_containing_type (struct die_info
*,
1479 struct dwarf2_cu
*);
1481 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1482 struct dwarf2_cu
*);
1484 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1486 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1488 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1490 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1491 const char *suffix
, int physname
,
1492 struct dwarf2_cu
*cu
);
1494 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1496 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1498 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1500 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1502 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1504 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1506 /* Return the .debug_loclists section to use for cu. */
1507 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1509 /* Return the .debug_rnglists section to use for cu. */
1510 static struct dwarf2_section_info
*cu_debug_rnglists_section
1511 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1513 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1514 values. Keep the items ordered with increasing constraints compliance. */
1517 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1518 PC_BOUNDS_NOT_PRESENT
,
1520 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1521 were present but they do not form a valid range of PC addresses. */
1524 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1527 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1531 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1532 CORE_ADDR
*, CORE_ADDR
*,
1536 static void get_scope_pc_bounds (struct die_info
*,
1537 CORE_ADDR
*, CORE_ADDR
*,
1538 struct dwarf2_cu
*);
1540 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1541 CORE_ADDR
, struct dwarf2_cu
*);
1543 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1544 struct dwarf2_cu
*);
1546 static void dwarf2_attach_fields_to_type (struct field_info
*,
1547 struct type
*, struct dwarf2_cu
*);
1549 static void dwarf2_add_member_fn (struct field_info
*,
1550 struct die_info
*, struct type
*,
1551 struct dwarf2_cu
*);
1553 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1555 struct dwarf2_cu
*);
1557 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1559 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1561 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1563 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1565 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1567 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1569 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1571 static struct type
*read_module_type (struct die_info
*die
,
1572 struct dwarf2_cu
*cu
);
1574 static const char *namespace_name (struct die_info
*die
,
1575 int *is_anonymous
, struct dwarf2_cu
*);
1577 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1579 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1582 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1583 struct dwarf2_cu
*);
1585 static struct die_info
*read_die_and_siblings_1
1586 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1589 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1590 const gdb_byte
*info_ptr
,
1591 const gdb_byte
**new_info_ptr
,
1592 struct die_info
*parent
);
1594 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1595 struct die_info
**, const gdb_byte
*,
1598 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1599 struct die_info
**, const gdb_byte
*);
1601 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1603 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1606 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1608 static const char *dwarf2_full_name (const char *name
,
1609 struct die_info
*die
,
1610 struct dwarf2_cu
*cu
);
1612 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1613 struct dwarf2_cu
*cu
);
1615 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1616 struct dwarf2_cu
**);
1618 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1620 static void dump_die_for_error (struct die_info
*);
1622 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1625 /*static*/ void dump_die (struct die_info
*, int max_level
);
1627 static void store_in_ref_table (struct die_info
*,
1628 struct dwarf2_cu
*);
1630 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1631 const struct attribute
*,
1632 struct dwarf2_cu
**);
1634 static struct die_info
*follow_die_ref (struct die_info
*,
1635 const struct attribute
*,
1636 struct dwarf2_cu
**);
1638 static struct die_info
*follow_die_sig (struct die_info
*,
1639 const struct attribute
*,
1640 struct dwarf2_cu
**);
1642 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1643 struct dwarf2_cu
*);
1645 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1646 const struct attribute
*,
1647 struct dwarf2_cu
*);
1649 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1650 dwarf2_per_objfile
*per_objfile
);
1652 static void read_signatured_type (signatured_type
*sig_type
,
1653 dwarf2_per_objfile
*per_objfile
);
1655 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1656 struct die_info
*die
, struct dwarf2_cu
*cu
,
1657 struct dynamic_prop
*prop
, struct type
*type
);
1659 /* memory allocation interface */
1661 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1663 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1665 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1667 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1668 struct dwarf2_loclist_baton
*baton
,
1669 const struct attribute
*attr
);
1671 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1673 struct dwarf2_cu
*cu
,
1676 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1677 const gdb_byte
*info_ptr
,
1678 const struct abbrev_info
*abbrev
);
1680 static hashval_t
partial_die_hash (const void *item
);
1682 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1684 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1685 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1686 dwarf2_per_objfile
*per_objfile
);
1688 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1689 struct die_info
*comp_unit_die
,
1690 enum language pretend_language
);
1692 static struct type
*set_die_type (struct die_info
*, struct type
*,
1693 struct dwarf2_cu
*, bool = false);
1695 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1697 static int create_all_type_units (dwarf2_per_objfile
*per_objfile
);
1699 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1700 dwarf2_per_objfile
*per_objfile
,
1701 dwarf2_cu
*existing_cu
,
1703 enum language pretend_language
);
1705 static void process_full_comp_unit (dwarf2_cu
*cu
,
1706 enum language pretend_language
);
1708 static void process_full_type_unit (dwarf2_cu
*cu
,
1709 enum language pretend_language
);
1711 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1712 struct dwarf2_per_cu_data
*);
1714 static void dwarf2_mark (struct dwarf2_cu
*);
1716 static struct type
*get_die_type_at_offset (sect_offset
,
1717 dwarf2_per_cu_data
*per_cu
,
1718 dwarf2_per_objfile
*per_objfile
);
1720 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1722 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1723 dwarf2_per_objfile
*per_objfile
,
1724 enum language pretend_language
);
1726 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1728 /* Class, the destructor of which frees all allocated queue entries. This
1729 will only have work to do if an error was thrown while processing the
1730 dwarf. If no error was thrown then the queue entries should have all
1731 been processed, and freed, as we went along. */
1733 class dwarf2_queue_guard
1736 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1737 : m_per_objfile (per_objfile
)
1739 gdb_assert (!m_per_objfile
->per_bfd
->queue
.has_value ());
1741 m_per_objfile
->per_bfd
->queue
.emplace ();
1744 /* Free any entries remaining on the queue. There should only be
1745 entries left if we hit an error while processing the dwarf. */
1746 ~dwarf2_queue_guard ()
1748 gdb_assert (m_per_objfile
->per_bfd
->queue
.has_value ());
1750 m_per_objfile
->per_bfd
->queue
.reset ();
1753 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1756 dwarf2_per_objfile
*m_per_objfile
;
1759 dwarf2_queue_item::~dwarf2_queue_item ()
1761 /* Anything still marked queued is likely to be in an
1762 inconsistent state, so discard it. */
1765 per_objfile
->remove_cu (per_cu
);
1770 /* The return type of find_file_and_directory. Note, the enclosed
1771 string pointers are only valid while this object is valid. */
1773 struct file_and_directory
1775 /* The filename. This is never NULL. */
1778 /* The compilation directory. NULL if not known. If we needed to
1779 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1780 points directly to the DW_AT_comp_dir string attribute owned by
1781 the obstack that owns the DIE. */
1782 const char *comp_dir
;
1784 /* If we needed to build a new string for comp_dir, this is what
1785 owns the storage. */
1786 std::string comp_dir_storage
;
1789 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1790 struct dwarf2_cu
*cu
);
1792 static htab_up
allocate_signatured_type_table ();
1794 static htab_up
allocate_dwo_unit_table ();
1796 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1797 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1798 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1800 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1802 static struct dwo_unit
*lookup_dwo_comp_unit
1803 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1804 ULONGEST signature
);
1806 static struct dwo_unit
*lookup_dwo_type_unit
1807 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1809 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1811 /* A unique pointer to a dwo_file. */
1813 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1815 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1817 static void check_producer (struct dwarf2_cu
*cu
);
1819 static void free_line_header_voidp (void *arg
);
1821 /* Various complaints about symbol reading that don't abort the process. */
1824 dwarf2_debug_line_missing_file_complaint (void)
1826 complaint (_(".debug_line section has line data without a file"));
1830 dwarf2_debug_line_missing_end_sequence_complaint (void)
1832 complaint (_(".debug_line section has line "
1833 "program sequence without an end"));
1837 dwarf2_complex_location_expr_complaint (void)
1839 complaint (_("location expression too complex"));
1843 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1846 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1851 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1853 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1857 /* Hash function for line_header_hash. */
1860 line_header_hash (const struct line_header
*ofs
)
1862 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1865 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1868 line_header_hash_voidp (const void *item
)
1870 const struct line_header
*ofs
= (const struct line_header
*) item
;
1872 return line_header_hash (ofs
);
1875 /* Equality function for line_header_hash. */
1878 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1880 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1881 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1883 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1884 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1889 /* See declaration. */
1891 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1894 can_copy (can_copy_
)
1897 names
= &dwarf2_elf_names
;
1899 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1900 locate_sections (obfd
, sec
, *names
);
1903 dwarf2_per_bfd::~dwarf2_per_bfd ()
1905 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1906 per_cu
->imported_symtabs_free ();
1908 for (signatured_type
*sig_type
: all_type_units
)
1909 sig_type
->per_cu
.imported_symtabs_free ();
1911 /* Everything else should be on this->obstack. */
1917 dwarf2_per_objfile::remove_all_cus ()
1919 gdb_assert (!this->per_bfd
->queue
.has_value ());
1921 for (auto pair
: m_dwarf2_cus
)
1924 m_dwarf2_cus
.clear ();
1927 /* A helper class that calls free_cached_comp_units on
1930 class free_cached_comp_units
1934 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1935 : m_per_objfile (per_objfile
)
1939 ~free_cached_comp_units ()
1941 m_per_objfile
->remove_all_cus ();
1944 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1948 dwarf2_per_objfile
*m_per_objfile
;
1954 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1956 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1958 return this->m_symtabs
[per_cu
->index
] != nullptr;
1964 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1966 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1968 return this->m_symtabs
[per_cu
->index
];
1974 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1975 compunit_symtab
*symtab
)
1977 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1978 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1980 this->m_symtabs
[per_cu
->index
] = symtab
;
1983 /* Try to locate the sections we need for DWARF 2 debugging
1984 information and return true if we have enough to do something.
1985 NAMES points to the dwarf2 section names, or is NULL if the standard
1986 ELF names are used. CAN_COPY is true for formats where symbol
1987 interposition is possible and so symbol values must follow copy
1988 relocation rules. */
1991 dwarf2_has_info (struct objfile
*objfile
,
1992 const struct dwarf2_debug_sections
*names
,
1995 if (objfile
->flags
& OBJF_READNEVER
)
1998 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2000 if (per_objfile
== NULL
)
2002 dwarf2_per_bfd
*per_bfd
;
2004 /* We can share a "dwarf2_per_bfd" with other objfiles if the
2005 BFD doesn't require relocations.
2007 We don't share with objfiles for which -readnow was requested,
2008 because it would complicate things when loading the same BFD with
2009 -readnow and then without -readnow. */
2010 if (!gdb_bfd_requires_relocations (objfile
->obfd
)
2011 && (objfile
->flags
& OBJF_READNOW
) == 0)
2013 /* See if one has been created for this BFD yet. */
2014 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
2016 if (per_bfd
== nullptr)
2018 /* No, create it now. */
2019 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
2020 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
2025 /* No sharing possible, create one specifically for this objfile. */
2026 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
2027 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
2030 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
2033 return (!per_objfile
->per_bfd
->info
.is_virtual
2034 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
2035 && !per_objfile
->per_bfd
->abbrev
.is_virtual
2036 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
2039 /* See declaration. */
2042 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
2043 const dwarf2_debug_sections
&names
)
2045 flagword aflag
= bfd_section_flags (sectp
);
2047 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2050 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2051 > bfd_get_file_size (abfd
))
2053 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2054 warning (_("Discarding section %s which has a section size (%s"
2055 ") larger than the file size [in module %s]"),
2056 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2057 bfd_get_filename (abfd
));
2059 else if (names
.info
.matches (sectp
->name
))
2061 this->info
.s
.section
= sectp
;
2062 this->info
.size
= bfd_section_size (sectp
);
2064 else if (names
.abbrev
.matches (sectp
->name
))
2066 this->abbrev
.s
.section
= sectp
;
2067 this->abbrev
.size
= bfd_section_size (sectp
);
2069 else if (names
.line
.matches (sectp
->name
))
2071 this->line
.s
.section
= sectp
;
2072 this->line
.size
= bfd_section_size (sectp
);
2074 else if (names
.loc
.matches (sectp
->name
))
2076 this->loc
.s
.section
= sectp
;
2077 this->loc
.size
= bfd_section_size (sectp
);
2079 else if (names
.loclists
.matches (sectp
->name
))
2081 this->loclists
.s
.section
= sectp
;
2082 this->loclists
.size
= bfd_section_size (sectp
);
2084 else if (names
.macinfo
.matches (sectp
->name
))
2086 this->macinfo
.s
.section
= sectp
;
2087 this->macinfo
.size
= bfd_section_size (sectp
);
2089 else if (names
.macro
.matches (sectp
->name
))
2091 this->macro
.s
.section
= sectp
;
2092 this->macro
.size
= bfd_section_size (sectp
);
2094 else if (names
.str
.matches (sectp
->name
))
2096 this->str
.s
.section
= sectp
;
2097 this->str
.size
= bfd_section_size (sectp
);
2099 else if (names
.str_offsets
.matches (sectp
->name
))
2101 this->str_offsets
.s
.section
= sectp
;
2102 this->str_offsets
.size
= bfd_section_size (sectp
);
2104 else if (names
.line_str
.matches (sectp
->name
))
2106 this->line_str
.s
.section
= sectp
;
2107 this->line_str
.size
= bfd_section_size (sectp
);
2109 else if (names
.addr
.matches (sectp
->name
))
2111 this->addr
.s
.section
= sectp
;
2112 this->addr
.size
= bfd_section_size (sectp
);
2114 else if (names
.frame
.matches (sectp
->name
))
2116 this->frame
.s
.section
= sectp
;
2117 this->frame
.size
= bfd_section_size (sectp
);
2119 else if (names
.eh_frame
.matches (sectp
->name
))
2121 this->eh_frame
.s
.section
= sectp
;
2122 this->eh_frame
.size
= bfd_section_size (sectp
);
2124 else if (names
.ranges
.matches (sectp
->name
))
2126 this->ranges
.s
.section
= sectp
;
2127 this->ranges
.size
= bfd_section_size (sectp
);
2129 else if (names
.rnglists
.matches (sectp
->name
))
2131 this->rnglists
.s
.section
= sectp
;
2132 this->rnglists
.size
= bfd_section_size (sectp
);
2134 else if (names
.types
.matches (sectp
->name
))
2136 struct dwarf2_section_info type_section
;
2138 memset (&type_section
, 0, sizeof (type_section
));
2139 type_section
.s
.section
= sectp
;
2140 type_section
.size
= bfd_section_size (sectp
);
2142 this->types
.push_back (type_section
);
2144 else if (names
.gdb_index
.matches (sectp
->name
))
2146 this->gdb_index
.s
.section
= sectp
;
2147 this->gdb_index
.size
= bfd_section_size (sectp
);
2149 else if (names
.debug_names
.matches (sectp
->name
))
2151 this->debug_names
.s
.section
= sectp
;
2152 this->debug_names
.size
= bfd_section_size (sectp
);
2154 else if (names
.debug_aranges
.matches (sectp
->name
))
2156 this->debug_aranges
.s
.section
= sectp
;
2157 this->debug_aranges
.size
= bfd_section_size (sectp
);
2160 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2161 && bfd_section_vma (sectp
) == 0)
2162 this->has_section_at_zero
= true;
2165 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2169 dwarf2_get_section_info (struct objfile
*objfile
,
2170 enum dwarf2_section_enum sect
,
2171 asection
**sectp
, const gdb_byte
**bufp
,
2172 bfd_size_type
*sizep
)
2174 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2175 struct dwarf2_section_info
*info
;
2177 /* We may see an objfile without any DWARF, in which case we just
2179 if (per_objfile
== NULL
)
2188 case DWARF2_DEBUG_FRAME
:
2189 info
= &per_objfile
->per_bfd
->frame
;
2191 case DWARF2_EH_FRAME
:
2192 info
= &per_objfile
->per_bfd
->eh_frame
;
2195 gdb_assert_not_reached ("unexpected section");
2198 info
->read (objfile
);
2200 *sectp
= info
->get_bfd_section ();
2201 *bufp
= info
->buffer
;
2202 *sizep
= info
->size
;
2206 /* DWARF quick_symbol_functions support. */
2208 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2209 unique line tables, so we maintain a separate table of all .debug_line
2210 derived entries to support the sharing.
2211 All the quick functions need is the list of file names. We discard the
2212 line_header when we're done and don't need to record it here. */
2213 struct quick_file_names
2215 /* The data used to construct the hash key. */
2216 struct stmt_list_hash hash
;
2218 /* The number of entries in file_names, real_names. */
2219 unsigned int num_file_names
;
2221 /* The file names from the line table, after being run through
2223 const char **file_names
;
2225 /* The file names from the line table after being run through
2226 gdb_realpath. These are computed lazily. */
2227 const char **real_names
;
2230 /* When using the index (and thus not using psymtabs), each CU has an
2231 object of this type. This is used to hold information needed by
2232 the various "quick" methods. */
2233 struct dwarf2_per_cu_quick_data
2235 /* The file table. This can be NULL if there was no file table
2236 or it's currently not read in.
2237 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2238 struct quick_file_names
*file_names
;
2240 /* A temporary mark bit used when iterating over all CUs in
2241 expand_symtabs_matching. */
2242 unsigned int mark
: 1;
2244 /* True if we've tried to read the file table and found there isn't one.
2245 There will be no point in trying to read it again next time. */
2246 unsigned int no_file_data
: 1;
2249 /* A subclass of psymbol_functions that arranges to read the DWARF
2250 partial symbols when needed. */
2251 struct lazy_dwarf_reader
: public psymbol_functions
2253 using psymbol_functions::psymbol_functions
;
2255 bool can_lazily_read_symbols () override
2260 void read_partial_symbols (struct objfile
*objfile
) override
2262 if (dwarf2_has_info (objfile
, nullptr))
2263 dwarf2_build_psymtabs (objfile
, this);
2267 static quick_symbol_functions_up
2268 make_lazy_dwarf_reader ()
2270 return quick_symbol_functions_up (new lazy_dwarf_reader
);
2273 struct dwarf2_base_index_functions
: public quick_symbol_functions
2275 bool has_symbols (struct objfile
*objfile
) override
;
2277 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
2279 void forget_cached_source_info (struct objfile
*objfile
) override
;
2281 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
2284 bool *symbol_found_p
) override
2286 *symbol_found_p
= false;
2287 return language_unknown
;
2290 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
2292 void expand_all_symtabs (struct objfile
*objfile
) override
;
2294 struct compunit_symtab
*find_pc_sect_compunit_symtab
2295 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
2296 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
2298 struct compunit_symtab
*find_compunit_symtab_by_address
2299 (struct objfile
*objfile
, CORE_ADDR address
) override
2304 void map_symbol_filenames (struct objfile
*objfile
,
2305 gdb::function_view
<symbol_filename_ftype
> fun
,
2306 bool need_fullname
) override
;
2309 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
2311 void dump (struct objfile
*objfile
) override
;
2313 void expand_matching_symbols
2315 const lookup_name_info
&lookup_name
,
2318 symbol_compare_ftype
*ordered_compare
) override
;
2320 bool expand_symtabs_matching
2321 (struct objfile
*objfile
,
2322 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2323 const lookup_name_info
*lookup_name
,
2324 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2325 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2326 block_search_flags search_flags
,
2328 enum search_domain kind
) override
;
2331 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
2333 void dump (struct objfile
*objfile
) override
;
2335 void expand_matching_symbols
2337 const lookup_name_info
&lookup_name
,
2340 symbol_compare_ftype
*ordered_compare
) override
;
2342 bool expand_symtabs_matching
2343 (struct objfile
*objfile
,
2344 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2345 const lookup_name_info
*lookup_name
,
2346 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2347 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2348 block_search_flags search_flags
,
2350 enum search_domain kind
) override
;
2353 static quick_symbol_functions_up
2354 make_dwarf_gdb_index ()
2356 return quick_symbol_functions_up (new dwarf2_gdb_index
);
2359 static quick_symbol_functions_up
2360 make_dwarf_debug_names ()
2362 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
2365 /* Utility hash function for a stmt_list_hash. */
2368 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2372 if (stmt_list_hash
->dwo_unit
!= NULL
)
2373 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2374 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2378 /* Utility equality function for a stmt_list_hash. */
2381 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2382 const struct stmt_list_hash
*rhs
)
2384 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2386 if (lhs
->dwo_unit
!= NULL
2387 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2390 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2393 /* Hash function for a quick_file_names. */
2396 hash_file_name_entry (const void *e
)
2398 const struct quick_file_names
*file_data
2399 = (const struct quick_file_names
*) e
;
2401 return hash_stmt_list_entry (&file_data
->hash
);
2404 /* Equality function for a quick_file_names. */
2407 eq_file_name_entry (const void *a
, const void *b
)
2409 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2410 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2412 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2415 /* Delete function for a quick_file_names. */
2418 delete_file_name_entry (void *e
)
2420 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2423 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2425 xfree ((void*) file_data
->file_names
[i
]);
2426 if (file_data
->real_names
)
2427 xfree ((void*) file_data
->real_names
[i
]);
2430 /* The space for the struct itself lives on the obstack, so we don't
2434 /* Create a quick_file_names hash table. */
2437 create_quick_file_names_table (unsigned int nr_initial_entries
)
2439 return htab_up (htab_create_alloc (nr_initial_entries
,
2440 hash_file_name_entry
, eq_file_name_entry
,
2441 delete_file_name_entry
, xcalloc
, xfree
));
2444 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2445 function is unrelated to symtabs, symtab would have to be created afterwards.
2446 You should call age_cached_comp_units after processing the CU. */
2449 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2452 if (per_cu
->is_debug_types
)
2453 load_full_type_unit (per_cu
, per_objfile
);
2455 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2456 skip_partial
, language_minimal
);
2458 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2460 return nullptr; /* Dummy CU. */
2462 dwarf2_find_base_address (cu
->dies
, cu
);
2467 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2470 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2471 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2473 /* Skip type_unit_groups, reading the type units they contain
2474 is handled elsewhere. */
2475 if (per_cu
->type_unit_group_p ())
2479 /* The destructor of dwarf2_queue_guard frees any entries left on
2480 the queue. After this point we're guaranteed to leave this function
2481 with the dwarf queue empty. */
2482 dwarf2_queue_guard
q_guard (per_objfile
);
2484 if (!per_objfile
->symtab_set_p (per_cu
))
2486 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2487 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2489 /* If we just loaded a CU from a DWO, and we're working with an index
2490 that may badly handle TUs, load all the TUs in that DWO as well.
2491 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2492 if (!per_cu
->is_debug_types
2494 && cu
->dwo_unit
!= NULL
2495 && per_objfile
->per_bfd
->index_table
!= NULL
2496 && per_objfile
->per_bfd
->index_table
->version
<= 7
2497 /* DWP files aren't supported yet. */
2498 && get_dwp_file (per_objfile
) == NULL
)
2499 queue_and_load_all_dwo_tus (cu
);
2502 process_queue (per_objfile
);
2505 /* Age the cache, releasing compilation units that have not
2506 been used recently. */
2507 per_objfile
->age_comp_units ();
2510 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2511 the per-objfile for which this symtab is instantiated.
2513 Returns the resulting symbol table. */
2515 static struct compunit_symtab
*
2516 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2517 dwarf2_per_objfile
*per_objfile
,
2520 gdb_assert (per_objfile
->per_bfd
->using_index
);
2522 if (!per_objfile
->symtab_set_p (per_cu
))
2524 free_cached_comp_units
freer (per_objfile
);
2525 scoped_restore decrementer
= increment_reading_symtab ();
2526 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2527 process_cu_includes (per_objfile
);
2530 return per_objfile
->get_symtab (per_cu
);
2533 /* See declaration. */
2535 dwarf2_per_cu_data
*
2536 dwarf2_per_bfd::get_cutu (int index
)
2538 if (index
>= this->all_comp_units
.size ())
2540 index
-= this->all_comp_units
.size ();
2541 gdb_assert (index
< this->all_type_units
.size ());
2542 return &this->all_type_units
[index
]->per_cu
;
2545 return this->all_comp_units
[index
];
2548 /* See declaration. */
2550 dwarf2_per_cu_data
*
2551 dwarf2_per_bfd::get_cu (int index
)
2553 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2555 return this->all_comp_units
[index
];
2558 /* See declaration. */
2561 dwarf2_per_bfd::get_tu (int index
)
2563 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2565 return this->all_type_units
[index
];
2570 dwarf2_per_cu_data
*
2571 dwarf2_per_bfd::allocate_per_cu ()
2573 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2574 result
->per_bfd
= this;
2575 result
->index
= m_num_psymtabs
++;
2582 dwarf2_per_bfd::allocate_signatured_type ()
2584 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2585 result
->per_cu
.per_bfd
= this;
2586 result
->per_cu
.index
= m_num_psymtabs
++;
2590 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2591 obstack, and constructed with the specified field values. */
2593 static dwarf2_per_cu_data
*
2594 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2595 struct dwarf2_section_info
*section
,
2597 sect_offset sect_off
, ULONGEST length
)
2599 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2600 the_cu
->sect_off
= sect_off
;
2601 the_cu
->length
= length
;
2602 the_cu
->section
= section
;
2603 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2604 struct dwarf2_per_cu_quick_data
);
2605 the_cu
->is_dwz
= is_dwz
;
2609 /* A helper for create_cus_from_index that handles a given list of
2613 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2614 const gdb_byte
*cu_list
, offset_type n_elements
,
2615 struct dwarf2_section_info
*section
,
2618 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2620 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2622 sect_offset sect_off
2623 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2624 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2627 dwarf2_per_cu_data
*per_cu
2628 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2630 per_bfd
->all_comp_units
.push_back (per_cu
);
2634 /* Read the CU list from the mapped index, and use it to create all
2635 the CU objects for PER_BFD. */
2638 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2639 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2640 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2642 gdb_assert (per_bfd
->all_comp_units
.empty ());
2643 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2645 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2648 if (dwz_elements
== 0)
2651 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2652 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2656 /* Create the signatured type hash table from the index. */
2659 create_signatured_type_table_from_index
2660 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2661 const gdb_byte
*bytes
, offset_type elements
)
2663 gdb_assert (per_bfd
->all_type_units
.empty ());
2664 per_bfd
->all_type_units
.reserve (elements
/ 3);
2666 htab_up sig_types_hash
= allocate_signatured_type_table ();
2668 for (offset_type i
= 0; i
< elements
; i
+= 3)
2670 struct signatured_type
*sig_type
;
2673 cu_offset type_offset_in_tu
;
2675 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2676 sect_offset sect_off
2677 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2679 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2681 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2684 sig_type
= per_bfd
->allocate_signatured_type ();
2685 sig_type
->signature
= signature
;
2686 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2687 sig_type
->per_cu
.is_debug_types
= 1;
2688 sig_type
->per_cu
.section
= section
;
2689 sig_type
->per_cu
.sect_off
= sect_off
;
2690 sig_type
->per_cu
.v
.quick
2691 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2692 struct dwarf2_per_cu_quick_data
);
2694 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2697 per_bfd
->all_type_units
.push_back (sig_type
);
2700 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2703 /* Create the signatured type hash table from .debug_names. */
2706 create_signatured_type_table_from_debug_names
2707 (dwarf2_per_objfile
*per_objfile
,
2708 const mapped_debug_names
&map
,
2709 struct dwarf2_section_info
*section
,
2710 struct dwarf2_section_info
*abbrev_section
)
2712 struct objfile
*objfile
= per_objfile
->objfile
;
2714 section
->read (objfile
);
2715 abbrev_section
->read (objfile
);
2717 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
2718 per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2720 htab_up sig_types_hash
= allocate_signatured_type_table ();
2722 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2724 struct signatured_type
*sig_type
;
2727 sect_offset sect_off
2728 = (sect_offset
) (extract_unsigned_integer
2729 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2731 map
.dwarf5_byte_order
));
2733 comp_unit_head cu_header
;
2734 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2736 section
->buffer
+ to_underlying (sect_off
),
2739 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2740 sig_type
->signature
= cu_header
.signature
;
2741 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2742 sig_type
->per_cu
.is_debug_types
= 1;
2743 sig_type
->per_cu
.section
= section
;
2744 sig_type
->per_cu
.sect_off
= sect_off
;
2745 sig_type
->per_cu
.v
.quick
2746 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2747 struct dwarf2_per_cu_quick_data
);
2749 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2752 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2755 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2758 /* Read the address map data from the mapped index, and use it to
2759 populate the psymtabs_addrmap. */
2762 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2763 struct mapped_index
*index
)
2765 struct objfile
*objfile
= per_objfile
->objfile
;
2766 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2767 struct gdbarch
*gdbarch
= objfile
->arch ();
2768 const gdb_byte
*iter
, *end
;
2769 struct addrmap
*mutable_map
;
2772 auto_obstack temp_obstack
;
2774 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2776 iter
= index
->address_table
.data ();
2777 end
= iter
+ index
->address_table
.size ();
2779 baseaddr
= objfile
->text_section_offset ();
2783 ULONGEST hi
, lo
, cu_index
;
2784 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2786 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2788 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2793 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2794 hex_string (lo
), hex_string (hi
));
2798 if (cu_index
>= per_bfd
->all_comp_units
.size ())
2800 complaint (_(".gdb_index address table has invalid CU number %u"),
2801 (unsigned) cu_index
);
2805 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2806 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2807 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2808 per_bfd
->get_cu (cu_index
));
2811 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2815 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2816 populate the psymtabs_addrmap. */
2819 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2820 struct dwarf2_section_info
*section
)
2822 struct objfile
*objfile
= per_objfile
->objfile
;
2823 bfd
*abfd
= objfile
->obfd
;
2824 struct gdbarch
*gdbarch
= objfile
->arch ();
2825 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2826 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2828 auto_obstack temp_obstack
;
2829 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2831 std::unordered_map
<sect_offset
,
2832 dwarf2_per_cu_data
*,
2833 gdb::hash_enum
<sect_offset
>>
2834 debug_info_offset_to_per_cu
;
2835 for (dwarf2_per_cu_data
*per_cu
: per_bfd
->all_comp_units
)
2837 const auto insertpair
2838 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2839 if (!insertpair
.second
)
2841 warning (_("Section .debug_aranges in %s has duplicate "
2842 "debug_info_offset %s, ignoring .debug_aranges."),
2843 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2848 section
->read (objfile
);
2850 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2852 const gdb_byte
*addr
= section
->buffer
;
2854 while (addr
< section
->buffer
+ section
->size
)
2856 const gdb_byte
*const entry_addr
= addr
;
2857 unsigned int bytes_read
;
2859 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2863 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2864 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2865 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2866 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2868 warning (_("Section .debug_aranges in %s entry at offset %s "
2869 "length %s exceeds section length %s, "
2870 "ignoring .debug_aranges."),
2871 objfile_name (objfile
),
2872 plongest (entry_addr
- section
->buffer
),
2873 plongest (bytes_read
+ entry_length
),
2874 pulongest (section
->size
));
2878 /* The version number. */
2879 const uint16_t version
= read_2_bytes (abfd
, addr
);
2883 warning (_("Section .debug_aranges in %s entry at offset %s "
2884 "has unsupported version %d, ignoring .debug_aranges."),
2885 objfile_name (objfile
),
2886 plongest (entry_addr
- section
->buffer
), version
);
2890 const uint64_t debug_info_offset
2891 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2892 addr
+= offset_size
;
2893 const auto per_cu_it
2894 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2895 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2897 warning (_("Section .debug_aranges in %s entry at offset %s "
2898 "debug_info_offset %s does not exists, "
2899 "ignoring .debug_aranges."),
2900 objfile_name (objfile
),
2901 plongest (entry_addr
- section
->buffer
),
2902 pulongest (debug_info_offset
));
2905 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2907 const uint8_t address_size
= *addr
++;
2908 if (address_size
< 1 || address_size
> 8)
2910 warning (_("Section .debug_aranges in %s entry at offset %s "
2911 "address_size %u is invalid, ignoring .debug_aranges."),
2912 objfile_name (objfile
),
2913 plongest (entry_addr
- section
->buffer
), address_size
);
2917 const uint8_t segment_selector_size
= *addr
++;
2918 if (segment_selector_size
!= 0)
2920 warning (_("Section .debug_aranges in %s entry at offset %s "
2921 "segment_selector_size %u is not supported, "
2922 "ignoring .debug_aranges."),
2923 objfile_name (objfile
),
2924 plongest (entry_addr
- section
->buffer
),
2925 segment_selector_size
);
2929 /* Must pad to an alignment boundary that is twice the address
2930 size. It is undocumented by the DWARF standard but GCC does
2932 for (size_t padding
= ((-(addr
- section
->buffer
))
2933 & (2 * address_size
- 1));
2934 padding
> 0; padding
--)
2937 warning (_("Section .debug_aranges in %s entry at offset %s "
2938 "padding is not zero, ignoring .debug_aranges."),
2939 objfile_name (objfile
),
2940 plongest (entry_addr
- section
->buffer
));
2946 if (addr
+ 2 * address_size
> entry_end
)
2948 warning (_("Section .debug_aranges in %s entry at offset %s "
2949 "address list is not properly terminated, "
2950 "ignoring .debug_aranges."),
2951 objfile_name (objfile
),
2952 plongest (entry_addr
- section
->buffer
));
2955 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2957 addr
+= address_size
;
2958 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2960 addr
+= address_size
;
2961 if (start
== 0 && length
== 0)
2963 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2965 /* Symbol was eliminated due to a COMDAT group. */
2968 ULONGEST end
= start
+ length
;
2969 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2971 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2973 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2977 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2981 /* A helper function that reads the .gdb_index from BUFFER and fills
2982 in MAP. FILENAME is the name of the file containing the data;
2983 it is used for error reporting. DEPRECATED_OK is true if it is
2984 ok to use deprecated sections.
2986 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2987 out parameters that are filled in with information about the CU and
2988 TU lists in the section.
2990 Returns true if all went well, false otherwise. */
2993 read_gdb_index_from_buffer (const char *filename
,
2995 gdb::array_view
<const gdb_byte
> buffer
,
2996 struct mapped_index
*map
,
2997 const gdb_byte
**cu_list
,
2998 offset_type
*cu_list_elements
,
2999 const gdb_byte
**types_list
,
3000 offset_type
*types_list_elements
)
3002 const gdb_byte
*addr
= &buffer
[0];
3003 offset_view
metadata (buffer
);
3005 /* Version check. */
3006 offset_type version
= metadata
[0];
3007 /* Versions earlier than 3 emitted every copy of a psymbol. This
3008 causes the index to behave very poorly for certain requests. Version 3
3009 contained incomplete addrmap. So, it seems better to just ignore such
3013 static int warning_printed
= 0;
3014 if (!warning_printed
)
3016 warning (_("Skipping obsolete .gdb_index section in %s."),
3018 warning_printed
= 1;
3022 /* Index version 4 uses a different hash function than index version
3025 Versions earlier than 6 did not emit psymbols for inlined
3026 functions. Using these files will cause GDB not to be able to
3027 set breakpoints on inlined functions by name, so we ignore these
3028 indices unless the user has done
3029 "set use-deprecated-index-sections on". */
3030 if (version
< 6 && !deprecated_ok
)
3032 static int warning_printed
= 0;
3033 if (!warning_printed
)
3036 Skipping deprecated .gdb_index section in %s.\n\
3037 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3038 to use the section anyway."),
3040 warning_printed
= 1;
3044 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3045 of the TU (for symbols coming from TUs),
3046 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3047 Plus gold-generated indices can have duplicate entries for global symbols,
3048 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3049 These are just performance bugs, and we can't distinguish gdb-generated
3050 indices from gold-generated ones, so issue no warning here. */
3052 /* Indexes with higher version than the one supported by GDB may be no
3053 longer backward compatible. */
3057 map
->version
= version
;
3060 *cu_list
= addr
+ metadata
[i
];
3061 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
3064 *types_list
= addr
+ metadata
[i
];
3065 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
3068 const gdb_byte
*address_table
= addr
+ metadata
[i
];
3069 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
3071 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3074 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
3075 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
3077 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
3081 map
->constant_pool
= buffer
.slice (metadata
[i
]);
3086 /* Callback types for dwarf2_read_gdb_index. */
3088 typedef gdb::function_view
3089 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3090 get_gdb_index_contents_ftype
;
3091 typedef gdb::function_view
3092 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3093 get_gdb_index_contents_dwz_ftype
;
3095 /* Read .gdb_index. If everything went ok, initialize the "quick"
3096 elements of all the CUs and return 1. Otherwise, return 0. */
3099 dwarf2_read_gdb_index
3100 (dwarf2_per_objfile
*per_objfile
,
3101 get_gdb_index_contents_ftype get_gdb_index_contents
,
3102 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3104 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3105 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3106 struct dwz_file
*dwz
;
3107 struct objfile
*objfile
= per_objfile
->objfile
;
3108 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3110 gdb::array_view
<const gdb_byte
> main_index_contents
3111 = get_gdb_index_contents (objfile
, per_bfd
);
3113 if (main_index_contents
.empty ())
3116 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3117 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3118 use_deprecated_index_sections
,
3119 main_index_contents
, map
.get (), &cu_list
,
3120 &cu_list_elements
, &types_list
,
3121 &types_list_elements
))
3124 /* Don't use the index if it's empty. */
3125 if (map
->symbol_table
.empty ())
3128 /* If there is a .dwz file, read it so we can get its CU list as
3130 dwz
= dwarf2_get_dwz_file (per_bfd
);
3133 struct mapped_index dwz_map
;
3134 const gdb_byte
*dwz_types_ignore
;
3135 offset_type dwz_types_elements_ignore
;
3137 gdb::array_view
<const gdb_byte
> dwz_index_content
3138 = get_gdb_index_contents_dwz (objfile
, dwz
);
3140 if (dwz_index_content
.empty ())
3143 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3144 1, dwz_index_content
, &dwz_map
,
3145 &dwz_list
, &dwz_list_elements
,
3147 &dwz_types_elements_ignore
))
3149 warning (_("could not read '.gdb_index' section from %s; skipping"),
3150 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3155 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
3158 if (types_list_elements
)
3160 /* We can only handle a single .debug_types when we have an
3162 if (per_bfd
->types
.size () != 1)
3165 dwarf2_section_info
*section
= &per_bfd
->types
[0];
3167 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
3168 types_list_elements
);
3171 create_addrmap_from_index (per_objfile
, map
.get ());
3173 per_bfd
->index_table
= std::move (map
);
3174 per_bfd
->using_index
= 1;
3175 per_bfd
->quick_file_names_table
=
3176 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
3181 /* die_reader_func for dw2_get_file_names. */
3184 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3185 struct die_info
*comp_unit_die
)
3187 struct dwarf2_cu
*cu
= reader
->cu
;
3188 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3189 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3190 struct dwarf2_per_cu_data
*lh_cu
;
3191 struct attribute
*attr
;
3193 struct quick_file_names
*qfn
;
3195 gdb_assert (! this_cu
->is_debug_types
);
3197 /* Our callers never want to match partial units -- instead they
3198 will match the enclosing full CU. */
3199 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3201 this_cu
->v
.quick
->no_file_data
= 1;
3209 sect_offset line_offset
{};
3211 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3212 if (attr
!= nullptr && attr
->form_is_unsigned ())
3214 struct quick_file_names find_entry
;
3216 line_offset
= (sect_offset
) attr
->as_unsigned ();
3218 /* We may have already read in this line header (TU line header sharing).
3219 If we have we're done. */
3220 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3221 find_entry
.hash
.line_sect_off
= line_offset
;
3222 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3223 &find_entry
, INSERT
);
3226 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3230 lh
= dwarf_decode_line_header (line_offset
, cu
);
3234 lh_cu
->v
.quick
->no_file_data
= 1;
3238 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3239 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3240 qfn
->hash
.line_sect_off
= line_offset
;
3241 gdb_assert (slot
!= NULL
);
3244 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3247 if (strcmp (fnd
.name
, "<unknown>") != 0)
3250 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3252 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3253 qfn
->num_file_names
);
3255 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3256 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3257 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3258 fnd
.comp_dir
).release ();
3259 qfn
->real_names
= NULL
;
3261 lh_cu
->v
.quick
->file_names
= qfn
;
3264 /* A helper for the "quick" functions which attempts to read the line
3265 table for THIS_CU. */
3267 static struct quick_file_names
*
3268 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3269 dwarf2_per_objfile
*per_objfile
)
3271 /* This should never be called for TUs. */
3272 gdb_assert (! this_cu
->is_debug_types
);
3273 /* Nor type unit groups. */
3274 gdb_assert (! this_cu
->type_unit_group_p ());
3276 if (this_cu
->v
.quick
->file_names
!= NULL
)
3277 return this_cu
->v
.quick
->file_names
;
3278 /* If we know there is no line data, no point in looking again. */
3279 if (this_cu
->v
.quick
->no_file_data
)
3282 cutu_reader
reader (this_cu
, per_objfile
);
3283 if (!reader
.dummy_p
)
3284 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
3286 if (this_cu
->v
.quick
->no_file_data
)
3288 return this_cu
->v
.quick
->file_names
;
3291 /* A helper for the "quick" functions which computes and caches the
3292 real path for a given file name from the line table. */
3295 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3296 struct quick_file_names
*qfn
, int index
)
3298 if (qfn
->real_names
== NULL
)
3299 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3300 qfn
->num_file_names
, const char *);
3302 if (qfn
->real_names
[index
] == NULL
)
3303 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3305 return qfn
->real_names
[index
];
3309 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3311 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3312 dwarf2_per_cu_data
*dwarf_cu
= per_objfile
->per_bfd
->all_comp_units
.back ();
3313 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3318 return compunit_primary_filetab (cust
);
3321 /* Traversal function for dw2_forget_cached_source_info. */
3324 dw2_free_cached_file_names (void **slot
, void *info
)
3326 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3328 if (file_data
->real_names
)
3332 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3334 xfree ((void*) file_data
->real_names
[i
]);
3335 file_data
->real_names
[i
] = NULL
;
3343 dwarf2_base_index_functions::forget_cached_source_info
3344 (struct objfile
*objfile
)
3346 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3348 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3349 dw2_free_cached_file_names
, NULL
);
3352 /* Struct used to manage iterating over all CUs looking for a symbol. */
3354 struct dw2_symtab_iterator
3356 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3357 dwarf2_per_objfile
*per_objfile
;
3358 /* If set, only look for symbols that match that block. Valid values are
3359 GLOBAL_BLOCK and STATIC_BLOCK. */
3360 gdb::optional
<block_enum
> block_index
;
3361 /* The kind of symbol we're looking for. */
3363 /* The list of CUs from the index entry of the symbol,
3364 or NULL if not found. */
3366 /* The next element in VEC to look at. */
3368 /* The number of elements in VEC, or zero if there is no match. */
3370 /* Have we seen a global version of the symbol?
3371 If so we can ignore all further global instances.
3372 This is to work around gold/15646, inefficient gold-generated
3377 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3380 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3381 dwarf2_per_objfile
*per_objfile
,
3382 gdb::optional
<block_enum
> block_index
,
3383 domain_enum domain
, offset_type namei
)
3385 iter
->per_objfile
= per_objfile
;
3386 iter
->block_index
= block_index
;
3387 iter
->domain
= domain
;
3389 iter
->global_seen
= 0;
3393 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3394 /* index is NULL if OBJF_READNOW. */
3398 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3399 offset_type vec_idx
= index
->symbol_vec_index (namei
);
3401 iter
->vec
= offset_view (index
->constant_pool
.slice (vec_idx
));
3402 iter
->length
= iter
->vec
[0];
3405 /* Return the next matching CU or NULL if there are no more. */
3407 static struct dwarf2_per_cu_data
*
3408 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3410 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3412 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3414 offset_type cu_index_and_attrs
= iter
->vec
[iter
->next
+ 1];
3415 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3416 gdb_index_symbol_kind symbol_kind
=
3417 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3418 /* Only check the symbol attributes if they're present.
3419 Indices prior to version 7 don't record them,
3420 and indices >= 7 may elide them for certain symbols
3421 (gold does this). */
3423 (per_objfile
->per_bfd
->index_table
->version
>= 7
3424 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3426 /* Don't crash on bad data. */
3427 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
3428 + per_objfile
->per_bfd
->all_type_units
.size ()))
3430 complaint (_(".gdb_index entry has bad CU index"
3431 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3435 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
3437 /* Skip if already read in. */
3438 if (per_objfile
->symtab_set_p (per_cu
))
3441 /* Check static vs global. */
3444 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3446 if (iter
->block_index
.has_value ())
3448 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3450 if (is_static
!= want_static
)
3454 /* Work around gold/15646. */
3456 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3458 if (iter
->global_seen
)
3461 iter
->global_seen
= 1;
3465 /* Only check the symbol's kind if it has one. */
3468 switch (iter
->domain
)
3471 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3472 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3473 /* Some types are also in VAR_DOMAIN. */
3474 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3478 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3482 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3486 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3502 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
3508 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3509 int total
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3510 + per_objfile
->per_bfd
->all_type_units
.size ());
3513 for (int i
= 0; i
< total
; ++i
)
3515 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3517 if (!per_objfile
->symtab_set_p (per_cu
))
3520 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3521 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3524 /* This dumps minimal information about the index.
3525 It is called via "mt print objfiles".
3526 One use is to verify .gdb_index has been loaded by the
3527 gdb.dwarf2/gdb-index.exp testcase. */
3530 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3532 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3534 gdb_assert (per_objfile
->per_bfd
->using_index
);
3535 printf_filtered (".gdb_index:");
3536 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3538 printf_filtered (" version %d\n",
3539 per_objfile
->per_bfd
->index_table
->version
);
3542 printf_filtered (" faked for \"readnow\"\n");
3543 printf_filtered ("\n");
3547 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3549 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3550 int total_units
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3551 + per_objfile
->per_bfd
->all_type_units
.size ());
3553 for (int i
= 0; i
< total_units
; ++i
)
3555 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3557 /* We don't want to directly expand a partial CU, because if we
3558 read it with the wrong language, then assertion failures can
3559 be triggered later on. See PR symtab/23010. So, tell
3560 dw2_instantiate_symtab to skip partial CUs -- any important
3561 partial CU will be read via DW_TAG_imported_unit anyway. */
3562 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3567 dw2_expand_symtabs_matching_symbol
3568 (mapped_index_base
&index
,
3569 const lookup_name_info
&lookup_name_in
,
3570 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3571 gdb::function_view
<bool (offset_type
)> match_callback
,
3572 dwarf2_per_objfile
*per_objfile
);
3575 dw2_expand_symtabs_matching_one
3576 (dwarf2_per_cu_data
*per_cu
,
3577 dwarf2_per_objfile
*per_objfile
,
3578 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3579 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3582 dwarf2_gdb_index::expand_matching_symbols
3583 (struct objfile
*objfile
,
3584 const lookup_name_info
&name
, domain_enum domain
,
3586 symbol_compare_ftype
*ordered_compare
)
3589 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3591 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3593 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3595 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3597 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3598 auto matcher
= [&] (const char *symname
)
3600 if (ordered_compare
== nullptr)
3602 return ordered_compare (symname
, match_name
) == 0;
3605 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
3606 [&] (offset_type namei
)
3608 struct dw2_symtab_iterator iter
;
3609 struct dwarf2_per_cu_data
*per_cu
;
3611 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3613 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3614 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3621 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3622 proceed assuming all symtabs have been read in. */
3626 /* Starting from a search name, return the string that finds the upper
3627 bound of all strings that start with SEARCH_NAME in a sorted name
3628 list. Returns the empty string to indicate that the upper bound is
3629 the end of the list. */
3632 make_sort_after_prefix_name (const char *search_name
)
3634 /* When looking to complete "func", we find the upper bound of all
3635 symbols that start with "func" by looking for where we'd insert
3636 the closest string that would follow "func" in lexicographical
3637 order. Usually, that's "func"-with-last-character-incremented,
3638 i.e. "fund". Mind non-ASCII characters, though. Usually those
3639 will be UTF-8 multi-byte sequences, but we can't be certain.
3640 Especially mind the 0xff character, which is a valid character in
3641 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3642 rule out compilers allowing it in identifiers. Note that
3643 conveniently, strcmp/strcasecmp are specified to compare
3644 characters interpreted as unsigned char. So what we do is treat
3645 the whole string as a base 256 number composed of a sequence of
3646 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3647 to 0, and carries 1 to the following more-significant position.
3648 If the very first character in SEARCH_NAME ends up incremented
3649 and carries/overflows, then the upper bound is the end of the
3650 list. The string after the empty string is also the empty
3653 Some examples of this operation:
3655 SEARCH_NAME => "+1" RESULT
3659 "\xff" "a" "\xff" => "\xff" "b"
3664 Then, with these symbols for example:
3670 completing "func" looks for symbols between "func" and
3671 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3672 which finds "func" and "func1", but not "fund".
3676 funcÿ (Latin1 'ÿ' [0xff])
3680 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3681 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3685 ÿÿ (Latin1 'ÿ' [0xff])
3688 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3689 the end of the list.
3691 std::string after
= search_name
;
3692 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3694 if (!after
.empty ())
3695 after
.back () = (unsigned char) after
.back () + 1;
3699 /* See declaration. */
3701 std::pair
<std::vector
<name_component
>::const_iterator
,
3702 std::vector
<name_component
>::const_iterator
>
3703 mapped_index_base::find_name_components_bounds
3704 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3705 dwarf2_per_objfile
*per_objfile
) const
3708 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3710 const char *lang_name
3711 = lookup_name_without_params
.language_lookup_name (lang
);
3713 /* Comparison function object for lower_bound that matches against a
3714 given symbol name. */
3715 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3718 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3719 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3720 return name_cmp (elem_name
, name
) < 0;
3723 /* Comparison function object for upper_bound that matches against a
3724 given symbol name. */
3725 auto lookup_compare_upper
= [&] (const char *name
,
3726 const name_component
&elem
)
3728 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3729 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3730 return name_cmp (name
, elem_name
) < 0;
3733 auto begin
= this->name_components
.begin ();
3734 auto end
= this->name_components
.end ();
3736 /* Find the lower bound. */
3739 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3742 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3745 /* Find the upper bound. */
3748 if (lookup_name_without_params
.completion_mode ())
3750 /* In completion mode, we want UPPER to point past all
3751 symbols names that have the same prefix. I.e., with
3752 these symbols, and completing "func":
3754 function << lower bound
3756 other_function << upper bound
3758 We find the upper bound by looking for the insertion
3759 point of "func"-with-last-character-incremented,
3761 std::string after
= make_sort_after_prefix_name (lang_name
);
3764 return std::lower_bound (lower
, end
, after
.c_str (),
3765 lookup_compare_lower
);
3768 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3771 return {lower
, upper
};
3774 /* See declaration. */
3777 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3779 if (!this->name_components
.empty ())
3782 this->name_components_casing
= case_sensitivity
;
3784 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3786 /* The code below only knows how to break apart components of C++
3787 symbol names (and other languages that use '::' as
3788 namespace/module separator) and Ada symbol names. */
3789 auto count
= this->symbol_name_count ();
3790 for (offset_type idx
= 0; idx
< count
; idx
++)
3792 if (this->symbol_name_slot_invalid (idx
))
3795 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3797 /* Add each name component to the name component table. */
3798 unsigned int previous_len
= 0;
3800 if (strstr (name
, "::") != nullptr)
3802 for (unsigned int current_len
= cp_find_first_component (name
);
3803 name
[current_len
] != '\0';
3804 current_len
+= cp_find_first_component (name
+ current_len
))
3806 gdb_assert (name
[current_len
] == ':');
3807 this->name_components
.push_back ({previous_len
, idx
});
3808 /* Skip the '::'. */
3810 previous_len
= current_len
;
3815 /* Handle the Ada encoded (aka mangled) form here. */
3816 for (const char *iter
= strstr (name
, "__");
3818 iter
= strstr (iter
, "__"))
3820 this->name_components
.push_back ({previous_len
, idx
});
3822 previous_len
= iter
- name
;
3826 this->name_components
.push_back ({previous_len
, idx
});
3829 /* Sort name_components elements by name. */
3830 auto name_comp_compare
= [&] (const name_component
&left
,
3831 const name_component
&right
)
3833 const char *left_qualified
3834 = this->symbol_name_at (left
.idx
, per_objfile
);
3835 const char *right_qualified
3836 = this->symbol_name_at (right
.idx
, per_objfile
);
3838 const char *left_name
= left_qualified
+ left
.name_offset
;
3839 const char *right_name
= right_qualified
+ right
.name_offset
;
3841 return name_cmp (left_name
, right_name
) < 0;
3844 std::sort (this->name_components
.begin (),
3845 this->name_components
.end (),
3849 /* Helper for dw2_expand_symtabs_matching that works with a
3850 mapped_index_base instead of the containing objfile. This is split
3851 to a separate function in order to be able to unit test the
3852 name_components matching using a mock mapped_index_base. For each
3853 symbol name that matches, calls MATCH_CALLBACK, passing it the
3854 symbol's index in the mapped_index_base symbol table. */
3857 dw2_expand_symtabs_matching_symbol
3858 (mapped_index_base
&index
,
3859 const lookup_name_info
&lookup_name_in
,
3860 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3861 gdb::function_view
<bool (offset_type
)> match_callback
,
3862 dwarf2_per_objfile
*per_objfile
)
3864 lookup_name_info lookup_name_without_params
3865 = lookup_name_in
.make_ignore_params ();
3867 /* Build the symbol name component sorted vector, if we haven't
3869 index
.build_name_components (per_objfile
);
3871 /* The same symbol may appear more than once in the range though.
3872 E.g., if we're looking for symbols that complete "w", and we have
3873 a symbol named "w1::w2", we'll find the two name components for
3874 that same symbol in the range. To be sure we only call the
3875 callback once per symbol, we first collect the symbol name
3876 indexes that matched in a temporary vector and ignore
3878 std::vector
<offset_type
> matches
;
3880 struct name_and_matcher
3882 symbol_name_matcher_ftype
*matcher
;
3885 bool operator== (const name_and_matcher
&other
) const
3887 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3891 /* A vector holding all the different symbol name matchers, for all
3893 std::vector
<name_and_matcher
> matchers
;
3895 for (int i
= 0; i
< nr_languages
; i
++)
3897 enum language lang_e
= (enum language
) i
;
3899 const language_defn
*lang
= language_def (lang_e
);
3900 symbol_name_matcher_ftype
*name_matcher
3901 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
3903 name_and_matcher key
{
3905 lookup_name_without_params
.language_lookup_name (lang_e
)
3908 /* Don't insert the same comparison routine more than once.
3909 Note that we do this linear walk. This is not a problem in
3910 practice because the number of supported languages is
3912 if (std::find (matchers
.begin (), matchers
.end (), key
)
3915 matchers
.push_back (std::move (key
));
3918 = index
.find_name_components_bounds (lookup_name_without_params
,
3919 lang_e
, per_objfile
);
3921 /* Now for each symbol name in range, check to see if we have a name
3922 match, and if so, call the MATCH_CALLBACK callback. */
3924 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3926 const char *qualified
3927 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
3929 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3930 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3933 matches
.push_back (bounds
.first
->idx
);
3937 std::sort (matches
.begin (), matches
.end ());
3939 /* Finally call the callback, once per match. */
3942 for (offset_type idx
: matches
)
3946 if (!match_callback (idx
))
3955 /* Above we use a type wider than idx's for 'prev', since 0 and
3956 (offset_type)-1 are both possible values. */
3957 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3964 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3966 /* A mock .gdb_index/.debug_names-like name index table, enough to
3967 exercise dw2_expand_symtabs_matching_symbol, which works with the
3968 mapped_index_base interface. Builds an index from the symbol list
3969 passed as parameter to the constructor. */
3970 class mock_mapped_index
: public mapped_index_base
3973 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3974 : m_symbol_table (symbols
)
3977 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3979 /* Return the number of names in the symbol table. */
3980 size_t symbol_name_count () const override
3982 return m_symbol_table
.size ();
3985 /* Get the name of the symbol at IDX in the symbol table. */
3986 const char *symbol_name_at
3987 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
3989 return m_symbol_table
[idx
];
3993 gdb::array_view
<const char *> m_symbol_table
;
3996 /* Convenience function that converts a NULL pointer to a "<null>"
3997 string, to pass to print routines. */
4000 string_or_null (const char *str
)
4002 return str
!= NULL
? str
: "<null>";
4005 /* Check if a lookup_name_info built from
4006 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4007 index. EXPECTED_LIST is the list of expected matches, in expected
4008 matching order. If no match expected, then an empty list is
4009 specified. Returns true on success. On failure prints a warning
4010 indicating the file:line that failed, and returns false. */
4013 check_match (const char *file
, int line
,
4014 mock_mapped_index
&mock_index
,
4015 const char *name
, symbol_name_match_type match_type
,
4016 bool completion_mode
,
4017 std::initializer_list
<const char *> expected_list
,
4018 dwarf2_per_objfile
*per_objfile
)
4020 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4022 bool matched
= true;
4024 auto mismatch
= [&] (const char *expected_str
,
4027 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4028 "expected=\"%s\", got=\"%s\"\n"),
4030 (match_type
== symbol_name_match_type::FULL
4032 name
, string_or_null (expected_str
), string_or_null (got
));
4036 auto expected_it
= expected_list
.begin ();
4037 auto expected_end
= expected_list
.end ();
4039 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4041 [&] (offset_type idx
)
4043 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4044 const char *expected_str
4045 = expected_it
== expected_end
? NULL
: *expected_it
++;
4047 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4048 mismatch (expected_str
, matched_name
);
4052 const char *expected_str
4053 = expected_it
== expected_end
? NULL
: *expected_it
++;
4054 if (expected_str
!= NULL
)
4055 mismatch (expected_str
, NULL
);
4060 /* The symbols added to the mock mapped_index for testing (in
4062 static const char *test_symbols
[] = {
4071 "ns2::tmpl<int>::foo2",
4072 "(anonymous namespace)::A::B::C",
4074 /* These are used to check that the increment-last-char in the
4075 matching algorithm for completion doesn't match "t1_fund" when
4076 completing "t1_func". */
4082 /* A UTF-8 name with multi-byte sequences to make sure that
4083 cp-name-parser understands this as a single identifier ("função"
4084 is "function" in PT). */
4087 /* \377 (0xff) is Latin1 'ÿ'. */
4090 /* \377 (0xff) is Latin1 'ÿ'. */
4094 /* A name with all sorts of complications. Starts with "z" to make
4095 it easier for the completion tests below. */
4096 #define Z_SYM_NAME \
4097 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4098 "::tuple<(anonymous namespace)::ui*, " \
4099 "std::default_delete<(anonymous namespace)::ui>, void>"
4104 /* Returns true if the mapped_index_base::find_name_component_bounds
4105 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4106 in completion mode. */
4109 check_find_bounds_finds (mapped_index_base
&index
,
4110 const char *search_name
,
4111 gdb::array_view
<const char *> expected_syms
,
4112 dwarf2_per_objfile
*per_objfile
)
4114 lookup_name_info
lookup_name (search_name
,
4115 symbol_name_match_type::FULL
, true);
4117 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4121 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4122 if (distance
!= expected_syms
.size ())
4125 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4127 auto nc_elem
= bounds
.first
+ exp_elem
;
4128 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4129 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4136 /* Test the lower-level mapped_index::find_name_component_bounds
4140 test_mapped_index_find_name_component_bounds ()
4142 mock_mapped_index
mock_index (test_symbols
);
4144 mock_index
.build_name_components (NULL
/* per_objfile */);
4146 /* Test the lower-level mapped_index::find_name_component_bounds
4147 method in completion mode. */
4149 static const char *expected_syms
[] = {
4154 SELF_CHECK (check_find_bounds_finds
4155 (mock_index
, "t1_func", expected_syms
,
4156 NULL
/* per_objfile */));
4159 /* Check that the increment-last-char in the name matching algorithm
4160 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4162 static const char *expected_syms1
[] = {
4166 SELF_CHECK (check_find_bounds_finds
4167 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4169 static const char *expected_syms2
[] = {
4172 SELF_CHECK (check_find_bounds_finds
4173 (mock_index
, "\377\377", expected_syms2
,
4174 NULL
/* per_objfile */));
4178 /* Test dw2_expand_symtabs_matching_symbol. */
4181 test_dw2_expand_symtabs_matching_symbol ()
4183 mock_mapped_index
mock_index (test_symbols
);
4185 /* We let all tests run until the end even if some fails, for debug
4187 bool any_mismatch
= false;
4189 /* Create the expected symbols list (an initializer_list). Needed
4190 because lists have commas, and we need to pass them to CHECK,
4191 which is a macro. */
4192 #define EXPECT(...) { __VA_ARGS__ }
4194 /* Wrapper for check_match that passes down the current
4195 __FILE__/__LINE__. */
4196 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4197 any_mismatch |= !check_match (__FILE__, __LINE__, \
4199 NAME, MATCH_TYPE, COMPLETION_MODE, \
4200 EXPECTED_LIST, NULL)
4202 /* Identity checks. */
4203 for (const char *sym
: test_symbols
)
4205 /* Should be able to match all existing symbols. */
4206 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4209 /* Should be able to match all existing symbols with
4211 std::string with_params
= std::string (sym
) + "(int)";
4212 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4215 /* Should be able to match all existing symbols with
4216 parameters and qualifiers. */
4217 with_params
= std::string (sym
) + " ( int ) const";
4218 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4221 /* This should really find sym, but cp-name-parser.y doesn't
4222 know about lvalue/rvalue qualifiers yet. */
4223 with_params
= std::string (sym
) + " ( int ) &&";
4224 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4228 /* Check that the name matching algorithm for completion doesn't get
4229 confused with Latin1 'ÿ' / 0xff. */
4231 static const char str
[] = "\377";
4232 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4233 EXPECT ("\377", "\377\377123"));
4236 /* Check that the increment-last-char in the matching algorithm for
4237 completion doesn't match "t1_fund" when completing "t1_func". */
4239 static const char str
[] = "t1_func";
4240 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4241 EXPECT ("t1_func", "t1_func1"));
4244 /* Check that completion mode works at each prefix of the expected
4247 static const char str
[] = "function(int)";
4248 size_t len
= strlen (str
);
4251 for (size_t i
= 1; i
< len
; i
++)
4253 lookup
.assign (str
, i
);
4254 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4255 EXPECT ("function"));
4259 /* While "w" is a prefix of both components, the match function
4260 should still only be called once. */
4262 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4264 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4268 /* Same, with a "complicated" symbol. */
4270 static const char str
[] = Z_SYM_NAME
;
4271 size_t len
= strlen (str
);
4274 for (size_t i
= 1; i
< len
; i
++)
4276 lookup
.assign (str
, i
);
4277 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4278 EXPECT (Z_SYM_NAME
));
4282 /* In FULL mode, an incomplete symbol doesn't match. */
4284 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4288 /* A complete symbol with parameters matches any overload, since the
4289 index has no overload info. */
4291 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4292 EXPECT ("std::zfunction", "std::zfunction2"));
4293 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4294 EXPECT ("std::zfunction", "std::zfunction2"));
4295 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4296 EXPECT ("std::zfunction", "std::zfunction2"));
4299 /* Check that whitespace is ignored appropriately. A symbol with a
4300 template argument list. */
4302 static const char expected
[] = "ns::foo<int>";
4303 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4305 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4309 /* Check that whitespace is ignored appropriately. A symbol with a
4310 template argument list that includes a pointer. */
4312 static const char expected
[] = "ns::foo<char*>";
4313 /* Try both completion and non-completion modes. */
4314 static const bool completion_mode
[2] = {false, true};
4315 for (size_t i
= 0; i
< 2; i
++)
4317 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4318 completion_mode
[i
], EXPECT (expected
));
4319 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4320 completion_mode
[i
], EXPECT (expected
));
4322 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4323 completion_mode
[i
], EXPECT (expected
));
4324 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4325 completion_mode
[i
], EXPECT (expected
));
4330 /* Check method qualifiers are ignored. */
4331 static const char expected
[] = "ns::foo<char*>";
4332 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4333 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4334 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4335 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4336 CHECK_MATCH ("foo < char * > ( int ) const",
4337 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4338 CHECK_MATCH ("foo < char * > ( int ) &&",
4339 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4342 /* Test lookup names that don't match anything. */
4344 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4347 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4351 /* Some wild matching tests, exercising "(anonymous namespace)",
4352 which should not be confused with a parameter list. */
4354 static const char *syms
[] = {
4358 "A :: B :: C ( int )",
4363 for (const char *s
: syms
)
4365 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4366 EXPECT ("(anonymous namespace)::A::B::C"));
4371 static const char expected
[] = "ns2::tmpl<int>::foo2";
4372 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4374 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4378 SELF_CHECK (!any_mismatch
);
4387 test_mapped_index_find_name_component_bounds ();
4388 test_dw2_expand_symtabs_matching_symbol ();
4391 }} // namespace selftests::dw2_expand_symtabs_matching
4393 #endif /* GDB_SELF_TEST */
4395 /* If FILE_MATCHER is NULL or if PER_CU has
4396 dwarf2_per_cu_quick_data::MARK set (see
4397 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4398 EXPANSION_NOTIFY on it. */
4401 dw2_expand_symtabs_matching_one
4402 (dwarf2_per_cu_data
*per_cu
,
4403 dwarf2_per_objfile
*per_objfile
,
4404 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4405 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4407 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4409 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4411 compunit_symtab
*symtab
4412 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4413 gdb_assert (symtab
!= nullptr);
4415 if (expansion_notify
!= NULL
&& symtab_was_null
)
4416 return expansion_notify (symtab
);
4421 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4422 matched, to expand corresponding CUs that were marked. IDX is the
4423 index of the symbol name that matched. */
4426 dw2_expand_marked_cus
4427 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4428 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4429 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4430 block_search_flags search_flags
,
4433 offset_type vec_len
, vec_idx
;
4434 bool global_seen
= false;
4435 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4437 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
4439 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4441 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
4442 /* This value is only valid for index versions >= 7. */
4443 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4444 gdb_index_symbol_kind symbol_kind
=
4445 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4446 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4447 /* Only check the symbol attributes if they're present.
4448 Indices prior to version 7 don't record them,
4449 and indices >= 7 may elide them for certain symbols
4450 (gold does this). */
4453 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4455 /* Work around gold/15646. */
4458 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4466 /* Only check the symbol's kind if it has one. */
4471 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
4476 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
4482 case VARIABLES_DOMAIN
:
4483 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4486 case FUNCTIONS_DOMAIN
:
4487 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4491 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4494 case MODULES_DOMAIN
:
4495 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4503 /* Don't crash on bad data. */
4504 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
4505 + per_objfile
->per_bfd
->all_type_units
.size ()))
4507 complaint (_(".gdb_index entry has bad CU index"
4508 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4512 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
4513 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4521 /* If FILE_MATCHER is non-NULL, set all the
4522 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4523 that match FILE_MATCHER. */
4526 dw_expand_symtabs_matching_file_matcher
4527 (dwarf2_per_objfile
*per_objfile
,
4528 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4530 if (file_matcher
== NULL
)
4533 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4535 NULL
, xcalloc
, xfree
));
4536 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4538 NULL
, xcalloc
, xfree
));
4540 /* The rule is CUs specify all the files, including those used by
4541 any TU, so there's no need to scan TUs here. */
4543 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4547 per_cu
->v
.quick
->mark
= 0;
4549 /* We only need to look at symtabs not already expanded. */
4550 if (per_objfile
->symtab_set_p (per_cu
))
4553 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4554 if (file_data
== NULL
)
4557 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4559 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4561 per_cu
->v
.quick
->mark
= 1;
4565 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4567 const char *this_real_name
;
4569 if (file_matcher (file_data
->file_names
[j
], false))
4571 per_cu
->v
.quick
->mark
= 1;
4575 /* Before we invoke realpath, which can get expensive when many
4576 files are involved, do a quick comparison of the basenames. */
4577 if (!basenames_may_differ
4578 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4582 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4583 if (file_matcher (this_real_name
, false))
4585 per_cu
->v
.quick
->mark
= 1;
4590 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4591 ? visited_found
.get ()
4592 : visited_not_found
.get (),
4599 dwarf2_gdb_index::expand_symtabs_matching
4600 (struct objfile
*objfile
,
4601 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4602 const lookup_name_info
*lookup_name
,
4603 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4604 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4605 block_search_flags search_flags
,
4607 enum search_domain kind
)
4609 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4611 /* index_table is NULL if OBJF_READNOW. */
4612 if (!per_objfile
->per_bfd
->index_table
)
4615 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4617 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4619 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4623 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4631 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4634 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4636 [&] (offset_type idx
)
4638 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
4639 expansion_notify
, search_flags
, kind
))
4647 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4650 static struct compunit_symtab
*
4651 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4656 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4657 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4660 if (cust
->includes
== NULL
)
4663 for (i
= 0; cust
->includes
[i
]; ++i
)
4665 struct compunit_symtab
*s
= cust
->includes
[i
];
4667 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4675 struct compunit_symtab
*
4676 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4677 (struct objfile
*objfile
,
4678 struct bound_minimal_symbol msymbol
,
4680 struct obj_section
*section
,
4683 struct dwarf2_per_cu_data
*data
;
4684 struct compunit_symtab
*result
;
4686 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4687 if (per_objfile
->per_bfd
->index_addrmap
== nullptr)
4690 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4691 data
= ((struct dwarf2_per_cu_data
*)
4692 addrmap_find (per_objfile
->per_bfd
->index_addrmap
,
4697 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4698 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4699 paddress (objfile
->arch (), pc
));
4701 result
= recursively_find_pc_sect_compunit_symtab
4702 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4704 gdb_assert (result
!= NULL
);
4709 dwarf2_base_index_functions::map_symbol_filenames
4710 (struct objfile
*objfile
,
4711 gdb::function_view
<symbol_filename_ftype
> fun
,
4714 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4716 if (!per_objfile
->per_bfd
->filenames_cache
)
4718 per_objfile
->per_bfd
->filenames_cache
.emplace ();
4720 htab_up
visited (htab_create_alloc (10,
4721 htab_hash_pointer
, htab_eq_pointer
,
4722 NULL
, xcalloc
, xfree
));
4724 /* The rule is CUs specify all the files, including those used
4725 by any TU, so there's no need to scan TUs here. We can
4726 ignore file names coming from already-expanded CUs. */
4728 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4730 if (per_objfile
->symtab_set_p (per_cu
))
4732 void **slot
= htab_find_slot (visited
.get (),
4733 per_cu
->v
.quick
->file_names
,
4736 *slot
= per_cu
->v
.quick
->file_names
;
4740 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4742 /* We only need to look at symtabs not already expanded. */
4743 if (per_objfile
->symtab_set_p (per_cu
))
4746 quick_file_names
*file_data
4747 = dw2_get_file_names (per_cu
, per_objfile
);
4748 if (file_data
== NULL
)
4751 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4754 /* Already visited. */
4759 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4761 const char *filename
= file_data
->file_names
[j
];
4762 per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
4767 per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
4769 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4772 this_real_name
= gdb_realpath (filename
);
4773 fun (filename
, this_real_name
.get ());
4778 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
4783 /* DWARF-5 debug_names reader. */
4785 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4786 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4788 /* A helper function that reads the .debug_names section in SECTION
4789 and fills in MAP. FILENAME is the name of the file containing the
4790 section; it is used for error reporting.
4792 Returns true if all went well, false otherwise. */
4795 read_debug_names_from_section (struct objfile
*objfile
,
4796 const char *filename
,
4797 struct dwarf2_section_info
*section
,
4798 mapped_debug_names
&map
)
4800 if (section
->empty ())
4803 /* Older elfutils strip versions could keep the section in the main
4804 executable while splitting it for the separate debug info file. */
4805 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4808 section
->read (objfile
);
4810 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4812 const gdb_byte
*addr
= section
->buffer
;
4814 bfd
*const abfd
= section
->get_bfd_owner ();
4816 unsigned int bytes_read
;
4817 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4820 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4821 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4822 if (bytes_read
+ length
!= section
->size
)
4824 /* There may be multiple per-CU indices. */
4825 warning (_("Section .debug_names in %s length %s does not match "
4826 "section length %s, ignoring .debug_names."),
4827 filename
, plongest (bytes_read
+ length
),
4828 pulongest (section
->size
));
4832 /* The version number. */
4833 uint16_t version
= read_2_bytes (abfd
, addr
);
4837 warning (_("Section .debug_names in %s has unsupported version %d, "
4838 "ignoring .debug_names."),
4844 uint16_t padding
= read_2_bytes (abfd
, addr
);
4848 warning (_("Section .debug_names in %s has unsupported padding %d, "
4849 "ignoring .debug_names."),
4854 /* comp_unit_count - The number of CUs in the CU list. */
4855 map
.cu_count
= read_4_bytes (abfd
, addr
);
4858 /* local_type_unit_count - The number of TUs in the local TU
4860 map
.tu_count
= read_4_bytes (abfd
, addr
);
4863 /* foreign_type_unit_count - The number of TUs in the foreign TU
4865 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4867 if (foreign_tu_count
!= 0)
4869 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4870 "ignoring .debug_names."),
4871 filename
, static_cast<unsigned long> (foreign_tu_count
));
4875 /* bucket_count - The number of hash buckets in the hash lookup
4877 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4880 /* name_count - The number of unique names in the index. */
4881 map
.name_count
= read_4_bytes (abfd
, addr
);
4884 /* abbrev_table_size - The size in bytes of the abbreviations
4886 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4889 /* augmentation_string_size - The size in bytes of the augmentation
4890 string. This value is rounded up to a multiple of 4. */
4891 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4893 map
.augmentation_is_gdb
= ((augmentation_string_size
4894 == sizeof (dwarf5_augmentation
))
4895 && memcmp (addr
, dwarf5_augmentation
,
4896 sizeof (dwarf5_augmentation
)) == 0);
4897 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4898 addr
+= augmentation_string_size
;
4901 map
.cu_table_reordered
= addr
;
4902 addr
+= map
.cu_count
* map
.offset_size
;
4904 /* List of Local TUs */
4905 map
.tu_table_reordered
= addr
;
4906 addr
+= map
.tu_count
* map
.offset_size
;
4908 /* Hash Lookup Table */
4909 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4910 addr
+= map
.bucket_count
* 4;
4911 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4912 addr
+= map
.name_count
* 4;
4915 map
.name_table_string_offs_reordered
= addr
;
4916 addr
+= map
.name_count
* map
.offset_size
;
4917 map
.name_table_entry_offs_reordered
= addr
;
4918 addr
+= map
.name_count
* map
.offset_size
;
4920 const gdb_byte
*abbrev_table_start
= addr
;
4923 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4928 const auto insertpair
4929 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4930 if (!insertpair
.second
)
4932 warning (_("Section .debug_names in %s has duplicate index %s, "
4933 "ignoring .debug_names."),
4934 filename
, pulongest (index_num
));
4937 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4938 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4943 mapped_debug_names::index_val::attr attr
;
4944 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4946 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4948 if (attr
.form
== DW_FORM_implicit_const
)
4950 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4954 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4956 indexval
.attr_vec
.push_back (std::move (attr
));
4959 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4961 warning (_("Section .debug_names in %s has abbreviation_table "
4962 "of size %s vs. written as %u, ignoring .debug_names."),
4963 filename
, plongest (addr
- abbrev_table_start
),
4967 map
.entry_pool
= addr
;
4972 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4976 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
4977 const mapped_debug_names
&map
,
4978 dwarf2_section_info
§ion
,
4981 if (!map
.augmentation_is_gdb
)
4983 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
4985 sect_offset sect_off
4986 = (sect_offset
) (extract_unsigned_integer
4987 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4989 map
.dwarf5_byte_order
));
4990 /* We don't know the length of the CU, because the CU list in a
4991 .debug_names index can be incomplete, so we can't use the start
4992 of the next CU as end of this CU. We create the CUs here with
4993 length 0, and in cutu_reader::cutu_reader we'll fill in the
4995 dwarf2_per_cu_data
*per_cu
4996 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4998 per_bfd
->all_comp_units
.push_back (per_cu
);
5003 sect_offset sect_off_prev
;
5004 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5006 sect_offset sect_off_next
;
5007 if (i
< map
.cu_count
)
5010 = (sect_offset
) (extract_unsigned_integer
5011 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5013 map
.dwarf5_byte_order
));
5016 sect_off_next
= (sect_offset
) section
.size
;
5019 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5020 dwarf2_per_cu_data
*per_cu
5021 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5022 sect_off_prev
, length
);
5023 per_bfd
->all_comp_units
.push_back (per_cu
);
5025 sect_off_prev
= sect_off_next
;
5029 /* Read the CU list from the mapped index, and use it to create all
5030 the CU objects for this dwarf2_per_objfile. */
5033 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5034 const mapped_debug_names
&map
,
5035 const mapped_debug_names
&dwz_map
)
5037 gdb_assert (per_bfd
->all_comp_units
.empty ());
5038 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5040 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5041 false /* is_dwz */);
5043 if (dwz_map
.cu_count
== 0)
5046 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5047 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5051 /* Read .debug_names. If everything went ok, initialize the "quick"
5052 elements of all the CUs and return true. Otherwise, return false. */
5055 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
5057 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5058 mapped_debug_names dwz_map
;
5059 struct objfile
*objfile
= per_objfile
->objfile
;
5060 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5062 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5063 &per_bfd
->debug_names
, *map
))
5066 /* Don't use the index if it's empty. */
5067 if (map
->name_count
== 0)
5070 /* If there is a .dwz file, read it so we can get its CU list as
5072 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5075 if (!read_debug_names_from_section (objfile
,
5076 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5077 &dwz
->debug_names
, dwz_map
))
5079 warning (_("could not read '.debug_names' section from %s; skipping"),
5080 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5085 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
5087 if (map
->tu_count
!= 0)
5089 /* We can only handle a single .debug_types when we have an
5091 if (per_bfd
->types
.size () != 1)
5094 dwarf2_section_info
*section
= &per_bfd
->types
[0];
5096 create_signatured_type_table_from_debug_names
5097 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
5100 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
5102 per_bfd
->debug_names_table
= std::move (map
);
5103 per_bfd
->using_index
= 1;
5104 per_bfd
->quick_file_names_table
=
5105 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5110 /* Type used to manage iterating over all CUs looking for a symbol for
5113 class dw2_debug_names_iterator
5116 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5117 block_search_flags block_index
,
5119 const char *name
, dwarf2_per_objfile
*per_objfile
)
5120 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5121 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5122 m_per_objfile (per_objfile
)
5125 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5126 search_domain search
, uint32_t namei
,
5127 dwarf2_per_objfile
*per_objfile
,
5128 domain_enum domain
= UNDEF_DOMAIN
)
5132 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5133 m_per_objfile (per_objfile
)
5136 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5137 block_search_flags block_index
, domain_enum domain
,
5138 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5139 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5140 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5141 m_per_objfile (per_objfile
)
5144 /* Return the next matching CU or NULL if there are no more. */
5145 dwarf2_per_cu_data
*next ();
5148 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5150 dwarf2_per_objfile
*per_objfile
);
5151 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5153 dwarf2_per_objfile
*per_objfile
);
5155 /* The internalized form of .debug_names. */
5156 const mapped_debug_names
&m_map
;
5158 /* Restrict the search to these blocks. */
5159 block_search_flags m_block_index
= (SEARCH_GLOBAL_BLOCK
5160 | SEARCH_STATIC_BLOCK
);
5162 /* The kind of symbol we're looking for. */
5163 const domain_enum m_domain
= UNDEF_DOMAIN
;
5164 const search_domain m_search
= ALL_DOMAIN
;
5166 /* The list of CUs from the index entry of the symbol, or NULL if
5168 const gdb_byte
*m_addr
;
5170 dwarf2_per_objfile
*m_per_objfile
;
5174 mapped_debug_names::namei_to_name
5175 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5177 const ULONGEST namei_string_offs
5178 = extract_unsigned_integer ((name_table_string_offs_reordered
5179 + namei
* offset_size
),
5182 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5185 /* Find a slot in .debug_names for the object named NAME. If NAME is
5186 found, return pointer to its pool data. If NAME cannot be found,
5190 dw2_debug_names_iterator::find_vec_in_debug_names
5191 (const mapped_debug_names
&map
, const char *name
,
5192 dwarf2_per_objfile
*per_objfile
)
5194 int (*cmp
) (const char *, const char *);
5196 gdb::unique_xmalloc_ptr
<char> without_params
;
5197 if (current_language
->la_language
== language_cplus
5198 || current_language
->la_language
== language_fortran
5199 || current_language
->la_language
== language_d
)
5201 /* NAME is already canonical. Drop any qualifiers as
5202 .debug_names does not contain any. */
5204 if (strchr (name
, '(') != NULL
)
5206 without_params
= cp_remove_params (name
);
5207 if (without_params
!= NULL
)
5208 name
= without_params
.get ();
5212 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5214 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5216 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5217 (map
.bucket_table_reordered
5218 + (full_hash
% map
.bucket_count
)), 4,
5219 map
.dwarf5_byte_order
);
5223 if (namei
>= map
.name_count
)
5225 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5227 namei
, map
.name_count
,
5228 objfile_name (per_objfile
->objfile
));
5234 const uint32_t namei_full_hash
5235 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5236 (map
.hash_table_reordered
+ namei
), 4,
5237 map
.dwarf5_byte_order
);
5238 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5241 if (full_hash
== namei_full_hash
)
5243 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5245 #if 0 /* An expensive sanity check. */
5246 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5248 complaint (_("Wrong .debug_names hash for string at index %u "
5250 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5255 if (cmp (namei_string
, name
) == 0)
5257 const ULONGEST namei_entry_offs
5258 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5259 + namei
* map
.offset_size
),
5260 map
.offset_size
, map
.dwarf5_byte_order
);
5261 return map
.entry_pool
+ namei_entry_offs
;
5266 if (namei
>= map
.name_count
)
5272 dw2_debug_names_iterator::find_vec_in_debug_names
5273 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5275 if (namei
>= map
.name_count
)
5277 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5279 namei
, map
.name_count
,
5280 objfile_name (per_objfile
->objfile
));
5284 const ULONGEST namei_entry_offs
5285 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5286 + namei
* map
.offset_size
),
5287 map
.offset_size
, map
.dwarf5_byte_order
);
5288 return map
.entry_pool
+ namei_entry_offs
;
5291 /* See dw2_debug_names_iterator. */
5293 dwarf2_per_cu_data
*
5294 dw2_debug_names_iterator::next ()
5299 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5300 struct objfile
*objfile
= m_per_objfile
->objfile
;
5301 bfd
*const abfd
= objfile
->obfd
;
5305 unsigned int bytes_read
;
5306 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5307 m_addr
+= bytes_read
;
5311 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5312 if (indexval_it
== m_map
.abbrev_map
.cend ())
5314 complaint (_("Wrong .debug_names undefined abbrev code %s "
5316 pulongest (abbrev
), objfile_name (objfile
));
5319 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5320 enum class symbol_linkage
{
5324 } symbol_linkage_
= symbol_linkage::unknown
;
5325 dwarf2_per_cu_data
*per_cu
= NULL
;
5326 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5331 case DW_FORM_implicit_const
:
5332 ull
= attr
.implicit_const
;
5334 case DW_FORM_flag_present
:
5338 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5339 m_addr
+= bytes_read
;
5342 ull
= read_4_bytes (abfd
, m_addr
);
5346 ull
= read_8_bytes (abfd
, m_addr
);
5349 case DW_FORM_ref_sig8
:
5350 ull
= read_8_bytes (abfd
, m_addr
);
5354 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5355 dwarf_form_name (attr
.form
),
5356 objfile_name (objfile
));
5359 switch (attr
.dw_idx
)
5361 case DW_IDX_compile_unit
:
5362 /* Don't crash on bad data. */
5363 if (ull
>= per_bfd
->all_comp_units
.size ())
5365 complaint (_(".debug_names entry has bad CU index %s"
5368 objfile_name (objfile
));
5371 per_cu
= per_bfd
->get_cutu (ull
);
5373 case DW_IDX_type_unit
:
5374 /* Don't crash on bad data. */
5375 if (ull
>= per_bfd
->all_type_units
.size ())
5377 complaint (_(".debug_names entry has bad TU index %s"
5380 objfile_name (objfile
));
5383 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5385 case DW_IDX_die_offset
:
5386 /* In a per-CU index (as opposed to a per-module index), index
5387 entries without CU attribute implicitly refer to the single CU. */
5389 per_cu
= per_bfd
->get_cu (0);
5391 case DW_IDX_GNU_internal
:
5392 if (!m_map
.augmentation_is_gdb
)
5394 symbol_linkage_
= symbol_linkage::static_
;
5396 case DW_IDX_GNU_external
:
5397 if (!m_map
.augmentation_is_gdb
)
5399 symbol_linkage_
= symbol_linkage::extern_
;
5404 /* Skip if already read in. */
5405 if (m_per_objfile
->symtab_set_p (per_cu
))
5408 /* Check static vs global. */
5409 if (symbol_linkage_
!= symbol_linkage::unknown
)
5411 if (symbol_linkage_
== symbol_linkage::static_
)
5413 if ((m_block_index
& SEARCH_STATIC_BLOCK
) == 0)
5418 if ((m_block_index
& SEARCH_GLOBAL_BLOCK
) == 0)
5423 /* Match dw2_symtab_iter_next, symbol_kind
5424 and debug_names::psymbol_tag. */
5428 switch (indexval
.dwarf_tag
)
5430 case DW_TAG_variable
:
5431 case DW_TAG_subprogram
:
5432 /* Some types are also in VAR_DOMAIN. */
5433 case DW_TAG_typedef
:
5434 case DW_TAG_structure_type
:
5441 switch (indexval
.dwarf_tag
)
5443 case DW_TAG_typedef
:
5444 case DW_TAG_structure_type
:
5451 switch (indexval
.dwarf_tag
)
5454 case DW_TAG_variable
:
5461 switch (indexval
.dwarf_tag
)
5473 /* Match dw2_expand_symtabs_matching, symbol_kind and
5474 debug_names::psymbol_tag. */
5477 case VARIABLES_DOMAIN
:
5478 switch (indexval
.dwarf_tag
)
5480 case DW_TAG_variable
:
5486 case FUNCTIONS_DOMAIN
:
5487 switch (indexval
.dwarf_tag
)
5489 case DW_TAG_subprogram
:
5496 switch (indexval
.dwarf_tag
)
5498 case DW_TAG_typedef
:
5499 case DW_TAG_structure_type
:
5505 case MODULES_DOMAIN
:
5506 switch (indexval
.dwarf_tag
)
5520 /* This dumps minimal information about .debug_names. It is called
5521 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5522 uses this to verify that .debug_names has been loaded. */
5525 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5527 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5529 gdb_assert (per_objfile
->per_bfd
->using_index
);
5530 printf_filtered (".debug_names:");
5531 if (per_objfile
->per_bfd
->debug_names_table
)
5532 printf_filtered (" exists\n");
5534 printf_filtered (" faked for \"readnow\"\n");
5535 printf_filtered ("\n");
5539 dwarf2_debug_names_index::expand_matching_symbols
5540 (struct objfile
*objfile
,
5541 const lookup_name_info
&name
, domain_enum domain
,
5543 symbol_compare_ftype
*ordered_compare
)
5545 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5547 /* debug_names_table is NULL if OBJF_READNOW. */
5548 if (!per_objfile
->per_bfd
->debug_names_table
)
5551 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5552 const block_search_flags block_flags
5553 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
5555 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5556 auto matcher
= [&] (const char *symname
)
5558 if (ordered_compare
== nullptr)
5560 return ordered_compare (symname
, match_name
) == 0;
5563 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
5564 [&] (offset_type namei
)
5566 /* The name was matched, now expand corresponding CUs that were
5568 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
5571 struct dwarf2_per_cu_data
*per_cu
;
5572 while ((per_cu
= iter
.next ()) != NULL
)
5573 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5580 dwarf2_debug_names_index::expand_symtabs_matching
5581 (struct objfile
*objfile
,
5582 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5583 const lookup_name_info
*lookup_name
,
5584 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5585 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5586 block_search_flags search_flags
,
5588 enum search_domain kind
)
5590 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5592 /* debug_names_table is NULL if OBJF_READNOW. */
5593 if (!per_objfile
->per_bfd
->debug_names_table
)
5596 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5598 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5600 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5604 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5612 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5615 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5617 [&] (offset_type namei
)
5619 /* The name was matched, now expand corresponding CUs that were
5621 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
5623 struct dwarf2_per_cu_data
*per_cu
;
5624 while ((per_cu
= iter
.next ()) != NULL
)
5625 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5635 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5636 to either a dwarf2_per_bfd or dwz_file object. */
5638 template <typename T
>
5639 static gdb::array_view
<const gdb_byte
>
5640 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5642 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5644 if (section
->empty ())
5647 /* Older elfutils strip versions could keep the section in the main
5648 executable while splitting it for the separate debug info file. */
5649 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5652 section
->read (obj
);
5654 /* dwarf2_section_info::size is a bfd_size_type, while
5655 gdb::array_view works with size_t. On 32-bit hosts, with
5656 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5657 is 32-bit. So we need an explicit narrowing conversion here.
5658 This is fine, because it's impossible to allocate or mmap an
5659 array/buffer larger than what size_t can represent. */
5660 return gdb::make_array_view (section
->buffer
, section
->size
);
5663 /* Lookup the index cache for the contents of the index associated to
5666 static gdb::array_view
<const gdb_byte
>
5667 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5669 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5670 if (build_id
== nullptr)
5673 return global_index_cache
.lookup_gdb_index (build_id
,
5674 &dwarf2_per_bfd
->index_cache_res
);
5677 /* Same as the above, but for DWZ. */
5679 static gdb::array_view
<const gdb_byte
>
5680 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5682 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5683 if (build_id
== nullptr)
5686 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5689 /* See dwarf2/public.h. */
5692 dwarf2_initialize_objfile (struct objfile
*objfile
)
5694 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5695 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5697 dwarf_read_debug_printf ("called");
5699 /* If we're about to read full symbols, don't bother with the
5700 indices. In this case we also don't care if some other debug
5701 format is making psymtabs, because they are all about to be
5703 if ((objfile
->flags
& OBJF_READNOW
))
5705 dwarf_read_debug_printf ("readnow requested");
5707 /* When using READNOW, the using_index flag (set below) indicates that
5708 PER_BFD was already initialized, when we loaded some other objfile. */
5709 if (per_bfd
->using_index
)
5711 dwarf_read_debug_printf ("using_index already set");
5712 per_objfile
->resize_symtabs ();
5713 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5717 per_bfd
->using_index
= 1;
5718 create_all_comp_units (per_objfile
);
5719 create_all_type_units (per_objfile
);
5720 per_bfd
->quick_file_names_table
5721 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5722 per_objfile
->resize_symtabs ();
5724 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
5725 + per_bfd
->all_type_units
.size ()); ++i
)
5727 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
5729 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5730 struct dwarf2_per_cu_quick_data
);
5733 /* Arrange for gdb to see the "quick" functions. However, these
5734 functions will be no-ops because we will have expanded all
5736 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5740 /* Was a debug names index already read when we processed an objfile sharing
5742 if (per_bfd
->debug_names_table
!= nullptr)
5744 dwarf_read_debug_printf ("re-using shared debug names table");
5745 per_objfile
->resize_symtabs ();
5746 objfile
->qf
.push_front (make_dwarf_debug_names ());
5750 /* Was a GDB index already read when we processed an objfile sharing
5752 if (per_bfd
->index_table
!= nullptr)
5754 dwarf_read_debug_printf ("re-using shared index table");
5755 per_objfile
->resize_symtabs ();
5756 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5760 /* There might already be partial symtabs built for this BFD. This happens
5761 when loading the same binary twice with the index-cache enabled. If so,
5762 don't try to read an index. The objfile / per_objfile initialization will
5763 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
5765 if (per_bfd
->partial_symtabs
!= nullptr)
5767 dwarf_read_debug_printf ("re-using shared partial symtabs");
5768 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5772 if (dwarf2_read_debug_names (per_objfile
))
5774 dwarf_read_debug_printf ("found debug names");
5775 per_objfile
->resize_symtabs ();
5776 objfile
->qf
.push_front (make_dwarf_debug_names ());
5780 if (dwarf2_read_gdb_index (per_objfile
,
5781 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5782 get_gdb_index_contents_from_section
<dwz_file
>))
5784 dwarf_read_debug_printf ("found gdb index from file");
5785 per_objfile
->resize_symtabs ();
5786 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5790 /* ... otherwise, try to find the index in the index cache. */
5791 if (dwarf2_read_gdb_index (per_objfile
,
5792 get_gdb_index_contents_from_cache
,
5793 get_gdb_index_contents_from_cache_dwz
))
5795 dwarf_read_debug_printf ("found gdb index from cache");
5796 global_index_cache
.hit ();
5797 per_objfile
->resize_symtabs ();
5798 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5802 global_index_cache
.miss ();
5803 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5808 /* Build a partial symbol table. */
5811 dwarf2_build_psymtabs (struct objfile
*objfile
, psymbol_functions
*psf
)
5813 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5814 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5816 if (per_bfd
->partial_symtabs
!= nullptr)
5818 /* Partial symbols were already read, so now we can simply
5822 psf
= new psymbol_functions (per_bfd
->partial_symtabs
);
5823 objfile
->qf
.emplace_front (psf
);
5826 psf
->set_partial_symtabs (per_bfd
->partial_symtabs
);
5827 per_objfile
->resize_symtabs ();
5833 psf
= new psymbol_functions
;
5834 objfile
->qf
.emplace_front (psf
);
5836 const std::shared_ptr
<psymtab_storage
> &partial_symtabs
5837 = psf
->get_partial_symtabs ();
5839 /* Set the local reference to partial symtabs, so that we don't try
5840 to read them again if reading another objfile with the same BFD.
5841 If we can't in fact share, this won't make a difference anyway as
5842 the dwarf2_per_bfd object won't be shared. */
5843 per_bfd
->partial_symtabs
= partial_symtabs
;
5847 /* This isn't really ideal: all the data we allocate on the
5848 objfile's obstack is still uselessly kept around. However,
5849 freeing it seems unsafe. */
5850 psymtab_discarder
psymtabs (partial_symtabs
.get ());
5851 dwarf2_build_psymtabs_hard (per_objfile
);
5854 per_objfile
->resize_symtabs ();
5856 /* (maybe) store an index in the cache. */
5857 global_index_cache
.store (per_objfile
);
5859 catch (const gdb_exception_error
&except
)
5861 exception_print (gdb_stderr
, except
);
5865 /* Find the base address of the compilation unit for range lists and
5866 location lists. It will normally be specified by DW_AT_low_pc.
5867 In DWARF-3 draft 4, the base address could be overridden by
5868 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5869 compilation units with discontinuous ranges. */
5872 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5874 struct attribute
*attr
;
5876 cu
->base_address
.reset ();
5878 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5879 if (attr
!= nullptr)
5880 cu
->base_address
= attr
->as_address ();
5883 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5884 if (attr
!= nullptr)
5885 cu
->base_address
= attr
->as_address ();
5889 /* Helper function that returns the proper abbrev section for
5892 static struct dwarf2_section_info
*
5893 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5895 struct dwarf2_section_info
*abbrev
;
5896 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
5898 if (this_cu
->is_dwz
)
5899 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
5901 abbrev
= &per_bfd
->abbrev
;
5906 /* Fetch the abbreviation table offset from a comp or type unit header. */
5909 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
5910 struct dwarf2_section_info
*section
,
5911 sect_offset sect_off
)
5913 bfd
*abfd
= section
->get_bfd_owner ();
5914 const gdb_byte
*info_ptr
;
5915 unsigned int initial_length_size
, offset_size
;
5918 section
->read (per_objfile
->objfile
);
5919 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5920 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5921 offset_size
= initial_length_size
== 4 ? 4 : 8;
5922 info_ptr
+= initial_length_size
;
5924 version
= read_2_bytes (abfd
, info_ptr
);
5928 /* Skip unit type and address size. */
5932 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5935 /* A partial symtab that is used only for include files. */
5936 struct dwarf2_include_psymtab
: public partial_symtab
5938 dwarf2_include_psymtab (const char *filename
,
5939 psymtab_storage
*partial_symtabs
,
5940 objfile_per_bfd_storage
*objfile_per_bfd
)
5941 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
5945 void read_symtab (struct objfile
*objfile
) override
5947 /* It's an include file, no symbols to read for it.
5948 Everything is in the includer symtab. */
5950 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5951 expansion of the includer psymtab. We use the dependencies[0] field to
5952 model the includer. But if we go the regular route of calling
5953 expand_psymtab here, and having expand_psymtab call expand_dependencies
5954 to expand the includer, we'll only use expand_psymtab on the includer
5955 (making it a non-toplevel psymtab), while if we expand the includer via
5956 another path, we'll use read_symtab (making it a toplevel psymtab).
5957 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5958 psymtab, and trigger read_symtab on the includer here directly. */
5959 includer ()->read_symtab (objfile
);
5962 void expand_psymtab (struct objfile
*objfile
) override
5964 /* This is not called by read_symtab, and should not be called by any
5965 expand_dependencies. */
5969 bool readin_p (struct objfile
*objfile
) const override
5971 return includer ()->readin_p (objfile
);
5974 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
5980 partial_symtab
*includer () const
5982 /* An include psymtab has exactly one dependency: the psymtab that
5984 gdb_assert (this->number_of_dependencies
== 1);
5985 return this->dependencies
[0];
5989 /* Allocate a new partial symtab for file named NAME and mark this new
5990 partial symtab as being an include of PST. */
5993 dwarf2_create_include_psymtab (dwarf2_per_bfd
*per_bfd
,
5995 dwarf2_psymtab
*pst
,
5996 psymtab_storage
*partial_symtabs
,
5997 objfile_per_bfd_storage
*objfile_per_bfd
)
5999 dwarf2_include_psymtab
*subpst
6000 = new dwarf2_include_psymtab (name
, partial_symtabs
, objfile_per_bfd
);
6002 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6003 subpst
->dirname
= pst
->dirname
;
6005 subpst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (1);
6006 subpst
->dependencies
[0] = pst
;
6007 subpst
->number_of_dependencies
= 1;
6010 /* Read the Line Number Program data and extract the list of files
6011 included by the source file represented by PST. Build an include
6012 partial symtab for each of these included files. */
6015 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6016 struct die_info
*die
,
6017 dwarf2_psymtab
*pst
)
6020 struct attribute
*attr
;
6022 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6023 if (attr
!= nullptr && attr
->form_is_unsigned ())
6024 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
6026 return; /* No linetable, so no includes. */
6028 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6029 that we pass in the raw text_low here; that is ok because we're
6030 only decoding the line table to make include partial symtabs, and
6031 so the addresses aren't really used. */
6032 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6033 pst
->raw_text_low (), 1);
6037 hash_signatured_type (const void *item
)
6039 const struct signatured_type
*sig_type
6040 = (const struct signatured_type
*) item
;
6042 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6043 return sig_type
->signature
;
6047 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6049 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6050 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6052 return lhs
->signature
== rhs
->signature
;
6055 /* Allocate a hash table for signatured types. */
6058 allocate_signatured_type_table ()
6060 return htab_up (htab_create_alloc (41,
6061 hash_signatured_type
,
6063 NULL
, xcalloc
, xfree
));
6066 /* A helper function to add a signatured type CU to a table. */
6069 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6071 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6072 std::vector
<signatured_type
*> *all_type_units
6073 = (std::vector
<signatured_type
*> *) datum
;
6075 all_type_units
->push_back (sigt
);
6080 /* A helper for create_debug_types_hash_table. Read types from SECTION
6081 and fill them into TYPES_HTAB. It will process only type units,
6082 therefore DW_UT_type. */
6085 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6086 struct dwo_file
*dwo_file
,
6087 dwarf2_section_info
*section
, htab_up
&types_htab
,
6088 rcuh_kind section_kind
)
6090 struct objfile
*objfile
= per_objfile
->objfile
;
6091 struct dwarf2_section_info
*abbrev_section
;
6093 const gdb_byte
*info_ptr
, *end_ptr
;
6095 abbrev_section
= (dwo_file
!= NULL
6096 ? &dwo_file
->sections
.abbrev
6097 : &per_objfile
->per_bfd
->abbrev
);
6099 dwarf_read_debug_printf ("Reading %s for %s",
6100 section
->get_name (),
6101 abbrev_section
->get_file_name ());
6103 section
->read (objfile
);
6104 info_ptr
= section
->buffer
;
6106 if (info_ptr
== NULL
)
6109 /* We can't set abfd until now because the section may be empty or
6110 not present, in which case the bfd is unknown. */
6111 abfd
= section
->get_bfd_owner ();
6113 /* We don't use cutu_reader here because we don't need to read
6114 any dies: the signature is in the header. */
6116 end_ptr
= info_ptr
+ section
->size
;
6117 while (info_ptr
< end_ptr
)
6119 struct signatured_type
*sig_type
;
6120 struct dwo_unit
*dwo_tu
;
6122 const gdb_byte
*ptr
= info_ptr
;
6123 struct comp_unit_head header
;
6124 unsigned int length
;
6126 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6128 /* Initialize it due to a false compiler warning. */
6129 header
.signature
= -1;
6130 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6132 /* We need to read the type's signature in order to build the hash
6133 table, but we don't need anything else just yet. */
6135 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6136 abbrev_section
, ptr
, section_kind
);
6138 length
= header
.get_length ();
6140 /* Skip dummy type units. */
6141 if (ptr
>= info_ptr
+ length
6142 || peek_abbrev_code (abfd
, ptr
) == 0
6143 || (header
.unit_type
!= DW_UT_type
6144 && header
.unit_type
!= DW_UT_split_type
))
6150 if (types_htab
== NULL
)
6153 types_htab
= allocate_dwo_unit_table ();
6155 types_htab
= allocate_signatured_type_table ();
6161 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6162 dwo_tu
->dwo_file
= dwo_file
;
6163 dwo_tu
->signature
= header
.signature
;
6164 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6165 dwo_tu
->section
= section
;
6166 dwo_tu
->sect_off
= sect_off
;
6167 dwo_tu
->length
= length
;
6171 /* N.B.: type_offset is not usable if this type uses a DWO file.
6172 The real type_offset is in the DWO file. */
6174 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6175 sig_type
->signature
= header
.signature
;
6176 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6177 sig_type
->per_cu
.is_debug_types
= 1;
6178 sig_type
->per_cu
.section
= section
;
6179 sig_type
->per_cu
.sect_off
= sect_off
;
6180 sig_type
->per_cu
.length
= length
;
6183 slot
= htab_find_slot (types_htab
.get (),
6184 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6186 gdb_assert (slot
!= NULL
);
6189 sect_offset dup_sect_off
;
6193 const struct dwo_unit
*dup_tu
6194 = (const struct dwo_unit
*) *slot
;
6196 dup_sect_off
= dup_tu
->sect_off
;
6200 const struct signatured_type
*dup_tu
6201 = (const struct signatured_type
*) *slot
;
6203 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6206 complaint (_("debug type entry at offset %s is duplicate to"
6207 " the entry at offset %s, signature %s"),
6208 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6209 hex_string (header
.signature
));
6211 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6213 dwarf_read_debug_printf_v (" offset %s, signature %s",
6214 sect_offset_str (sect_off
),
6215 hex_string (header
.signature
));
6221 /* Create the hash table of all entries in the .debug_types
6222 (or .debug_types.dwo) section(s).
6223 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6224 otherwise it is NULL.
6226 The result is a pointer to the hash table or NULL if there are no types.
6228 Note: This function processes DWO files only, not DWP files. */
6231 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6232 struct dwo_file
*dwo_file
,
6233 gdb::array_view
<dwarf2_section_info
> type_sections
,
6234 htab_up
&types_htab
)
6236 for (dwarf2_section_info
§ion
: type_sections
)
6237 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6241 /* Create the hash table of all entries in the .debug_types section,
6242 and initialize all_type_units.
6243 The result is zero if there is an error (e.g. missing .debug_types section),
6244 otherwise non-zero. */
6247 create_all_type_units (dwarf2_per_objfile
*per_objfile
)
6251 create_debug_type_hash_table (per_objfile
, NULL
, &per_objfile
->per_bfd
->info
,
6252 types_htab
, rcuh_kind::COMPILE
);
6253 create_debug_types_hash_table (per_objfile
, NULL
, per_objfile
->per_bfd
->types
,
6255 if (types_htab
== NULL
)
6257 per_objfile
->per_bfd
->signatured_types
= NULL
;
6261 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6263 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
6264 per_objfile
->per_bfd
->all_type_units
.reserve
6265 (htab_elements (per_objfile
->per_bfd
->signatured_types
.get ()));
6267 htab_traverse_noresize (per_objfile
->per_bfd
->signatured_types
.get (),
6268 add_signatured_type_cu_to_table
,
6269 &per_objfile
->per_bfd
->all_type_units
);
6274 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6275 If SLOT is non-NULL, it is the entry to use in the hash table.
6276 Otherwise we find one. */
6278 static struct signatured_type
*
6279 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6281 if (per_objfile
->per_bfd
->all_type_units
.size ()
6282 == per_objfile
->per_bfd
->all_type_units
.capacity ())
6283 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6285 signatured_type
*sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6287 per_objfile
->resize_symtabs ();
6289 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6290 sig_type
->signature
= sig
;
6291 sig_type
->per_cu
.is_debug_types
= 1;
6292 if (per_objfile
->per_bfd
->using_index
)
6294 sig_type
->per_cu
.v
.quick
=
6295 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6296 struct dwarf2_per_cu_quick_data
);
6301 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6304 gdb_assert (*slot
== NULL
);
6306 /* The rest of sig_type must be filled in by the caller. */
6310 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6311 Fill in SIG_ENTRY with DWO_ENTRY. */
6314 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6315 struct signatured_type
*sig_entry
,
6316 struct dwo_unit
*dwo_entry
)
6318 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6320 /* Make sure we're not clobbering something we don't expect to. */
6321 gdb_assert (! sig_entry
->per_cu
.queued
);
6322 gdb_assert (per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6323 if (per_bfd
->using_index
)
6325 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6326 gdb_assert (!per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6329 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6330 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6331 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6332 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6333 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6335 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6336 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6337 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6338 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6339 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6340 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6341 sig_entry
->dwo_unit
= dwo_entry
;
6344 /* Subroutine of lookup_signatured_type.
6345 If we haven't read the TU yet, create the signatured_type data structure
6346 for a TU to be read in directly from a DWO file, bypassing the stub.
6347 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6348 using .gdb_index, then when reading a CU we want to stay in the DWO file
6349 containing that CU. Otherwise we could end up reading several other DWO
6350 files (due to comdat folding) to process the transitive closure of all the
6351 mentioned TUs, and that can be slow. The current DWO file will have every
6352 type signature that it needs.
6353 We only do this for .gdb_index because in the psymtab case we already have
6354 to read all the DWOs to build the type unit groups. */
6356 static struct signatured_type
*
6357 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6359 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6360 struct dwo_file
*dwo_file
;
6361 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6362 struct signatured_type find_sig_entry
, *sig_entry
;
6365 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6367 /* If TU skeletons have been removed then we may not have read in any
6369 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6370 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6372 /* We only ever need to read in one copy of a signatured type.
6373 Use the global signatured_types array to do our own comdat-folding
6374 of types. If this is the first time we're reading this TU, and
6375 the TU has an entry in .gdb_index, replace the recorded data from
6376 .gdb_index with this TU. */
6378 find_sig_entry
.signature
= sig
;
6379 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6380 &find_sig_entry
, INSERT
);
6381 sig_entry
= (struct signatured_type
*) *slot
;
6383 /* We can get here with the TU already read, *or* in the process of being
6384 read. Don't reassign the global entry to point to this DWO if that's
6385 the case. Also note that if the TU is already being read, it may not
6386 have come from a DWO, the program may be a mix of Fission-compiled
6387 code and non-Fission-compiled code. */
6389 /* Have we already tried to read this TU?
6390 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6391 needn't exist in the global table yet). */
6392 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6395 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6396 dwo_unit of the TU itself. */
6397 dwo_file
= cu
->dwo_unit
->dwo_file
;
6399 /* Ok, this is the first time we're reading this TU. */
6400 if (dwo_file
->tus
== NULL
)
6402 find_dwo_entry
.signature
= sig
;
6403 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6405 if (dwo_entry
== NULL
)
6408 /* If the global table doesn't have an entry for this TU, add one. */
6409 if (sig_entry
== NULL
)
6410 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6412 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6413 sig_entry
->per_cu
.tu_read
= 1;
6417 /* Subroutine of lookup_signatured_type.
6418 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6419 then try the DWP file. If the TU stub (skeleton) has been removed then
6420 it won't be in .gdb_index. */
6422 static struct signatured_type
*
6423 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6425 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6426 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6427 struct dwo_unit
*dwo_entry
;
6428 struct signatured_type find_sig_entry
, *sig_entry
;
6431 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6432 gdb_assert (dwp_file
!= NULL
);
6434 /* If TU skeletons have been removed then we may not have read in any
6436 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6437 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6439 find_sig_entry
.signature
= sig
;
6440 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6441 &find_sig_entry
, INSERT
);
6442 sig_entry
= (struct signatured_type
*) *slot
;
6444 /* Have we already tried to read this TU?
6445 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6446 needn't exist in the global table yet). */
6447 if (sig_entry
!= NULL
)
6450 if (dwp_file
->tus
== NULL
)
6452 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6453 1 /* is_debug_types */);
6454 if (dwo_entry
== NULL
)
6457 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6458 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6463 /* Lookup a signature based type for DW_FORM_ref_sig8.
6464 Returns NULL if signature SIG is not present in the table.
6465 It is up to the caller to complain about this. */
6467 static struct signatured_type
*
6468 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6470 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6472 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6474 /* We're in a DWO/DWP file, and we're using .gdb_index.
6475 These cases require special processing. */
6476 if (get_dwp_file (per_objfile
) == NULL
)
6477 return lookup_dwo_signatured_type (cu
, sig
);
6479 return lookup_dwp_signatured_type (cu
, sig
);
6483 struct signatured_type find_entry
, *entry
;
6485 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6487 find_entry
.signature
= sig
;
6488 entry
= ((struct signatured_type
*)
6489 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6495 /* Low level DIE reading support. */
6497 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6500 init_cu_die_reader (struct die_reader_specs
*reader
,
6501 struct dwarf2_cu
*cu
,
6502 struct dwarf2_section_info
*section
,
6503 struct dwo_file
*dwo_file
,
6504 struct abbrev_table
*abbrev_table
)
6506 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6507 reader
->abfd
= section
->get_bfd_owner ();
6509 reader
->dwo_file
= dwo_file
;
6510 reader
->die_section
= section
;
6511 reader
->buffer
= section
->buffer
;
6512 reader
->buffer_end
= section
->buffer
+ section
->size
;
6513 reader
->abbrev_table
= abbrev_table
;
6516 /* Subroutine of cutu_reader to simplify it.
6517 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6518 There's just a lot of work to do, and cutu_reader is big enough
6521 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6522 from it to the DIE in the DWO. If NULL we are skipping the stub.
6523 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6524 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6525 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6526 STUB_COMP_DIR may be non-NULL.
6527 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6528 are filled in with the info of the DIE from the DWO file.
6529 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6530 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6531 kept around for at least as long as *RESULT_READER.
6533 The result is non-zero if a valid (non-dummy) DIE was found. */
6536 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6537 struct dwo_unit
*dwo_unit
,
6538 struct die_info
*stub_comp_unit_die
,
6539 const char *stub_comp_dir
,
6540 struct die_reader_specs
*result_reader
,
6541 const gdb_byte
**result_info_ptr
,
6542 struct die_info
**result_comp_unit_die
,
6543 abbrev_table_up
*result_dwo_abbrev_table
)
6545 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6546 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6547 struct objfile
*objfile
= per_objfile
->objfile
;
6549 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6550 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6551 int i
,num_extra_attrs
;
6552 struct dwarf2_section_info
*dwo_abbrev_section
;
6553 struct die_info
*comp_unit_die
;
6555 /* At most one of these may be provided. */
6556 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6558 /* These attributes aren't processed until later:
6559 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6560 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6561 referenced later. However, these attributes are found in the stub
6562 which we won't have later. In order to not impose this complication
6563 on the rest of the code, we read them here and copy them to the
6572 if (stub_comp_unit_die
!= NULL
)
6574 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6576 if (!per_cu
->is_debug_types
)
6577 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6578 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6579 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6580 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6581 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6583 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6585 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6586 We need the value before we can process DW_AT_ranges values from the
6588 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6590 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6591 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6592 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6593 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6595 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6597 else if (stub_comp_dir
!= NULL
)
6599 /* Reconstruct the comp_dir attribute to simplify the code below. */
6600 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6601 comp_dir
->name
= DW_AT_comp_dir
;
6602 comp_dir
->form
= DW_FORM_string
;
6603 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6606 /* Set up for reading the DWO CU/TU. */
6607 cu
->dwo_unit
= dwo_unit
;
6608 dwarf2_section_info
*section
= dwo_unit
->section
;
6609 section
->read (objfile
);
6610 abfd
= section
->get_bfd_owner ();
6611 begin_info_ptr
= info_ptr
= (section
->buffer
6612 + to_underlying (dwo_unit
->sect_off
));
6613 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6615 if (per_cu
->is_debug_types
)
6617 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6619 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6620 section
, dwo_abbrev_section
,
6621 info_ptr
, rcuh_kind::TYPE
);
6622 /* This is not an assert because it can be caused by bad debug info. */
6623 if (sig_type
->signature
!= cu
->header
.signature
)
6625 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6626 " TU at offset %s [in module %s]"),
6627 hex_string (sig_type
->signature
),
6628 hex_string (cu
->header
.signature
),
6629 sect_offset_str (dwo_unit
->sect_off
),
6630 bfd_get_filename (abfd
));
6632 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6633 /* For DWOs coming from DWP files, we don't know the CU length
6634 nor the type's offset in the TU until now. */
6635 dwo_unit
->length
= cu
->header
.get_length ();
6636 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6638 /* Establish the type offset that can be used to lookup the type.
6639 For DWO files, we don't know it until now. */
6640 sig_type
->type_offset_in_section
6641 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6645 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6646 section
, dwo_abbrev_section
,
6647 info_ptr
, rcuh_kind::COMPILE
);
6648 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6649 /* For DWOs coming from DWP files, we don't know the CU length
6651 dwo_unit
->length
= cu
->header
.get_length ();
6654 dwo_abbrev_section
->read (objfile
);
6655 *result_dwo_abbrev_table
6656 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6657 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6658 result_dwo_abbrev_table
->get ());
6660 /* Read in the die, but leave space to copy over the attributes
6661 from the stub. This has the benefit of simplifying the rest of
6662 the code - all the work to maintain the illusion of a single
6663 DW_TAG_{compile,type}_unit DIE is done here. */
6664 num_extra_attrs
= ((stmt_list
!= NULL
)
6668 + (comp_dir
!= NULL
));
6669 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6672 /* Copy over the attributes from the stub to the DIE we just read in. */
6673 comp_unit_die
= *result_comp_unit_die
;
6674 i
= comp_unit_die
->num_attrs
;
6675 if (stmt_list
!= NULL
)
6676 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6678 comp_unit_die
->attrs
[i
++] = *low_pc
;
6679 if (high_pc
!= NULL
)
6680 comp_unit_die
->attrs
[i
++] = *high_pc
;
6682 comp_unit_die
->attrs
[i
++] = *ranges
;
6683 if (comp_dir
!= NULL
)
6684 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6685 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6687 if (dwarf_die_debug
)
6689 fprintf_unfiltered (gdb_stdlog
,
6690 "Read die from %s@0x%x of %s:\n",
6691 section
->get_name (),
6692 (unsigned) (begin_info_ptr
- section
->buffer
),
6693 bfd_get_filename (abfd
));
6694 dump_die (comp_unit_die
, dwarf_die_debug
);
6697 /* Skip dummy compilation units. */
6698 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6699 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6702 *result_info_ptr
= info_ptr
;
6706 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6707 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6708 signature is part of the header. */
6709 static gdb::optional
<ULONGEST
>
6710 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6712 if (cu
->header
.version
>= 5)
6713 return cu
->header
.signature
;
6714 struct attribute
*attr
;
6715 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6716 if (attr
== nullptr || !attr
->form_is_unsigned ())
6717 return gdb::optional
<ULONGEST
> ();
6718 return attr
->as_unsigned ();
6721 /* Subroutine of cutu_reader to simplify it.
6722 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6723 Returns NULL if the specified DWO unit cannot be found. */
6725 static struct dwo_unit
*
6726 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6728 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6729 struct dwo_unit
*dwo_unit
;
6730 const char *comp_dir
;
6732 gdb_assert (cu
!= NULL
);
6734 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6735 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6736 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6738 if (per_cu
->is_debug_types
)
6739 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6742 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6744 if (!signature
.has_value ())
6745 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6747 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6749 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6755 /* Subroutine of cutu_reader to simplify it.
6756 See it for a description of the parameters.
6757 Read a TU directly from a DWO file, bypassing the stub. */
6760 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6761 dwarf2_per_objfile
*per_objfile
,
6762 dwarf2_cu
*existing_cu
)
6764 struct signatured_type
*sig_type
;
6766 /* Verify we can do the following downcast, and that we have the
6768 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6769 sig_type
= (struct signatured_type
*) this_cu
;
6770 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6774 if (existing_cu
!= nullptr)
6777 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6778 /* There's no need to do the rereading_dwo_cu handling that
6779 cutu_reader does since we don't read the stub. */
6783 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6784 in per_objfile yet. */
6785 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6786 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6787 cu
= m_new_cu
.get ();
6790 /* A future optimization, if needed, would be to use an existing
6791 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6792 could share abbrev tables. */
6794 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6795 NULL
/* stub_comp_unit_die */,
6796 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6799 &m_dwo_abbrev_table
) == 0)
6806 /* Initialize a CU (or TU) and read its DIEs.
6807 If the CU defers to a DWO file, read the DWO file as well.
6809 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6810 Otherwise the table specified in the comp unit header is read in and used.
6811 This is an optimization for when we already have the abbrev table.
6813 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6816 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6817 dwarf2_per_objfile
*per_objfile
,
6818 struct abbrev_table
*abbrev_table
,
6819 dwarf2_cu
*existing_cu
,
6821 : die_reader_specs
{},
6824 struct objfile
*objfile
= per_objfile
->objfile
;
6825 struct dwarf2_section_info
*section
= this_cu
->section
;
6826 bfd
*abfd
= section
->get_bfd_owner ();
6827 const gdb_byte
*begin_info_ptr
;
6828 struct signatured_type
*sig_type
= NULL
;
6829 struct dwarf2_section_info
*abbrev_section
;
6830 /* Non-zero if CU currently points to a DWO file and we need to
6831 reread it. When this happens we need to reread the skeleton die
6832 before we can reread the DWO file (this only applies to CUs, not TUs). */
6833 int rereading_dwo_cu
= 0;
6835 if (dwarf_die_debug
)
6836 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6837 this_cu
->is_debug_types
? "type" : "comp",
6838 sect_offset_str (this_cu
->sect_off
));
6840 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6841 file (instead of going through the stub), short-circuit all of this. */
6842 if (this_cu
->reading_dwo_directly
)
6844 /* Narrow down the scope of possibilities to have to understand. */
6845 gdb_assert (this_cu
->is_debug_types
);
6846 gdb_assert (abbrev_table
== NULL
);
6847 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
6851 /* This is cheap if the section is already read in. */
6852 section
->read (objfile
);
6854 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6856 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6860 if (existing_cu
!= nullptr)
6863 /* If this CU is from a DWO file we need to start over, we need to
6864 refetch the attributes from the skeleton CU.
6865 This could be optimized by retrieving those attributes from when we
6866 were here the first time: the previous comp_unit_die was stored in
6867 comp_unit_obstack. But there's no data yet that we need this
6869 if (cu
->dwo_unit
!= NULL
)
6870 rereading_dwo_cu
= 1;
6874 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6875 in per_objfile yet. */
6876 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6877 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6878 cu
= m_new_cu
.get ();
6881 /* Get the header. */
6882 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6884 /* We already have the header, there's no need to read it in again. */
6885 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6889 if (this_cu
->is_debug_types
)
6891 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6892 section
, abbrev_section
,
6893 info_ptr
, rcuh_kind::TYPE
);
6895 /* Since per_cu is the first member of struct signatured_type,
6896 we can go from a pointer to one to a pointer to the other. */
6897 sig_type
= (struct signatured_type
*) this_cu
;
6898 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6899 gdb_assert (sig_type
->type_offset_in_tu
6900 == cu
->header
.type_cu_offset_in_tu
);
6901 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6903 /* LENGTH has not been set yet for type units if we're
6904 using .gdb_index. */
6905 this_cu
->length
= cu
->header
.get_length ();
6907 /* Establish the type offset that can be used to lookup the type. */
6908 sig_type
->type_offset_in_section
=
6909 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6911 this_cu
->dwarf_version
= cu
->header
.version
;
6915 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6916 section
, abbrev_section
,
6918 rcuh_kind::COMPILE
);
6920 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6921 if (this_cu
->length
== 0)
6922 this_cu
->length
= cu
->header
.get_length ();
6924 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6925 this_cu
->dwarf_version
= cu
->header
.version
;
6929 /* Skip dummy compilation units. */
6930 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6931 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6937 /* If we don't have them yet, read the abbrevs for this compilation unit.
6938 And if we need to read them now, make sure they're freed when we're
6940 if (abbrev_table
!= NULL
)
6941 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6944 abbrev_section
->read (objfile
);
6945 m_abbrev_table_holder
6946 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
6947 abbrev_table
= m_abbrev_table_holder
.get ();
6950 /* Read the top level CU/TU die. */
6951 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6952 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6954 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6960 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6961 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6962 table from the DWO file and pass the ownership over to us. It will be
6963 referenced from READER, so we must make sure to free it after we're done
6966 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6967 DWO CU, that this test will fail (the attribute will not be present). */
6968 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6969 if (dwo_name
!= nullptr)
6971 struct dwo_unit
*dwo_unit
;
6972 struct die_info
*dwo_comp_unit_die
;
6974 if (comp_unit_die
->has_children
)
6976 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6977 " has children (offset %s) [in module %s]"),
6978 sect_offset_str (this_cu
->sect_off
),
6979 bfd_get_filename (abfd
));
6981 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
6982 if (dwo_unit
!= NULL
)
6984 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
6985 comp_unit_die
, NULL
,
6988 &m_dwo_abbrev_table
) == 0)
6994 comp_unit_die
= dwo_comp_unit_die
;
6998 /* Yikes, we couldn't find the rest of the DIE, we only have
6999 the stub. A complaint has already been logged. There's
7000 not much more we can do except pass on the stub DIE to
7001 die_reader_func. We don't want to throw an error on bad
7008 cutu_reader::keep ()
7010 /* Done, clean up. */
7011 gdb_assert (!dummy_p
);
7012 if (m_new_cu
!= NULL
)
7014 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7016 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7017 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7021 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7022 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7023 assumed to have already done the lookup to find the DWO file).
7025 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7026 THIS_CU->is_debug_types, but nothing else.
7028 We fill in THIS_CU->length.
7030 THIS_CU->cu is always freed when done.
7031 This is done in order to not leave THIS_CU->cu in a state where we have
7032 to care whether it refers to the "main" CU or the DWO CU.
7034 When parent_cu is passed, it is used to provide a default value for
7035 str_offsets_base and addr_base from the parent. */
7037 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7038 dwarf2_per_objfile
*per_objfile
,
7039 struct dwarf2_cu
*parent_cu
,
7040 struct dwo_file
*dwo_file
)
7041 : die_reader_specs
{},
7044 struct objfile
*objfile
= per_objfile
->objfile
;
7045 struct dwarf2_section_info
*section
= this_cu
->section
;
7046 bfd
*abfd
= section
->get_bfd_owner ();
7047 struct dwarf2_section_info
*abbrev_section
;
7048 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7050 if (dwarf_die_debug
)
7051 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7052 this_cu
->is_debug_types
? "type" : "comp",
7053 sect_offset_str (this_cu
->sect_off
));
7055 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7057 abbrev_section
= (dwo_file
!= NULL
7058 ? &dwo_file
->sections
.abbrev
7059 : get_abbrev_section_for_cu (this_cu
));
7061 /* This is cheap if the section is already read in. */
7062 section
->read (objfile
);
7064 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7066 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7067 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
7068 section
, abbrev_section
, info_ptr
,
7069 (this_cu
->is_debug_types
7071 : rcuh_kind::COMPILE
));
7073 if (parent_cu
!= nullptr)
7075 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7076 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7078 this_cu
->length
= m_new_cu
->header
.get_length ();
7080 /* Skip dummy compilation units. */
7081 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7082 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7088 abbrev_section
->read (objfile
);
7089 m_abbrev_table_holder
7090 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
7092 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7093 m_abbrev_table_holder
.get ());
7094 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7098 /* Type Unit Groups.
7100 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7101 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7102 so that all types coming from the same compilation (.o file) are grouped
7103 together. A future step could be to put the types in the same symtab as
7104 the CU the types ultimately came from. */
7107 hash_type_unit_group (const void *item
)
7109 const struct type_unit_group
*tu_group
7110 = (const struct type_unit_group
*) item
;
7112 return hash_stmt_list_entry (&tu_group
->hash
);
7116 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7118 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7119 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7121 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7124 /* Allocate a hash table for type unit groups. */
7127 allocate_type_unit_groups_table ()
7129 return htab_up (htab_create_alloc (3,
7130 hash_type_unit_group
,
7132 NULL
, xcalloc
, xfree
));
7135 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7136 partial symtabs. We combine several TUs per psymtab to not let the size
7137 of any one psymtab grow too big. */
7138 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7139 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7141 /* Helper routine for get_type_unit_group.
7142 Create the type_unit_group object used to hold one or more TUs. */
7144 static struct type_unit_group
*
7145 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7147 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7148 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7149 struct dwarf2_per_cu_data
*per_cu
;
7150 struct type_unit_group
*tu_group
;
7152 tu_group
= OBSTACK_ZALLOC (&per_bfd
->obstack
, type_unit_group
);
7153 per_cu
= &tu_group
->per_cu
;
7154 per_cu
->per_bfd
= per_bfd
;
7156 if (per_bfd
->using_index
)
7158 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7159 struct dwarf2_per_cu_quick_data
);
7163 unsigned int line_offset
= to_underlying (line_offset_struct
);
7164 dwarf2_psymtab
*pst
;
7167 /* Give the symtab a useful name for debug purposes. */
7168 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7169 name
= string_printf ("<type_units_%d>",
7170 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7172 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7174 pst
= create_partial_symtab (per_cu
, per_objfile
, name
.c_str ());
7175 pst
->anonymous
= true;
7178 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7179 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7184 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7185 STMT_LIST is a DW_AT_stmt_list attribute. */
7187 static struct type_unit_group
*
7188 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7190 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7191 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7192 struct type_unit_group
*tu_group
;
7194 unsigned int line_offset
;
7195 struct type_unit_group type_unit_group_for_lookup
;
7197 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7198 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7200 /* Do we need to create a new group, or can we use an existing one? */
7202 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
7204 line_offset
= stmt_list
->as_unsigned ();
7205 ++tu_stats
->nr_symtab_sharers
;
7209 /* Ugh, no stmt_list. Rare, but we have to handle it.
7210 We can do various things here like create one group per TU or
7211 spread them over multiple groups to split up the expansion work.
7212 To avoid worst case scenarios (too many groups or too large groups)
7213 we, umm, group them in bunches. */
7214 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7215 | (tu_stats
->nr_stmt_less_type_units
7216 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7217 ++tu_stats
->nr_stmt_less_type_units
;
7220 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7221 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7222 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7223 &type_unit_group_for_lookup
, INSERT
);
7226 tu_group
= (struct type_unit_group
*) *slot
;
7227 gdb_assert (tu_group
!= NULL
);
7231 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7232 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7234 ++tu_stats
->nr_symtabs
;
7240 /* Partial symbol tables. */
7242 /* Create a psymtab named NAME and assign it to PER_CU.
7244 The caller must fill in the following details:
7245 dirname, textlow, texthigh. */
7247 static dwarf2_psymtab
*
7248 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7249 dwarf2_per_objfile
*per_objfile
,
7253 = new dwarf2_psymtab (name
, per_objfile
->per_bfd
->partial_symtabs
.get (),
7254 per_objfile
->objfile
->per_bfd
, per_cu
);
7256 pst
->psymtabs_addrmap_supported
= true;
7258 /* This is the glue that links PST into GDB's symbol API. */
7259 per_cu
->v
.psymtab
= pst
;
7264 /* DIE reader function for process_psymtab_comp_unit. */
7267 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7268 const gdb_byte
*info_ptr
,
7269 struct die_info
*comp_unit_die
,
7270 enum language pretend_language
)
7272 struct dwarf2_cu
*cu
= reader
->cu
;
7273 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7274 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7275 struct objfile
*objfile
= per_objfile
->objfile
;
7276 struct gdbarch
*gdbarch
= objfile
->arch ();
7277 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7279 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7280 dwarf2_psymtab
*pst
;
7281 enum pc_bounds_kind cu_bounds_kind
;
7282 const char *filename
;
7284 gdb_assert (! per_cu
->is_debug_types
);
7286 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7288 /* Allocate a new partial symbol table structure. */
7289 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7290 static const char artificial
[] = "<artificial>";
7291 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7292 if (filename
== NULL
)
7294 else if (strcmp (filename
, artificial
) == 0)
7296 debug_filename
.reset (concat (artificial
, "@",
7297 sect_offset_str (per_cu
->sect_off
),
7299 filename
= debug_filename
.get ();
7302 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7304 /* This must be done before calling dwarf2_build_include_psymtabs. */
7305 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7307 baseaddr
= objfile
->text_section_offset ();
7309 dwarf2_find_base_address (comp_unit_die
, cu
);
7311 /* Possibly set the default values of LOWPC and HIGHPC from
7313 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7314 &best_highpc
, cu
, pst
);
7315 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7318 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7321 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7323 /* Store the contiguous range if it is not empty; it can be
7324 empty for CUs with no code. */
7325 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7329 /* Check if comp unit has_children.
7330 If so, read the rest of the partial symbols from this comp unit.
7331 If not, there's no more debug_info for this comp unit. */
7332 if (comp_unit_die
->has_children
)
7334 struct partial_die_info
*first_die
;
7335 CORE_ADDR lowpc
, highpc
;
7337 lowpc
= ((CORE_ADDR
) -1);
7338 highpc
= ((CORE_ADDR
) 0);
7340 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7342 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7343 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7345 /* If we didn't find a lowpc, set it to highpc to avoid
7346 complaints from `maint check'. */
7347 if (lowpc
== ((CORE_ADDR
) -1))
7350 /* If the compilation unit didn't have an explicit address range,
7351 then use the information extracted from its child dies. */
7352 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7355 best_highpc
= highpc
;
7358 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7359 best_lowpc
+ baseaddr
)
7361 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7362 best_highpc
+ baseaddr
)
7367 if (!cu
->per_cu
->imported_symtabs_empty ())
7370 int len
= cu
->per_cu
->imported_symtabs_size ();
7372 /* Fill in 'dependencies' here; we fill in 'users' in a
7374 pst
->number_of_dependencies
= len
;
7376 = per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7377 for (i
= 0; i
< len
; ++i
)
7379 pst
->dependencies
[i
]
7380 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7383 cu
->per_cu
->imported_symtabs_free ();
7386 /* Get the list of files included in the current compilation unit,
7387 and build a psymtab for each of them. */
7388 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7390 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7391 ", %d global, %d static syms",
7392 per_cu
->is_debug_types
? "type" : "comp",
7393 sect_offset_str (per_cu
->sect_off
),
7394 paddress (gdbarch
, pst
->text_low (objfile
)),
7395 paddress (gdbarch
, pst
->text_high (objfile
)),
7396 (int) pst
->global_psymbols
.size (),
7397 (int) pst
->static_psymbols
.size ());
7400 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7401 Process compilation unit THIS_CU for a psymtab. */
7404 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7405 dwarf2_per_objfile
*per_objfile
,
7406 bool want_partial_unit
,
7407 enum language pretend_language
)
7409 /* If this compilation unit was already read in, free the
7410 cached copy in order to read it in again. This is
7411 necessary because we skipped some symbols when we first
7412 read in the compilation unit (see load_partial_dies).
7413 This problem could be avoided, but the benefit is unclear. */
7414 per_objfile
->remove_cu (this_cu
);
7416 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7418 switch (reader
.comp_unit_die
->tag
)
7420 case DW_TAG_compile_unit
:
7421 this_cu
->unit_type
= DW_UT_compile
;
7423 case DW_TAG_partial_unit
:
7424 this_cu
->unit_type
= DW_UT_partial
;
7426 case DW_TAG_type_unit
:
7427 this_cu
->unit_type
= DW_UT_type
;
7430 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
7431 dwarf_tag_name (reader
.comp_unit_die
->tag
),
7432 sect_offset_str (reader
.cu
->per_cu
->sect_off
),
7433 objfile_name (per_objfile
->objfile
));
7440 else if (this_cu
->is_debug_types
)
7441 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7442 reader
.comp_unit_die
);
7443 else if (want_partial_unit
7444 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7445 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7446 reader
.comp_unit_die
,
7449 this_cu
->lang
= reader
.cu
->language
;
7451 /* Age out any secondary CUs. */
7452 per_objfile
->age_comp_units ();
7455 /* Reader function for build_type_psymtabs. */
7458 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7459 const gdb_byte
*info_ptr
,
7460 struct die_info
*type_unit_die
)
7462 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7463 struct dwarf2_cu
*cu
= reader
->cu
;
7464 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7465 struct signatured_type
*sig_type
;
7466 struct type_unit_group
*tu_group
;
7467 struct attribute
*attr
;
7468 struct partial_die_info
*first_die
;
7469 CORE_ADDR lowpc
, highpc
;
7470 dwarf2_psymtab
*pst
;
7472 gdb_assert (per_cu
->is_debug_types
);
7473 sig_type
= (struct signatured_type
*) per_cu
;
7475 if (! type_unit_die
->has_children
)
7478 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7479 tu_group
= get_type_unit_group (cu
, attr
);
7481 if (tu_group
->tus
== nullptr)
7482 tu_group
->tus
= new std::vector
<signatured_type
*>;
7483 tu_group
->tus
->push_back (sig_type
);
7485 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7486 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7487 pst
->anonymous
= true;
7489 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7491 lowpc
= (CORE_ADDR
) -1;
7492 highpc
= (CORE_ADDR
) 0;
7493 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7498 /* Struct used to sort TUs by their abbreviation table offset. */
7500 struct tu_abbrev_offset
7502 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7503 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7506 signatured_type
*sig_type
;
7507 sect_offset abbrev_offset
;
7510 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7513 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7514 const struct tu_abbrev_offset
&b
)
7516 return a
.abbrev_offset
< b
.abbrev_offset
;
7519 /* Efficiently read all the type units.
7520 This does the bulk of the work for build_type_psymtabs.
7522 The efficiency is because we sort TUs by the abbrev table they use and
7523 only read each abbrev table once. In one program there are 200K TUs
7524 sharing 8K abbrev tables.
7526 The main purpose of this function is to support building the
7527 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7528 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7529 can collapse the search space by grouping them by stmt_list.
7530 The savings can be significant, in the same program from above the 200K TUs
7531 share 8K stmt_list tables.
7533 FUNC is expected to call get_type_unit_group, which will create the
7534 struct type_unit_group if necessary and add it to
7535 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7538 build_type_psymtabs_1 (dwarf2_per_objfile
*per_objfile
)
7540 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7541 abbrev_table_up abbrev_table
;
7542 sect_offset abbrev_offset
;
7544 /* It's up to the caller to not call us multiple times. */
7545 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7547 if (per_objfile
->per_bfd
->all_type_units
.empty ())
7550 /* TUs typically share abbrev tables, and there can be way more TUs than
7551 abbrev tables. Sort by abbrev table to reduce the number of times we
7552 read each abbrev table in.
7553 Alternatives are to punt or to maintain a cache of abbrev tables.
7554 This is simpler and efficient enough for now.
7556 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7557 symtab to use). Typically TUs with the same abbrev offset have the same
7558 stmt_list value too so in practice this should work well.
7560 The basic algorithm here is:
7562 sort TUs by abbrev table
7563 for each TU with same abbrev table:
7564 read abbrev table if first user
7565 read TU top level DIE
7566 [IWBN if DWO skeletons had DW_AT_stmt_list]
7569 dwarf_read_debug_printf ("Building type unit groups ...");
7571 /* Sort in a separate table to maintain the order of all_type_units
7572 for .gdb_index: TU indices directly index all_type_units. */
7573 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7574 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
7576 for (signatured_type
*sig_type
: per_objfile
->per_bfd
->all_type_units
)
7577 sorted_by_abbrev
.emplace_back
7578 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->per_cu
.section
,
7579 sig_type
->per_cu
.sect_off
));
7581 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7582 sort_tu_by_abbrev_offset
);
7584 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7586 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7588 /* Switch to the next abbrev table if necessary. */
7589 if (abbrev_table
== NULL
7590 || tu
.abbrev_offset
!= abbrev_offset
)
7592 abbrev_offset
= tu
.abbrev_offset
;
7593 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7595 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7596 ++tu_stats
->nr_uniq_abbrev_tables
;
7599 cutu_reader
reader (&tu
.sig_type
->per_cu
, per_objfile
,
7600 abbrev_table
.get (), nullptr, false);
7601 if (!reader
.dummy_p
)
7602 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7603 reader
.comp_unit_die
);
7607 /* Print collected type unit statistics. */
7610 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7612 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7614 dwarf_read_debug_printf ("Type unit statistics:");
7615 dwarf_read_debug_printf (" %zu TUs",
7616 per_objfile
->per_bfd
->all_type_units
.size ());
7617 dwarf_read_debug_printf (" %d uniq abbrev tables",
7618 tu_stats
->nr_uniq_abbrev_tables
);
7619 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7620 tu_stats
->nr_symtabs
);
7621 dwarf_read_debug_printf (" %d symtab sharers",
7622 tu_stats
->nr_symtab_sharers
);
7623 dwarf_read_debug_printf (" %d type units without a stmt_list",
7624 tu_stats
->nr_stmt_less_type_units
);
7625 dwarf_read_debug_printf (" %d all_type_units reallocs",
7626 tu_stats
->nr_all_type_units_reallocs
);
7629 /* Traversal function for build_type_psymtabs. */
7632 build_type_psymtab_dependencies (void **slot
, void *info
)
7634 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7635 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7636 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7637 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7638 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7639 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7642 gdb_assert (len
> 0);
7643 gdb_assert (per_cu
->type_unit_group_p ());
7645 pst
->number_of_dependencies
= len
;
7646 pst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7647 for (i
= 0; i
< len
; ++i
)
7649 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7650 gdb_assert (iter
->per_cu
.is_debug_types
);
7651 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7652 iter
->type_unit_group
= tu_group
;
7655 delete tu_group
->tus
;
7656 tu_group
->tus
= nullptr;
7661 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7662 Build partial symbol tables for the .debug_types comp-units. */
7665 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7667 if (! create_all_type_units (per_objfile
))
7670 build_type_psymtabs_1 (per_objfile
);
7673 /* Traversal function for process_skeletonless_type_unit.
7674 Read a TU in a DWO file and build partial symbols for it. */
7677 process_skeletonless_type_unit (void **slot
, void *info
)
7679 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7680 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7681 struct signatured_type find_entry
, *entry
;
7683 /* If this TU doesn't exist in the global table, add it and read it in. */
7685 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7686 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7688 find_entry
.signature
= dwo_unit
->signature
;
7689 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7690 &find_entry
, INSERT
);
7691 /* If we've already seen this type there's nothing to do. What's happening
7692 is we're doing our own version of comdat-folding here. */
7696 /* This does the job that create_all_type_units would have done for
7698 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7699 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7702 /* This does the job that build_type_psymtabs_1 would have done. */
7703 cutu_reader
reader (&entry
->per_cu
, per_objfile
, nullptr, nullptr, false);
7704 if (!reader
.dummy_p
)
7705 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7706 reader
.comp_unit_die
);
7711 /* Traversal function for process_skeletonless_type_units. */
7714 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7716 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7718 if (dwo_file
->tus
!= NULL
)
7719 htab_traverse_noresize (dwo_file
->tus
.get (),
7720 process_skeletonless_type_unit
, info
);
7725 /* Scan all TUs of DWO files, verifying we've processed them.
7726 This is needed in case a TU was emitted without its skeleton.
7727 Note: This can't be done until we know what all the DWO files are. */
7730 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7732 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7733 if (get_dwp_file (per_objfile
) == NULL
7734 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7736 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7737 process_dwo_file_for_skeletonless_type_units
,
7742 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7745 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7747 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7749 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7754 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7756 /* Set the 'user' field only if it is not already set. */
7757 if (pst
->dependencies
[j
]->user
== NULL
)
7758 pst
->dependencies
[j
]->user
= pst
;
7763 /* Build the partial symbol table by doing a quick pass through the
7764 .debug_info and .debug_abbrev sections. */
7767 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7769 struct objfile
*objfile
= per_objfile
->objfile
;
7770 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7772 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7773 objfile_name (objfile
));
7775 scoped_restore restore_reading_psyms
7776 = make_scoped_restore (&per_bfd
->reading_partial_symbols
, true);
7778 per_bfd
->info
.read (objfile
);
7780 /* Any cached compilation units will be linked by the per-objfile
7781 read_in_chain. Make sure to free them when we're done. */
7782 free_cached_comp_units
freer (per_objfile
);
7784 build_type_psymtabs (per_objfile
);
7786 create_all_comp_units (per_objfile
);
7788 /* Create a temporary address map on a temporary obstack. We later
7789 copy this to the final obstack. */
7790 auto_obstack temp_obstack
;
7792 scoped_restore save_psymtabs_addrmap
7793 = make_scoped_restore (&per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7794 addrmap_create_mutable (&temp_obstack
));
7796 for (dwarf2_per_cu_data
*per_cu
: per_bfd
->all_comp_units
)
7798 if (per_cu
->v
.psymtab
!= NULL
)
7799 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7801 process_psymtab_comp_unit (per_cu
, per_objfile
, false,
7805 /* This has to wait until we read the CUs, we need the list of DWOs. */
7806 process_skeletonless_type_units (per_objfile
);
7808 /* Now that all TUs have been processed we can fill in the dependencies. */
7809 if (per_bfd
->type_unit_groups
!= NULL
)
7811 htab_traverse_noresize (per_bfd
->type_unit_groups
.get (),
7812 build_type_psymtab_dependencies
, per_objfile
);
7815 if (dwarf_read_debug
> 0)
7816 print_tu_stats (per_objfile
);
7818 set_partial_user (per_objfile
);
7820 per_bfd
->partial_symtabs
->psymtabs_addrmap
7821 = addrmap_create_fixed (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7822 per_bfd
->partial_symtabs
->obstack ());
7823 /* At this point we want to keep the address map. */
7824 save_psymtabs_addrmap
.release ();
7826 dwarf_read_debug_printf ("Done building psymtabs of %s",
7827 objfile_name (objfile
));
7830 /* Load the partial DIEs for a secondary CU into memory.
7831 This is also used when rereading a primary CU with load_all_dies. */
7834 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7835 dwarf2_per_objfile
*per_objfile
,
7836 dwarf2_cu
*existing_cu
)
7838 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
7840 if (!reader
.dummy_p
)
7842 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7845 /* Check if comp unit has_children.
7846 If so, read the rest of the partial symbols from this comp unit.
7847 If not, there's no more debug_info for this comp unit. */
7848 if (reader
.comp_unit_die
->has_children
)
7849 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7856 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
7857 struct dwarf2_section_info
*section
,
7858 struct dwarf2_section_info
*abbrev_section
,
7859 unsigned int is_dwz
)
7861 const gdb_byte
*info_ptr
;
7862 struct objfile
*objfile
= per_objfile
->objfile
;
7864 dwarf_read_debug_printf ("Reading %s for %s",
7865 section
->get_name (),
7866 section
->get_file_name ());
7868 section
->read (objfile
);
7870 info_ptr
= section
->buffer
;
7872 while (info_ptr
< section
->buffer
+ section
->size
)
7874 struct dwarf2_per_cu_data
*this_cu
;
7876 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7878 comp_unit_head cu_header
;
7879 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
7880 abbrev_section
, info_ptr
,
7881 rcuh_kind::COMPILE
);
7883 /* Save the compilation unit for later lookup. */
7884 if (cu_header
.unit_type
!= DW_UT_type
)
7885 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
7888 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
7889 sig_type
->signature
= cu_header
.signature
;
7890 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7891 this_cu
= &sig_type
->per_cu
;
7893 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7894 this_cu
->sect_off
= sect_off
;
7895 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7896 this_cu
->is_dwz
= is_dwz
;
7897 this_cu
->section
= section
;
7899 per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
7901 info_ptr
= info_ptr
+ this_cu
->length
;
7905 /* Create a list of all compilation units in OBJFILE.
7906 This is only done for -readnow and building partial symtabs. */
7909 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
7911 gdb_assert (per_objfile
->per_bfd
->all_comp_units
.empty ());
7912 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
7913 &per_objfile
->per_bfd
->abbrev
, 0);
7915 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
7917 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1);
7920 /* Process all loaded DIEs for compilation unit CU, starting at
7921 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7922 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7923 DW_AT_ranges). See the comments of add_partial_subprogram on how
7924 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7927 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7928 CORE_ADDR
*highpc
, int set_addrmap
,
7929 struct dwarf2_cu
*cu
)
7931 struct partial_die_info
*pdi
;
7933 /* Now, march along the PDI's, descending into ones which have
7934 interesting children but skipping the children of the other ones,
7935 until we reach the end of the compilation unit. */
7943 /* Anonymous namespaces or modules have no name but have interesting
7944 children, so we need to look at them. Ditto for anonymous
7947 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7948 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7949 || pdi
->tag
== DW_TAG_imported_unit
7950 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7954 case DW_TAG_subprogram
:
7955 case DW_TAG_inlined_subroutine
:
7956 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7957 if (cu
->language
== language_cplus
)
7958 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7961 case DW_TAG_constant
:
7962 case DW_TAG_variable
:
7963 case DW_TAG_typedef
:
7964 case DW_TAG_union_type
:
7965 if (!pdi
->is_declaration
7966 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
7968 add_partial_symbol (pdi
, cu
);
7971 case DW_TAG_class_type
:
7972 case DW_TAG_interface_type
:
7973 case DW_TAG_structure_type
:
7974 if (!pdi
->is_declaration
)
7976 add_partial_symbol (pdi
, cu
);
7978 if ((cu
->language
== language_rust
7979 || cu
->language
== language_cplus
) && pdi
->has_children
)
7980 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7983 case DW_TAG_enumeration_type
:
7984 if (!pdi
->is_declaration
)
7985 add_partial_enumeration (pdi
, cu
);
7987 case DW_TAG_base_type
:
7988 case DW_TAG_subrange_type
:
7989 /* File scope base type definitions are added to the partial
7991 add_partial_symbol (pdi
, cu
);
7993 case DW_TAG_namespace
:
7994 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7997 if (!pdi
->is_declaration
)
7998 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8000 case DW_TAG_imported_unit
:
8002 struct dwarf2_per_cu_data
*per_cu
;
8004 /* For now we don't handle imported units in type units. */
8005 if (cu
->per_cu
->is_debug_types
)
8007 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8008 " supported in type units [in module %s]"),
8009 objfile_name (cu
->per_objfile
->objfile
));
8012 per_cu
= dwarf2_find_containing_comp_unit
8013 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8015 /* Go read the partial unit, if needed. */
8016 if (per_cu
->v
.psymtab
== NULL
)
8017 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8020 cu
->per_cu
->imported_symtabs_push (per_cu
);
8023 case DW_TAG_imported_declaration
:
8024 add_partial_symbol (pdi
, cu
);
8031 /* If the die has a sibling, skip to the sibling. */
8033 pdi
= pdi
->die_sibling
;
8037 /* Functions used to compute the fully scoped name of a partial DIE.
8039 Normally, this is simple. For C++, the parent DIE's fully scoped
8040 name is concatenated with "::" and the partial DIE's name.
8041 Enumerators are an exception; they use the scope of their parent
8042 enumeration type, i.e. the name of the enumeration type is not
8043 prepended to the enumerator.
8045 There are two complexities. One is DW_AT_specification; in this
8046 case "parent" means the parent of the target of the specification,
8047 instead of the direct parent of the DIE. The other is compilers
8048 which do not emit DW_TAG_namespace; in this case we try to guess
8049 the fully qualified name of structure types from their members'
8050 linkage names. This must be done using the DIE's children rather
8051 than the children of any DW_AT_specification target. We only need
8052 to do this for structures at the top level, i.e. if the target of
8053 any DW_AT_specification (if any; otherwise the DIE itself) does not
8056 /* Compute the scope prefix associated with PDI's parent, in
8057 compilation unit CU. The result will be allocated on CU's
8058 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8059 field. NULL is returned if no prefix is necessary. */
8061 partial_die_parent_scope (struct partial_die_info
*pdi
,
8062 struct dwarf2_cu
*cu
)
8064 const char *grandparent_scope
;
8065 struct partial_die_info
*parent
, *real_pdi
;
8067 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8068 then this means the parent of the specification DIE. */
8071 while (real_pdi
->has_specification
)
8073 auto res
= find_partial_die (real_pdi
->spec_offset
,
8074 real_pdi
->spec_is_dwz
, cu
);
8079 parent
= real_pdi
->die_parent
;
8083 if (parent
->scope_set
)
8084 return parent
->scope
;
8088 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8090 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8091 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8092 Work around this problem here. */
8093 if (cu
->language
== language_cplus
8094 && parent
->tag
== DW_TAG_namespace
8095 && strcmp (parent
->name (cu
), "::") == 0
8096 && grandparent_scope
== NULL
)
8098 parent
->scope
= NULL
;
8099 parent
->scope_set
= 1;
8103 /* Nested subroutines in Fortran get a prefix. */
8104 if (pdi
->tag
== DW_TAG_enumerator
)
8105 /* Enumerators should not get the name of the enumeration as a prefix. */
8106 parent
->scope
= grandparent_scope
;
8107 else if (parent
->tag
== DW_TAG_namespace
8108 || parent
->tag
== DW_TAG_module
8109 || parent
->tag
== DW_TAG_structure_type
8110 || parent
->tag
== DW_TAG_class_type
8111 || parent
->tag
== DW_TAG_interface_type
8112 || parent
->tag
== DW_TAG_union_type
8113 || parent
->tag
== DW_TAG_enumeration_type
8114 || (cu
->language
== language_fortran
8115 && parent
->tag
== DW_TAG_subprogram
8116 && pdi
->tag
== DW_TAG_subprogram
))
8118 if (grandparent_scope
== NULL
)
8119 parent
->scope
= parent
->name (cu
);
8121 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8123 parent
->name (cu
), 0, cu
);
8127 /* FIXME drow/2004-04-01: What should we be doing with
8128 function-local names? For partial symbols, we should probably be
8130 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8131 dwarf_tag_name (parent
->tag
),
8132 sect_offset_str (pdi
->sect_off
));
8133 parent
->scope
= grandparent_scope
;
8136 parent
->scope_set
= 1;
8137 return parent
->scope
;
8140 /* Return the fully scoped name associated with PDI, from compilation unit
8141 CU. The result will be allocated with malloc. */
8143 static gdb::unique_xmalloc_ptr
<char>
8144 partial_die_full_name (struct partial_die_info
*pdi
,
8145 struct dwarf2_cu
*cu
)
8147 const char *parent_scope
;
8149 /* If this is a template instantiation, we can not work out the
8150 template arguments from partial DIEs. So, unfortunately, we have
8151 to go through the full DIEs. At least any work we do building
8152 types here will be reused if full symbols are loaded later. */
8153 if (pdi
->has_template_arguments
)
8157 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8159 struct die_info
*die
;
8160 struct attribute attr
;
8161 struct dwarf2_cu
*ref_cu
= cu
;
8163 /* DW_FORM_ref_addr is using section offset. */
8164 attr
.name
= (enum dwarf_attribute
) 0;
8165 attr
.form
= DW_FORM_ref_addr
;
8166 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8167 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8169 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8173 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8174 if (parent_scope
== NULL
)
8177 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8183 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8185 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8186 struct objfile
*objfile
= per_objfile
->objfile
;
8187 struct gdbarch
*gdbarch
= objfile
->arch ();
8189 const char *actual_name
= NULL
;
8192 baseaddr
= objfile
->text_section_offset ();
8194 gdb::unique_xmalloc_ptr
<char> built_actual_name
8195 = partial_die_full_name (pdi
, cu
);
8196 if (built_actual_name
!= NULL
)
8197 actual_name
= built_actual_name
.get ();
8199 if (actual_name
== NULL
)
8200 actual_name
= pdi
->name (cu
);
8202 partial_symbol psymbol
;
8203 memset (&psymbol
, 0, sizeof (psymbol
));
8204 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8205 psymbol
.ginfo
.set_section_index (-1);
8207 /* The code below indicates that the psymbol should be installed by
8209 gdb::optional
<psymbol_placement
> where
;
8213 case DW_TAG_inlined_subroutine
:
8214 case DW_TAG_subprogram
:
8215 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8217 if (pdi
->is_external
8218 || cu
->language
== language_ada
8219 || (cu
->language
== language_fortran
8220 && pdi
->die_parent
!= NULL
8221 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8223 /* Normally, only "external" DIEs are part of the global scope.
8224 But in Ada and Fortran, we want to be able to access nested
8225 procedures globally. So all Ada and Fortran subprograms are
8226 stored in the global scope. */
8227 where
= psymbol_placement::GLOBAL
;
8230 where
= psymbol_placement::STATIC
;
8232 psymbol
.domain
= VAR_DOMAIN
;
8233 psymbol
.aclass
= LOC_BLOCK
;
8234 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8235 psymbol
.ginfo
.value
.address
= addr
;
8237 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8238 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8240 case DW_TAG_constant
:
8241 psymbol
.domain
= VAR_DOMAIN
;
8242 psymbol
.aclass
= LOC_STATIC
;
8243 where
= (pdi
->is_external
8244 ? psymbol_placement::GLOBAL
8245 : psymbol_placement::STATIC
);
8247 case DW_TAG_variable
:
8249 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8253 && !per_objfile
->per_bfd
->has_section_at_zero
)
8255 /* A global or static variable may also have been stripped
8256 out by the linker if unused, in which case its address
8257 will be nullified; do not add such variables into partial
8258 symbol table then. */
8260 else if (pdi
->is_external
)
8263 Don't enter into the minimal symbol tables as there is
8264 a minimal symbol table entry from the ELF symbols already.
8265 Enter into partial symbol table if it has a location
8266 descriptor or a type.
8267 If the location descriptor is missing, new_symbol will create
8268 a LOC_UNRESOLVED symbol, the address of the variable will then
8269 be determined from the minimal symbol table whenever the variable
8271 The address for the partial symbol table entry is not
8272 used by GDB, but it comes in handy for debugging partial symbol
8275 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8277 psymbol
.domain
= VAR_DOMAIN
;
8278 psymbol
.aclass
= LOC_STATIC
;
8279 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8280 psymbol
.ginfo
.value
.address
= addr
;
8281 where
= psymbol_placement::GLOBAL
;
8286 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8288 /* Static Variable. Skip symbols whose value we cannot know (those
8289 without location descriptors or constant values). */
8290 if (!has_loc
&& !pdi
->has_const_value
)
8293 psymbol
.domain
= VAR_DOMAIN
;
8294 psymbol
.aclass
= LOC_STATIC
;
8295 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8297 psymbol
.ginfo
.value
.address
= addr
;
8298 where
= psymbol_placement::STATIC
;
8301 case DW_TAG_array_type
:
8302 case DW_TAG_typedef
:
8303 case DW_TAG_base_type
:
8304 case DW_TAG_subrange_type
:
8305 psymbol
.domain
= VAR_DOMAIN
;
8306 psymbol
.aclass
= LOC_TYPEDEF
;
8307 where
= psymbol_placement::STATIC
;
8309 case DW_TAG_imported_declaration
:
8310 case DW_TAG_namespace
:
8311 psymbol
.domain
= VAR_DOMAIN
;
8312 psymbol
.aclass
= LOC_TYPEDEF
;
8313 where
= psymbol_placement::GLOBAL
;
8316 /* With Fortran 77 there might be a "BLOCK DATA" module
8317 available without any name. If so, we skip the module as it
8318 doesn't bring any value. */
8319 if (actual_name
!= nullptr)
8321 psymbol
.domain
= MODULE_DOMAIN
;
8322 psymbol
.aclass
= LOC_TYPEDEF
;
8323 where
= psymbol_placement::GLOBAL
;
8326 case DW_TAG_class_type
:
8327 case DW_TAG_interface_type
:
8328 case DW_TAG_structure_type
:
8329 case DW_TAG_union_type
:
8330 case DW_TAG_enumeration_type
:
8331 /* Skip external references. The DWARF standard says in the section
8332 about "Structure, Union, and Class Type Entries": "An incomplete
8333 structure, union or class type is represented by a structure,
8334 union or class entry that does not have a byte size attribute
8335 and that has a DW_AT_declaration attribute." */
8336 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8339 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8340 static vs. global. */
8341 psymbol
.domain
= STRUCT_DOMAIN
;
8342 psymbol
.aclass
= LOC_TYPEDEF
;
8343 where
= (cu
->language
== language_cplus
8344 ? psymbol_placement::GLOBAL
8345 : psymbol_placement::STATIC
);
8347 case DW_TAG_enumerator
:
8348 psymbol
.domain
= VAR_DOMAIN
;
8349 psymbol
.aclass
= LOC_CONST
;
8350 where
= (cu
->language
== language_cplus
8351 ? psymbol_placement::GLOBAL
8352 : psymbol_placement::STATIC
);
8358 if (where
.has_value ())
8360 if (built_actual_name
!= nullptr)
8361 actual_name
= objfile
->intern (actual_name
);
8362 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8363 psymbol
.ginfo
.set_linkage_name (actual_name
);
8366 psymbol
.ginfo
.set_demangled_name (actual_name
,
8367 &objfile
->objfile_obstack
);
8368 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8370 cu
->per_cu
->v
.psymtab
->add_psymbol
8371 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
8376 /* Read a partial die corresponding to a namespace; also, add a symbol
8377 corresponding to that namespace to the symbol table. NAMESPACE is
8378 the name of the enclosing namespace. */
8381 add_partial_namespace (struct partial_die_info
*pdi
,
8382 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8383 int set_addrmap
, struct dwarf2_cu
*cu
)
8385 /* Add a symbol for the namespace. */
8387 add_partial_symbol (pdi
, cu
);
8389 /* Now scan partial symbols in that namespace. */
8391 if (pdi
->has_children
)
8392 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8395 /* Read a partial die corresponding to a Fortran module. */
8398 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8399 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8401 /* Add a symbol for the namespace. */
8403 add_partial_symbol (pdi
, cu
);
8405 /* Now scan partial symbols in that module. */
8407 if (pdi
->has_children
)
8408 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8411 /* Read a partial die corresponding to a subprogram or an inlined
8412 subprogram and create a partial symbol for that subprogram.
8413 When the CU language allows it, this routine also defines a partial
8414 symbol for each nested subprogram that this subprogram contains.
8415 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8416 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8418 PDI may also be a lexical block, in which case we simply search
8419 recursively for subprograms defined inside that lexical block.
8420 Again, this is only performed when the CU language allows this
8421 type of definitions. */
8424 add_partial_subprogram (struct partial_die_info
*pdi
,
8425 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8426 int set_addrmap
, struct dwarf2_cu
*cu
)
8428 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8430 if (pdi
->has_pc_info
)
8432 if (pdi
->lowpc
< *lowpc
)
8433 *lowpc
= pdi
->lowpc
;
8434 if (pdi
->highpc
> *highpc
)
8435 *highpc
= pdi
->highpc
;
8438 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8439 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8440 struct gdbarch
*gdbarch
= objfile
->arch ();
8442 CORE_ADDR this_highpc
;
8443 CORE_ADDR this_lowpc
;
8445 baseaddr
= objfile
->text_section_offset ();
8447 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8448 pdi
->lowpc
+ baseaddr
)
8451 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8452 pdi
->highpc
+ baseaddr
)
8454 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8455 this_lowpc
, this_highpc
- 1,
8456 cu
->per_cu
->v
.psymtab
);
8460 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8462 if (!pdi
->is_declaration
)
8463 /* Ignore subprogram DIEs that do not have a name, they are
8464 illegal. Do not emit a complaint at this point, we will
8465 do so when we convert this psymtab into a symtab. */
8467 add_partial_symbol (pdi
, cu
);
8471 if (! pdi
->has_children
)
8474 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8476 pdi
= pdi
->die_child
;
8480 if (pdi
->tag
== DW_TAG_subprogram
8481 || pdi
->tag
== DW_TAG_inlined_subroutine
8482 || pdi
->tag
== DW_TAG_lexical_block
)
8483 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8484 pdi
= pdi
->die_sibling
;
8489 /* Read a partial die corresponding to an enumeration type. */
8492 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8493 struct dwarf2_cu
*cu
)
8495 struct partial_die_info
*pdi
;
8497 if (enum_pdi
->name (cu
) != NULL
)
8498 add_partial_symbol (enum_pdi
, cu
);
8500 pdi
= enum_pdi
->die_child
;
8503 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8504 complaint (_("malformed enumerator DIE ignored"));
8506 add_partial_symbol (pdi
, cu
);
8507 pdi
= pdi
->die_sibling
;
8511 /* Return the initial uleb128 in the die at INFO_PTR. */
8514 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8516 unsigned int bytes_read
;
8518 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8521 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8522 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8524 Return the corresponding abbrev, or NULL if the number is zero (indicating
8525 an empty DIE). In either case *BYTES_READ will be set to the length of
8526 the initial number. */
8528 static const struct abbrev_info
*
8529 peek_die_abbrev (const die_reader_specs
&reader
,
8530 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8532 dwarf2_cu
*cu
= reader
.cu
;
8533 bfd
*abfd
= reader
.abfd
;
8534 unsigned int abbrev_number
8535 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8537 if (abbrev_number
== 0)
8540 const abbrev_info
*abbrev
8541 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8544 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8545 " at offset %s [in module %s]"),
8546 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8547 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8553 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8554 Returns a pointer to the end of a series of DIEs, terminated by an empty
8555 DIE. Any children of the skipped DIEs will also be skipped. */
8557 static const gdb_byte
*
8558 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8562 unsigned int bytes_read
;
8563 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8567 return info_ptr
+ bytes_read
;
8569 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8573 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8574 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8575 abbrev corresponding to that skipped uleb128 should be passed in
8576 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8579 static const gdb_byte
*
8580 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8581 const struct abbrev_info
*abbrev
)
8583 unsigned int bytes_read
;
8584 struct attribute attr
;
8585 bfd
*abfd
= reader
->abfd
;
8586 struct dwarf2_cu
*cu
= reader
->cu
;
8587 const gdb_byte
*buffer
= reader
->buffer
;
8588 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8589 unsigned int form
, i
;
8591 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8593 /* The only abbrev we care about is DW_AT_sibling. */
8594 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8596 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8597 if (attr
.form
== DW_FORM_ref_addr
)
8598 complaint (_("ignoring absolute DW_AT_sibling"));
8601 sect_offset off
= attr
.get_ref_die_offset ();
8602 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8604 if (sibling_ptr
< info_ptr
)
8605 complaint (_("DW_AT_sibling points backwards"));
8606 else if (sibling_ptr
> reader
->buffer_end
)
8607 reader
->die_section
->overflow_complaint ();
8613 /* If it isn't DW_AT_sibling, skip this attribute. */
8614 form
= abbrev
->attrs
[i
].form
;
8618 case DW_FORM_ref_addr
:
8619 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8620 and later it is offset sized. */
8621 if (cu
->header
.version
== 2)
8622 info_ptr
+= cu
->header
.addr_size
;
8624 info_ptr
+= cu
->header
.offset_size
;
8626 case DW_FORM_GNU_ref_alt
:
8627 info_ptr
+= cu
->header
.offset_size
;
8630 info_ptr
+= cu
->header
.addr_size
;
8638 case DW_FORM_flag_present
:
8639 case DW_FORM_implicit_const
:
8656 case DW_FORM_ref_sig8
:
8659 case DW_FORM_data16
:
8662 case DW_FORM_string
:
8663 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8664 info_ptr
+= bytes_read
;
8666 case DW_FORM_sec_offset
:
8668 case DW_FORM_GNU_strp_alt
:
8669 info_ptr
+= cu
->header
.offset_size
;
8671 case DW_FORM_exprloc
:
8673 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8674 info_ptr
+= bytes_read
;
8676 case DW_FORM_block1
:
8677 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8679 case DW_FORM_block2
:
8680 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8682 case DW_FORM_block4
:
8683 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8689 case DW_FORM_ref_udata
:
8690 case DW_FORM_GNU_addr_index
:
8691 case DW_FORM_GNU_str_index
:
8692 case DW_FORM_rnglistx
:
8693 case DW_FORM_loclistx
:
8694 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8696 case DW_FORM_indirect
:
8697 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8698 info_ptr
+= bytes_read
;
8699 /* We need to continue parsing from here, so just go back to
8701 goto skip_attribute
;
8704 error (_("Dwarf Error: Cannot handle %s "
8705 "in DWARF reader [in module %s]"),
8706 dwarf_form_name (form
),
8707 bfd_get_filename (abfd
));
8711 if (abbrev
->has_children
)
8712 return skip_children (reader
, info_ptr
);
8717 /* Locate ORIG_PDI's sibling.
8718 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8720 static const gdb_byte
*
8721 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8722 struct partial_die_info
*orig_pdi
,
8723 const gdb_byte
*info_ptr
)
8725 /* Do we know the sibling already? */
8727 if (orig_pdi
->sibling
)
8728 return orig_pdi
->sibling
;
8730 /* Are there any children to deal with? */
8732 if (!orig_pdi
->has_children
)
8735 /* Skip the children the long way. */
8737 return skip_children (reader
, info_ptr
);
8740 /* Expand this partial symbol table into a full symbol table. SELF is
8744 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8746 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8748 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8750 /* If this psymtab is constructed from a debug-only objfile, the
8751 has_section_at_zero flag will not necessarily be correct. We
8752 can get the correct value for this flag by looking at the data
8753 associated with the (presumably stripped) associated objfile. */
8754 if (objfile
->separate_debug_objfile_backlink
)
8756 dwarf2_per_objfile
*per_objfile_backlink
8757 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8759 per_objfile
->per_bfd
->has_section_at_zero
8760 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8763 expand_psymtab (objfile
);
8765 process_cu_includes (per_objfile
);
8768 /* Reading in full CUs. */
8770 /* Add PER_CU to the queue. */
8773 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8774 dwarf2_per_objfile
*per_objfile
,
8775 enum language pretend_language
)
8779 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
8780 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
8783 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
8785 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8788 Return true if maybe_queue_comp_unit requires the caller to load the CU's
8789 DIEs, false otherwise.
8791 Explanation: there is an invariant that if a CU is queued for expansion
8792 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
8793 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
8794 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
8795 are not yet loaded, the the caller must load the CU's DIEs to ensure the
8796 invariant is respected.
8798 The caller is therefore not required to load the CU's DIEs (we return false)
8801 - the CU is already expanded, and therefore does not get enqueued
8802 - the CU gets enqueued for expansion, but its DIEs are already loaded
8804 Note that the caller should not use this function's return value as an
8805 indicator of whether the CU's DIEs are loaded right now, it should check
8806 that by calling `dwarf2_per_objfile::get_cu` instead. */
8809 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8810 dwarf2_per_cu_data
*per_cu
,
8811 dwarf2_per_objfile
*per_objfile
,
8812 enum language pretend_language
)
8814 /* We may arrive here during partial symbol reading, if we need full
8815 DIEs to process an unusual case (e.g. template arguments). Do
8816 not queue PER_CU, just tell our caller to load its DIEs. */
8817 if (per_cu
->per_bfd
->reading_partial_symbols
)
8819 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8821 if (cu
== NULL
|| cu
->dies
== NULL
)
8826 /* Mark the dependence relation so that we don't flush PER_CU
8828 if (dependent_cu
!= NULL
)
8829 dwarf2_add_dependence (dependent_cu
, per_cu
);
8831 /* If it's already on the queue, we have nothing to do. */
8834 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
8836 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
8838 /* If the CU is queued for expansion, it should not already be
8840 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
8842 /* The DIEs are already loaded, the caller doesn't need to do it. */
8846 bool queued
= false;
8847 if (!per_objfile
->symtab_set_p (per_cu
))
8849 /* Add it to the queue. */
8850 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8854 /* If the compilation unit is already loaded, just mark it as
8856 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8860 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
8861 and the DIEs are not already loaded. */
8862 return queued
&& cu
== nullptr;
8865 /* Process the queue. */
8868 process_queue (dwarf2_per_objfile
*per_objfile
)
8870 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
8871 objfile_name (per_objfile
->objfile
));
8873 /* The queue starts out with one item, but following a DIE reference
8874 may load a new CU, adding it to the end of the queue. */
8875 while (!per_objfile
->per_bfd
->queue
->empty ())
8877 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
8878 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8880 if (!per_objfile
->symtab_set_p (per_cu
))
8882 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8884 /* Skip dummy CUs. */
8887 unsigned int debug_print_threshold
;
8890 if (per_cu
->is_debug_types
)
8892 struct signatured_type
*sig_type
=
8893 (struct signatured_type
*) per_cu
;
8895 sprintf (buf
, "TU %s at offset %s",
8896 hex_string (sig_type
->signature
),
8897 sect_offset_str (per_cu
->sect_off
));
8898 /* There can be 100s of TUs.
8899 Only print them in verbose mode. */
8900 debug_print_threshold
= 2;
8904 sprintf (buf
, "CU at offset %s",
8905 sect_offset_str (per_cu
->sect_off
));
8906 debug_print_threshold
= 1;
8909 if (dwarf_read_debug
>= debug_print_threshold
)
8910 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
8912 if (per_cu
->is_debug_types
)
8913 process_full_type_unit (cu
, item
.pretend_language
);
8915 process_full_comp_unit (cu
, item
.pretend_language
);
8917 if (dwarf_read_debug
>= debug_print_threshold
)
8918 dwarf_read_debug_printf ("Done expanding %s", buf
);
8923 per_objfile
->per_bfd
->queue
->pop ();
8926 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
8927 objfile_name (per_objfile
->objfile
));
8930 /* Read in full symbols for PST, and anything it depends on. */
8933 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8935 gdb_assert (!readin_p (objfile
));
8937 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8938 free_cached_comp_units
freer (per_objfile
);
8939 expand_dependencies (objfile
);
8941 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
8942 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
8945 /* See psympriv.h. */
8948 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
8950 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8951 return per_objfile
->symtab_set_p (per_cu_data
);
8954 /* See psympriv.h. */
8957 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
8959 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8960 return per_objfile
->get_symtab (per_cu_data
);
8963 /* Trivial hash function for die_info: the hash value of a DIE
8964 is its offset in .debug_info for this objfile. */
8967 die_hash (const void *item
)
8969 const struct die_info
*die
= (const struct die_info
*) item
;
8971 return to_underlying (die
->sect_off
);
8974 /* Trivial comparison function for die_info structures: two DIEs
8975 are equal if they have the same offset. */
8978 die_eq (const void *item_lhs
, const void *item_rhs
)
8980 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8981 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8983 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8986 /* Load the DIEs associated with PER_CU into memory.
8988 In some cases, the caller, while reading partial symbols, will need to load
8989 the full symbols for the CU for some reason. It will already have a
8990 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
8991 rather than creating a new one. */
8994 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
8995 dwarf2_per_objfile
*per_objfile
,
8996 dwarf2_cu
*existing_cu
,
8998 enum language pretend_language
)
9000 gdb_assert (! this_cu
->is_debug_types
);
9002 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9006 struct dwarf2_cu
*cu
= reader
.cu
;
9007 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9009 gdb_assert (cu
->die_hash
== NULL
);
9011 htab_create_alloc_ex (cu
->header
.length
/ 12,
9015 &cu
->comp_unit_obstack
,
9016 hashtab_obstack_allocate
,
9017 dummy_obstack_deallocate
);
9019 if (reader
.comp_unit_die
->has_children
)
9020 reader
.comp_unit_die
->child
9021 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9022 &info_ptr
, reader
.comp_unit_die
);
9023 cu
->dies
= reader
.comp_unit_die
;
9024 /* comp_unit_die is not stored in die_hash, no need. */
9026 /* We try not to read any attributes in this function, because not
9027 all CUs needed for references have been loaded yet, and symbol
9028 table processing isn't initialized. But we have to set the CU language,
9029 or we won't be able to build types correctly.
9030 Similarly, if we do not read the producer, we can not apply
9031 producer-specific interpretation. */
9032 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9037 /* Add a DIE to the delayed physname list. */
9040 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9041 const char *name
, struct die_info
*die
,
9042 struct dwarf2_cu
*cu
)
9044 struct delayed_method_info mi
;
9046 mi
.fnfield_index
= fnfield_index
;
9050 cu
->method_list
.push_back (mi
);
9053 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9054 "const" / "volatile". If so, decrements LEN by the length of the
9055 modifier and return true. Otherwise return false. */
9059 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9061 size_t mod_len
= sizeof (mod
) - 1;
9062 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9070 /* Compute the physnames of any methods on the CU's method list.
9072 The computation of method physnames is delayed in order to avoid the
9073 (bad) condition that one of the method's formal parameters is of an as yet
9077 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9079 /* Only C++ delays computing physnames. */
9080 if (cu
->method_list
.empty ())
9082 gdb_assert (cu
->language
== language_cplus
);
9084 for (const delayed_method_info
&mi
: cu
->method_list
)
9086 const char *physname
;
9087 struct fn_fieldlist
*fn_flp
9088 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9089 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9090 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9091 = physname
? physname
: "";
9093 /* Since there's no tag to indicate whether a method is a
9094 const/volatile overload, extract that information out of the
9096 if (physname
!= NULL
)
9098 size_t len
= strlen (physname
);
9102 if (physname
[len
] == ')') /* shortcut */
9104 else if (check_modifier (physname
, len
, " const"))
9105 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9106 else if (check_modifier (physname
, len
, " volatile"))
9107 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9114 /* The list is no longer needed. */
9115 cu
->method_list
.clear ();
9118 /* Go objects should be embedded in a DW_TAG_module DIE,
9119 and it's not clear if/how imported objects will appear.
9120 To keep Go support simple until that's worked out,
9121 go back through what we've read and create something usable.
9122 We could do this while processing each DIE, and feels kinda cleaner,
9123 but that way is more invasive.
9124 This is to, for example, allow the user to type "p var" or "b main"
9125 without having to specify the package name, and allow lookups
9126 of module.object to work in contexts that use the expression
9130 fixup_go_packaging (struct dwarf2_cu
*cu
)
9132 gdb::unique_xmalloc_ptr
<char> package_name
;
9133 struct pending
*list
;
9136 for (list
= *cu
->get_builder ()->get_global_symbols ();
9140 for (i
= 0; i
< list
->nsyms
; ++i
)
9142 struct symbol
*sym
= list
->symbol
[i
];
9144 if (sym
->language () == language_go
9145 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9147 gdb::unique_xmalloc_ptr
<char> this_package_name
9148 (go_symbol_package_name (sym
));
9150 if (this_package_name
== NULL
)
9152 if (package_name
== NULL
)
9153 package_name
= std::move (this_package_name
);
9156 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9157 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9158 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9159 (symbol_symtab (sym
) != NULL
9160 ? symtab_to_filename_for_display
9161 (symbol_symtab (sym
))
9162 : objfile_name (objfile
)),
9163 this_package_name
.get (), package_name
.get ());
9169 if (package_name
!= NULL
)
9171 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9172 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9173 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9174 saved_package_name
);
9177 sym
= new (&objfile
->objfile_obstack
) symbol
;
9178 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9179 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9180 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9181 e.g., "main" finds the "main" module and not C's main(). */
9182 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9183 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9184 SYMBOL_TYPE (sym
) = type
;
9186 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9190 /* Allocate a fully-qualified name consisting of the two parts on the
9194 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9196 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9199 /* A helper that allocates a variant part to attach to a Rust enum
9200 type. OBSTACK is where the results should be allocated. TYPE is
9201 the type we're processing. DISCRIMINANT_INDEX is the index of the
9202 discriminant. It must be the index of one of the fields of TYPE,
9203 or -1 to mean there is no discriminant (univariant enum).
9204 DEFAULT_INDEX is the index of the default field; or -1 if there is
9205 no default. RANGES is indexed by "effective" field number (the
9206 field index, but omitting the discriminant and default fields) and
9207 must hold the discriminant values used by the variants. Note that
9208 RANGES must have a lifetime at least as long as OBSTACK -- either
9209 already allocated on it, or static. */
9212 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9213 int discriminant_index
, int default_index
,
9214 gdb::array_view
<discriminant_range
> ranges
)
9216 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
9217 gdb_assert (discriminant_index
== -1
9218 || (discriminant_index
>= 0
9219 && discriminant_index
< type
->num_fields ()));
9220 gdb_assert (default_index
== -1
9221 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9223 /* We have one variant for each non-discriminant field. */
9224 int n_variants
= type
->num_fields ();
9225 if (discriminant_index
!= -1)
9228 variant
*variants
= new (obstack
) variant
[n_variants
];
9231 for (int i
= 0; i
< type
->num_fields (); ++i
)
9233 if (i
== discriminant_index
)
9236 variants
[var_idx
].first_field
= i
;
9237 variants
[var_idx
].last_field
= i
+ 1;
9239 /* The default field does not need a range, but other fields do.
9240 We skipped the discriminant above. */
9241 if (i
!= default_index
)
9243 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9250 gdb_assert (range_idx
== ranges
.size ());
9251 gdb_assert (var_idx
== n_variants
);
9253 variant_part
*part
= new (obstack
) variant_part
;
9254 part
->discriminant_index
= discriminant_index
;
9255 /* If there is no discriminant, then whether it is signed is of no
9258 = (discriminant_index
== -1
9260 : type
->field (discriminant_index
).type ()->is_unsigned ());
9261 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9263 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9264 gdb::array_view
<variant_part
> *prop_value
9265 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9267 struct dynamic_prop prop
;
9268 prop
.set_variant_parts (prop_value
);
9270 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9273 /* Some versions of rustc emitted enums in an unusual way.
9275 Ordinary enums were emitted as unions. The first element of each
9276 structure in the union was named "RUST$ENUM$DISR". This element
9277 held the discriminant.
9279 These versions of Rust also implemented the "non-zero"
9280 optimization. When the enum had two values, and one is empty and
9281 the other holds a pointer that cannot be zero, the pointer is used
9282 as the discriminant, with a zero value meaning the empty variant.
9283 Here, the union's first member is of the form
9284 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9285 where the fieldnos are the indices of the fields that should be
9286 traversed in order to find the field (which may be several fields deep)
9287 and the variantname is the name of the variant of the case when the
9290 This function recognizes whether TYPE is of one of these forms,
9291 and, if so, smashes it to be a variant type. */
9294 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9296 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9298 /* We don't need to deal with empty enums. */
9299 if (type
->num_fields () == 0)
9302 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9303 if (type
->num_fields () == 1
9304 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9306 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9308 /* Decode the field name to find the offset of the
9310 ULONGEST bit_offset
= 0;
9311 struct type
*field_type
= type
->field (0).type ();
9312 while (name
[0] >= '0' && name
[0] <= '9')
9315 unsigned long index
= strtoul (name
, &tail
, 10);
9318 || index
>= field_type
->num_fields ()
9319 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9320 != FIELD_LOC_KIND_BITPOS
))
9322 complaint (_("Could not parse Rust enum encoding string \"%s\""
9324 TYPE_FIELD_NAME (type
, 0),
9325 objfile_name (objfile
));
9330 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9331 field_type
= field_type
->field (index
).type ();
9334 /* Smash this type to be a structure type. We have to do this
9335 because the type has already been recorded. */
9336 type
->set_code (TYPE_CODE_STRUCT
);
9337 type
->set_num_fields (3);
9338 /* Save the field we care about. */
9339 struct field saved_field
= type
->field (0);
9341 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9343 /* Put the discriminant at index 0. */
9344 type
->field (0).set_type (field_type
);
9345 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9346 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9347 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9349 /* The order of fields doesn't really matter, so put the real
9350 field at index 1 and the data-less field at index 2. */
9351 type
->field (1) = saved_field
;
9352 TYPE_FIELD_NAME (type
, 1)
9353 = rust_last_path_segment (type
->field (1).type ()->name ());
9354 type
->field (1).type ()->set_name
9355 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9356 TYPE_FIELD_NAME (type
, 1)));
9358 const char *dataless_name
9359 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9361 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9363 type
->field (2).set_type (dataless_type
);
9364 /* NAME points into the original discriminant name, which
9365 already has the correct lifetime. */
9366 TYPE_FIELD_NAME (type
, 2) = name
;
9367 SET_FIELD_BITPOS (type
->field (2), 0);
9369 /* Indicate that this is a variant type. */
9370 static discriminant_range ranges
[1] = { { 0, 0 } };
9371 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9373 /* A union with a single anonymous field is probably an old-style
9375 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9377 /* Smash this type to be a structure type. We have to do this
9378 because the type has already been recorded. */
9379 type
->set_code (TYPE_CODE_STRUCT
);
9381 struct type
*field_type
= type
->field (0).type ();
9382 const char *variant_name
9383 = rust_last_path_segment (field_type
->name ());
9384 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9385 field_type
->set_name
9386 (rust_fully_qualify (&objfile
->objfile_obstack
,
9387 type
->name (), variant_name
));
9389 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9393 struct type
*disr_type
= nullptr;
9394 for (int i
= 0; i
< type
->num_fields (); ++i
)
9396 disr_type
= type
->field (i
).type ();
9398 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9400 /* All fields of a true enum will be structs. */
9403 else if (disr_type
->num_fields () == 0)
9405 /* Could be data-less variant, so keep going. */
9406 disr_type
= nullptr;
9408 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9409 "RUST$ENUM$DISR") != 0)
9411 /* Not a Rust enum. */
9421 /* If we got here without a discriminant, then it's probably
9423 if (disr_type
== nullptr)
9426 /* Smash this type to be a structure type. We have to do this
9427 because the type has already been recorded. */
9428 type
->set_code (TYPE_CODE_STRUCT
);
9430 /* Make space for the discriminant field. */
9431 struct field
*disr_field
= &disr_type
->field (0);
9433 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9434 * sizeof (struct field
)));
9435 memcpy (new_fields
+ 1, type
->fields (),
9436 type
->num_fields () * sizeof (struct field
));
9437 type
->set_fields (new_fields
);
9438 type
->set_num_fields (type
->num_fields () + 1);
9440 /* Install the discriminant at index 0 in the union. */
9441 type
->field (0) = *disr_field
;
9442 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9443 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9445 /* We need a way to find the correct discriminant given a
9446 variant name. For convenience we build a map here. */
9447 struct type
*enum_type
= disr_field
->type ();
9448 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9449 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9451 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9454 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9455 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9459 int n_fields
= type
->num_fields ();
9460 /* We don't need a range entry for the discriminant, but we do
9461 need one for every other field, as there is no default
9463 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9466 /* Skip the discriminant here. */
9467 for (int i
= 1; i
< n_fields
; ++i
)
9469 /* Find the final word in the name of this variant's type.
9470 That name can be used to look up the correct
9472 const char *variant_name
9473 = rust_last_path_segment (type
->field (i
).type ()->name ());
9475 auto iter
= discriminant_map
.find (variant_name
);
9476 if (iter
!= discriminant_map
.end ())
9478 ranges
[i
- 1].low
= iter
->second
;
9479 ranges
[i
- 1].high
= iter
->second
;
9482 /* In Rust, each element should have the size of the
9484 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9486 /* Remove the discriminant field, if it exists. */
9487 struct type
*sub_type
= type
->field (i
).type ();
9488 if (sub_type
->num_fields () > 0)
9490 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9491 sub_type
->set_fields (sub_type
->fields () + 1);
9493 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9495 (rust_fully_qualify (&objfile
->objfile_obstack
,
9496 type
->name (), variant_name
));
9499 /* Indicate that this is a variant type. */
9500 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9501 gdb::array_view
<discriminant_range
> (ranges
,
9506 /* Rewrite some Rust unions to be structures with variants parts. */
9509 rust_union_quirks (struct dwarf2_cu
*cu
)
9511 gdb_assert (cu
->language
== language_rust
);
9512 for (type
*type_
: cu
->rust_unions
)
9513 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9514 /* We don't need this any more. */
9515 cu
->rust_unions
.clear ();
9520 type_unit_group_unshareable
*
9521 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9523 auto iter
= this->m_type_units
.find (tu_group
);
9524 if (iter
!= this->m_type_units
.end ())
9525 return iter
->second
.get ();
9527 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9528 type_unit_group_unshareable
*result
= uniq
.get ();
9529 this->m_type_units
[tu_group
] = std::move (uniq
);
9534 dwarf2_per_objfile::get_type_for_signatured_type
9535 (signatured_type
*sig_type
) const
9537 auto iter
= this->m_type_map
.find (sig_type
);
9538 if (iter
== this->m_type_map
.end ())
9541 return iter
->second
;
9544 void dwarf2_per_objfile::set_type_for_signatured_type
9545 (signatured_type
*sig_type
, struct type
*type
)
9547 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9549 this->m_type_map
[sig_type
] = type
;
9552 /* A helper function for computing the list of all symbol tables
9553 included by PER_CU. */
9556 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9557 htab_t all_children
, htab_t all_type_symtabs
,
9558 dwarf2_per_cu_data
*per_cu
,
9559 dwarf2_per_objfile
*per_objfile
,
9560 struct compunit_symtab
*immediate_parent
)
9562 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9565 /* This inclusion and its children have been processed. */
9571 /* Only add a CU if it has a symbol table. */
9572 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9575 /* If this is a type unit only add its symbol table if we haven't
9576 seen it yet (type unit per_cu's can share symtabs). */
9577 if (per_cu
->is_debug_types
)
9579 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9583 result
->push_back (cust
);
9584 if (cust
->user
== NULL
)
9585 cust
->user
= immediate_parent
;
9590 result
->push_back (cust
);
9591 if (cust
->user
== NULL
)
9592 cust
->user
= immediate_parent
;
9596 if (!per_cu
->imported_symtabs_empty ())
9597 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9599 recursively_compute_inclusions (result
, all_children
,
9600 all_type_symtabs
, ptr
, per_objfile
,
9605 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9609 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9610 dwarf2_per_objfile
*per_objfile
)
9612 gdb_assert (! per_cu
->is_debug_types
);
9614 if (!per_cu
->imported_symtabs_empty ())
9617 std::vector
<compunit_symtab
*> result_symtabs
;
9618 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9620 /* If we don't have a symtab, we can just skip this case. */
9624 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9626 NULL
, xcalloc
, xfree
));
9627 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9629 NULL
, xcalloc
, xfree
));
9631 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9633 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9634 all_type_symtabs
.get (), ptr
,
9638 /* Now we have a transitive closure of all the included symtabs. */
9639 len
= result_symtabs
.size ();
9641 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9642 struct compunit_symtab
*, len
+ 1);
9643 memcpy (cust
->includes
, result_symtabs
.data (),
9644 len
* sizeof (compunit_symtab
*));
9645 cust
->includes
[len
] = NULL
;
9649 /* Compute the 'includes' field for the symtabs of all the CUs we just
9653 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9655 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9657 if (! iter
->is_debug_types
)
9658 compute_compunit_symtab_includes (iter
, per_objfile
);
9661 per_objfile
->per_bfd
->just_read_cus
.clear ();
9664 /* Generate full symbol information for CU, whose DIEs have
9665 already been loaded into memory. */
9668 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9670 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9671 struct objfile
*objfile
= per_objfile
->objfile
;
9672 struct gdbarch
*gdbarch
= objfile
->arch ();
9673 CORE_ADDR lowpc
, highpc
;
9674 struct compunit_symtab
*cust
;
9676 struct block
*static_block
;
9679 baseaddr
= objfile
->text_section_offset ();
9681 /* Clear the list here in case something was left over. */
9682 cu
->method_list
.clear ();
9684 cu
->language
= pretend_language
;
9685 cu
->language_defn
= language_def (cu
->language
);
9687 dwarf2_find_base_address (cu
->dies
, cu
);
9689 /* Before we start reading the top-level DIE, ensure it has a valid tag
9691 switch (cu
->dies
->tag
)
9693 case DW_TAG_compile_unit
:
9694 case DW_TAG_partial_unit
:
9695 case DW_TAG_type_unit
:
9698 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
9699 dwarf_tag_name (cu
->dies
->tag
),
9700 sect_offset_str (cu
->per_cu
->sect_off
),
9701 objfile_name (per_objfile
->objfile
));
9704 /* Do line number decoding in read_file_scope () */
9705 process_die (cu
->dies
, cu
);
9707 /* For now fudge the Go package. */
9708 if (cu
->language
== language_go
)
9709 fixup_go_packaging (cu
);
9711 /* Now that we have processed all the DIEs in the CU, all the types
9712 should be complete, and it should now be safe to compute all of the
9714 compute_delayed_physnames (cu
);
9716 if (cu
->language
== language_rust
)
9717 rust_union_quirks (cu
);
9719 /* Some compilers don't define a DW_AT_high_pc attribute for the
9720 compilation unit. If the DW_AT_high_pc is missing, synthesize
9721 it, by scanning the DIE's below the compilation unit. */
9722 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9724 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9725 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9727 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9728 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9729 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9730 addrmap to help ensure it has an accurate map of pc values belonging to
9732 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9734 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9735 SECT_OFF_TEXT (objfile
),
9740 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9742 /* Set symtab language to language from DW_AT_language. If the
9743 compilation is from a C file generated by language preprocessors, do
9744 not set the language if it was already deduced by start_subfile. */
9745 if (!(cu
->language
== language_c
9746 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9747 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9749 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9750 produce DW_AT_location with location lists but it can be possibly
9751 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9752 there were bugs in prologue debug info, fixed later in GCC-4.5
9753 by "unwind info for epilogues" patch (which is not directly related).
9755 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9756 needed, it would be wrong due to missing DW_AT_producer there.
9758 Still one can confuse GDB by using non-standard GCC compilation
9759 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9761 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9762 cust
->locations_valid
= 1;
9764 if (gcc_4_minor
>= 5)
9765 cust
->epilogue_unwind_valid
= 1;
9767 cust
->call_site_htab
= cu
->call_site_htab
;
9770 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9772 /* Push it for inclusion processing later. */
9773 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9775 /* Not needed any more. */
9776 cu
->reset_builder ();
9779 /* Generate full symbol information for type unit CU, whose DIEs have
9780 already been loaded into memory. */
9783 process_full_type_unit (dwarf2_cu
*cu
,
9784 enum language pretend_language
)
9786 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9787 struct objfile
*objfile
= per_objfile
->objfile
;
9788 struct compunit_symtab
*cust
;
9789 struct signatured_type
*sig_type
;
9791 gdb_assert (cu
->per_cu
->is_debug_types
);
9792 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9794 /* Clear the list here in case something was left over. */
9795 cu
->method_list
.clear ();
9797 cu
->language
= pretend_language
;
9798 cu
->language_defn
= language_def (cu
->language
);
9800 /* The symbol tables are set up in read_type_unit_scope. */
9801 process_die (cu
->dies
, cu
);
9803 /* For now fudge the Go package. */
9804 if (cu
->language
== language_go
)
9805 fixup_go_packaging (cu
);
9807 /* Now that we have processed all the DIEs in the CU, all the types
9808 should be complete, and it should now be safe to compute all of the
9810 compute_delayed_physnames (cu
);
9812 if (cu
->language
== language_rust
)
9813 rust_union_quirks (cu
);
9815 /* TUs share symbol tables.
9816 If this is the first TU to use this symtab, complete the construction
9817 of it with end_expandable_symtab. Otherwise, complete the addition of
9818 this TU's symbols to the existing symtab. */
9819 type_unit_group_unshareable
*tug_unshare
=
9820 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9821 if (tug_unshare
->compunit_symtab
== NULL
)
9823 buildsym_compunit
*builder
= cu
->get_builder ();
9824 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9825 tug_unshare
->compunit_symtab
= cust
;
9829 /* Set symtab language to language from DW_AT_language. If the
9830 compilation is from a C file generated by language preprocessors,
9831 do not set the language if it was already deduced by
9833 if (!(cu
->language
== language_c
9834 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9835 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9840 cu
->get_builder ()->augment_type_symtab ();
9841 cust
= tug_unshare
->compunit_symtab
;
9844 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9846 /* Not needed any more. */
9847 cu
->reset_builder ();
9850 /* Process an imported unit DIE. */
9853 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9855 struct attribute
*attr
;
9857 /* For now we don't handle imported units in type units. */
9858 if (cu
->per_cu
->is_debug_types
)
9860 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9861 " supported in type units [in module %s]"),
9862 objfile_name (cu
->per_objfile
->objfile
));
9865 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9868 sect_offset sect_off
= attr
->get_ref_die_offset ();
9869 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9870 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9871 dwarf2_per_cu_data
*per_cu
9872 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
9874 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9875 into another compilation unit, at root level. Regard this as a hint,
9877 if (die
->parent
&& die
->parent
->parent
== NULL
9878 && per_cu
->unit_type
== DW_UT_compile
9879 && per_cu
->lang
== language_cplus
)
9882 /* If necessary, add it to the queue and load its DIEs. */
9883 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
9884 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
9885 false, cu
->language
);
9887 cu
->per_cu
->imported_symtabs_push (per_cu
);
9891 /* RAII object that represents a process_die scope: i.e.,
9892 starts/finishes processing a DIE. */
9893 class process_die_scope
9896 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9897 : m_die (die
), m_cu (cu
)
9899 /* We should only be processing DIEs not already in process. */
9900 gdb_assert (!m_die
->in_process
);
9901 m_die
->in_process
= true;
9904 ~process_die_scope ()
9906 m_die
->in_process
= false;
9908 /* If we're done processing the DIE for the CU that owns the line
9909 header, we don't need the line header anymore. */
9910 if (m_cu
->line_header_die_owner
== m_die
)
9912 delete m_cu
->line_header
;
9913 m_cu
->line_header
= NULL
;
9914 m_cu
->line_header_die_owner
= NULL
;
9923 /* Process a die and its children. */
9926 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9928 process_die_scope
scope (die
, cu
);
9932 case DW_TAG_padding
:
9934 case DW_TAG_compile_unit
:
9935 case DW_TAG_partial_unit
:
9936 read_file_scope (die
, cu
);
9938 case DW_TAG_type_unit
:
9939 read_type_unit_scope (die
, cu
);
9941 case DW_TAG_subprogram
:
9942 /* Nested subprograms in Fortran get a prefix. */
9943 if (cu
->language
== language_fortran
9944 && die
->parent
!= NULL
9945 && die
->parent
->tag
== DW_TAG_subprogram
)
9946 cu
->processing_has_namespace_info
= true;
9948 case DW_TAG_inlined_subroutine
:
9949 read_func_scope (die
, cu
);
9951 case DW_TAG_lexical_block
:
9952 case DW_TAG_try_block
:
9953 case DW_TAG_catch_block
:
9954 read_lexical_block_scope (die
, cu
);
9956 case DW_TAG_call_site
:
9957 case DW_TAG_GNU_call_site
:
9958 read_call_site_scope (die
, cu
);
9960 case DW_TAG_class_type
:
9961 case DW_TAG_interface_type
:
9962 case DW_TAG_structure_type
:
9963 case DW_TAG_union_type
:
9964 process_structure_scope (die
, cu
);
9966 case DW_TAG_enumeration_type
:
9967 process_enumeration_scope (die
, cu
);
9970 /* These dies have a type, but processing them does not create
9971 a symbol or recurse to process the children. Therefore we can
9972 read them on-demand through read_type_die. */
9973 case DW_TAG_subroutine_type
:
9974 case DW_TAG_set_type
:
9975 case DW_TAG_pointer_type
:
9976 case DW_TAG_ptr_to_member_type
:
9977 case DW_TAG_reference_type
:
9978 case DW_TAG_rvalue_reference_type
:
9979 case DW_TAG_string_type
:
9982 case DW_TAG_array_type
:
9983 /* We only need to handle this case for Ada -- in other
9984 languages, it's normal for the compiler to emit a typedef
9986 if (cu
->language
!= language_ada
)
9989 case DW_TAG_base_type
:
9990 case DW_TAG_subrange_type
:
9991 case DW_TAG_typedef
:
9992 /* Add a typedef symbol for the type definition, if it has a
9994 new_symbol (die
, read_type_die (die
, cu
), cu
);
9996 case DW_TAG_common_block
:
9997 read_common_block (die
, cu
);
9999 case DW_TAG_common_inclusion
:
10001 case DW_TAG_namespace
:
10002 cu
->processing_has_namespace_info
= true;
10003 read_namespace (die
, cu
);
10005 case DW_TAG_module
:
10006 cu
->processing_has_namespace_info
= true;
10007 read_module (die
, cu
);
10009 case DW_TAG_imported_declaration
:
10010 cu
->processing_has_namespace_info
= true;
10011 if (read_namespace_alias (die
, cu
))
10013 /* The declaration is not a global namespace alias. */
10014 /* Fall through. */
10015 case DW_TAG_imported_module
:
10016 cu
->processing_has_namespace_info
= true;
10017 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10018 || cu
->language
!= language_fortran
))
10019 complaint (_("Tag '%s' has unexpected children"),
10020 dwarf_tag_name (die
->tag
));
10021 read_import_statement (die
, cu
);
10024 case DW_TAG_imported_unit
:
10025 process_imported_unit_die (die
, cu
);
10028 case DW_TAG_variable
:
10029 read_variable (die
, cu
);
10033 new_symbol (die
, NULL
, cu
);
10038 /* DWARF name computation. */
10040 /* A helper function for dwarf2_compute_name which determines whether DIE
10041 needs to have the name of the scope prepended to the name listed in the
10045 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10047 struct attribute
*attr
;
10051 case DW_TAG_namespace
:
10052 case DW_TAG_typedef
:
10053 case DW_TAG_class_type
:
10054 case DW_TAG_interface_type
:
10055 case DW_TAG_structure_type
:
10056 case DW_TAG_union_type
:
10057 case DW_TAG_enumeration_type
:
10058 case DW_TAG_enumerator
:
10059 case DW_TAG_subprogram
:
10060 case DW_TAG_inlined_subroutine
:
10061 case DW_TAG_member
:
10062 case DW_TAG_imported_declaration
:
10065 case DW_TAG_variable
:
10066 case DW_TAG_constant
:
10067 /* We only need to prefix "globally" visible variables. These include
10068 any variable marked with DW_AT_external or any variable that
10069 lives in a namespace. [Variables in anonymous namespaces
10070 require prefixing, but they are not DW_AT_external.] */
10072 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10074 struct dwarf2_cu
*spec_cu
= cu
;
10076 return die_needs_namespace (die_specification (die
, &spec_cu
),
10080 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10081 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10082 && die
->parent
->tag
!= DW_TAG_module
)
10084 /* A variable in a lexical block of some kind does not need a
10085 namespace, even though in C++ such variables may be external
10086 and have a mangled name. */
10087 if (die
->parent
->tag
== DW_TAG_lexical_block
10088 || die
->parent
->tag
== DW_TAG_try_block
10089 || die
->parent
->tag
== DW_TAG_catch_block
10090 || die
->parent
->tag
== DW_TAG_subprogram
)
10099 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10100 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10101 defined for the given DIE. */
10103 static struct attribute
*
10104 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10106 struct attribute
*attr
;
10108 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10110 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10115 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10116 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10117 defined for the given DIE. */
10119 static const char *
10120 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10122 const char *linkage_name
;
10124 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10125 if (linkage_name
== NULL
)
10126 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10128 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10129 See https://github.com/rust-lang/rust/issues/32925. */
10130 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10131 && strchr (linkage_name
, '{') != NULL
)
10132 linkage_name
= NULL
;
10134 return linkage_name
;
10137 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10138 compute the physname for the object, which include a method's:
10139 - formal parameters (C++),
10140 - receiver type (Go),
10142 The term "physname" is a bit confusing.
10143 For C++, for example, it is the demangled name.
10144 For Go, for example, it's the mangled name.
10146 For Ada, return the DIE's linkage name rather than the fully qualified
10147 name. PHYSNAME is ignored..
10149 The result is allocated on the objfile->per_bfd's obstack and
10152 static const char *
10153 dwarf2_compute_name (const char *name
,
10154 struct die_info
*die
, struct dwarf2_cu
*cu
,
10157 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10160 name
= dwarf2_name (die
, cu
);
10162 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10163 but otherwise compute it by typename_concat inside GDB.
10164 FIXME: Actually this is not really true, or at least not always true.
10165 It's all very confusing. compute_and_set_names doesn't try to demangle
10166 Fortran names because there is no mangling standard. So new_symbol
10167 will set the demangled name to the result of dwarf2_full_name, and it is
10168 the demangled name that GDB uses if it exists. */
10169 if (cu
->language
== language_ada
10170 || (cu
->language
== language_fortran
&& physname
))
10172 /* For Ada unit, we prefer the linkage name over the name, as
10173 the former contains the exported name, which the user expects
10174 to be able to reference. Ideally, we want the user to be able
10175 to reference this entity using either natural or linkage name,
10176 but we haven't started looking at this enhancement yet. */
10177 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10179 if (linkage_name
!= NULL
)
10180 return linkage_name
;
10183 /* These are the only languages we know how to qualify names in. */
10185 && (cu
->language
== language_cplus
10186 || cu
->language
== language_fortran
|| cu
->language
== language_d
10187 || cu
->language
== language_rust
))
10189 if (die_needs_namespace (die
, cu
))
10191 const char *prefix
;
10192 const char *canonical_name
= NULL
;
10196 prefix
= determine_prefix (die
, cu
);
10197 if (*prefix
!= '\0')
10199 gdb::unique_xmalloc_ptr
<char> prefixed_name
10200 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10202 buf
.puts (prefixed_name
.get ());
10207 /* Template parameters may be specified in the DIE's DW_AT_name, or
10208 as children with DW_TAG_template_type_param or
10209 DW_TAG_value_type_param. If the latter, add them to the name
10210 here. If the name already has template parameters, then
10211 skip this step; some versions of GCC emit both, and
10212 it is more efficient to use the pre-computed name.
10214 Something to keep in mind about this process: it is very
10215 unlikely, or in some cases downright impossible, to produce
10216 something that will match the mangled name of a function.
10217 If the definition of the function has the same debug info,
10218 we should be able to match up with it anyway. But fallbacks
10219 using the minimal symbol, for instance to find a method
10220 implemented in a stripped copy of libstdc++, will not work.
10221 If we do not have debug info for the definition, we will have to
10222 match them up some other way.
10224 When we do name matching there is a related problem with function
10225 templates; two instantiated function templates are allowed to
10226 differ only by their return types, which we do not add here. */
10228 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10230 struct attribute
*attr
;
10231 struct die_info
*child
;
10233 const language_defn
*cplus_lang
= language_def (cu
->language
);
10235 die
->building_fullname
= 1;
10237 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10241 const gdb_byte
*bytes
;
10242 struct dwarf2_locexpr_baton
*baton
;
10245 if (child
->tag
!= DW_TAG_template_type_param
10246 && child
->tag
!= DW_TAG_template_value_param
)
10257 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10260 complaint (_("template parameter missing DW_AT_type"));
10261 buf
.puts ("UNKNOWN_TYPE");
10264 type
= die_type (child
, cu
);
10266 if (child
->tag
== DW_TAG_template_type_param
)
10268 cplus_lang
->print_type (type
, "", &buf
, -1, 0,
10269 &type_print_raw_options
);
10273 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10276 complaint (_("template parameter missing "
10277 "DW_AT_const_value"));
10278 buf
.puts ("UNKNOWN_VALUE");
10282 dwarf2_const_value_attr (attr
, type
, name
,
10283 &cu
->comp_unit_obstack
, cu
,
10284 &value
, &bytes
, &baton
);
10286 if (type
->has_no_signedness ())
10287 /* GDB prints characters as NUMBER 'CHAR'. If that's
10288 changed, this can use value_print instead. */
10289 cplus_lang
->printchar (value
, type
, &buf
);
10292 struct value_print_options opts
;
10295 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10299 baton
->per_objfile
);
10300 else if (bytes
!= NULL
)
10302 v
= allocate_value (type
);
10303 memcpy (value_contents_writeable (v
), bytes
,
10304 TYPE_LENGTH (type
));
10307 v
= value_from_longest (type
, value
);
10309 /* Specify decimal so that we do not depend on
10311 get_formatted_print_options (&opts
, 'd');
10313 value_print (v
, &buf
, &opts
);
10318 die
->building_fullname
= 0;
10322 /* Close the argument list, with a space if necessary
10323 (nested templates). */
10324 if (!buf
.empty () && buf
.string ().back () == '>')
10331 /* For C++ methods, append formal parameter type
10332 information, if PHYSNAME. */
10334 if (physname
&& die
->tag
== DW_TAG_subprogram
10335 && cu
->language
== language_cplus
)
10337 struct type
*type
= read_type_die (die
, cu
);
10339 c_type_print_args (type
, &buf
, 1, cu
->language
,
10340 &type_print_raw_options
);
10342 if (cu
->language
== language_cplus
)
10344 /* Assume that an artificial first parameter is
10345 "this", but do not crash if it is not. RealView
10346 marks unnamed (and thus unused) parameters as
10347 artificial; there is no way to differentiate
10349 if (type
->num_fields () > 0
10350 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10351 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10352 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10353 buf
.puts (" const");
10357 const std::string
&intermediate_name
= buf
.string ();
10359 if (cu
->language
== language_cplus
)
10361 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10364 /* If we only computed INTERMEDIATE_NAME, or if
10365 INTERMEDIATE_NAME is already canonical, then we need to
10367 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10368 name
= objfile
->intern (intermediate_name
);
10370 name
= canonical_name
;
10377 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10378 If scope qualifiers are appropriate they will be added. The result
10379 will be allocated on the storage_obstack, or NULL if the DIE does
10380 not have a name. NAME may either be from a previous call to
10381 dwarf2_name or NULL.
10383 The output string will be canonicalized (if C++). */
10385 static const char *
10386 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10388 return dwarf2_compute_name (name
, die
, cu
, 0);
10391 /* Construct a physname for the given DIE in CU. NAME may either be
10392 from a previous call to dwarf2_name or NULL. The result will be
10393 allocated on the objfile_objstack or NULL if the DIE does not have a
10396 The output string will be canonicalized (if C++). */
10398 static const char *
10399 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10401 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10402 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10405 /* In this case dwarf2_compute_name is just a shortcut not building anything
10407 if (!die_needs_namespace (die
, cu
))
10408 return dwarf2_compute_name (name
, die
, cu
, 1);
10410 if (cu
->language
!= language_rust
)
10411 mangled
= dw2_linkage_name (die
, cu
);
10413 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10415 gdb::unique_xmalloc_ptr
<char> demangled
;
10416 if (mangled
!= NULL
)
10419 if (language_def (cu
->language
)->store_sym_names_in_linkage_form_p ())
10421 /* Do nothing (do not demangle the symbol name). */
10425 /* Use DMGL_RET_DROP for C++ template functions to suppress
10426 their return type. It is easier for GDB users to search
10427 for such functions as `name(params)' than `long name(params)'.
10428 In such case the minimal symbol names do not match the full
10429 symbol names but for template functions there is never a need
10430 to look up their definition from their declaration so
10431 the only disadvantage remains the minimal symbol variant
10432 `long name(params)' does not have the proper inferior type. */
10433 demangled
.reset (gdb_demangle (mangled
,
10434 (DMGL_PARAMS
| DMGL_ANSI
10435 | DMGL_RET_DROP
)));
10438 canon
= demangled
.get ();
10446 if (canon
== NULL
|| check_physname
)
10448 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10450 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10452 /* It may not mean a bug in GDB. The compiler could also
10453 compute DW_AT_linkage_name incorrectly. But in such case
10454 GDB would need to be bug-to-bug compatible. */
10456 complaint (_("Computed physname <%s> does not match demangled <%s> "
10457 "(from linkage <%s>) - DIE at %s [in module %s]"),
10458 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10459 objfile_name (objfile
));
10461 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10462 is available here - over computed PHYSNAME. It is safer
10463 against both buggy GDB and buggy compilers. */
10477 retval
= objfile
->intern (retval
);
10482 /* Inspect DIE in CU for a namespace alias. If one exists, record
10483 a new symbol for it.
10485 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10488 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10490 struct attribute
*attr
;
10492 /* If the die does not have a name, this is not a namespace
10494 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10498 struct die_info
*d
= die
;
10499 struct dwarf2_cu
*imported_cu
= cu
;
10501 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10502 keep inspecting DIEs until we hit the underlying import. */
10503 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10504 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10506 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10510 d
= follow_die_ref (d
, attr
, &imported_cu
);
10511 if (d
->tag
!= DW_TAG_imported_declaration
)
10515 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10517 complaint (_("DIE at %s has too many recursively imported "
10518 "declarations"), sect_offset_str (d
->sect_off
));
10525 sect_offset sect_off
= attr
->get_ref_die_offset ();
10527 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10528 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10530 /* This declaration is a global namespace alias. Add
10531 a symbol for it whose type is the aliased namespace. */
10532 new_symbol (die
, type
, cu
);
10541 /* Return the using directives repository (global or local?) to use in the
10542 current context for CU.
10544 For Ada, imported declarations can materialize renamings, which *may* be
10545 global. However it is impossible (for now?) in DWARF to distinguish
10546 "external" imported declarations and "static" ones. As all imported
10547 declarations seem to be static in all other languages, make them all CU-wide
10548 global only in Ada. */
10550 static struct using_direct
**
10551 using_directives (struct dwarf2_cu
*cu
)
10553 if (cu
->language
== language_ada
10554 && cu
->get_builder ()->outermost_context_p ())
10555 return cu
->get_builder ()->get_global_using_directives ();
10557 return cu
->get_builder ()->get_local_using_directives ();
10560 /* Read the import statement specified by the given die and record it. */
10563 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10565 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10566 struct attribute
*import_attr
;
10567 struct die_info
*imported_die
, *child_die
;
10568 struct dwarf2_cu
*imported_cu
;
10569 const char *imported_name
;
10570 const char *imported_name_prefix
;
10571 const char *canonical_name
;
10572 const char *import_alias
;
10573 const char *imported_declaration
= NULL
;
10574 const char *import_prefix
;
10575 std::vector
<const char *> excludes
;
10577 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10578 if (import_attr
== NULL
)
10580 complaint (_("Tag '%s' has no DW_AT_import"),
10581 dwarf_tag_name (die
->tag
));
10586 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10587 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10588 if (imported_name
== NULL
)
10590 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10592 The import in the following code:
10606 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10607 <52> DW_AT_decl_file : 1
10608 <53> DW_AT_decl_line : 6
10609 <54> DW_AT_import : <0x75>
10610 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10611 <59> DW_AT_name : B
10612 <5b> DW_AT_decl_file : 1
10613 <5c> DW_AT_decl_line : 2
10614 <5d> DW_AT_type : <0x6e>
10616 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10617 <76> DW_AT_byte_size : 4
10618 <77> DW_AT_encoding : 5 (signed)
10620 imports the wrong die ( 0x75 instead of 0x58 ).
10621 This case will be ignored until the gcc bug is fixed. */
10625 /* Figure out the local name after import. */
10626 import_alias
= dwarf2_name (die
, cu
);
10628 /* Figure out where the statement is being imported to. */
10629 import_prefix
= determine_prefix (die
, cu
);
10631 /* Figure out what the scope of the imported die is and prepend it
10632 to the name of the imported die. */
10633 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10635 if (imported_die
->tag
!= DW_TAG_namespace
10636 && imported_die
->tag
!= DW_TAG_module
)
10638 imported_declaration
= imported_name
;
10639 canonical_name
= imported_name_prefix
;
10641 else if (strlen (imported_name_prefix
) > 0)
10642 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10643 imported_name_prefix
,
10644 (cu
->language
== language_d
? "." : "::"),
10645 imported_name
, (char *) NULL
);
10647 canonical_name
= imported_name
;
10649 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10650 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10651 child_die
= child_die
->sibling
)
10653 /* DWARF-4: A Fortran use statement with a “rename list” may be
10654 represented by an imported module entry with an import attribute
10655 referring to the module and owned entries corresponding to those
10656 entities that are renamed as part of being imported. */
10658 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10660 complaint (_("child DW_TAG_imported_declaration expected "
10661 "- DIE at %s [in module %s]"),
10662 sect_offset_str (child_die
->sect_off
),
10663 objfile_name (objfile
));
10667 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10668 if (import_attr
== NULL
)
10670 complaint (_("Tag '%s' has no DW_AT_import"),
10671 dwarf_tag_name (child_die
->tag
));
10676 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10678 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10679 if (imported_name
== NULL
)
10681 complaint (_("child DW_TAG_imported_declaration has unknown "
10682 "imported name - DIE at %s [in module %s]"),
10683 sect_offset_str (child_die
->sect_off
),
10684 objfile_name (objfile
));
10688 excludes
.push_back (imported_name
);
10690 process_die (child_die
, cu
);
10693 add_using_directive (using_directives (cu
),
10697 imported_declaration
,
10700 &objfile
->objfile_obstack
);
10703 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10704 types, but gives them a size of zero. Starting with version 14,
10705 ICC is compatible with GCC. */
10708 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10710 if (!cu
->checked_producer
)
10711 check_producer (cu
);
10713 return cu
->producer_is_icc_lt_14
;
10716 /* ICC generates a DW_AT_type for C void functions. This was observed on
10717 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10718 which says that void functions should not have a DW_AT_type. */
10721 producer_is_icc (struct dwarf2_cu
*cu
)
10723 if (!cu
->checked_producer
)
10724 check_producer (cu
);
10726 return cu
->producer_is_icc
;
10729 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10730 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10731 this, it was first present in GCC release 4.3.0. */
10734 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10736 if (!cu
->checked_producer
)
10737 check_producer (cu
);
10739 return cu
->producer_is_gcc_lt_4_3
;
10742 static file_and_directory
10743 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10745 file_and_directory res
;
10747 /* Find the filename. Do not use dwarf2_name here, since the filename
10748 is not a source language identifier. */
10749 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10750 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10752 if (res
.comp_dir
== NULL
10753 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10754 && IS_ABSOLUTE_PATH (res
.name
))
10756 res
.comp_dir_storage
= ldirname (res
.name
);
10757 if (!res
.comp_dir_storage
.empty ())
10758 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10760 if (res
.comp_dir
!= NULL
)
10762 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10763 directory, get rid of it. */
10764 const char *cp
= strchr (res
.comp_dir
, ':');
10766 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10767 res
.comp_dir
= cp
+ 1;
10770 if (res
.name
== NULL
)
10771 res
.name
= "<unknown>";
10776 /* Handle DW_AT_stmt_list for a compilation unit.
10777 DIE is the DW_TAG_compile_unit die for CU.
10778 COMP_DIR is the compilation directory. LOWPC is passed to
10779 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10782 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10783 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10785 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10786 struct attribute
*attr
;
10787 struct line_header line_header_local
;
10788 hashval_t line_header_local_hash
;
10790 int decode_mapping
;
10792 gdb_assert (! cu
->per_cu
->is_debug_types
);
10794 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10795 if (attr
== NULL
|| !attr
->form_is_unsigned ())
10798 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10800 /* The line header hash table is only created if needed (it exists to
10801 prevent redundant reading of the line table for partial_units).
10802 If we're given a partial_unit, we'll need it. If we're given a
10803 compile_unit, then use the line header hash table if it's already
10804 created, but don't create one just yet. */
10806 if (per_objfile
->line_header_hash
== NULL
10807 && die
->tag
== DW_TAG_partial_unit
)
10809 per_objfile
->line_header_hash
10810 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10811 line_header_eq_voidp
,
10812 free_line_header_voidp
,
10816 line_header_local
.sect_off
= line_offset
;
10817 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10818 line_header_local_hash
= line_header_hash (&line_header_local
);
10819 if (per_objfile
->line_header_hash
!= NULL
)
10821 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10822 &line_header_local
,
10823 line_header_local_hash
, NO_INSERT
);
10825 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10826 is not present in *SLOT (since if there is something in *SLOT then
10827 it will be for a partial_unit). */
10828 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10830 gdb_assert (*slot
!= NULL
);
10831 cu
->line_header
= (struct line_header
*) *slot
;
10836 /* dwarf_decode_line_header does not yet provide sufficient information.
10837 We always have to call also dwarf_decode_lines for it. */
10838 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10842 cu
->line_header
= lh
.release ();
10843 cu
->line_header_die_owner
= die
;
10845 if (per_objfile
->line_header_hash
== NULL
)
10849 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10850 &line_header_local
,
10851 line_header_local_hash
, INSERT
);
10852 gdb_assert (slot
!= NULL
);
10854 if (slot
!= NULL
&& *slot
== NULL
)
10856 /* This newly decoded line number information unit will be owned
10857 by line_header_hash hash table. */
10858 *slot
= cu
->line_header
;
10859 cu
->line_header_die_owner
= NULL
;
10863 /* We cannot free any current entry in (*slot) as that struct line_header
10864 may be already used by multiple CUs. Create only temporary decoded
10865 line_header for this CU - it may happen at most once for each line
10866 number information unit. And if we're not using line_header_hash
10867 then this is what we want as well. */
10868 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10870 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10871 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10876 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10879 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10881 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10882 struct objfile
*objfile
= per_objfile
->objfile
;
10883 struct gdbarch
*gdbarch
= objfile
->arch ();
10884 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10885 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10886 struct attribute
*attr
;
10887 struct die_info
*child_die
;
10888 CORE_ADDR baseaddr
;
10890 prepare_one_comp_unit (cu
, die
, cu
->language
);
10891 baseaddr
= objfile
->text_section_offset ();
10893 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10895 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10896 from finish_block. */
10897 if (lowpc
== ((CORE_ADDR
) -1))
10899 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10901 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10903 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10904 standardised yet. As a workaround for the language detection we fall
10905 back to the DW_AT_producer string. */
10906 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10907 cu
->language
= language_opencl
;
10909 /* Similar hack for Go. */
10910 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10911 set_cu_language (DW_LANG_Go
, cu
);
10913 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10915 /* Decode line number information if present. We do this before
10916 processing child DIEs, so that the line header table is available
10917 for DW_AT_decl_file. */
10918 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10920 /* Process all dies in compilation unit. */
10921 if (die
->child
!= NULL
)
10923 child_die
= die
->child
;
10924 while (child_die
&& child_die
->tag
)
10926 process_die (child_die
, cu
);
10927 child_die
= child_die
->sibling
;
10931 /* Decode macro information, if present. Dwarf 2 macro information
10932 refers to information in the line number info statement program
10933 header, so we can only read it if we've read the header
10935 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10937 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10938 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10940 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10941 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10943 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
10947 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10948 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10950 unsigned int macro_offset
= attr
->as_unsigned ();
10952 dwarf_decode_macros (cu
, macro_offset
, 0);
10958 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10960 struct type_unit_group
*tu_group
;
10962 struct attribute
*attr
;
10964 struct signatured_type
*sig_type
;
10966 gdb_assert (per_cu
->is_debug_types
);
10967 sig_type
= (struct signatured_type
*) per_cu
;
10969 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10971 /* If we're using .gdb_index (includes -readnow) then
10972 per_cu->type_unit_group may not have been set up yet. */
10973 if (sig_type
->type_unit_group
== NULL
)
10974 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10975 tu_group
= sig_type
->type_unit_group
;
10977 /* If we've already processed this stmt_list there's no real need to
10978 do it again, we could fake it and just recreate the part we need
10979 (file name,index -> symtab mapping). If data shows this optimization
10980 is useful we can do it then. */
10981 type_unit_group_unshareable
*tug_unshare
10982 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
10983 first_time
= tug_unshare
->compunit_symtab
== NULL
;
10985 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10988 if (attr
!= NULL
&& attr
->form_is_unsigned ())
10990 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10991 lh
= dwarf_decode_line_header (line_offset
, this);
10996 start_symtab ("", NULL
, 0);
10999 gdb_assert (tug_unshare
->symtabs
== NULL
);
11000 gdb_assert (m_builder
== nullptr);
11001 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11002 m_builder
.reset (new struct buildsym_compunit
11003 (COMPUNIT_OBJFILE (cust
), "",
11004 COMPUNIT_DIRNAME (cust
),
11005 compunit_language (cust
),
11007 list_in_scope
= get_builder ()->get_file_symbols ();
11012 line_header
= lh
.release ();
11013 line_header_die_owner
= die
;
11017 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11019 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11020 still initializing it, and our caller (a few levels up)
11021 process_full_type_unit still needs to know if this is the first
11024 tug_unshare
->symtabs
11025 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11026 struct symtab
*, line_header
->file_names_size ());
11028 auto &file_names
= line_header
->file_names ();
11029 for (i
= 0; i
< file_names
.size (); ++i
)
11031 file_entry
&fe
= file_names
[i
];
11032 dwarf2_start_subfile (this, fe
.name
,
11033 fe
.include_dir (line_header
));
11034 buildsym_compunit
*b
= get_builder ();
11035 if (b
->get_current_subfile ()->symtab
== NULL
)
11037 /* NOTE: start_subfile will recognize when it's been
11038 passed a file it has already seen. So we can't
11039 assume there's a simple mapping from
11040 cu->line_header->file_names to subfiles, plus
11041 cu->line_header->file_names may contain dups. */
11042 b
->get_current_subfile ()->symtab
11043 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11046 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11047 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11052 gdb_assert (m_builder
== nullptr);
11053 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11054 m_builder
.reset (new struct buildsym_compunit
11055 (COMPUNIT_OBJFILE (cust
), "",
11056 COMPUNIT_DIRNAME (cust
),
11057 compunit_language (cust
),
11059 list_in_scope
= get_builder ()->get_file_symbols ();
11061 auto &file_names
= line_header
->file_names ();
11062 for (i
= 0; i
< file_names
.size (); ++i
)
11064 file_entry
&fe
= file_names
[i
];
11065 fe
.symtab
= tug_unshare
->symtabs
[i
];
11069 /* The main symtab is allocated last. Type units don't have DW_AT_name
11070 so they don't have a "real" (so to speak) symtab anyway.
11071 There is later code that will assign the main symtab to all symbols
11072 that don't have one. We need to handle the case of a symbol with a
11073 missing symtab (DW_AT_decl_file) anyway. */
11076 /* Process DW_TAG_type_unit.
11077 For TUs we want to skip the first top level sibling if it's not the
11078 actual type being defined by this TU. In this case the first top
11079 level sibling is there to provide context only. */
11082 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11084 struct die_info
*child_die
;
11086 prepare_one_comp_unit (cu
, die
, language_minimal
);
11088 /* Initialize (or reinitialize) the machinery for building symtabs.
11089 We do this before processing child DIEs, so that the line header table
11090 is available for DW_AT_decl_file. */
11091 cu
->setup_type_unit_groups (die
);
11093 if (die
->child
!= NULL
)
11095 child_die
= die
->child
;
11096 while (child_die
&& child_die
->tag
)
11098 process_die (child_die
, cu
);
11099 child_die
= child_die
->sibling
;
11106 http://gcc.gnu.org/wiki/DebugFission
11107 http://gcc.gnu.org/wiki/DebugFissionDWP
11109 To simplify handling of both DWO files ("object" files with the DWARF info)
11110 and DWP files (a file with the DWOs packaged up into one file), we treat
11111 DWP files as having a collection of virtual DWO files. */
11114 hash_dwo_file (const void *item
)
11116 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11119 hash
= htab_hash_string (dwo_file
->dwo_name
);
11120 if (dwo_file
->comp_dir
!= NULL
)
11121 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11126 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11128 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11129 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11131 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11133 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11134 return lhs
->comp_dir
== rhs
->comp_dir
;
11135 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11138 /* Allocate a hash table for DWO files. */
11141 allocate_dwo_file_hash_table ()
11143 auto delete_dwo_file
= [] (void *item
)
11145 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11150 return htab_up (htab_create_alloc (41,
11157 /* Lookup DWO file DWO_NAME. */
11160 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11161 const char *dwo_name
,
11162 const char *comp_dir
)
11164 struct dwo_file find_entry
;
11167 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11168 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11170 find_entry
.dwo_name
= dwo_name
;
11171 find_entry
.comp_dir
= comp_dir
;
11172 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11179 hash_dwo_unit (const void *item
)
11181 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11183 /* This drops the top 32 bits of the id, but is ok for a hash. */
11184 return dwo_unit
->signature
;
11188 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11190 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11191 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11193 /* The signature is assumed to be unique within the DWO file.
11194 So while object file CU dwo_id's always have the value zero,
11195 that's OK, assuming each object file DWO file has only one CU,
11196 and that's the rule for now. */
11197 return lhs
->signature
== rhs
->signature
;
11200 /* Allocate a hash table for DWO CUs,TUs.
11201 There is one of these tables for each of CUs,TUs for each DWO file. */
11204 allocate_dwo_unit_table ()
11206 /* Start out with a pretty small number.
11207 Generally DWO files contain only one CU and maybe some TUs. */
11208 return htab_up (htab_create_alloc (3,
11211 NULL
, xcalloc
, xfree
));
11214 /* die_reader_func for create_dwo_cu. */
11217 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11218 const gdb_byte
*info_ptr
,
11219 struct die_info
*comp_unit_die
,
11220 struct dwo_file
*dwo_file
,
11221 struct dwo_unit
*dwo_unit
)
11223 struct dwarf2_cu
*cu
= reader
->cu
;
11224 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11225 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11227 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11228 if (!signature
.has_value ())
11230 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11231 " its dwo_id [in module %s]"),
11232 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11236 dwo_unit
->dwo_file
= dwo_file
;
11237 dwo_unit
->signature
= *signature
;
11238 dwo_unit
->section
= section
;
11239 dwo_unit
->sect_off
= sect_off
;
11240 dwo_unit
->length
= cu
->per_cu
->length
;
11242 dwarf_read_debug_printf (" offset %s, dwo_id %s",
11243 sect_offset_str (sect_off
),
11244 hex_string (dwo_unit
->signature
));
11247 /* Create the dwo_units for the CUs in a DWO_FILE.
11248 Note: This function processes DWO files only, not DWP files. */
11251 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11252 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11253 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11255 struct objfile
*objfile
= per_objfile
->objfile
;
11256 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11257 const gdb_byte
*info_ptr
, *end_ptr
;
11259 section
.read (objfile
);
11260 info_ptr
= section
.buffer
;
11262 if (info_ptr
== NULL
)
11265 dwarf_read_debug_printf ("Reading %s for %s:",
11266 section
.get_name (),
11267 section
.get_file_name ());
11269 end_ptr
= info_ptr
+ section
.size
;
11270 while (info_ptr
< end_ptr
)
11272 struct dwarf2_per_cu_data per_cu
;
11273 struct dwo_unit read_unit
{};
11274 struct dwo_unit
*dwo_unit
;
11276 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11278 memset (&per_cu
, 0, sizeof (per_cu
));
11279 per_cu
.per_bfd
= per_bfd
;
11280 per_cu
.is_debug_types
= 0;
11281 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11282 per_cu
.section
= §ion
;
11284 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11285 if (!reader
.dummy_p
)
11286 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11287 &dwo_file
, &read_unit
);
11288 info_ptr
+= per_cu
.length
;
11290 // If the unit could not be parsed, skip it.
11291 if (read_unit
.dwo_file
== NULL
)
11294 if (cus_htab
== NULL
)
11295 cus_htab
= allocate_dwo_unit_table ();
11297 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11299 *dwo_unit
= read_unit
;
11300 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11301 gdb_assert (slot
!= NULL
);
11304 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11305 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11307 complaint (_("debug cu entry at offset %s is duplicate to"
11308 " the entry at offset %s, signature %s"),
11309 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11310 hex_string (dwo_unit
->signature
));
11312 *slot
= (void *)dwo_unit
;
11316 /* DWP file .debug_{cu,tu}_index section format:
11317 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11318 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11320 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11321 officially standard DWP format was published with DWARF v5 and is called
11322 Version 5. There are no versions 3 or 4.
11326 Both index sections have the same format, and serve to map a 64-bit
11327 signature to a set of section numbers. Each section begins with a header,
11328 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11329 indexes, and a pool of 32-bit section numbers. The index sections will be
11330 aligned at 8-byte boundaries in the file.
11332 The index section header consists of:
11334 V, 32 bit version number
11336 N, 32 bit number of compilation units or type units in the index
11337 M, 32 bit number of slots in the hash table
11339 Numbers are recorded using the byte order of the application binary.
11341 The hash table begins at offset 16 in the section, and consists of an array
11342 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11343 order of the application binary). Unused slots in the hash table are 0.
11344 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11346 The parallel table begins immediately after the hash table
11347 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11348 array of 32-bit indexes (using the byte order of the application binary),
11349 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11350 table contains a 32-bit index into the pool of section numbers. For unused
11351 hash table slots, the corresponding entry in the parallel table will be 0.
11353 The pool of section numbers begins immediately following the hash table
11354 (at offset 16 + 12 * M from the beginning of the section). The pool of
11355 section numbers consists of an array of 32-bit words (using the byte order
11356 of the application binary). Each item in the array is indexed starting
11357 from 0. The hash table entry provides the index of the first section
11358 number in the set. Additional section numbers in the set follow, and the
11359 set is terminated by a 0 entry (section number 0 is not used in ELF).
11361 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11362 section must be the first entry in the set, and the .debug_abbrev.dwo must
11363 be the second entry. Other members of the set may follow in any order.
11367 DWP Versions 2 and 5:
11369 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11370 and the entries in the index tables are now offsets into these sections.
11371 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11374 Index Section Contents:
11376 Hash Table of Signatures dwp_hash_table.hash_table
11377 Parallel Table of Indices dwp_hash_table.unit_table
11378 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11379 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11381 The index section header consists of:
11383 V, 32 bit version number
11384 L, 32 bit number of columns in the table of section offsets
11385 N, 32 bit number of compilation units or type units in the index
11386 M, 32 bit number of slots in the hash table
11388 Numbers are recorded using the byte order of the application binary.
11390 The hash table has the same format as version 1.
11391 The parallel table of indices has the same format as version 1,
11392 except that the entries are origin-1 indices into the table of sections
11393 offsets and the table of section sizes.
11395 The table of offsets begins immediately following the parallel table
11396 (at offset 16 + 12 * M from the beginning of the section). The table is
11397 a two-dimensional array of 32-bit words (using the byte order of the
11398 application binary), with L columns and N+1 rows, in row-major order.
11399 Each row in the array is indexed starting from 0. The first row provides
11400 a key to the remaining rows: each column in this row provides an identifier
11401 for a debug section, and the offsets in the same column of subsequent rows
11402 refer to that section. The section identifiers for Version 2 are:
11404 DW_SECT_INFO 1 .debug_info.dwo
11405 DW_SECT_TYPES 2 .debug_types.dwo
11406 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11407 DW_SECT_LINE 4 .debug_line.dwo
11408 DW_SECT_LOC 5 .debug_loc.dwo
11409 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11410 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11411 DW_SECT_MACRO 8 .debug_macro.dwo
11413 The section identifiers for Version 5 are:
11415 DW_SECT_INFO_V5 1 .debug_info.dwo
11416 DW_SECT_RESERVED_V5 2 --
11417 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11418 DW_SECT_LINE_V5 4 .debug_line.dwo
11419 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11420 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11421 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11422 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11424 The offsets provided by the CU and TU index sections are the base offsets
11425 for the contributions made by each CU or TU to the corresponding section
11426 in the package file. Each CU and TU header contains an abbrev_offset
11427 field, used to find the abbreviations table for that CU or TU within the
11428 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11429 be interpreted as relative to the base offset given in the index section.
11430 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11431 should be interpreted as relative to the base offset for .debug_line.dwo,
11432 and offsets into other debug sections obtained from DWARF attributes should
11433 also be interpreted as relative to the corresponding base offset.
11435 The table of sizes begins immediately following the table of offsets.
11436 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11437 with L columns and N rows, in row-major order. Each row in the array is
11438 indexed starting from 1 (row 0 is shared by the two tables).
11442 Hash table lookup is handled the same in version 1 and 2:
11444 We assume that N and M will not exceed 2^32 - 1.
11445 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11447 Given a 64-bit compilation unit signature or a type signature S, an entry
11448 in the hash table is located as follows:
11450 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11451 the low-order k bits all set to 1.
11453 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11455 3) If the hash table entry at index H matches the signature, use that
11456 entry. If the hash table entry at index H is unused (all zeroes),
11457 terminate the search: the signature is not present in the table.
11459 4) Let H = (H + H') modulo M. Repeat at Step 3.
11461 Because M > N and H' and M are relatively prime, the search is guaranteed
11462 to stop at an unused slot or find the match. */
11464 /* Create a hash table to map DWO IDs to their CU/TU entry in
11465 .debug_{info,types}.dwo in DWP_FILE.
11466 Returns NULL if there isn't one.
11467 Note: This function processes DWP files only, not DWO files. */
11469 static struct dwp_hash_table
*
11470 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11471 struct dwp_file
*dwp_file
, int is_debug_types
)
11473 struct objfile
*objfile
= per_objfile
->objfile
;
11474 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11475 const gdb_byte
*index_ptr
, *index_end
;
11476 struct dwarf2_section_info
*index
;
11477 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11478 struct dwp_hash_table
*htab
;
11480 if (is_debug_types
)
11481 index
= &dwp_file
->sections
.tu_index
;
11483 index
= &dwp_file
->sections
.cu_index
;
11485 if (index
->empty ())
11487 index
->read (objfile
);
11489 index_ptr
= index
->buffer
;
11490 index_end
= index_ptr
+ index
->size
;
11492 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11493 For now it's safe to just read 4 bytes (particularly as it's difficult to
11494 tell if you're dealing with Version 5 before you've read the version). */
11495 version
= read_4_bytes (dbfd
, index_ptr
);
11497 if (version
== 2 || version
== 5)
11498 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11502 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11504 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11507 if (version
!= 1 && version
!= 2 && version
!= 5)
11509 error (_("Dwarf Error: unsupported DWP file version (%s)"
11510 " [in module %s]"),
11511 pulongest (version
), dwp_file
->name
);
11513 if (nr_slots
!= (nr_slots
& -nr_slots
))
11515 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11516 " is not power of 2 [in module %s]"),
11517 pulongest (nr_slots
), dwp_file
->name
);
11520 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11521 htab
->version
= version
;
11522 htab
->nr_columns
= nr_columns
;
11523 htab
->nr_units
= nr_units
;
11524 htab
->nr_slots
= nr_slots
;
11525 htab
->hash_table
= index_ptr
;
11526 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11528 /* Exit early if the table is empty. */
11529 if (nr_slots
== 0 || nr_units
== 0
11530 || (version
== 2 && nr_columns
== 0)
11531 || (version
== 5 && nr_columns
== 0))
11533 /* All must be zero. */
11534 if (nr_slots
!= 0 || nr_units
!= 0
11535 || (version
== 2 && nr_columns
!= 0)
11536 || (version
== 5 && nr_columns
!= 0))
11538 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11539 " all zero [in modules %s]"),
11547 htab
->section_pool
.v1
.indices
=
11548 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11549 /* It's harder to decide whether the section is too small in v1.
11550 V1 is deprecated anyway so we punt. */
11552 else if (version
== 2)
11554 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11555 int *ids
= htab
->section_pool
.v2
.section_ids
;
11556 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11557 /* Reverse map for error checking. */
11558 int ids_seen
[DW_SECT_MAX
+ 1];
11561 if (nr_columns
< 2)
11563 error (_("Dwarf Error: bad DWP hash table, too few columns"
11564 " in section table [in module %s]"),
11567 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11569 error (_("Dwarf Error: bad DWP hash table, too many columns"
11570 " in section table [in module %s]"),
11573 memset (ids
, 255, sizeof_ids
);
11574 memset (ids_seen
, 255, sizeof (ids_seen
));
11575 for (i
= 0; i
< nr_columns
; ++i
)
11577 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11579 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11581 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11582 " in section table [in module %s]"),
11583 id
, dwp_file
->name
);
11585 if (ids_seen
[id
] != -1)
11587 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11588 " id %d in section table [in module %s]"),
11589 id
, dwp_file
->name
);
11594 /* Must have exactly one info or types section. */
11595 if (((ids_seen
[DW_SECT_INFO
] != -1)
11596 + (ids_seen
[DW_SECT_TYPES
] != -1))
11599 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11600 " DWO info/types section [in module %s]"),
11603 /* Must have an abbrev section. */
11604 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11606 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11607 " section [in module %s]"),
11610 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11611 htab
->section_pool
.v2
.sizes
=
11612 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11613 * nr_units
* nr_columns
);
11614 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11615 * nr_units
* nr_columns
))
11618 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11619 " [in module %s]"),
11623 else /* version == 5 */
11625 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11626 int *ids
= htab
->section_pool
.v5
.section_ids
;
11627 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11628 /* Reverse map for error checking. */
11629 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11631 if (nr_columns
< 2)
11633 error (_("Dwarf Error: bad DWP hash table, too few columns"
11634 " in section table [in module %s]"),
11637 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11639 error (_("Dwarf Error: bad DWP hash table, too many columns"
11640 " in section table [in module %s]"),
11643 memset (ids
, 255, sizeof_ids
);
11644 memset (ids_seen
, 255, sizeof (ids_seen
));
11645 for (int i
= 0; i
< nr_columns
; ++i
)
11647 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11649 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11651 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11652 " in section table [in module %s]"),
11653 id
, dwp_file
->name
);
11655 if (ids_seen
[id
] != -1)
11657 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11658 " id %d in section table [in module %s]"),
11659 id
, dwp_file
->name
);
11664 /* Must have seen an info section. */
11665 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11667 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11668 " DWO info/types section [in module %s]"),
11671 /* Must have an abbrev section. */
11672 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11674 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11675 " section [in module %s]"),
11678 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11679 htab
->section_pool
.v5
.sizes
11680 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11681 * nr_units
* nr_columns
);
11682 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11683 * nr_units
* nr_columns
))
11686 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11687 " [in module %s]"),
11695 /* Update SECTIONS with the data from SECTP.
11697 This function is like the other "locate" section routines, but in
11698 this context the sections to read comes from the DWP V1 hash table,
11699 not the full ELF section table.
11701 The result is non-zero for success, or zero if an error was found. */
11704 locate_v1_virtual_dwo_sections (asection
*sectp
,
11705 struct virtual_v1_dwo_sections
*sections
)
11707 const struct dwop_section_names
*names
= &dwop_section_names
;
11709 if (names
->abbrev_dwo
.matches (sectp
->name
))
11711 /* There can be only one. */
11712 if (sections
->abbrev
.s
.section
!= NULL
)
11714 sections
->abbrev
.s
.section
= sectp
;
11715 sections
->abbrev
.size
= bfd_section_size (sectp
);
11717 else if (names
->info_dwo
.matches (sectp
->name
)
11718 || names
->types_dwo
.matches (sectp
->name
))
11720 /* There can be only one. */
11721 if (sections
->info_or_types
.s
.section
!= NULL
)
11723 sections
->info_or_types
.s
.section
= sectp
;
11724 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11726 else if (names
->line_dwo
.matches (sectp
->name
))
11728 /* There can be only one. */
11729 if (sections
->line
.s
.section
!= NULL
)
11731 sections
->line
.s
.section
= sectp
;
11732 sections
->line
.size
= bfd_section_size (sectp
);
11734 else if (names
->loc_dwo
.matches (sectp
->name
))
11736 /* There can be only one. */
11737 if (sections
->loc
.s
.section
!= NULL
)
11739 sections
->loc
.s
.section
= sectp
;
11740 sections
->loc
.size
= bfd_section_size (sectp
);
11742 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11744 /* There can be only one. */
11745 if (sections
->macinfo
.s
.section
!= NULL
)
11747 sections
->macinfo
.s
.section
= sectp
;
11748 sections
->macinfo
.size
= bfd_section_size (sectp
);
11750 else if (names
->macro_dwo
.matches (sectp
->name
))
11752 /* There can be only one. */
11753 if (sections
->macro
.s
.section
!= NULL
)
11755 sections
->macro
.s
.section
= sectp
;
11756 sections
->macro
.size
= bfd_section_size (sectp
);
11758 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11760 /* There can be only one. */
11761 if (sections
->str_offsets
.s
.section
!= NULL
)
11763 sections
->str_offsets
.s
.section
= sectp
;
11764 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11768 /* No other kind of section is valid. */
11775 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11776 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11777 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11778 This is for DWP version 1 files. */
11780 static struct dwo_unit
*
11781 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11782 struct dwp_file
*dwp_file
,
11783 uint32_t unit_index
,
11784 const char *comp_dir
,
11785 ULONGEST signature
, int is_debug_types
)
11787 const struct dwp_hash_table
*dwp_htab
=
11788 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11789 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11790 const char *kind
= is_debug_types
? "TU" : "CU";
11791 struct dwo_file
*dwo_file
;
11792 struct dwo_unit
*dwo_unit
;
11793 struct virtual_v1_dwo_sections sections
;
11794 void **dwo_file_slot
;
11797 gdb_assert (dwp_file
->version
== 1);
11799 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
11800 kind
, pulongest (unit_index
), hex_string (signature
),
11803 /* Fetch the sections of this DWO unit.
11804 Put a limit on the number of sections we look for so that bad data
11805 doesn't cause us to loop forever. */
11807 #define MAX_NR_V1_DWO_SECTIONS \
11808 (1 /* .debug_info or .debug_types */ \
11809 + 1 /* .debug_abbrev */ \
11810 + 1 /* .debug_line */ \
11811 + 1 /* .debug_loc */ \
11812 + 1 /* .debug_str_offsets */ \
11813 + 1 /* .debug_macro or .debug_macinfo */ \
11814 + 1 /* trailing zero */)
11816 memset (§ions
, 0, sizeof (sections
));
11818 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11821 uint32_t section_nr
=
11822 read_4_bytes (dbfd
,
11823 dwp_htab
->section_pool
.v1
.indices
11824 + (unit_index
+ i
) * sizeof (uint32_t));
11826 if (section_nr
== 0)
11828 if (section_nr
>= dwp_file
->num_sections
)
11830 error (_("Dwarf Error: bad DWP hash table, section number too large"
11831 " [in module %s]"),
11835 sectp
= dwp_file
->elf_sections
[section_nr
];
11836 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11838 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11839 " [in module %s]"),
11845 || sections
.info_or_types
.empty ()
11846 || sections
.abbrev
.empty ())
11848 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11849 " [in module %s]"),
11852 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11854 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11855 " [in module %s]"),
11859 /* It's easier for the rest of the code if we fake a struct dwo_file and
11860 have dwo_unit "live" in that. At least for now.
11862 The DWP file can be made up of a random collection of CUs and TUs.
11863 However, for each CU + set of TUs that came from the same original DWO
11864 file, we can combine them back into a virtual DWO file to save space
11865 (fewer struct dwo_file objects to allocate). Remember that for really
11866 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11868 std::string virtual_dwo_name
=
11869 string_printf ("virtual-dwo/%d-%d-%d-%d",
11870 sections
.abbrev
.get_id (),
11871 sections
.line
.get_id (),
11872 sections
.loc
.get_id (),
11873 sections
.str_offsets
.get_id ());
11874 /* Can we use an existing virtual DWO file? */
11875 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11877 /* Create one if necessary. */
11878 if (*dwo_file_slot
== NULL
)
11880 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11881 virtual_dwo_name
.c_str ());
11883 dwo_file
= new struct dwo_file
;
11884 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11885 dwo_file
->comp_dir
= comp_dir
;
11886 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11887 dwo_file
->sections
.line
= sections
.line
;
11888 dwo_file
->sections
.loc
= sections
.loc
;
11889 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11890 dwo_file
->sections
.macro
= sections
.macro
;
11891 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11892 /* The "str" section is global to the entire DWP file. */
11893 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11894 /* The info or types section is assigned below to dwo_unit,
11895 there's no need to record it in dwo_file.
11896 Also, we can't simply record type sections in dwo_file because
11897 we record a pointer into the vector in dwo_unit. As we collect more
11898 types we'll grow the vector and eventually have to reallocate space
11899 for it, invalidating all copies of pointers into the previous
11901 *dwo_file_slot
= dwo_file
;
11905 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11906 virtual_dwo_name
.c_str ());
11908 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11911 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11912 dwo_unit
->dwo_file
= dwo_file
;
11913 dwo_unit
->signature
= signature
;
11914 dwo_unit
->section
=
11915 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11916 *dwo_unit
->section
= sections
.info_or_types
;
11917 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11922 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
11923 simplify them. Given a pointer to the containing section SECTION, and
11924 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
11925 virtual section of just that piece. */
11927 static struct dwarf2_section_info
11928 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
11929 struct dwarf2_section_info
*section
,
11930 bfd_size_type offset
, bfd_size_type size
)
11932 struct dwarf2_section_info result
;
11935 gdb_assert (section
!= NULL
);
11936 gdb_assert (!section
->is_virtual
);
11938 memset (&result
, 0, sizeof (result
));
11939 result
.s
.containing_section
= section
;
11940 result
.is_virtual
= true;
11945 sectp
= section
->get_bfd_section ();
11947 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11948 bounds of the real section. This is a pretty-rare event, so just
11949 flag an error (easier) instead of a warning and trying to cope. */
11951 || offset
+ size
> bfd_section_size (sectp
))
11953 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
11954 " in section %s [in module %s]"),
11955 sectp
? bfd_section_name (sectp
) : "<unknown>",
11956 objfile_name (per_objfile
->objfile
));
11959 result
.virtual_offset
= offset
;
11960 result
.size
= size
;
11964 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11965 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11966 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11967 This is for DWP version 2 files. */
11969 static struct dwo_unit
*
11970 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
11971 struct dwp_file
*dwp_file
,
11972 uint32_t unit_index
,
11973 const char *comp_dir
,
11974 ULONGEST signature
, int is_debug_types
)
11976 const struct dwp_hash_table
*dwp_htab
=
11977 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11978 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11979 const char *kind
= is_debug_types
? "TU" : "CU";
11980 struct dwo_file
*dwo_file
;
11981 struct dwo_unit
*dwo_unit
;
11982 struct virtual_v2_or_v5_dwo_sections sections
;
11983 void **dwo_file_slot
;
11986 gdb_assert (dwp_file
->version
== 2);
11988 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
11989 kind
, pulongest (unit_index
), hex_string (signature
),
11992 /* Fetch the section offsets of this DWO unit. */
11994 memset (§ions
, 0, sizeof (sections
));
11996 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11998 uint32_t offset
= read_4_bytes (dbfd
,
11999 dwp_htab
->section_pool
.v2
.offsets
12000 + (((unit_index
- 1) * dwp_htab
->nr_columns
12002 * sizeof (uint32_t)));
12003 uint32_t size
= read_4_bytes (dbfd
,
12004 dwp_htab
->section_pool
.v2
.sizes
12005 + (((unit_index
- 1) * dwp_htab
->nr_columns
12007 * sizeof (uint32_t)));
12009 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12012 case DW_SECT_TYPES
:
12013 sections
.info_or_types_offset
= offset
;
12014 sections
.info_or_types_size
= size
;
12016 case DW_SECT_ABBREV
:
12017 sections
.abbrev_offset
= offset
;
12018 sections
.abbrev_size
= size
;
12021 sections
.line_offset
= offset
;
12022 sections
.line_size
= size
;
12025 sections
.loc_offset
= offset
;
12026 sections
.loc_size
= size
;
12028 case DW_SECT_STR_OFFSETS
:
12029 sections
.str_offsets_offset
= offset
;
12030 sections
.str_offsets_size
= size
;
12032 case DW_SECT_MACINFO
:
12033 sections
.macinfo_offset
= offset
;
12034 sections
.macinfo_size
= size
;
12036 case DW_SECT_MACRO
:
12037 sections
.macro_offset
= offset
;
12038 sections
.macro_size
= size
;
12043 /* It's easier for the rest of the code if we fake a struct dwo_file and
12044 have dwo_unit "live" in that. At least for now.
12046 The DWP file can be made up of a random collection of CUs and TUs.
12047 However, for each CU + set of TUs that came from the same original DWO
12048 file, we can combine them back into a virtual DWO file to save space
12049 (fewer struct dwo_file objects to allocate). Remember that for really
12050 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12052 std::string virtual_dwo_name
=
12053 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12054 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12055 (long) (sections
.line_size
? sections
.line_offset
: 0),
12056 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12057 (long) (sections
.str_offsets_size
12058 ? sections
.str_offsets_offset
: 0));
12059 /* Can we use an existing virtual DWO file? */
12060 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12062 /* Create one if necessary. */
12063 if (*dwo_file_slot
== NULL
)
12065 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12066 virtual_dwo_name
.c_str ());
12068 dwo_file
= new struct dwo_file
;
12069 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12070 dwo_file
->comp_dir
= comp_dir
;
12071 dwo_file
->sections
.abbrev
=
12072 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12073 sections
.abbrev_offset
,
12074 sections
.abbrev_size
);
12075 dwo_file
->sections
.line
=
12076 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
12077 sections
.line_offset
,
12078 sections
.line_size
);
12079 dwo_file
->sections
.loc
=
12080 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
12081 sections
.loc_offset
, sections
.loc_size
);
12082 dwo_file
->sections
.macinfo
=
12083 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12084 sections
.macinfo_offset
,
12085 sections
.macinfo_size
);
12086 dwo_file
->sections
.macro
=
12087 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
12088 sections
.macro_offset
,
12089 sections
.macro_size
);
12090 dwo_file
->sections
.str_offsets
=
12091 create_dwp_v2_or_v5_section (per_objfile
,
12092 &dwp_file
->sections
.str_offsets
,
12093 sections
.str_offsets_offset
,
12094 sections
.str_offsets_size
);
12095 /* The "str" section is global to the entire DWP file. */
12096 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12097 /* The info or types section is assigned below to dwo_unit,
12098 there's no need to record it in dwo_file.
12099 Also, we can't simply record type sections in dwo_file because
12100 we record a pointer into the vector in dwo_unit. As we collect more
12101 types we'll grow the vector and eventually have to reallocate space
12102 for it, invalidating all copies of pointers into the previous
12104 *dwo_file_slot
= dwo_file
;
12108 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12109 virtual_dwo_name
.c_str ());
12111 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12114 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12115 dwo_unit
->dwo_file
= dwo_file
;
12116 dwo_unit
->signature
= signature
;
12117 dwo_unit
->section
=
12118 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12119 *dwo_unit
->section
= create_dwp_v2_or_v5_section
12122 ? &dwp_file
->sections
.types
12123 : &dwp_file
->sections
.info
,
12124 sections
.info_or_types_offset
,
12125 sections
.info_or_types_size
);
12126 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12131 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12132 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12133 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12134 This is for DWP version 5 files. */
12136 static struct dwo_unit
*
12137 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
12138 struct dwp_file
*dwp_file
,
12139 uint32_t unit_index
,
12140 const char *comp_dir
,
12141 ULONGEST signature
, int is_debug_types
)
12143 const struct dwp_hash_table
*dwp_htab
12144 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12145 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12146 const char *kind
= is_debug_types
? "TU" : "CU";
12147 struct dwo_file
*dwo_file
;
12148 struct dwo_unit
*dwo_unit
;
12149 struct virtual_v2_or_v5_dwo_sections sections
{};
12150 void **dwo_file_slot
;
12152 gdb_assert (dwp_file
->version
== 5);
12154 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
12155 kind
, pulongest (unit_index
), hex_string (signature
),
12158 /* Fetch the section offsets of this DWO unit. */
12160 /* memset (§ions, 0, sizeof (sections)); */
12162 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12164 uint32_t offset
= read_4_bytes (dbfd
,
12165 dwp_htab
->section_pool
.v5
.offsets
12166 + (((unit_index
- 1)
12167 * dwp_htab
->nr_columns
12169 * sizeof (uint32_t)));
12170 uint32_t size
= read_4_bytes (dbfd
,
12171 dwp_htab
->section_pool
.v5
.sizes
12172 + (((unit_index
- 1) * dwp_htab
->nr_columns
12174 * sizeof (uint32_t)));
12176 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
12178 case DW_SECT_ABBREV_V5
:
12179 sections
.abbrev_offset
= offset
;
12180 sections
.abbrev_size
= size
;
12182 case DW_SECT_INFO_V5
:
12183 sections
.info_or_types_offset
= offset
;
12184 sections
.info_or_types_size
= size
;
12186 case DW_SECT_LINE_V5
:
12187 sections
.line_offset
= offset
;
12188 sections
.line_size
= size
;
12190 case DW_SECT_LOCLISTS_V5
:
12191 sections
.loclists_offset
= offset
;
12192 sections
.loclists_size
= size
;
12194 case DW_SECT_MACRO_V5
:
12195 sections
.macro_offset
= offset
;
12196 sections
.macro_size
= size
;
12198 case DW_SECT_RNGLISTS_V5
:
12199 sections
.rnglists_offset
= offset
;
12200 sections
.rnglists_size
= size
;
12202 case DW_SECT_STR_OFFSETS_V5
:
12203 sections
.str_offsets_offset
= offset
;
12204 sections
.str_offsets_size
= size
;
12206 case DW_SECT_RESERVED_V5
:
12212 /* It's easier for the rest of the code if we fake a struct dwo_file and
12213 have dwo_unit "live" in that. At least for now.
12215 The DWP file can be made up of a random collection of CUs and TUs.
12216 However, for each CU + set of TUs that came from the same original DWO
12217 file, we can combine them back into a virtual DWO file to save space
12218 (fewer struct dwo_file objects to allocate). Remember that for really
12219 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12221 std::string virtual_dwo_name
=
12222 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
12223 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12224 (long) (sections
.line_size
? sections
.line_offset
: 0),
12225 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
12226 (long) (sections
.str_offsets_size
12227 ? sections
.str_offsets_offset
: 0),
12228 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
12229 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
12230 /* Can we use an existing virtual DWO file? */
12231 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
12232 virtual_dwo_name
.c_str (),
12234 /* Create one if necessary. */
12235 if (*dwo_file_slot
== NULL
)
12237 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12238 virtual_dwo_name
.c_str ());
12240 dwo_file
= new struct dwo_file
;
12241 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12242 dwo_file
->comp_dir
= comp_dir
;
12243 dwo_file
->sections
.abbrev
=
12244 create_dwp_v2_or_v5_section (per_objfile
,
12245 &dwp_file
->sections
.abbrev
,
12246 sections
.abbrev_offset
,
12247 sections
.abbrev_size
);
12248 dwo_file
->sections
.line
=
12249 create_dwp_v2_or_v5_section (per_objfile
,
12250 &dwp_file
->sections
.line
,
12251 sections
.line_offset
, sections
.line_size
);
12252 dwo_file
->sections
.macro
=
12253 create_dwp_v2_or_v5_section (per_objfile
,
12254 &dwp_file
->sections
.macro
,
12255 sections
.macro_offset
,
12256 sections
.macro_size
);
12257 dwo_file
->sections
.loclists
=
12258 create_dwp_v2_or_v5_section (per_objfile
,
12259 &dwp_file
->sections
.loclists
,
12260 sections
.loclists_offset
,
12261 sections
.loclists_size
);
12262 dwo_file
->sections
.rnglists
=
12263 create_dwp_v2_or_v5_section (per_objfile
,
12264 &dwp_file
->sections
.rnglists
,
12265 sections
.rnglists_offset
,
12266 sections
.rnglists_size
);
12267 dwo_file
->sections
.str_offsets
=
12268 create_dwp_v2_or_v5_section (per_objfile
,
12269 &dwp_file
->sections
.str_offsets
,
12270 sections
.str_offsets_offset
,
12271 sections
.str_offsets_size
);
12272 /* The "str" section is global to the entire DWP file. */
12273 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12274 /* The info or types section is assigned below to dwo_unit,
12275 there's no need to record it in dwo_file.
12276 Also, we can't simply record type sections in dwo_file because
12277 we record a pointer into the vector in dwo_unit. As we collect more
12278 types we'll grow the vector and eventually have to reallocate space
12279 for it, invalidating all copies of pointers into the previous
12281 *dwo_file_slot
= dwo_file
;
12285 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12286 virtual_dwo_name
.c_str ());
12288 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12291 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12292 dwo_unit
->dwo_file
= dwo_file
;
12293 dwo_unit
->signature
= signature
;
12295 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12296 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12297 &dwp_file
->sections
.info
,
12298 sections
.info_or_types_offset
,
12299 sections
.info_or_types_size
);
12300 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12305 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12306 Returns NULL if the signature isn't found. */
12308 static struct dwo_unit
*
12309 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12310 struct dwp_file
*dwp_file
, const char *comp_dir
,
12311 ULONGEST signature
, int is_debug_types
)
12313 const struct dwp_hash_table
*dwp_htab
=
12314 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12315 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12316 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12317 uint32_t hash
= signature
& mask
;
12318 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12321 struct dwo_unit find_dwo_cu
;
12323 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12324 find_dwo_cu
.signature
= signature
;
12325 slot
= htab_find_slot (is_debug_types
12326 ? dwp_file
->loaded_tus
.get ()
12327 : dwp_file
->loaded_cus
.get (),
12328 &find_dwo_cu
, INSERT
);
12331 return (struct dwo_unit
*) *slot
;
12333 /* Use a for loop so that we don't loop forever on bad debug info. */
12334 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12336 ULONGEST signature_in_table
;
12338 signature_in_table
=
12339 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12340 if (signature_in_table
== signature
)
12342 uint32_t unit_index
=
12343 read_4_bytes (dbfd
,
12344 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12346 if (dwp_file
->version
== 1)
12348 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12349 unit_index
, comp_dir
,
12350 signature
, is_debug_types
);
12352 else if (dwp_file
->version
== 2)
12354 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12355 unit_index
, comp_dir
,
12356 signature
, is_debug_types
);
12358 else /* version == 5 */
12360 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12361 unit_index
, comp_dir
,
12362 signature
, is_debug_types
);
12364 return (struct dwo_unit
*) *slot
;
12366 if (signature_in_table
== 0)
12368 hash
= (hash
+ hash2
) & mask
;
12371 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12372 " [in module %s]"),
12376 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12377 Open the file specified by FILE_NAME and hand it off to BFD for
12378 preliminary analysis. Return a newly initialized bfd *, which
12379 includes a canonicalized copy of FILE_NAME.
12380 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12381 SEARCH_CWD is true if the current directory is to be searched.
12382 It will be searched before debug-file-directory.
12383 If successful, the file is added to the bfd include table of the
12384 objfile's bfd (see gdb_bfd_record_inclusion).
12385 If unable to find/open the file, return NULL.
12386 NOTE: This function is derived from symfile_bfd_open. */
12388 static gdb_bfd_ref_ptr
12389 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12390 const char *file_name
, int is_dwp
, int search_cwd
)
12393 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12394 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12395 to debug_file_directory. */
12396 const char *search_path
;
12397 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12399 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12402 if (*debug_file_directory
!= '\0')
12404 search_path_holder
.reset (concat (".", dirname_separator_string
,
12405 debug_file_directory
,
12407 search_path
= search_path_holder
.get ();
12413 search_path
= debug_file_directory
;
12415 /* Add the path for the executable binary to the list of search paths. */
12416 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
12417 search_path_holder
.reset (concat (objfile_dir
.c_str (),
12418 dirname_separator_string
,
12419 search_path
, nullptr));
12420 search_path
= search_path_holder
.get ();
12422 openp_flags flags
= OPF_RETURN_REALPATH
;
12424 flags
|= OPF_SEARCH_IN_PATH
;
12426 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12427 desc
= openp (search_path
, flags
, file_name
,
12428 O_RDONLY
| O_BINARY
, &absolute_name
);
12432 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12434 if (sym_bfd
== NULL
)
12436 bfd_set_cacheable (sym_bfd
.get (), 1);
12438 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12441 /* Success. Record the bfd as having been included by the objfile's bfd.
12442 This is important because things like demangled_names_hash lives in the
12443 objfile's per_bfd space and may have references to things like symbol
12444 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12445 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12450 /* Try to open DWO file FILE_NAME.
12451 COMP_DIR is the DW_AT_comp_dir attribute.
12452 The result is the bfd handle of the file.
12453 If there is a problem finding or opening the file, return NULL.
12454 Upon success, the canonicalized path of the file is stored in the bfd,
12455 same as symfile_bfd_open. */
12457 static gdb_bfd_ref_ptr
12458 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12459 const char *file_name
, const char *comp_dir
)
12461 if (IS_ABSOLUTE_PATH (file_name
))
12462 return try_open_dwop_file (per_objfile
, file_name
,
12463 0 /*is_dwp*/, 0 /*search_cwd*/);
12465 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12467 if (comp_dir
!= NULL
)
12469 gdb::unique_xmalloc_ptr
<char> path_to_try
12470 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12472 /* NOTE: If comp_dir is a relative path, this will also try the
12473 search path, which seems useful. */
12474 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12476 1 /*search_cwd*/));
12481 /* That didn't work, try debug-file-directory, which, despite its name,
12482 is a list of paths. */
12484 if (*debug_file_directory
== '\0')
12487 return try_open_dwop_file (per_objfile
, file_name
,
12488 0 /*is_dwp*/, 1 /*search_cwd*/);
12491 /* This function is mapped across the sections and remembers the offset and
12492 size of each of the DWO debugging sections we are interested in. */
12495 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12496 dwo_sections
*dwo_sections
)
12498 const struct dwop_section_names
*names
= &dwop_section_names
;
12500 if (names
->abbrev_dwo
.matches (sectp
->name
))
12502 dwo_sections
->abbrev
.s
.section
= sectp
;
12503 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12505 else if (names
->info_dwo
.matches (sectp
->name
))
12507 dwo_sections
->info
.s
.section
= sectp
;
12508 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12510 else if (names
->line_dwo
.matches (sectp
->name
))
12512 dwo_sections
->line
.s
.section
= sectp
;
12513 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12515 else if (names
->loc_dwo
.matches (sectp
->name
))
12517 dwo_sections
->loc
.s
.section
= sectp
;
12518 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12520 else if (names
->loclists_dwo
.matches (sectp
->name
))
12522 dwo_sections
->loclists
.s
.section
= sectp
;
12523 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12525 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12527 dwo_sections
->macinfo
.s
.section
= sectp
;
12528 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12530 else if (names
->macro_dwo
.matches (sectp
->name
))
12532 dwo_sections
->macro
.s
.section
= sectp
;
12533 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12535 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12537 dwo_sections
->rnglists
.s
.section
= sectp
;
12538 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12540 else if (names
->str_dwo
.matches (sectp
->name
))
12542 dwo_sections
->str
.s
.section
= sectp
;
12543 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12545 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12547 dwo_sections
->str_offsets
.s
.section
= sectp
;
12548 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12550 else if (names
->types_dwo
.matches (sectp
->name
))
12552 struct dwarf2_section_info type_section
;
12554 memset (&type_section
, 0, sizeof (type_section
));
12555 type_section
.s
.section
= sectp
;
12556 type_section
.size
= bfd_section_size (sectp
);
12557 dwo_sections
->types
.push_back (type_section
);
12561 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12562 by PER_CU. This is for the non-DWP case.
12563 The result is NULL if DWO_NAME can't be found. */
12565 static struct dwo_file
*
12566 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12567 const char *comp_dir
)
12569 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12571 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12574 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12579 dwo_file_up
dwo_file (new struct dwo_file
);
12580 dwo_file
->dwo_name
= dwo_name
;
12581 dwo_file
->comp_dir
= comp_dir
;
12582 dwo_file
->dbfd
= std::move (dbfd
);
12584 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12585 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12586 &dwo_file
->sections
);
12588 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12591 if (cu
->per_cu
->dwarf_version
< 5)
12593 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12594 dwo_file
->sections
.types
, dwo_file
->tus
);
12598 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12599 &dwo_file
->sections
.info
, dwo_file
->tus
,
12600 rcuh_kind::COMPILE
);
12603 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12605 return dwo_file
.release ();
12608 /* This function is mapped across the sections and remembers the offset and
12609 size of each of the DWP debugging sections common to version 1 and 2 that
12610 we are interested in. */
12613 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12614 dwp_file
*dwp_file
)
12616 const struct dwop_section_names
*names
= &dwop_section_names
;
12617 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12619 /* Record the ELF section number for later lookup: this is what the
12620 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12621 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12622 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12624 /* Look for specific sections that we need. */
12625 if (names
->str_dwo
.matches (sectp
->name
))
12627 dwp_file
->sections
.str
.s
.section
= sectp
;
12628 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12630 else if (names
->cu_index
.matches (sectp
->name
))
12632 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12633 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12635 else if (names
->tu_index
.matches (sectp
->name
))
12637 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12638 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12642 /* This function is mapped across the sections and remembers the offset and
12643 size of each of the DWP version 2 debugging sections that we are interested
12644 in. This is split into a separate function because we don't know if we
12645 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12648 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12650 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12651 const struct dwop_section_names
*names
= &dwop_section_names
;
12652 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12654 /* Record the ELF section number for later lookup: this is what the
12655 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12656 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12657 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12659 /* Look for specific sections that we need. */
12660 if (names
->abbrev_dwo
.matches (sectp
->name
))
12662 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12663 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12665 else if (names
->info_dwo
.matches (sectp
->name
))
12667 dwp_file
->sections
.info
.s
.section
= sectp
;
12668 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12670 else if (names
->line_dwo
.matches (sectp
->name
))
12672 dwp_file
->sections
.line
.s
.section
= sectp
;
12673 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12675 else if (names
->loc_dwo
.matches (sectp
->name
))
12677 dwp_file
->sections
.loc
.s
.section
= sectp
;
12678 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12680 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12682 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12683 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12685 else if (names
->macro_dwo
.matches (sectp
->name
))
12687 dwp_file
->sections
.macro
.s
.section
= sectp
;
12688 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12690 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12692 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12693 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12695 else if (names
->types_dwo
.matches (sectp
->name
))
12697 dwp_file
->sections
.types
.s
.section
= sectp
;
12698 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12702 /* This function is mapped across the sections and remembers the offset and
12703 size of each of the DWP version 5 debugging sections that we are interested
12704 in. This is split into a separate function because we don't know if we
12705 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12708 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12710 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12711 const struct dwop_section_names
*names
= &dwop_section_names
;
12712 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12714 /* Record the ELF section number for later lookup: this is what the
12715 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12716 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12717 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12719 /* Look for specific sections that we need. */
12720 if (names
->abbrev_dwo
.matches (sectp
->name
))
12722 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12723 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12725 else if (names
->info_dwo
.matches (sectp
->name
))
12727 dwp_file
->sections
.info
.s
.section
= sectp
;
12728 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12730 else if (names
->line_dwo
.matches (sectp
->name
))
12732 dwp_file
->sections
.line
.s
.section
= sectp
;
12733 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12735 else if (names
->loclists_dwo
.matches (sectp
->name
))
12737 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12738 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12740 else if (names
->macro_dwo
.matches (sectp
->name
))
12742 dwp_file
->sections
.macro
.s
.section
= sectp
;
12743 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12745 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12747 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12748 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12750 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12752 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12753 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12757 /* Hash function for dwp_file loaded CUs/TUs. */
12760 hash_dwp_loaded_cutus (const void *item
)
12762 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12764 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12765 return dwo_unit
->signature
;
12768 /* Equality function for dwp_file loaded CUs/TUs. */
12771 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12773 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12774 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12776 return dua
->signature
== dub
->signature
;
12779 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12782 allocate_dwp_loaded_cutus_table ()
12784 return htab_up (htab_create_alloc (3,
12785 hash_dwp_loaded_cutus
,
12786 eq_dwp_loaded_cutus
,
12787 NULL
, xcalloc
, xfree
));
12790 /* Try to open DWP file FILE_NAME.
12791 The result is the bfd handle of the file.
12792 If there is a problem finding or opening the file, return NULL.
12793 Upon success, the canonicalized path of the file is stored in the bfd,
12794 same as symfile_bfd_open. */
12796 static gdb_bfd_ref_ptr
12797 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12799 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12801 1 /*search_cwd*/));
12805 /* Work around upstream bug 15652.
12806 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12807 [Whether that's a "bug" is debatable, but it is getting in our way.]
12808 We have no real idea where the dwp file is, because gdb's realpath-ing
12809 of the executable's path may have discarded the needed info.
12810 [IWBN if the dwp file name was recorded in the executable, akin to
12811 .gnu_debuglink, but that doesn't exist yet.]
12812 Strip the directory from FILE_NAME and search again. */
12813 if (*debug_file_directory
!= '\0')
12815 /* Don't implicitly search the current directory here.
12816 If the user wants to search "." to handle this case,
12817 it must be added to debug-file-directory. */
12818 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12826 /* Initialize the use of the DWP file for the current objfile.
12827 By convention the name of the DWP file is ${objfile}.dwp.
12828 The result is NULL if it can't be found. */
12830 static std::unique_ptr
<struct dwp_file
>
12831 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12833 struct objfile
*objfile
= per_objfile
->objfile
;
12835 /* Try to find first .dwp for the binary file before any symbolic links
12838 /* If the objfile is a debug file, find the name of the real binary
12839 file and get the name of dwp file from there. */
12840 std::string dwp_name
;
12841 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12843 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12844 const char *backlink_basename
= lbasename (backlink
->original_name
);
12846 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12849 dwp_name
= objfile
->original_name
;
12851 dwp_name
+= ".dwp";
12853 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12855 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12857 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12858 dwp_name
= objfile_name (objfile
);
12859 dwp_name
+= ".dwp";
12860 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12865 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
12867 return std::unique_ptr
<dwp_file
> ();
12870 const char *name
= bfd_get_filename (dbfd
.get ());
12871 std::unique_ptr
<struct dwp_file
> dwp_file
12872 (new struct dwp_file (name
, std::move (dbfd
)));
12874 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12875 dwp_file
->elf_sections
=
12876 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12877 dwp_file
->num_sections
, asection
*);
12879 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12880 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12883 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12885 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12887 /* The DWP file version is stored in the hash table. Oh well. */
12888 if (dwp_file
->cus
&& dwp_file
->tus
12889 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12891 /* Technically speaking, we should try to limp along, but this is
12892 pretty bizarre. We use pulongest here because that's the established
12893 portability solution (e.g, we cannot use %u for uint32_t). */
12894 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12895 " TU version %s [in DWP file %s]"),
12896 pulongest (dwp_file
->cus
->version
),
12897 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12901 dwp_file
->version
= dwp_file
->cus
->version
;
12902 else if (dwp_file
->tus
)
12903 dwp_file
->version
= dwp_file
->tus
->version
;
12905 dwp_file
->version
= 2;
12907 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12909 if (dwp_file
->version
== 2)
12910 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12913 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12917 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12918 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12920 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
12921 dwarf_read_debug_printf (" %s CUs, %s TUs",
12922 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12923 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12928 /* Wrapper around open_and_init_dwp_file, only open it once. */
12930 static struct dwp_file
*
12931 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12933 if (!per_objfile
->per_bfd
->dwp_checked
)
12935 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12936 per_objfile
->per_bfd
->dwp_checked
= 1;
12938 return per_objfile
->per_bfd
->dwp_file
.get ();
12941 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12942 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12943 or in the DWP file for the objfile, referenced by THIS_UNIT.
12944 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12945 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12947 This is called, for example, when wanting to read a variable with a
12948 complex location. Therefore we don't want to do file i/o for every call.
12949 Therefore we don't want to look for a DWO file on every call.
12950 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12951 then we check if we've already seen DWO_NAME, and only THEN do we check
12954 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12955 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12957 static struct dwo_unit
*
12958 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12959 ULONGEST signature
, int is_debug_types
)
12961 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12962 struct objfile
*objfile
= per_objfile
->objfile
;
12963 const char *kind
= is_debug_types
? "TU" : "CU";
12964 void **dwo_file_slot
;
12965 struct dwo_file
*dwo_file
;
12966 struct dwp_file
*dwp_file
;
12968 /* First see if there's a DWP file.
12969 If we have a DWP file but didn't find the DWO inside it, don't
12970 look for the original DWO file. It makes gdb behave differently
12971 depending on whether one is debugging in the build tree. */
12973 dwp_file
= get_dwp_file (per_objfile
);
12974 if (dwp_file
!= NULL
)
12976 const struct dwp_hash_table
*dwp_htab
=
12977 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12979 if (dwp_htab
!= NULL
)
12981 struct dwo_unit
*dwo_cutu
=
12982 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12985 if (dwo_cutu
!= NULL
)
12987 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
12988 kind
, hex_string (signature
),
12989 host_address_to_string (dwo_cutu
));
12997 /* No DWP file, look for the DWO file. */
12999 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
13000 if (*dwo_file_slot
== NULL
)
13002 /* Read in the file and build a table of the CUs/TUs it contains. */
13003 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
13005 /* NOTE: This will be NULL if unable to open the file. */
13006 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13008 if (dwo_file
!= NULL
)
13010 struct dwo_unit
*dwo_cutu
= NULL
;
13012 if (is_debug_types
&& dwo_file
->tus
)
13014 struct dwo_unit find_dwo_cutu
;
13016 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13017 find_dwo_cutu
.signature
= signature
;
13019 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
13022 else if (!is_debug_types
&& dwo_file
->cus
)
13024 struct dwo_unit find_dwo_cutu
;
13026 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13027 find_dwo_cutu
.signature
= signature
;
13028 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
13032 if (dwo_cutu
!= NULL
)
13034 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
13035 kind
, dwo_name
, hex_string (signature
),
13036 host_address_to_string (dwo_cutu
));
13043 /* We didn't find it. This could mean a dwo_id mismatch, or
13044 someone deleted the DWO/DWP file, or the search path isn't set up
13045 correctly to find the file. */
13047 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
13048 kind
, dwo_name
, hex_string (signature
));
13050 /* This is a warning and not a complaint because it can be caused by
13051 pilot error (e.g., user accidentally deleting the DWO). */
13053 /* Print the name of the DWP file if we looked there, helps the user
13054 better diagnose the problem. */
13055 std::string dwp_text
;
13057 if (dwp_file
!= NULL
)
13058 dwp_text
= string_printf (" [in DWP file %s]",
13059 lbasename (dwp_file
->name
));
13061 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13062 " [in module %s]"),
13063 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
13064 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
13069 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13070 See lookup_dwo_cutu_unit for details. */
13072 static struct dwo_unit
*
13073 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13074 ULONGEST signature
)
13076 gdb_assert (!cu
->per_cu
->is_debug_types
);
13078 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
13081 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13082 See lookup_dwo_cutu_unit for details. */
13084 static struct dwo_unit
*
13085 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
13087 gdb_assert (cu
->per_cu
->is_debug_types
);
13089 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
13091 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
13094 /* Traversal function for queue_and_load_all_dwo_tus. */
13097 queue_and_load_dwo_tu (void **slot
, void *info
)
13099 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13100 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
13101 ULONGEST signature
= dwo_unit
->signature
;
13102 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
13104 if (sig_type
!= NULL
)
13106 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13108 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13109 a real dependency of PER_CU on SIG_TYPE. That is detected later
13110 while processing PER_CU. */
13111 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
13112 load_full_type_unit (sig_cu
, cu
->per_objfile
);
13113 cu
->per_cu
->imported_symtabs_push (sig_cu
);
13119 /* Queue all TUs contained in the DWO of CU to be read in.
13120 The DWO may have the only definition of the type, though it may not be
13121 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13122 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13125 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
13127 struct dwo_unit
*dwo_unit
;
13128 struct dwo_file
*dwo_file
;
13130 gdb_assert (cu
!= nullptr);
13131 gdb_assert (!cu
->per_cu
->is_debug_types
);
13132 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
13134 dwo_unit
= cu
->dwo_unit
;
13135 gdb_assert (dwo_unit
!= NULL
);
13137 dwo_file
= dwo_unit
->dwo_file
;
13138 if (dwo_file
->tus
!= NULL
)
13139 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
13142 /* Read in various DIEs. */
13144 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13145 Inherit only the children of the DW_AT_abstract_origin DIE not being
13146 already referenced by DW_AT_abstract_origin from the children of the
13150 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13152 struct die_info
*child_die
;
13153 sect_offset
*offsetp
;
13154 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13155 struct die_info
*origin_die
;
13156 /* Iterator of the ORIGIN_DIE children. */
13157 struct die_info
*origin_child_die
;
13158 struct attribute
*attr
;
13159 struct dwarf2_cu
*origin_cu
;
13160 struct pending
**origin_previous_list_in_scope
;
13162 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13166 /* Note that following die references may follow to a die in a
13170 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13172 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13174 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13175 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13177 if (die
->tag
!= origin_die
->tag
13178 && !(die
->tag
== DW_TAG_inlined_subroutine
13179 && origin_die
->tag
== DW_TAG_subprogram
))
13180 complaint (_("DIE %s and its abstract origin %s have different tags"),
13181 sect_offset_str (die
->sect_off
),
13182 sect_offset_str (origin_die
->sect_off
));
13184 /* Find if the concrete and abstract trees are structurally the
13185 same. This is a shallow traversal and it is not bullet-proof;
13186 the compiler can trick the debugger into believing that the trees
13187 are isomorphic, whereas they actually are not. However, the
13188 likelyhood of this happening is pretty low, and a full-fledged
13189 check would be an overkill. */
13190 bool are_isomorphic
= true;
13191 die_info
*concrete_child
= die
->child
;
13192 die_info
*abstract_child
= origin_die
->child
;
13193 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
13195 if (concrete_child
== nullptr
13196 || abstract_child
== nullptr
13197 || concrete_child
->tag
!= abstract_child
->tag
)
13199 are_isomorphic
= false;
13203 concrete_child
= concrete_child
->sibling
;
13204 abstract_child
= abstract_child
->sibling
;
13207 /* Walk the origin's children in parallel to the concrete children.
13208 This helps match an origin child in case the debug info misses
13209 DW_AT_abstract_origin attributes. Keep in mind that the abstract
13210 origin tree may not have the same tree structure as the concrete
13212 die_info
*corresponding_abstract_child
13213 = are_isomorphic
? origin_die
->child
: nullptr;
13215 std::vector
<sect_offset
> offsets
;
13217 for (child_die
= die
->child
;
13218 child_die
&& child_die
->tag
;
13219 child_die
= child_die
->sibling
)
13221 struct die_info
*child_origin_die
;
13222 struct dwarf2_cu
*child_origin_cu
;
13224 /* We are trying to process concrete instance entries:
13225 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13226 it's not relevant to our analysis here. i.e. detecting DIEs that are
13227 present in the abstract instance but not referenced in the concrete
13229 if (child_die
->tag
== DW_TAG_call_site
13230 || child_die
->tag
== DW_TAG_GNU_call_site
)
13232 if (are_isomorphic
)
13233 corresponding_abstract_child
13234 = corresponding_abstract_child
->sibling
;
13238 /* For each CHILD_DIE, find the corresponding child of
13239 ORIGIN_DIE. If there is more than one layer of
13240 DW_AT_abstract_origin, follow them all; there shouldn't be,
13241 but GCC versions at least through 4.4 generate this (GCC PR
13243 child_origin_die
= child_die
;
13244 child_origin_cu
= cu
;
13247 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13251 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13255 /* If missing DW_AT_abstract_origin, try the corresponding child
13256 of the origin. Clang emits such lexical scopes. */
13257 if (child_origin_die
== child_die
13258 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
13260 && child_die
->tag
== DW_TAG_lexical_block
)
13261 child_origin_die
= corresponding_abstract_child
;
13263 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13264 counterpart may exist. */
13265 if (child_origin_die
!= child_die
)
13267 if (child_die
->tag
!= child_origin_die
->tag
13268 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13269 && child_origin_die
->tag
== DW_TAG_subprogram
))
13270 complaint (_("Child DIE %s and its abstract origin %s have "
13272 sect_offset_str (child_die
->sect_off
),
13273 sect_offset_str (child_origin_die
->sect_off
));
13274 if (child_origin_die
->parent
!= origin_die
)
13275 complaint (_("Child DIE %s and its abstract origin %s have "
13276 "different parents"),
13277 sect_offset_str (child_die
->sect_off
),
13278 sect_offset_str (child_origin_die
->sect_off
));
13280 offsets
.push_back (child_origin_die
->sect_off
);
13283 if (are_isomorphic
)
13284 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
13286 std::sort (offsets
.begin (), offsets
.end ());
13287 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13288 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13289 if (offsetp
[-1] == *offsetp
)
13290 complaint (_("Multiple children of DIE %s refer "
13291 "to DIE %s as their abstract origin"),
13292 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13294 offsetp
= offsets
.data ();
13295 origin_child_die
= origin_die
->child
;
13296 while (origin_child_die
&& origin_child_die
->tag
)
13298 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13299 while (offsetp
< offsets_end
13300 && *offsetp
< origin_child_die
->sect_off
)
13302 if (offsetp
>= offsets_end
13303 || *offsetp
> origin_child_die
->sect_off
)
13305 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13306 Check whether we're already processing ORIGIN_CHILD_DIE.
13307 This can happen with mutually referenced abstract_origins.
13309 if (!origin_child_die
->in_process
)
13310 process_die (origin_child_die
, origin_cu
);
13312 origin_child_die
= origin_child_die
->sibling
;
13314 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13316 if (cu
!= origin_cu
)
13317 compute_delayed_physnames (origin_cu
);
13321 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13323 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13324 struct gdbarch
*gdbarch
= objfile
->arch ();
13325 struct context_stack
*newobj
;
13328 struct die_info
*child_die
;
13329 struct attribute
*attr
, *call_line
, *call_file
;
13331 CORE_ADDR baseaddr
;
13332 struct block
*block
;
13333 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13334 std::vector
<struct symbol
*> template_args
;
13335 struct template_symbol
*templ_func
= NULL
;
13339 /* If we do not have call site information, we can't show the
13340 caller of this inlined function. That's too confusing, so
13341 only use the scope for local variables. */
13342 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13343 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13344 if (call_line
== NULL
|| call_file
== NULL
)
13346 read_lexical_block_scope (die
, cu
);
13351 baseaddr
= objfile
->text_section_offset ();
13353 name
= dwarf2_name (die
, cu
);
13355 /* Ignore functions with missing or empty names. These are actually
13356 illegal according to the DWARF standard. */
13359 complaint (_("missing name for subprogram DIE at %s"),
13360 sect_offset_str (die
->sect_off
));
13364 /* Ignore functions with missing or invalid low and high pc attributes. */
13365 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13366 <= PC_BOUNDS_INVALID
)
13368 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13369 if (attr
== nullptr || !attr
->as_boolean ())
13370 complaint (_("cannot get low and high bounds "
13371 "for subprogram DIE at %s"),
13372 sect_offset_str (die
->sect_off
));
13376 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13377 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13379 /* If we have any template arguments, then we must allocate a
13380 different sort of symbol. */
13381 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13383 if (child_die
->tag
== DW_TAG_template_type_param
13384 || child_die
->tag
== DW_TAG_template_value_param
)
13386 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13387 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13392 gdb_assert (cu
->get_builder () != nullptr);
13393 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13394 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13395 (struct symbol
*) templ_func
);
13397 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13398 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13401 /* If there is a location expression for DW_AT_frame_base, record
13403 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13404 if (attr
!= nullptr)
13405 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13407 /* If there is a location for the static link, record it. */
13408 newobj
->static_link
= NULL
;
13409 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13410 if (attr
!= nullptr)
13412 newobj
->static_link
13413 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13414 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13418 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13420 if (die
->child
!= NULL
)
13422 child_die
= die
->child
;
13423 while (child_die
&& child_die
->tag
)
13425 if (child_die
->tag
== DW_TAG_template_type_param
13426 || child_die
->tag
== DW_TAG_template_value_param
)
13428 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13431 template_args
.push_back (arg
);
13434 process_die (child_die
, cu
);
13435 child_die
= child_die
->sibling
;
13439 inherit_abstract_dies (die
, cu
);
13441 /* If we have a DW_AT_specification, we might need to import using
13442 directives from the context of the specification DIE. See the
13443 comment in determine_prefix. */
13444 if (cu
->language
== language_cplus
13445 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13447 struct dwarf2_cu
*spec_cu
= cu
;
13448 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13452 child_die
= spec_die
->child
;
13453 while (child_die
&& child_die
->tag
)
13455 if (child_die
->tag
== DW_TAG_imported_module
)
13456 process_die (child_die
, spec_cu
);
13457 child_die
= child_die
->sibling
;
13460 /* In some cases, GCC generates specification DIEs that
13461 themselves contain DW_AT_specification attributes. */
13462 spec_die
= die_specification (spec_die
, &spec_cu
);
13466 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13467 /* Make a block for the local symbols within. */
13468 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13469 cstk
.static_link
, lowpc
, highpc
);
13471 /* For C++, set the block's scope. */
13472 if ((cu
->language
== language_cplus
13473 || cu
->language
== language_fortran
13474 || cu
->language
== language_d
13475 || cu
->language
== language_rust
)
13476 && cu
->processing_has_namespace_info
)
13477 block_set_scope (block
, determine_prefix (die
, cu
),
13478 &objfile
->objfile_obstack
);
13480 /* If we have address ranges, record them. */
13481 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13483 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13485 /* Attach template arguments to function. */
13486 if (!template_args
.empty ())
13488 gdb_assert (templ_func
!= NULL
);
13490 templ_func
->n_template_arguments
= template_args
.size ();
13491 templ_func
->template_arguments
13492 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13493 templ_func
->n_template_arguments
);
13494 memcpy (templ_func
->template_arguments
,
13495 template_args
.data (),
13496 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13498 /* Make sure that the symtab is set on the new symbols. Even
13499 though they don't appear in this symtab directly, other parts
13500 of gdb assume that symbols do, and this is reasonably
13502 for (symbol
*sym
: template_args
)
13503 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13506 /* In C++, we can have functions nested inside functions (e.g., when
13507 a function declares a class that has methods). This means that
13508 when we finish processing a function scope, we may need to go
13509 back to building a containing block's symbol lists. */
13510 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13511 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13513 /* If we've finished processing a top-level function, subsequent
13514 symbols go in the file symbol list. */
13515 if (cu
->get_builder ()->outermost_context_p ())
13516 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13519 /* Process all the DIES contained within a lexical block scope. Start
13520 a new scope, process the dies, and then close the scope. */
13523 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13525 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13526 struct gdbarch
*gdbarch
= objfile
->arch ();
13527 CORE_ADDR lowpc
, highpc
;
13528 struct die_info
*child_die
;
13529 CORE_ADDR baseaddr
;
13531 baseaddr
= objfile
->text_section_offset ();
13533 /* Ignore blocks with missing or invalid low and high pc attributes. */
13534 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13535 as multiple lexical blocks? Handling children in a sane way would
13536 be nasty. Might be easier to properly extend generic blocks to
13537 describe ranges. */
13538 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13540 case PC_BOUNDS_NOT_PRESENT
:
13541 /* DW_TAG_lexical_block has no attributes, process its children as if
13542 there was no wrapping by that DW_TAG_lexical_block.
13543 GCC does no longer produces such DWARF since GCC r224161. */
13544 for (child_die
= die
->child
;
13545 child_die
!= NULL
&& child_die
->tag
;
13546 child_die
= child_die
->sibling
)
13548 /* We might already be processing this DIE. This can happen
13549 in an unusual circumstance -- where a subroutine A
13550 appears lexically in another subroutine B, but A actually
13551 inlines B. The recursion is broken here, rather than in
13552 inherit_abstract_dies, because it seems better to simply
13553 drop concrete children here. */
13554 if (!child_die
->in_process
)
13555 process_die (child_die
, cu
);
13558 case PC_BOUNDS_INVALID
:
13561 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13562 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13564 cu
->get_builder ()->push_context (0, lowpc
);
13565 if (die
->child
!= NULL
)
13567 child_die
= die
->child
;
13568 while (child_die
&& child_die
->tag
)
13570 process_die (child_die
, cu
);
13571 child_die
= child_die
->sibling
;
13574 inherit_abstract_dies (die
, cu
);
13575 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13577 if (*cu
->get_builder ()->get_local_symbols () != NULL
13578 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13580 struct block
*block
13581 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13582 cstk
.start_addr
, highpc
);
13584 /* Note that recording ranges after traversing children, as we
13585 do here, means that recording a parent's ranges entails
13586 walking across all its children's ranges as they appear in
13587 the address map, which is quadratic behavior.
13589 It would be nicer to record the parent's ranges before
13590 traversing its children, simply overriding whatever you find
13591 there. But since we don't even decide whether to create a
13592 block until after we've traversed its children, that's hard
13594 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13596 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13597 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13600 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13603 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13605 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13606 struct objfile
*objfile
= per_objfile
->objfile
;
13607 struct gdbarch
*gdbarch
= objfile
->arch ();
13608 CORE_ADDR pc
, baseaddr
;
13609 struct attribute
*attr
;
13610 struct call_site
*call_site
, call_site_local
;
13613 struct die_info
*child_die
;
13615 baseaddr
= objfile
->text_section_offset ();
13617 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13620 /* This was a pre-DWARF-5 GNU extension alias
13621 for DW_AT_call_return_pc. */
13622 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13626 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13627 "DIE %s [in module %s]"),
13628 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13631 pc
= attr
->as_address () + baseaddr
;
13632 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13634 if (cu
->call_site_htab
== NULL
)
13635 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13636 NULL
, &objfile
->objfile_obstack
,
13637 hashtab_obstack_allocate
, NULL
);
13638 call_site_local
.pc
= pc
;
13639 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13642 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13643 "DIE %s [in module %s]"),
13644 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13645 objfile_name (objfile
));
13649 /* Count parameters at the caller. */
13652 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13653 child_die
= child_die
->sibling
)
13655 if (child_die
->tag
!= DW_TAG_call_site_parameter
13656 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13658 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13659 "DW_TAG_call_site child DIE %s [in module %s]"),
13660 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13661 objfile_name (objfile
));
13669 = ((struct call_site
*)
13670 obstack_alloc (&objfile
->objfile_obstack
,
13671 sizeof (*call_site
)
13672 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13674 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13675 call_site
->pc
= pc
;
13677 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13678 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13680 struct die_info
*func_die
;
13682 /* Skip also over DW_TAG_inlined_subroutine. */
13683 for (func_die
= die
->parent
;
13684 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13685 && func_die
->tag
!= DW_TAG_subroutine_type
;
13686 func_die
= func_die
->parent
);
13688 /* DW_AT_call_all_calls is a superset
13689 of DW_AT_call_all_tail_calls. */
13691 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13692 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13693 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13694 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13696 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13697 not complete. But keep CALL_SITE for look ups via call_site_htab,
13698 both the initial caller containing the real return address PC and
13699 the final callee containing the current PC of a chain of tail
13700 calls do not need to have the tail call list complete. But any
13701 function candidate for a virtual tail call frame searched via
13702 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13703 determined unambiguously. */
13707 struct type
*func_type
= NULL
;
13710 func_type
= get_die_type (func_die
, cu
);
13711 if (func_type
!= NULL
)
13713 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13715 /* Enlist this call site to the function. */
13716 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13717 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13720 complaint (_("Cannot find function owning DW_TAG_call_site "
13721 "DIE %s [in module %s]"),
13722 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13726 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13728 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13730 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13733 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13734 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13736 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13737 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13738 /* Keep NULL DWARF_BLOCK. */;
13739 else if (attr
->form_is_block ())
13741 struct dwarf2_locexpr_baton
*dlbaton
;
13742 struct dwarf_block
*block
= attr
->as_block ();
13744 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13745 dlbaton
->data
= block
->data
;
13746 dlbaton
->size
= block
->size
;
13747 dlbaton
->per_objfile
= per_objfile
;
13748 dlbaton
->per_cu
= cu
->per_cu
;
13750 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13752 else if (attr
->form_is_ref ())
13754 struct dwarf2_cu
*target_cu
= cu
;
13755 struct die_info
*target_die
;
13757 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13758 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13759 if (die_is_declaration (target_die
, target_cu
))
13761 const char *target_physname
;
13763 /* Prefer the mangled name; otherwise compute the demangled one. */
13764 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13765 if (target_physname
== NULL
)
13766 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13767 if (target_physname
== NULL
)
13768 complaint (_("DW_AT_call_target target DIE has invalid "
13769 "physname, for referencing DIE %s [in module %s]"),
13770 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13772 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13778 /* DW_AT_entry_pc should be preferred. */
13779 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13780 <= PC_BOUNDS_INVALID
)
13781 complaint (_("DW_AT_call_target target DIE has invalid "
13782 "low pc, for referencing DIE %s [in module %s]"),
13783 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13786 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13787 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13792 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13793 "block nor reference, for DIE %s [in module %s]"),
13794 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13796 call_site
->per_cu
= cu
->per_cu
;
13797 call_site
->per_objfile
= per_objfile
;
13799 for (child_die
= die
->child
;
13800 child_die
&& child_die
->tag
;
13801 child_die
= child_die
->sibling
)
13803 struct call_site_parameter
*parameter
;
13804 struct attribute
*loc
, *origin
;
13806 if (child_die
->tag
!= DW_TAG_call_site_parameter
13807 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13809 /* Already printed the complaint above. */
13813 gdb_assert (call_site
->parameter_count
< nparams
);
13814 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13816 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13817 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13818 register is contained in DW_AT_call_value. */
13820 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13821 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13822 if (origin
== NULL
)
13824 /* This was a pre-DWARF-5 GNU extension alias
13825 for DW_AT_call_parameter. */
13826 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13828 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13830 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13832 sect_offset sect_off
= origin
->get_ref_die_offset ();
13833 if (!cu
->header
.offset_in_cu_p (sect_off
))
13835 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13836 binding can be done only inside one CU. Such referenced DIE
13837 therefore cannot be even moved to DW_TAG_partial_unit. */
13838 complaint (_("DW_AT_call_parameter offset is not in CU for "
13839 "DW_TAG_call_site child DIE %s [in module %s]"),
13840 sect_offset_str (child_die
->sect_off
),
13841 objfile_name (objfile
));
13844 parameter
->u
.param_cu_off
13845 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13847 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13849 complaint (_("No DW_FORM_block* DW_AT_location for "
13850 "DW_TAG_call_site child DIE %s [in module %s]"),
13851 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13856 struct dwarf_block
*block
= loc
->as_block ();
13858 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13859 (block
->data
, &block
->data
[block
->size
]);
13860 if (parameter
->u
.dwarf_reg
!= -1)
13861 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13862 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
13863 &block
->data
[block
->size
],
13864 ¶meter
->u
.fb_offset
))
13865 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13868 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13869 "for DW_FORM_block* DW_AT_location is supported for "
13870 "DW_TAG_call_site child DIE %s "
13872 sect_offset_str (child_die
->sect_off
),
13873 objfile_name (objfile
));
13878 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13880 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13881 if (attr
== NULL
|| !attr
->form_is_block ())
13883 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13884 "DW_TAG_call_site child DIE %s [in module %s]"),
13885 sect_offset_str (child_die
->sect_off
),
13886 objfile_name (objfile
));
13890 struct dwarf_block
*block
= attr
->as_block ();
13891 parameter
->value
= block
->data
;
13892 parameter
->value_size
= block
->size
;
13894 /* Parameters are not pre-cleared by memset above. */
13895 parameter
->data_value
= NULL
;
13896 parameter
->data_value_size
= 0;
13897 call_site
->parameter_count
++;
13899 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13901 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13902 if (attr
!= nullptr)
13904 if (!attr
->form_is_block ())
13905 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13906 "DW_TAG_call_site child DIE %s [in module %s]"),
13907 sect_offset_str (child_die
->sect_off
),
13908 objfile_name (objfile
));
13911 block
= attr
->as_block ();
13912 parameter
->data_value
= block
->data
;
13913 parameter
->data_value_size
= block
->size
;
13919 /* Helper function for read_variable. If DIE represents a virtual
13920 table, then return the type of the concrete object that is
13921 associated with the virtual table. Otherwise, return NULL. */
13923 static struct type
*
13924 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13926 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13930 /* Find the type DIE. */
13931 struct die_info
*type_die
= NULL
;
13932 struct dwarf2_cu
*type_cu
= cu
;
13934 if (attr
->form_is_ref ())
13935 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13936 if (type_die
== NULL
)
13939 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13941 return die_containing_type (type_die
, type_cu
);
13944 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13947 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13949 struct rust_vtable_symbol
*storage
= NULL
;
13951 if (cu
->language
== language_rust
)
13953 struct type
*containing_type
= rust_containing_type (die
, cu
);
13955 if (containing_type
!= NULL
)
13957 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13959 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13960 storage
->concrete_type
= containing_type
;
13961 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13965 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13966 struct attribute
*abstract_origin
13967 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13968 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13969 if (res
== NULL
&& loc
&& abstract_origin
)
13971 /* We have a variable without a name, but with a location and an abstract
13972 origin. This may be a concrete instance of an abstract variable
13973 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13975 struct dwarf2_cu
*origin_cu
= cu
;
13976 struct die_info
*origin_die
13977 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13978 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13979 per_objfile
->per_bfd
->abstract_to_concrete
13980 [origin_die
->sect_off
].push_back (die
->sect_off
);
13984 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13985 reading .debug_rnglists.
13986 Callback's type should be:
13987 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13988 Return true if the attributes are present and valid, otherwise,
13991 template <typename Callback
>
13993 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13994 dwarf_tag tag
, Callback
&&callback
)
13996 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13997 struct objfile
*objfile
= per_objfile
->objfile
;
13998 bfd
*obfd
= objfile
->obfd
;
13999 /* Base address selection entry. */
14000 gdb::optional
<CORE_ADDR
> base
;
14001 const gdb_byte
*buffer
;
14002 CORE_ADDR baseaddr
;
14003 bool overflow
= false;
14004 ULONGEST addr_index
;
14005 struct dwarf2_section_info
*rnglists_section
;
14007 base
= cu
->base_address
;
14008 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
14009 rnglists_section
->read (objfile
);
14011 if (offset
>= rnglists_section
->size
)
14013 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14017 buffer
= rnglists_section
->buffer
+ offset
;
14019 baseaddr
= objfile
->text_section_offset ();
14023 /* Initialize it due to a false compiler warning. */
14024 CORE_ADDR range_beginning
= 0, range_end
= 0;
14025 const gdb_byte
*buf_end
= (rnglists_section
->buffer
14026 + rnglists_section
->size
);
14027 unsigned int bytes_read
;
14029 if (buffer
== buf_end
)
14034 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14037 case DW_RLE_end_of_list
:
14039 case DW_RLE_base_address
:
14040 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14045 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14046 buffer
+= bytes_read
;
14048 case DW_RLE_base_addressx
:
14049 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14050 buffer
+= bytes_read
;
14051 base
= read_addr_index (cu
, addr_index
);
14053 case DW_RLE_start_length
:
14054 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14059 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14061 buffer
+= bytes_read
;
14062 range_end
= (range_beginning
14063 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14064 buffer
+= bytes_read
;
14065 if (buffer
> buf_end
)
14071 case DW_RLE_startx_length
:
14072 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14073 buffer
+= bytes_read
;
14074 range_beginning
= read_addr_index (cu
, addr_index
);
14075 if (buffer
> buf_end
)
14080 range_end
= (range_beginning
14081 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14082 buffer
+= bytes_read
;
14084 case DW_RLE_offset_pair
:
14085 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14086 buffer
+= bytes_read
;
14087 if (buffer
> buf_end
)
14092 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14093 buffer
+= bytes_read
;
14094 if (buffer
> buf_end
)
14100 case DW_RLE_start_end
:
14101 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14106 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14108 buffer
+= bytes_read
;
14109 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14110 buffer
+= bytes_read
;
14112 case DW_RLE_startx_endx
:
14113 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14114 buffer
+= bytes_read
;
14115 range_beginning
= read_addr_index (cu
, addr_index
);
14116 if (buffer
> buf_end
)
14121 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14122 buffer
+= bytes_read
;
14123 range_end
= read_addr_index (cu
, addr_index
);
14126 complaint (_("Invalid .debug_rnglists data (no base address)"));
14129 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14131 if (rlet
== DW_RLE_base_address
)
14134 if (range_beginning
> range_end
)
14136 /* Inverted range entries are invalid. */
14137 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14141 /* Empty range entries have no effect. */
14142 if (range_beginning
== range_end
)
14145 /* Only DW_RLE_offset_pair needs the base address added. */
14146 if (rlet
== DW_RLE_offset_pair
)
14148 if (!base
.has_value ())
14150 /* We have no valid base address for the DW_RLE_offset_pair. */
14151 complaint (_("Invalid .debug_rnglists data (no base address for "
14152 "DW_RLE_offset_pair)"));
14156 range_beginning
+= *base
;
14157 range_end
+= *base
;
14160 /* A not-uncommon case of bad debug info.
14161 Don't pollute the addrmap with bad data. */
14162 if (range_beginning
+ baseaddr
== 0
14163 && !per_objfile
->per_bfd
->has_section_at_zero
)
14165 complaint (_(".debug_rnglists entry has start address of zero"
14166 " [in module %s]"), objfile_name (objfile
));
14170 callback (range_beginning
, range_end
);
14175 complaint (_("Offset %d is not terminated "
14176 "for DW_AT_ranges attribute"),
14184 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14185 Callback's type should be:
14186 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14187 Return 1 if the attributes are present and valid, otherwise, return 0. */
14189 template <typename Callback
>
14191 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
14192 Callback
&&callback
)
14194 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14195 struct objfile
*objfile
= per_objfile
->objfile
;
14196 struct comp_unit_head
*cu_header
= &cu
->header
;
14197 bfd
*obfd
= objfile
->obfd
;
14198 unsigned int addr_size
= cu_header
->addr_size
;
14199 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14200 /* Base address selection entry. */
14201 gdb::optional
<CORE_ADDR
> base
;
14202 unsigned int dummy
;
14203 const gdb_byte
*buffer
;
14204 CORE_ADDR baseaddr
;
14206 if (cu_header
->version
>= 5)
14207 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
14209 base
= cu
->base_address
;
14211 per_objfile
->per_bfd
->ranges
.read (objfile
);
14212 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
14214 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14218 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
14220 baseaddr
= objfile
->text_section_offset ();
14224 CORE_ADDR range_beginning
, range_end
;
14226 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14227 buffer
+= addr_size
;
14228 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14229 buffer
+= addr_size
;
14230 offset
+= 2 * addr_size
;
14232 /* An end of list marker is a pair of zero addresses. */
14233 if (range_beginning
== 0 && range_end
== 0)
14234 /* Found the end of list entry. */
14237 /* Each base address selection entry is a pair of 2 values.
14238 The first is the largest possible address, the second is
14239 the base address. Check for a base address here. */
14240 if ((range_beginning
& mask
) == mask
)
14242 /* If we found the largest possible address, then we already
14243 have the base address in range_end. */
14248 if (!base
.has_value ())
14250 /* We have no valid base address for the ranges
14252 complaint (_("Invalid .debug_ranges data (no base address)"));
14256 if (range_beginning
> range_end
)
14258 /* Inverted range entries are invalid. */
14259 complaint (_("Invalid .debug_ranges data (inverted range)"));
14263 /* Empty range entries have no effect. */
14264 if (range_beginning
== range_end
)
14267 range_beginning
+= *base
;
14268 range_end
+= *base
;
14270 /* A not-uncommon case of bad debug info.
14271 Don't pollute the addrmap with bad data. */
14272 if (range_beginning
+ baseaddr
== 0
14273 && !per_objfile
->per_bfd
->has_section_at_zero
)
14275 complaint (_(".debug_ranges entry has start address of zero"
14276 " [in module %s]"), objfile_name (objfile
));
14280 callback (range_beginning
, range_end
);
14286 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14287 Return 1 if the attributes are present and valid, otherwise, return 0.
14288 If RANGES_PST is not NULL we should set up the `psymtabs_addrmap'. */
14291 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14292 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14293 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
14295 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14296 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
14297 struct gdbarch
*gdbarch
= objfile
->arch ();
14298 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14301 CORE_ADDR high
= 0;
14304 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14305 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14307 if (ranges_pst
!= NULL
)
14312 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14313 range_beginning
+ baseaddr
)
14315 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14316 range_end
+ baseaddr
)
14318 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
14319 lowpc
, highpc
- 1, ranges_pst
);
14322 /* FIXME: This is recording everything as a low-high
14323 segment of consecutive addresses. We should have a
14324 data structure for discontiguous block ranges
14328 low
= range_beginning
;
14334 if (range_beginning
< low
)
14335 low
= range_beginning
;
14336 if (range_end
> high
)
14344 /* If the first entry is an end-of-list marker, the range
14345 describes an empty scope, i.e. no instructions. */
14351 *high_return
= high
;
14355 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14356 definition for the return value. *LOWPC and *HIGHPC are set iff
14357 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14359 static enum pc_bounds_kind
14360 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14361 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14362 dwarf2_psymtab
*pst
)
14364 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14365 struct attribute
*attr
;
14366 struct attribute
*attr_high
;
14368 CORE_ADDR high
= 0;
14369 enum pc_bounds_kind ret
;
14371 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14374 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14375 if (attr
!= nullptr)
14377 low
= attr
->as_address ();
14378 high
= attr_high
->as_address ();
14379 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14383 /* Found high w/o low attribute. */
14384 return PC_BOUNDS_INVALID
;
14386 /* Found consecutive range of addresses. */
14387 ret
= PC_BOUNDS_HIGH_LOW
;
14391 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14392 if (attr
!= nullptr && attr
->form_is_unsigned ())
14394 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14395 on DWARF version). */
14396 ULONGEST ranges_offset
= attr
->as_unsigned ();
14398 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14400 if (die
->tag
!= DW_TAG_compile_unit
)
14401 ranges_offset
+= cu
->gnu_ranges_base
;
14403 /* Value of the DW_AT_ranges attribute is the offset in the
14404 .debug_ranges section. */
14405 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14407 return PC_BOUNDS_INVALID
;
14408 /* Found discontinuous range of addresses. */
14409 ret
= PC_BOUNDS_RANGES
;
14412 return PC_BOUNDS_NOT_PRESENT
;
14415 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14417 return PC_BOUNDS_INVALID
;
14419 /* When using the GNU linker, .gnu.linkonce. sections are used to
14420 eliminate duplicate copies of functions and vtables and such.
14421 The linker will arbitrarily choose one and discard the others.
14422 The AT_*_pc values for such functions refer to local labels in
14423 these sections. If the section from that file was discarded, the
14424 labels are not in the output, so the relocs get a value of 0.
14425 If this is a discarded function, mark the pc bounds as invalid,
14426 so that GDB will ignore it. */
14427 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14428 return PC_BOUNDS_INVALID
;
14436 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14437 its low and high PC addresses. Do nothing if these addresses could not
14438 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14439 and HIGHPC to the high address if greater than HIGHPC. */
14442 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14443 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14444 struct dwarf2_cu
*cu
)
14446 CORE_ADDR low
, high
;
14447 struct die_info
*child
= die
->child
;
14449 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14451 *lowpc
= std::min (*lowpc
, low
);
14452 *highpc
= std::max (*highpc
, high
);
14455 /* If the language does not allow nested subprograms (either inside
14456 subprograms or lexical blocks), we're done. */
14457 if (cu
->language
!= language_ada
)
14460 /* Check all the children of the given DIE. If it contains nested
14461 subprograms, then check their pc bounds. Likewise, we need to
14462 check lexical blocks as well, as they may also contain subprogram
14464 while (child
&& child
->tag
)
14466 if (child
->tag
== DW_TAG_subprogram
14467 || child
->tag
== DW_TAG_lexical_block
)
14468 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14469 child
= child
->sibling
;
14473 /* Get the low and high pc's represented by the scope DIE, and store
14474 them in *LOWPC and *HIGHPC. If the correct values can't be
14475 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14478 get_scope_pc_bounds (struct die_info
*die
,
14479 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14480 struct dwarf2_cu
*cu
)
14482 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14483 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14484 CORE_ADDR current_low
, current_high
;
14486 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14487 >= PC_BOUNDS_RANGES
)
14489 best_low
= current_low
;
14490 best_high
= current_high
;
14494 struct die_info
*child
= die
->child
;
14496 while (child
&& child
->tag
)
14498 switch (child
->tag
) {
14499 case DW_TAG_subprogram
:
14500 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14502 case DW_TAG_namespace
:
14503 case DW_TAG_module
:
14504 /* FIXME: carlton/2004-01-16: Should we do this for
14505 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14506 that current GCC's always emit the DIEs corresponding
14507 to definitions of methods of classes as children of a
14508 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14509 the DIEs giving the declarations, which could be
14510 anywhere). But I don't see any reason why the
14511 standards says that they have to be there. */
14512 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14514 if (current_low
!= ((CORE_ADDR
) -1))
14516 best_low
= std::min (best_low
, current_low
);
14517 best_high
= std::max (best_high
, current_high
);
14525 child
= child
->sibling
;
14530 *highpc
= best_high
;
14533 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14537 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14538 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14540 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14541 struct gdbarch
*gdbarch
= objfile
->arch ();
14542 struct attribute
*attr
;
14543 struct attribute
*attr_high
;
14545 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14548 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14549 if (attr
!= nullptr)
14551 CORE_ADDR low
= attr
->as_address ();
14552 CORE_ADDR high
= attr_high
->as_address ();
14554 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14557 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14558 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14559 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14563 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14564 if (attr
!= nullptr && attr
->form_is_unsigned ())
14566 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14567 on DWARF version). */
14568 ULONGEST ranges_offset
= attr
->as_unsigned ();
14570 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14572 if (die
->tag
!= DW_TAG_compile_unit
)
14573 ranges_offset
+= cu
->gnu_ranges_base
;
14575 std::vector
<blockrange
> blockvec
;
14576 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14577 [&] (CORE_ADDR start
, CORE_ADDR end
)
14581 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14582 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14583 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14584 blockvec
.emplace_back (start
, end
);
14587 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14591 /* Check whether the producer field indicates either of GCC < 4.6, or the
14592 Intel C/C++ compiler, and cache the result in CU. */
14595 check_producer (struct dwarf2_cu
*cu
)
14599 if (cu
->producer
== NULL
)
14601 /* For unknown compilers expect their behavior is DWARF version
14604 GCC started to support .debug_types sections by -gdwarf-4 since
14605 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14606 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14607 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14608 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14610 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14612 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14613 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14615 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14617 cu
->producer_is_icc
= true;
14618 cu
->producer_is_icc_lt_14
= major
< 14;
14620 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14621 cu
->producer_is_codewarrior
= true;
14624 /* For other non-GCC compilers, expect their behavior is DWARF version
14628 cu
->checked_producer
= true;
14631 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14632 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14633 during 4.6.0 experimental. */
14636 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14638 if (!cu
->checked_producer
)
14639 check_producer (cu
);
14641 return cu
->producer_is_gxx_lt_4_6
;
14645 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14646 with incorrect is_stmt attributes. */
14649 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14651 if (!cu
->checked_producer
)
14652 check_producer (cu
);
14654 return cu
->producer_is_codewarrior
;
14657 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14658 If that attribute is not available, return the appropriate
14661 static enum dwarf_access_attribute
14662 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14664 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14665 if (attr
!= nullptr)
14667 LONGEST value
= attr
->constant_value (-1);
14668 if (value
== DW_ACCESS_public
14669 || value
== DW_ACCESS_protected
14670 || value
== DW_ACCESS_private
)
14671 return (dwarf_access_attribute
) value
;
14672 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14676 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14678 /* The default DWARF 2 accessibility for members is public, the default
14679 accessibility for inheritance is private. */
14681 if (die
->tag
!= DW_TAG_inheritance
)
14682 return DW_ACCESS_public
;
14684 return DW_ACCESS_private
;
14688 /* DWARF 3+ defines the default accessibility a different way. The same
14689 rules apply now for DW_TAG_inheritance as for the members and it only
14690 depends on the container kind. */
14692 if (die
->parent
->tag
== DW_TAG_class_type
)
14693 return DW_ACCESS_private
;
14695 return DW_ACCESS_public
;
14699 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14700 offset. If the attribute was not found return 0, otherwise return
14701 1. If it was found but could not properly be handled, set *OFFSET
14705 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14708 struct attribute
*attr
;
14710 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14715 /* Note that we do not check for a section offset first here.
14716 This is because DW_AT_data_member_location is new in DWARF 4,
14717 so if we see it, we can assume that a constant form is really
14718 a constant and not a section offset. */
14719 if (attr
->form_is_constant ())
14720 *offset
= attr
->constant_value (0);
14721 else if (attr
->form_is_section_offset ())
14722 dwarf2_complex_location_expr_complaint ();
14723 else if (attr
->form_is_block ())
14724 *offset
= decode_locdesc (attr
->as_block (), cu
);
14726 dwarf2_complex_location_expr_complaint ();
14734 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14737 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14738 struct field
*field
)
14740 struct attribute
*attr
;
14742 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14745 if (attr
->form_is_constant ())
14747 LONGEST offset
= attr
->constant_value (0);
14748 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14750 else if (attr
->form_is_section_offset ())
14751 dwarf2_complex_location_expr_complaint ();
14752 else if (attr
->form_is_block ())
14755 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14757 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14760 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14761 struct objfile
*objfile
= per_objfile
->objfile
;
14762 struct dwarf2_locexpr_baton
*dlbaton
14763 = XOBNEW (&objfile
->objfile_obstack
,
14764 struct dwarf2_locexpr_baton
);
14765 dlbaton
->data
= attr
->as_block ()->data
;
14766 dlbaton
->size
= attr
->as_block ()->size
;
14767 /* When using this baton, we want to compute the address
14768 of the field, not the value. This is why
14769 is_reference is set to false here. */
14770 dlbaton
->is_reference
= false;
14771 dlbaton
->per_objfile
= per_objfile
;
14772 dlbaton
->per_cu
= cu
->per_cu
;
14774 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14778 dwarf2_complex_location_expr_complaint ();
14782 /* Add an aggregate field to the field list. */
14785 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14786 struct dwarf2_cu
*cu
)
14788 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14789 struct gdbarch
*gdbarch
= objfile
->arch ();
14790 struct nextfield
*new_field
;
14791 struct attribute
*attr
;
14793 const char *fieldname
= "";
14795 if (die
->tag
== DW_TAG_inheritance
)
14797 fip
->baseclasses
.emplace_back ();
14798 new_field
= &fip
->baseclasses
.back ();
14802 fip
->fields
.emplace_back ();
14803 new_field
= &fip
->fields
.back ();
14806 new_field
->offset
= die
->sect_off
;
14808 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14809 if (new_field
->accessibility
!= DW_ACCESS_public
)
14810 fip
->non_public_fields
= true;
14812 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14813 if (attr
!= nullptr)
14814 new_field
->virtuality
= attr
->as_virtuality ();
14816 new_field
->virtuality
= DW_VIRTUALITY_none
;
14818 fp
= &new_field
->field
;
14820 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14822 /* Data member other than a C++ static data member. */
14824 /* Get type of field. */
14825 fp
->set_type (die_type (die
, cu
));
14827 SET_FIELD_BITPOS (*fp
, 0);
14829 /* Get bit size of field (zero if none). */
14830 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14831 if (attr
!= nullptr)
14833 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
14837 FIELD_BITSIZE (*fp
) = 0;
14840 /* Get bit offset of field. */
14841 handle_data_member_location (die
, cu
, fp
);
14842 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14843 if (attr
!= nullptr && attr
->form_is_constant ())
14845 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14847 /* For big endian bits, the DW_AT_bit_offset gives the
14848 additional bit offset from the MSB of the containing
14849 anonymous object to the MSB of the field. We don't
14850 have to do anything special since we don't need to
14851 know the size of the anonymous object. */
14852 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14853 + attr
->constant_value (0)));
14857 /* For little endian bits, compute the bit offset to the
14858 MSB of the anonymous object, subtract off the number of
14859 bits from the MSB of the field to the MSB of the
14860 object, and then subtract off the number of bits of
14861 the field itself. The result is the bit offset of
14862 the LSB of the field. */
14863 int anonymous_size
;
14864 int bit_offset
= attr
->constant_value (0);
14866 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14867 if (attr
!= nullptr && attr
->form_is_constant ())
14869 /* The size of the anonymous object containing
14870 the bit field is explicit, so use the
14871 indicated size (in bytes). */
14872 anonymous_size
= attr
->constant_value (0);
14876 /* The size of the anonymous object containing
14877 the bit field must be inferred from the type
14878 attribute of the data member containing the
14880 anonymous_size
= TYPE_LENGTH (fp
->type ());
14882 SET_FIELD_BITPOS (*fp
,
14883 (FIELD_BITPOS (*fp
)
14884 + anonymous_size
* bits_per_byte
14885 - bit_offset
- FIELD_BITSIZE (*fp
)));
14888 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14890 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14891 + attr
->constant_value (0)));
14893 /* Get name of field. */
14894 fieldname
= dwarf2_name (die
, cu
);
14895 if (fieldname
== NULL
)
14898 /* The name is already allocated along with this objfile, so we don't
14899 need to duplicate it for the type. */
14900 fp
->name
= fieldname
;
14902 /* Change accessibility for artificial fields (e.g. virtual table
14903 pointer or virtual base class pointer) to private. */
14904 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14906 FIELD_ARTIFICIAL (*fp
) = 1;
14907 new_field
->accessibility
= DW_ACCESS_private
;
14908 fip
->non_public_fields
= true;
14911 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14913 /* C++ static member. */
14915 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14916 is a declaration, but all versions of G++ as of this writing
14917 (so through at least 3.2.1) incorrectly generate
14918 DW_TAG_variable tags. */
14920 const char *physname
;
14922 /* Get name of field. */
14923 fieldname
= dwarf2_name (die
, cu
);
14924 if (fieldname
== NULL
)
14927 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14929 /* Only create a symbol if this is an external value.
14930 new_symbol checks this and puts the value in the global symbol
14931 table, which we want. If it is not external, new_symbol
14932 will try to put the value in cu->list_in_scope which is wrong. */
14933 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14935 /* A static const member, not much different than an enum as far as
14936 we're concerned, except that we can support more types. */
14937 new_symbol (die
, NULL
, cu
);
14940 /* Get physical name. */
14941 physname
= dwarf2_physname (fieldname
, die
, cu
);
14943 /* The name is already allocated along with this objfile, so we don't
14944 need to duplicate it for the type. */
14945 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14946 fp
->set_type (die_type (die
, cu
));
14947 FIELD_NAME (*fp
) = fieldname
;
14949 else if (die
->tag
== DW_TAG_inheritance
)
14951 /* C++ base class field. */
14952 handle_data_member_location (die
, cu
, fp
);
14953 FIELD_BITSIZE (*fp
) = 0;
14954 fp
->set_type (die_type (die
, cu
));
14955 FIELD_NAME (*fp
) = fp
->type ()->name ();
14958 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14961 /* Can the type given by DIE define another type? */
14964 type_can_define_types (const struct die_info
*die
)
14968 case DW_TAG_typedef
:
14969 case DW_TAG_class_type
:
14970 case DW_TAG_structure_type
:
14971 case DW_TAG_union_type
:
14972 case DW_TAG_enumeration_type
:
14980 /* Add a type definition defined in the scope of the FIP's class. */
14983 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14984 struct dwarf2_cu
*cu
)
14986 struct decl_field fp
;
14987 memset (&fp
, 0, sizeof (fp
));
14989 gdb_assert (type_can_define_types (die
));
14991 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14992 fp
.name
= dwarf2_name (die
, cu
);
14993 fp
.type
= read_type_die (die
, cu
);
14995 /* Save accessibility. */
14996 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
14997 switch (accessibility
)
14999 case DW_ACCESS_public
:
15000 /* The assumed value if neither private nor protected. */
15002 case DW_ACCESS_private
:
15005 case DW_ACCESS_protected
:
15006 fp
.is_protected
= 1;
15010 if (die
->tag
== DW_TAG_typedef
)
15011 fip
->typedef_field_list
.push_back (fp
);
15013 fip
->nested_types_list
.push_back (fp
);
15016 /* A convenience typedef that's used when finding the discriminant
15017 field for a variant part. */
15018 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
15021 /* Compute the discriminant range for a given variant. OBSTACK is
15022 where the results will be stored. VARIANT is the variant to
15023 process. IS_UNSIGNED indicates whether the discriminant is signed
15026 static const gdb::array_view
<discriminant_range
>
15027 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
15030 std::vector
<discriminant_range
> ranges
;
15032 if (variant
.default_branch
)
15035 if (variant
.discr_list_data
== nullptr)
15037 discriminant_range r
15038 = {variant
.discriminant_value
, variant
.discriminant_value
};
15039 ranges
.push_back (r
);
15043 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
15044 variant
.discr_list_data
->size
);
15045 while (!data
.empty ())
15047 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
15049 complaint (_("invalid discriminant marker: %d"), data
[0]);
15052 bool is_range
= data
[0] == DW_DSC_range
;
15053 data
= data
.slice (1);
15055 ULONGEST low
, high
;
15056 unsigned int bytes_read
;
15060 complaint (_("DW_AT_discr_list missing low value"));
15064 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
15066 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
15068 data
= data
.slice (bytes_read
);
15074 complaint (_("DW_AT_discr_list missing high value"));
15078 high
= read_unsigned_leb128 (nullptr, data
.data (),
15081 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
15083 data
= data
.slice (bytes_read
);
15088 ranges
.push_back ({ low
, high
});
15092 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
15094 std::copy (ranges
.begin (), ranges
.end (), result
);
15095 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
15098 static const gdb::array_view
<variant_part
> create_variant_parts
15099 (struct obstack
*obstack
,
15100 const offset_map_type
&offset_map
,
15101 struct field_info
*fi
,
15102 const std::vector
<variant_part_builder
> &variant_parts
);
15104 /* Fill in a "struct variant" for a given variant field. RESULT is
15105 the variant to fill in. OBSTACK is where any needed allocations
15106 will be done. OFFSET_MAP holds the mapping from section offsets to
15107 fields for the type. FI describes the fields of the type we're
15108 processing. FIELD is the variant field we're converting. */
15111 create_one_variant (variant
&result
, struct obstack
*obstack
,
15112 const offset_map_type
&offset_map
,
15113 struct field_info
*fi
, const variant_field
&field
)
15115 result
.discriminants
= convert_variant_range (obstack
, field
, false);
15116 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
15117 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
15118 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
15119 field
.variant_parts
);
15122 /* Fill in a "struct variant_part" for a given variant part. RESULT
15123 is the variant part to fill in. OBSTACK is where any needed
15124 allocations will be done. OFFSET_MAP holds the mapping from
15125 section offsets to fields for the type. FI describes the fields of
15126 the type we're processing. BUILDER is the variant part to be
15130 create_one_variant_part (variant_part
&result
,
15131 struct obstack
*obstack
,
15132 const offset_map_type
&offset_map
,
15133 struct field_info
*fi
,
15134 const variant_part_builder
&builder
)
15136 auto iter
= offset_map
.find (builder
.discriminant_offset
);
15137 if (iter
== offset_map
.end ())
15139 result
.discriminant_index
= -1;
15140 /* Doesn't matter. */
15141 result
.is_unsigned
= false;
15145 result
.discriminant_index
= iter
->second
;
15147 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
15150 size_t n
= builder
.variants
.size ();
15151 variant
*output
= new (obstack
) variant
[n
];
15152 for (size_t i
= 0; i
< n
; ++i
)
15153 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
15154 builder
.variants
[i
]);
15156 result
.variants
= gdb::array_view
<variant
> (output
, n
);
15159 /* Create a vector of variant parts that can be attached to a type.
15160 OBSTACK is where any needed allocations will be done. OFFSET_MAP
15161 holds the mapping from section offsets to fields for the type. FI
15162 describes the fields of the type we're processing. VARIANT_PARTS
15163 is the vector to convert. */
15165 static const gdb::array_view
<variant_part
>
15166 create_variant_parts (struct obstack
*obstack
,
15167 const offset_map_type
&offset_map
,
15168 struct field_info
*fi
,
15169 const std::vector
<variant_part_builder
> &variant_parts
)
15171 if (variant_parts
.empty ())
15174 size_t n
= variant_parts
.size ();
15175 variant_part
*result
= new (obstack
) variant_part
[n
];
15176 for (size_t i
= 0; i
< n
; ++i
)
15177 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
15180 return gdb::array_view
<variant_part
> (result
, n
);
15183 /* Compute the variant part vector for FIP, attaching it to TYPE when
15187 add_variant_property (struct field_info
*fip
, struct type
*type
,
15188 struct dwarf2_cu
*cu
)
15190 /* Map section offsets of fields to their field index. Note the
15191 field index here does not take the number of baseclasses into
15193 offset_map_type offset_map
;
15194 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
15195 offset_map
[fip
->fields
[i
].offset
] = i
;
15197 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15198 gdb::array_view
<variant_part
> parts
15199 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
15200 fip
->variant_parts
);
15202 struct dynamic_prop prop
;
15203 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
15204 obstack_copy (&objfile
->objfile_obstack
, &parts
,
15207 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
15210 /* Create the vector of fields, and attach it to the type. */
15213 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15214 struct dwarf2_cu
*cu
)
15216 int nfields
= fip
->nfields ();
15218 /* Record the field count, allocate space for the array of fields,
15219 and create blank accessibility bitfields if necessary. */
15220 type
->set_num_fields (nfields
);
15222 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
15224 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15226 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15228 TYPE_FIELD_PRIVATE_BITS (type
) =
15229 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15230 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15232 TYPE_FIELD_PROTECTED_BITS (type
) =
15233 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15234 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15236 TYPE_FIELD_IGNORE_BITS (type
) =
15237 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15238 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15241 /* If the type has baseclasses, allocate and clear a bit vector for
15242 TYPE_FIELD_VIRTUAL_BITS. */
15243 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15245 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15246 unsigned char *pointer
;
15248 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15249 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15250 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15251 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15252 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15255 if (!fip
->variant_parts
.empty ())
15256 add_variant_property (fip
, type
, cu
);
15258 /* Copy the saved-up fields into the field vector. */
15259 for (int i
= 0; i
< nfields
; ++i
)
15261 struct nextfield
&field
15262 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15263 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15265 type
->field (i
) = field
.field
;
15266 switch (field
.accessibility
)
15268 case DW_ACCESS_private
:
15269 if (cu
->language
!= language_ada
)
15270 SET_TYPE_FIELD_PRIVATE (type
, i
);
15273 case DW_ACCESS_protected
:
15274 if (cu
->language
!= language_ada
)
15275 SET_TYPE_FIELD_PROTECTED (type
, i
);
15278 case DW_ACCESS_public
:
15282 /* Unknown accessibility. Complain and treat it as public. */
15284 complaint (_("unsupported accessibility %d"),
15285 field
.accessibility
);
15289 if (i
< fip
->baseclasses
.size ())
15291 switch (field
.virtuality
)
15293 case DW_VIRTUALITY_virtual
:
15294 case DW_VIRTUALITY_pure_virtual
:
15295 if (cu
->language
== language_ada
)
15296 error (_("unexpected virtuality in component of Ada type"));
15297 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15304 /* Return true if this member function is a constructor, false
15308 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15310 const char *fieldname
;
15311 const char *type_name
;
15314 if (die
->parent
== NULL
)
15317 if (die
->parent
->tag
!= DW_TAG_structure_type
15318 && die
->parent
->tag
!= DW_TAG_union_type
15319 && die
->parent
->tag
!= DW_TAG_class_type
)
15322 fieldname
= dwarf2_name (die
, cu
);
15323 type_name
= dwarf2_name (die
->parent
, cu
);
15324 if (fieldname
== NULL
|| type_name
== NULL
)
15327 len
= strlen (fieldname
);
15328 return (strncmp (fieldname
, type_name
, len
) == 0
15329 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15332 /* Add a member function to the proper fieldlist. */
15335 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15336 struct type
*type
, struct dwarf2_cu
*cu
)
15338 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15339 struct attribute
*attr
;
15341 struct fnfieldlist
*flp
= nullptr;
15342 struct fn_field
*fnp
;
15343 const char *fieldname
;
15344 struct type
*this_type
;
15346 if (cu
->language
== language_ada
)
15347 error (_("unexpected member function in Ada type"));
15349 /* Get name of member function. */
15350 fieldname
= dwarf2_name (die
, cu
);
15351 if (fieldname
== NULL
)
15354 /* Look up member function name in fieldlist. */
15355 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15357 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15359 flp
= &fip
->fnfieldlists
[i
];
15364 /* Create a new fnfieldlist if necessary. */
15365 if (flp
== nullptr)
15367 fip
->fnfieldlists
.emplace_back ();
15368 flp
= &fip
->fnfieldlists
.back ();
15369 flp
->name
= fieldname
;
15370 i
= fip
->fnfieldlists
.size () - 1;
15373 /* Create a new member function field and add it to the vector of
15375 flp
->fnfields
.emplace_back ();
15376 fnp
= &flp
->fnfields
.back ();
15378 /* Delay processing of the physname until later. */
15379 if (cu
->language
== language_cplus
)
15380 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15384 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15385 fnp
->physname
= physname
? physname
: "";
15388 fnp
->type
= alloc_type (objfile
);
15389 this_type
= read_type_die (die
, cu
);
15390 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15392 int nparams
= this_type
->num_fields ();
15394 /* TYPE is the domain of this method, and THIS_TYPE is the type
15395 of the method itself (TYPE_CODE_METHOD). */
15396 smash_to_method_type (fnp
->type
, type
,
15397 TYPE_TARGET_TYPE (this_type
),
15398 this_type
->fields (),
15399 this_type
->num_fields (),
15400 this_type
->has_varargs ());
15402 /* Handle static member functions.
15403 Dwarf2 has no clean way to discern C++ static and non-static
15404 member functions. G++ helps GDB by marking the first
15405 parameter for non-static member functions (which is the this
15406 pointer) as artificial. We obtain this information from
15407 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15408 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15409 fnp
->voffset
= VOFFSET_STATIC
;
15412 complaint (_("member function type missing for '%s'"),
15413 dwarf2_full_name (fieldname
, die
, cu
));
15415 /* Get fcontext from DW_AT_containing_type if present. */
15416 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15417 fnp
->fcontext
= die_containing_type (die
, cu
);
15419 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15420 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15422 /* Get accessibility. */
15423 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15424 switch (accessibility
)
15426 case DW_ACCESS_private
:
15427 fnp
->is_private
= 1;
15429 case DW_ACCESS_protected
:
15430 fnp
->is_protected
= 1;
15434 /* Check for artificial methods. */
15435 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15436 if (attr
&& attr
->as_boolean ())
15437 fnp
->is_artificial
= 1;
15439 /* Check for defaulted methods. */
15440 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15441 if (attr
!= nullptr)
15442 fnp
->defaulted
= attr
->defaulted ();
15444 /* Check for deleted methods. */
15445 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15446 if (attr
!= nullptr && attr
->as_boolean ())
15447 fnp
->is_deleted
= 1;
15449 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15451 /* Get index in virtual function table if it is a virtual member
15452 function. For older versions of GCC, this is an offset in the
15453 appropriate virtual table, as specified by DW_AT_containing_type.
15454 For everyone else, it is an expression to be evaluated relative
15455 to the object address. */
15457 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15458 if (attr
!= nullptr)
15460 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15462 struct dwarf_block
*block
= attr
->as_block ();
15464 if (block
->data
[0] == DW_OP_constu
)
15466 /* Old-style GCC. */
15467 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15469 else if (block
->data
[0] == DW_OP_deref
15470 || (block
->size
> 1
15471 && block
->data
[0] == DW_OP_deref_size
15472 && block
->data
[1] == cu
->header
.addr_size
))
15474 fnp
->voffset
= decode_locdesc (block
, cu
);
15475 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15476 dwarf2_complex_location_expr_complaint ();
15478 fnp
->voffset
/= cu
->header
.addr_size
;
15482 dwarf2_complex_location_expr_complaint ();
15484 if (!fnp
->fcontext
)
15486 /* If there is no `this' field and no DW_AT_containing_type,
15487 we cannot actually find a base class context for the
15489 if (this_type
->num_fields () == 0
15490 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15492 complaint (_("cannot determine context for virtual member "
15493 "function \"%s\" (offset %s)"),
15494 fieldname
, sect_offset_str (die
->sect_off
));
15499 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15503 else if (attr
->form_is_section_offset ())
15505 dwarf2_complex_location_expr_complaint ();
15509 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15515 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15516 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15518 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15519 complaint (_("Member function \"%s\" (offset %s) is virtual "
15520 "but the vtable offset is not specified"),
15521 fieldname
, sect_offset_str (die
->sect_off
));
15522 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15523 TYPE_CPLUS_DYNAMIC (type
) = 1;
15528 /* Create the vector of member function fields, and attach it to the type. */
15531 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15532 struct dwarf2_cu
*cu
)
15534 if (cu
->language
== language_ada
)
15535 error (_("unexpected member functions in Ada type"));
15537 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15538 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15540 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15542 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15544 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15545 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15547 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15548 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15549 fn_flp
->fn_fields
= (struct fn_field
*)
15550 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15552 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15553 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15556 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15559 /* Returns non-zero if NAME is the name of a vtable member in CU's
15560 language, zero otherwise. */
15562 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15564 static const char vptr
[] = "_vptr";
15566 /* Look for the C++ form of the vtable. */
15567 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15573 /* GCC outputs unnamed structures that are really pointers to member
15574 functions, with the ABI-specified layout. If TYPE describes
15575 such a structure, smash it into a member function type.
15577 GCC shouldn't do this; it should just output pointer to member DIEs.
15578 This is GCC PR debug/28767. */
15581 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15583 struct type
*pfn_type
, *self_type
, *new_type
;
15585 /* Check for a structure with no name and two children. */
15586 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15589 /* Check for __pfn and __delta members. */
15590 if (TYPE_FIELD_NAME (type
, 0) == NULL
15591 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15592 || TYPE_FIELD_NAME (type
, 1) == NULL
15593 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15596 /* Find the type of the method. */
15597 pfn_type
= type
->field (0).type ();
15598 if (pfn_type
== NULL
15599 || pfn_type
->code () != TYPE_CODE_PTR
15600 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15603 /* Look for the "this" argument. */
15604 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15605 if (pfn_type
->num_fields () == 0
15606 /* || pfn_type->field (0).type () == NULL */
15607 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15610 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15611 new_type
= alloc_type (objfile
);
15612 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15613 pfn_type
->fields (), pfn_type
->num_fields (),
15614 pfn_type
->has_varargs ());
15615 smash_to_methodptr_type (type
, new_type
);
15618 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15619 requires rewriting, then copy it and return the updated copy.
15620 Otherwise return nullptr. */
15622 static struct type
*
15623 rewrite_array_type (struct type
*type
)
15625 if (type
->code () != TYPE_CODE_ARRAY
)
15628 struct type
*index_type
= type
->index_type ();
15629 range_bounds
*current_bounds
= index_type
->bounds ();
15631 /* Handle multi-dimensional arrays. */
15632 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15633 if (new_target
== nullptr)
15635 /* Maybe we don't need to rewrite this array. */
15636 if (current_bounds
->low
.kind () == PROP_CONST
15637 && current_bounds
->high
.kind () == PROP_CONST
)
15641 /* Either the target type was rewritten, or the bounds have to be
15642 updated. Either way we want to copy the type and update
15644 struct type
*copy
= copy_type (type
);
15645 int nfields
= copy
->num_fields ();
15647 = ((struct field
*) TYPE_ZALLOC (copy
,
15648 nfields
* sizeof (struct field
)));
15649 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15650 copy
->set_fields (new_fields
);
15651 if (new_target
!= nullptr)
15652 TYPE_TARGET_TYPE (copy
) = new_target
;
15654 struct type
*index_copy
= copy_type (index_type
);
15655 range_bounds
*bounds
15656 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15657 sizeof (range_bounds
));
15658 *bounds
= *current_bounds
;
15659 bounds
->low
.set_const_val (1);
15660 bounds
->high
.set_const_val (0);
15661 index_copy
->set_bounds (bounds
);
15662 copy
->set_index_type (index_copy
);
15667 /* While some versions of GCC will generate complicated DWARF for an
15668 array (see quirk_ada_thick_pointer), more recent versions were
15669 modified to emit an explicit thick pointer structure. However, in
15670 this case, the array still has DWARF expressions for its ranges,
15671 and these must be ignored. */
15674 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15677 gdb_assert (cu
->language
== language_ada
);
15679 /* Check for a structure with two children. */
15680 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15683 /* Check for P_ARRAY and P_BOUNDS members. */
15684 if (TYPE_FIELD_NAME (type
, 0) == NULL
15685 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
15686 || TYPE_FIELD_NAME (type
, 1) == NULL
15687 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
15690 /* Make sure we're looking at a pointer to an array. */
15691 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15694 /* The Ada code already knows how to handle these types, so all that
15695 we need to do is turn the bounds into static bounds. However, we
15696 don't want to rewrite existing array or index types in-place,
15697 because those may be referenced in other contexts where this
15698 rewriting is undesirable. */
15699 struct type
*new_ary_type
15700 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15701 if (new_ary_type
!= nullptr)
15702 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15705 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15706 appropriate error checking and issuing complaints if there is a
15710 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15712 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15714 if (attr
== nullptr)
15717 if (!attr
->form_is_constant ())
15719 complaint (_("DW_AT_alignment must have constant form"
15720 " - DIE at %s [in module %s]"),
15721 sect_offset_str (die
->sect_off
),
15722 objfile_name (cu
->per_objfile
->objfile
));
15726 LONGEST val
= attr
->constant_value (0);
15729 complaint (_("DW_AT_alignment value must not be negative"
15730 " - DIE at %s [in module %s]"),
15731 sect_offset_str (die
->sect_off
),
15732 objfile_name (cu
->per_objfile
->objfile
));
15735 ULONGEST align
= val
;
15739 complaint (_("DW_AT_alignment value must not be zero"
15740 " - DIE at %s [in module %s]"),
15741 sect_offset_str (die
->sect_off
),
15742 objfile_name (cu
->per_objfile
->objfile
));
15745 if ((align
& (align
- 1)) != 0)
15747 complaint (_("DW_AT_alignment value must be a power of 2"
15748 " - DIE at %s [in module %s]"),
15749 sect_offset_str (die
->sect_off
),
15750 objfile_name (cu
->per_objfile
->objfile
));
15757 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15758 the alignment for TYPE. */
15761 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15764 if (!set_type_align (type
, get_alignment (cu
, die
)))
15765 complaint (_("DW_AT_alignment value too large"
15766 " - DIE at %s [in module %s]"),
15767 sect_offset_str (die
->sect_off
),
15768 objfile_name (cu
->per_objfile
->objfile
));
15771 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15772 constant for a type, according to DWARF5 spec, Table 5.5. */
15775 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15780 case DW_CC_pass_by_reference
:
15781 case DW_CC_pass_by_value
:
15785 complaint (_("unrecognized DW_AT_calling_convention value "
15786 "(%s) for a type"), pulongest (value
));
15791 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15792 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15793 also according to GNU-specific values (see include/dwarf2.h). */
15796 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15801 case DW_CC_program
:
15805 case DW_CC_GNU_renesas_sh
:
15806 case DW_CC_GNU_borland_fastcall_i386
:
15807 case DW_CC_GDB_IBM_OpenCL
:
15811 complaint (_("unrecognized DW_AT_calling_convention value "
15812 "(%s) for a subroutine"), pulongest (value
));
15817 /* Called when we find the DIE that starts a structure or union scope
15818 (definition) to create a type for the structure or union. Fill in
15819 the type's name and general properties; the members will not be
15820 processed until process_structure_scope. A symbol table entry for
15821 the type will also not be done until process_structure_scope (assuming
15822 the type has a name).
15824 NOTE: we need to call these functions regardless of whether or not the
15825 DIE has a DW_AT_name attribute, since it might be an anonymous
15826 structure or union. This gets the type entered into our set of
15827 user defined types. */
15829 static struct type
*
15830 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15832 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15834 struct attribute
*attr
;
15837 /* If the definition of this type lives in .debug_types, read that type.
15838 Don't follow DW_AT_specification though, that will take us back up
15839 the chain and we want to go down. */
15840 attr
= die
->attr (DW_AT_signature
);
15841 if (attr
!= nullptr)
15843 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15845 /* The type's CU may not be the same as CU.
15846 Ensure TYPE is recorded with CU in die_type_hash. */
15847 return set_die_type (die
, type
, cu
);
15850 type
= alloc_type (objfile
);
15851 INIT_CPLUS_SPECIFIC (type
);
15853 name
= dwarf2_name (die
, cu
);
15856 if (cu
->language
== language_cplus
15857 || cu
->language
== language_d
15858 || cu
->language
== language_rust
)
15860 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15862 /* dwarf2_full_name might have already finished building the DIE's
15863 type. If so, there is no need to continue. */
15864 if (get_die_type (die
, cu
) != NULL
)
15865 return get_die_type (die
, cu
);
15867 type
->set_name (full_name
);
15871 /* The name is already allocated along with this objfile, so
15872 we don't need to duplicate it for the type. */
15873 type
->set_name (name
);
15877 if (die
->tag
== DW_TAG_structure_type
)
15879 type
->set_code (TYPE_CODE_STRUCT
);
15881 else if (die
->tag
== DW_TAG_union_type
)
15883 type
->set_code (TYPE_CODE_UNION
);
15887 type
->set_code (TYPE_CODE_STRUCT
);
15890 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15891 type
->set_is_declared_class (true);
15893 /* Store the calling convention in the type if it's available in
15894 the die. Otherwise the calling convention remains set to
15895 the default value DW_CC_normal. */
15896 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15897 if (attr
!= nullptr
15898 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
15900 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15901 TYPE_CPLUS_CALLING_CONVENTION (type
)
15902 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
15905 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15906 if (attr
!= nullptr)
15908 if (attr
->form_is_constant ())
15909 TYPE_LENGTH (type
) = attr
->constant_value (0);
15912 struct dynamic_prop prop
;
15913 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15914 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15915 TYPE_LENGTH (type
) = 0;
15920 TYPE_LENGTH (type
) = 0;
15923 maybe_set_alignment (cu
, die
, type
);
15925 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15927 /* ICC<14 does not output the required DW_AT_declaration on
15928 incomplete types, but gives them a size of zero. */
15929 type
->set_is_stub (true);
15932 type
->set_stub_is_supported (true);
15934 if (die_is_declaration (die
, cu
))
15935 type
->set_is_stub (true);
15936 else if (attr
== NULL
&& die
->child
== NULL
15937 && producer_is_realview (cu
->producer
))
15938 /* RealView does not output the required DW_AT_declaration
15939 on incomplete types. */
15940 type
->set_is_stub (true);
15942 /* We need to add the type field to the die immediately so we don't
15943 infinitely recurse when dealing with pointers to the structure
15944 type within the structure itself. */
15945 set_die_type (die
, type
, cu
);
15947 /* set_die_type should be already done. */
15948 set_descriptive_type (type
, die
, cu
);
15953 static void handle_struct_member_die
15954 (struct die_info
*child_die
,
15956 struct field_info
*fi
,
15957 std::vector
<struct symbol
*> *template_args
,
15958 struct dwarf2_cu
*cu
);
15960 /* A helper for handle_struct_member_die that handles
15961 DW_TAG_variant_part. */
15964 handle_variant_part (struct die_info
*die
, struct type
*type
,
15965 struct field_info
*fi
,
15966 std::vector
<struct symbol
*> *template_args
,
15967 struct dwarf2_cu
*cu
)
15969 variant_part_builder
*new_part
;
15970 if (fi
->current_variant_part
== nullptr)
15972 fi
->variant_parts
.emplace_back ();
15973 new_part
= &fi
->variant_parts
.back ();
15975 else if (!fi
->current_variant_part
->processing_variant
)
15977 complaint (_("nested DW_TAG_variant_part seen "
15978 "- DIE at %s [in module %s]"),
15979 sect_offset_str (die
->sect_off
),
15980 objfile_name (cu
->per_objfile
->objfile
));
15985 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15986 current
.variant_parts
.emplace_back ();
15987 new_part
= ¤t
.variant_parts
.back ();
15990 /* When we recurse, we want callees to add to this new variant
15992 scoped_restore save_current_variant_part
15993 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15995 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15998 /* It's a univariant form, an extension we support. */
16000 else if (discr
->form_is_ref ())
16002 struct dwarf2_cu
*target_cu
= cu
;
16003 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16005 new_part
->discriminant_offset
= target_die
->sect_off
;
16009 complaint (_("DW_AT_discr does not have DIE reference form"
16010 " - DIE at %s [in module %s]"),
16011 sect_offset_str (die
->sect_off
),
16012 objfile_name (cu
->per_objfile
->objfile
));
16015 for (die_info
*child_die
= die
->child
;
16017 child_die
= child_die
->sibling
)
16018 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
16021 /* A helper for handle_struct_member_die that handles
16025 handle_variant (struct die_info
*die
, struct type
*type
,
16026 struct field_info
*fi
,
16027 std::vector
<struct symbol
*> *template_args
,
16028 struct dwarf2_cu
*cu
)
16030 if (fi
->current_variant_part
== nullptr)
16032 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
16033 "- DIE at %s [in module %s]"),
16034 sect_offset_str (die
->sect_off
),
16035 objfile_name (cu
->per_objfile
->objfile
));
16038 if (fi
->current_variant_part
->processing_variant
)
16040 complaint (_("nested DW_TAG_variant seen "
16041 "- DIE at %s [in module %s]"),
16042 sect_offset_str (die
->sect_off
),
16043 objfile_name (cu
->per_objfile
->objfile
));
16047 scoped_restore save_processing_variant
16048 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
16051 fi
->current_variant_part
->variants
.emplace_back ();
16052 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
16053 variant
.first_field
= fi
->fields
.size ();
16055 /* In a variant we want to get the discriminant and also add a
16056 field for our sole member child. */
16057 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
16058 if (discr
== nullptr || !discr
->form_is_constant ())
16060 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
16061 if (discr
== nullptr || discr
->as_block ()->size
== 0)
16062 variant
.default_branch
= true;
16064 variant
.discr_list_data
= discr
->as_block ();
16067 variant
.discriminant_value
= discr
->constant_value (0);
16069 for (die_info
*variant_child
= die
->child
;
16070 variant_child
!= NULL
;
16071 variant_child
= variant_child
->sibling
)
16072 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
16074 variant
.last_field
= fi
->fields
.size ();
16077 /* A helper for process_structure_scope that handles a single member
16081 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16082 struct field_info
*fi
,
16083 std::vector
<struct symbol
*> *template_args
,
16084 struct dwarf2_cu
*cu
)
16086 if (child_die
->tag
== DW_TAG_member
16087 || child_die
->tag
== DW_TAG_variable
)
16089 /* NOTE: carlton/2002-11-05: A C++ static data member
16090 should be a DW_TAG_member that is a declaration, but
16091 all versions of G++ as of this writing (so through at
16092 least 3.2.1) incorrectly generate DW_TAG_variable
16093 tags for them instead. */
16094 dwarf2_add_field (fi
, child_die
, cu
);
16096 else if (child_die
->tag
== DW_TAG_subprogram
)
16098 /* Rust doesn't have member functions in the C++ sense.
16099 However, it does emit ordinary functions as children
16100 of a struct DIE. */
16101 if (cu
->language
== language_rust
)
16102 read_func_scope (child_die
, cu
);
16105 /* C++ member function. */
16106 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16109 else if (child_die
->tag
== DW_TAG_inheritance
)
16111 /* C++ base class field. */
16112 dwarf2_add_field (fi
, child_die
, cu
);
16114 else if (type_can_define_types (child_die
))
16115 dwarf2_add_type_defn (fi
, child_die
, cu
);
16116 else if (child_die
->tag
== DW_TAG_template_type_param
16117 || child_die
->tag
== DW_TAG_template_value_param
)
16119 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16122 template_args
->push_back (arg
);
16124 else if (child_die
->tag
== DW_TAG_variant_part
)
16125 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
16126 else if (child_die
->tag
== DW_TAG_variant
)
16127 handle_variant (child_die
, type
, fi
, template_args
, cu
);
16130 /* Finish creating a structure or union type, including filling in
16131 its members and creating a symbol for it. */
16134 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16136 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16137 struct die_info
*child_die
;
16140 type
= get_die_type (die
, cu
);
16142 type
= read_structure_type (die
, cu
);
16144 bool has_template_parameters
= false;
16145 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16147 struct field_info fi
;
16148 std::vector
<struct symbol
*> template_args
;
16150 child_die
= die
->child
;
16152 while (child_die
&& child_die
->tag
)
16154 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16155 child_die
= child_die
->sibling
;
16158 /* Attach template arguments to type. */
16159 if (!template_args
.empty ())
16161 has_template_parameters
= true;
16162 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16163 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16164 TYPE_TEMPLATE_ARGUMENTS (type
)
16165 = XOBNEWVEC (&objfile
->objfile_obstack
,
16167 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16168 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16169 template_args
.data (),
16170 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16171 * sizeof (struct symbol
*)));
16174 /* Attach fields and member functions to the type. */
16175 if (fi
.nfields () > 0)
16176 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16177 if (!fi
.fnfieldlists
.empty ())
16179 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16181 /* Get the type which refers to the base class (possibly this
16182 class itself) which contains the vtable pointer for the current
16183 class from the DW_AT_containing_type attribute. This use of
16184 DW_AT_containing_type is a GNU extension. */
16186 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16188 struct type
*t
= die_containing_type (die
, cu
);
16190 set_type_vptr_basetype (type
, t
);
16195 /* Our own class provides vtbl ptr. */
16196 for (i
= t
->num_fields () - 1;
16197 i
>= TYPE_N_BASECLASSES (t
);
16200 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16202 if (is_vtable_name (fieldname
, cu
))
16204 set_type_vptr_fieldno (type
, i
);
16209 /* Complain if virtual function table field not found. */
16210 if (i
< TYPE_N_BASECLASSES (t
))
16211 complaint (_("virtual function table pointer "
16212 "not found when defining class '%s'"),
16213 type
->name () ? type
->name () : "");
16217 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16220 else if (cu
->producer
16221 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16223 /* The IBM XLC compiler does not provide direct indication
16224 of the containing type, but the vtable pointer is
16225 always named __vfp. */
16229 for (i
= type
->num_fields () - 1;
16230 i
>= TYPE_N_BASECLASSES (type
);
16233 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16235 set_type_vptr_fieldno (type
, i
);
16236 set_type_vptr_basetype (type
, type
);
16243 /* Copy fi.typedef_field_list linked list elements content into the
16244 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16245 if (!fi
.typedef_field_list
.empty ())
16247 int count
= fi
.typedef_field_list
.size ();
16249 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16250 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16251 = ((struct decl_field
*)
16253 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16254 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16256 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16257 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16260 /* Copy fi.nested_types_list linked list elements content into the
16261 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16262 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16264 int count
= fi
.nested_types_list
.size ();
16266 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16267 TYPE_NESTED_TYPES_ARRAY (type
)
16268 = ((struct decl_field
*)
16269 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16270 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16272 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16273 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16277 quirk_gcc_member_function_pointer (type
, objfile
);
16278 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16279 cu
->rust_unions
.push_back (type
);
16280 else if (cu
->language
== language_ada
)
16281 quirk_ada_thick_pointer_struct (die
, cu
, type
);
16283 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16284 snapshots) has been known to create a die giving a declaration
16285 for a class that has, as a child, a die giving a definition for a
16286 nested class. So we have to process our children even if the
16287 current die is a declaration. Normally, of course, a declaration
16288 won't have any children at all. */
16290 child_die
= die
->child
;
16292 while (child_die
!= NULL
&& child_die
->tag
)
16294 if (child_die
->tag
== DW_TAG_member
16295 || child_die
->tag
== DW_TAG_variable
16296 || child_die
->tag
== DW_TAG_inheritance
16297 || child_die
->tag
== DW_TAG_template_value_param
16298 || child_die
->tag
== DW_TAG_template_type_param
)
16303 process_die (child_die
, cu
);
16305 child_die
= child_die
->sibling
;
16308 /* Do not consider external references. According to the DWARF standard,
16309 these DIEs are identified by the fact that they have no byte_size
16310 attribute, and a declaration attribute. */
16311 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16312 || !die_is_declaration (die
, cu
)
16313 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16315 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16317 if (has_template_parameters
)
16319 struct symtab
*symtab
;
16320 if (sym
!= nullptr)
16321 symtab
= symbol_symtab (sym
);
16322 else if (cu
->line_header
!= nullptr)
16324 /* Any related symtab will do. */
16326 = cu
->line_header
->file_names ()[0].symtab
;
16331 complaint (_("could not find suitable "
16332 "symtab for template parameter"
16333 " - DIE at %s [in module %s]"),
16334 sect_offset_str (die
->sect_off
),
16335 objfile_name (objfile
));
16338 if (symtab
!= nullptr)
16340 /* Make sure that the symtab is set on the new symbols.
16341 Even though they don't appear in this symtab directly,
16342 other parts of gdb assume that symbols do, and this is
16343 reasonably true. */
16344 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16345 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16351 /* Assuming DIE is an enumeration type, and TYPE is its associated
16352 type, update TYPE using some information only available in DIE's
16353 children. In particular, the fields are computed. */
16356 update_enumeration_type_from_children (struct die_info
*die
,
16358 struct dwarf2_cu
*cu
)
16360 struct die_info
*child_die
;
16361 int unsigned_enum
= 1;
16364 auto_obstack obstack
;
16365 std::vector
<struct field
> fields
;
16367 for (child_die
= die
->child
;
16368 child_die
!= NULL
&& child_die
->tag
;
16369 child_die
= child_die
->sibling
)
16371 struct attribute
*attr
;
16373 const gdb_byte
*bytes
;
16374 struct dwarf2_locexpr_baton
*baton
;
16377 if (child_die
->tag
!= DW_TAG_enumerator
)
16380 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16384 name
= dwarf2_name (child_die
, cu
);
16386 name
= "<anonymous enumerator>";
16388 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16389 &value
, &bytes
, &baton
);
16397 if (count_one_bits_ll (value
) >= 2)
16401 fields
.emplace_back ();
16402 struct field
&field
= fields
.back ();
16403 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16404 SET_FIELD_ENUMVAL (field
, value
);
16407 if (!fields
.empty ())
16409 type
->set_num_fields (fields
.size ());
16412 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16413 memcpy (type
->fields (), fields
.data (),
16414 sizeof (struct field
) * fields
.size ());
16418 type
->set_is_unsigned (true);
16421 type
->set_is_flag_enum (true);
16424 /* Given a DW_AT_enumeration_type die, set its type. We do not
16425 complete the type's fields yet, or create any symbols. */
16427 static struct type
*
16428 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16430 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16432 struct attribute
*attr
;
16435 /* If the definition of this type lives in .debug_types, read that type.
16436 Don't follow DW_AT_specification though, that will take us back up
16437 the chain and we want to go down. */
16438 attr
= die
->attr (DW_AT_signature
);
16439 if (attr
!= nullptr)
16441 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16443 /* The type's CU may not be the same as CU.
16444 Ensure TYPE is recorded with CU in die_type_hash. */
16445 return set_die_type (die
, type
, cu
);
16448 type
= alloc_type (objfile
);
16450 type
->set_code (TYPE_CODE_ENUM
);
16451 name
= dwarf2_full_name (NULL
, die
, cu
);
16453 type
->set_name (name
);
16455 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16458 struct type
*underlying_type
= die_type (die
, cu
);
16460 TYPE_TARGET_TYPE (type
) = underlying_type
;
16463 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16464 if (attr
!= nullptr)
16466 TYPE_LENGTH (type
) = attr
->constant_value (0);
16470 TYPE_LENGTH (type
) = 0;
16473 maybe_set_alignment (cu
, die
, type
);
16475 /* The enumeration DIE can be incomplete. In Ada, any type can be
16476 declared as private in the package spec, and then defined only
16477 inside the package body. Such types are known as Taft Amendment
16478 Types. When another package uses such a type, an incomplete DIE
16479 may be generated by the compiler. */
16480 if (die_is_declaration (die
, cu
))
16481 type
->set_is_stub (true);
16483 /* If this type has an underlying type that is not a stub, then we
16484 may use its attributes. We always use the "unsigned" attribute
16485 in this situation, because ordinarily we guess whether the type
16486 is unsigned -- but the guess can be wrong and the underlying type
16487 can tell us the reality. However, we defer to a local size
16488 attribute if one exists, because this lets the compiler override
16489 the underlying type if needed. */
16490 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16492 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16493 underlying_type
= check_typedef (underlying_type
);
16495 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16497 if (TYPE_LENGTH (type
) == 0)
16498 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16500 if (TYPE_RAW_ALIGN (type
) == 0
16501 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16502 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16505 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
16507 set_die_type (die
, type
, cu
);
16509 /* Finish the creation of this type by using the enum's children.
16510 Note that, as usual, this must come after set_die_type to avoid
16511 infinite recursion when trying to compute the names of the
16513 update_enumeration_type_from_children (die
, type
, cu
);
16518 /* Given a pointer to a die which begins an enumeration, process all
16519 the dies that define the members of the enumeration, and create the
16520 symbol for the enumeration type.
16522 NOTE: We reverse the order of the element list. */
16525 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16527 struct type
*this_type
;
16529 this_type
= get_die_type (die
, cu
);
16530 if (this_type
== NULL
)
16531 this_type
= read_enumeration_type (die
, cu
);
16533 if (die
->child
!= NULL
)
16535 struct die_info
*child_die
;
16538 child_die
= die
->child
;
16539 while (child_die
&& child_die
->tag
)
16541 if (child_die
->tag
!= DW_TAG_enumerator
)
16543 process_die (child_die
, cu
);
16547 name
= dwarf2_name (child_die
, cu
);
16549 new_symbol (child_die
, this_type
, cu
);
16552 child_die
= child_die
->sibling
;
16556 /* If we are reading an enum from a .debug_types unit, and the enum
16557 is a declaration, and the enum is not the signatured type in the
16558 unit, then we do not want to add a symbol for it. Adding a
16559 symbol would in some cases obscure the true definition of the
16560 enum, giving users an incomplete type when the definition is
16561 actually available. Note that we do not want to do this for all
16562 enums which are just declarations, because C++0x allows forward
16563 enum declarations. */
16564 if (cu
->per_cu
->is_debug_types
16565 && die_is_declaration (die
, cu
))
16567 struct signatured_type
*sig_type
;
16569 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16570 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16571 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16575 new_symbol (die
, this_type
, cu
);
16578 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16579 expression for an index type and finds the corresponding field
16580 offset in the hidden "P_BOUNDS" structure. Returns true on success
16581 and updates *FIELD, false if it fails to recognize an
16585 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16586 int *bounds_offset
, struct field
*field
,
16587 struct dwarf2_cu
*cu
)
16589 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16590 if (attr
== nullptr || !attr
->form_is_block ())
16593 const struct dwarf_block
*block
= attr
->as_block ();
16594 const gdb_byte
*start
= block
->data
;
16595 const gdb_byte
*end
= block
->data
+ block
->size
;
16597 /* The expression to recognize generally looks like:
16599 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16600 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16602 However, the second "plus_uconst" may be missing:
16604 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16605 DW_OP_deref_size: 4)
16607 This happens when the field is at the start of the structure.
16609 Also, the final deref may not be sized:
16611 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16614 This happens when the size of the index type happens to be the
16615 same as the architecture's word size. This can occur with or
16616 without the second plus_uconst. */
16618 if (end
- start
< 2)
16620 if (*start
++ != DW_OP_push_object_address
)
16622 if (*start
++ != DW_OP_plus_uconst
)
16625 uint64_t this_bound_off
;
16626 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16627 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16629 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16630 is consistent among all bounds. */
16631 if (*bounds_offset
== -1)
16632 *bounds_offset
= this_bound_off
;
16633 else if (*bounds_offset
!= this_bound_off
)
16636 if (start
== end
|| *start
++ != DW_OP_deref
)
16642 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16644 /* This means an offset of 0. */
16646 else if (*start
++ != DW_OP_plus_uconst
)
16650 /* The size is the parameter to DW_OP_plus_uconst. */
16652 start
= gdb_read_uleb128 (start
, end
, &val
);
16653 if (start
== nullptr)
16655 if ((int) val
!= val
)
16664 if (*start
== DW_OP_deref_size
)
16666 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16667 if (start
== nullptr)
16670 else if (*start
== DW_OP_deref
)
16672 size
= cu
->header
.addr_size
;
16678 SET_FIELD_BITPOS (*field
, 8 * offset
);
16679 if (size
!= TYPE_LENGTH (field
->type ()))
16680 FIELD_BITSIZE (*field
) = 8 * size
;
16685 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16686 some kinds of Ada arrays:
16688 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16689 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16690 <11e0> DW_AT_data_location: 2 byte block: 97 6
16691 (DW_OP_push_object_address; DW_OP_deref)
16692 <11e3> DW_AT_type : <0x1173>
16693 <11e7> DW_AT_sibling : <0x1201>
16694 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16695 <11ec> DW_AT_type : <0x1206>
16696 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16697 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16698 DW_OP_deref_size: 4)
16699 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16700 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16701 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16703 This actually represents a "thick pointer", which is a structure
16704 with two elements: one that is a pointer to the array data, and one
16705 that is a pointer to another structure; this second structure holds
16708 This returns a new type on success, or nullptr if this didn't
16709 recognize the type. */
16711 static struct type
*
16712 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16715 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16716 /* So far we've only seen this with block form. */
16717 if (attr
== nullptr || !attr
->form_is_block ())
16720 /* Note that this will fail if the structure layout is changed by
16721 the compiler. However, we have no good way to recognize some
16722 other layout, because we don't know what expression the compiler
16723 might choose to emit should this happen. */
16724 struct dwarf_block
*blk
= attr
->as_block ();
16726 || blk
->data
[0] != DW_OP_push_object_address
16727 || blk
->data
[1] != DW_OP_deref
)
16730 int bounds_offset
= -1;
16731 int max_align
= -1;
16732 std::vector
<struct field
> range_fields
;
16733 for (struct die_info
*child_die
= die
->child
;
16735 child_die
= child_die
->sibling
)
16737 if (child_die
->tag
== DW_TAG_subrange_type
)
16739 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16741 int this_align
= type_align (underlying
);
16742 if (this_align
> max_align
)
16743 max_align
= this_align
;
16745 range_fields
.emplace_back ();
16746 range_fields
.emplace_back ();
16748 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16749 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16751 lower
.set_type (underlying
);
16752 FIELD_ARTIFICIAL (lower
) = 1;
16754 upper
.set_type (underlying
);
16755 FIELD_ARTIFICIAL (upper
) = 1;
16757 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16758 &bounds_offset
, &lower
, cu
)
16759 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16760 &bounds_offset
, &upper
, cu
))
16765 /* This shouldn't really happen, but double-check that we found
16766 where the bounds are stored. */
16767 if (bounds_offset
== -1)
16770 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16771 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16775 /* Set the name of each field in the bounds. */
16776 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16777 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
16778 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16779 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
16782 struct type
*bounds
= alloc_type (objfile
);
16783 bounds
->set_code (TYPE_CODE_STRUCT
);
16785 bounds
->set_num_fields (range_fields
.size ());
16787 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16788 * sizeof (struct field
))));
16789 memcpy (bounds
->fields (), range_fields
.data (),
16790 bounds
->num_fields () * sizeof (struct field
));
16792 int last_fieldno
= range_fields
.size () - 1;
16793 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
16794 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16795 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16797 /* Rewrite the existing array type in place. Specifically, we
16798 remove any dynamic properties we might have read, and we replace
16799 the index types. */
16800 struct type
*iter
= type
;
16801 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16803 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16804 iter
->main_type
->dyn_prop_list
= nullptr;
16805 iter
->set_index_type
16806 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16807 iter
= TYPE_TARGET_TYPE (iter
);
16810 struct type
*result
= alloc_type (objfile
);
16811 result
->set_code (TYPE_CODE_STRUCT
);
16813 result
->set_num_fields (2);
16815 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16816 * sizeof (struct field
))));
16818 /* The names are chosen to coincide with what the compiler does with
16819 -fgnat-encodings=all, which the Ada code in gdb already
16821 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
16822 result
->field (0).set_type (lookup_pointer_type (type
));
16824 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
16825 result
->field (1).set_type (lookup_pointer_type (bounds
));
16826 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
16828 result
->set_name (type
->name ());
16829 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16830 + TYPE_LENGTH (result
->field (1).type ()));
16835 /* Extract all information from a DW_TAG_array_type DIE and put it in
16836 the DIE's type field. For now, this only handles one dimensional
16839 static struct type
*
16840 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16842 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16843 struct die_info
*child_die
;
16845 struct type
*element_type
, *range_type
, *index_type
;
16846 struct attribute
*attr
;
16848 struct dynamic_prop
*byte_stride_prop
= NULL
;
16849 unsigned int bit_stride
= 0;
16851 element_type
= die_type (die
, cu
);
16853 /* The die_type call above may have already set the type for this DIE. */
16854 type
= get_die_type (die
, cu
);
16858 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16862 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16865 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16866 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16870 complaint (_("unable to read array DW_AT_byte_stride "
16871 " - DIE at %s [in module %s]"),
16872 sect_offset_str (die
->sect_off
),
16873 objfile_name (cu
->per_objfile
->objfile
));
16874 /* Ignore this attribute. We will likely not be able to print
16875 arrays of this type correctly, but there is little we can do
16876 to help if we cannot read the attribute's value. */
16877 byte_stride_prop
= NULL
;
16881 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16883 bit_stride
= attr
->constant_value (0);
16885 /* Irix 6.2 native cc creates array types without children for
16886 arrays with unspecified length. */
16887 if (die
->child
== NULL
)
16889 index_type
= objfile_type (objfile
)->builtin_int
;
16890 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16891 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16892 byte_stride_prop
, bit_stride
);
16893 return set_die_type (die
, type
, cu
);
16896 std::vector
<struct type
*> range_types
;
16897 child_die
= die
->child
;
16898 while (child_die
&& child_die
->tag
)
16900 if (child_die
->tag
== DW_TAG_subrange_type
)
16902 struct type
*child_type
= read_type_die (child_die
, cu
);
16904 if (child_type
!= NULL
)
16906 /* The range type was succesfully read. Save it for the
16907 array type creation. */
16908 range_types
.push_back (child_type
);
16911 child_die
= child_die
->sibling
;
16914 if (range_types
.empty ())
16916 complaint (_("unable to find array range - DIE at %s [in module %s]"),
16917 sect_offset_str (die
->sect_off
),
16918 objfile_name (cu
->per_objfile
->objfile
));
16922 /* Dwarf2 dimensions are output from left to right, create the
16923 necessary array types in backwards order. */
16925 type
= element_type
;
16927 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16931 while (i
< range_types
.size ())
16933 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16934 byte_stride_prop
, bit_stride
);
16936 byte_stride_prop
= nullptr;
16941 size_t ndim
= range_types
.size ();
16944 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16945 byte_stride_prop
, bit_stride
);
16947 byte_stride_prop
= nullptr;
16951 gdb_assert (type
!= element_type
);
16953 /* Understand Dwarf2 support for vector types (like they occur on
16954 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16955 array type. This is not part of the Dwarf2/3 standard yet, but a
16956 custom vendor extension. The main difference between a regular
16957 array and the vector variant is that vectors are passed by value
16959 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16960 if (attr
!= nullptr)
16961 make_vector_type (type
);
16963 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16964 implementation may choose to implement triple vectors using this
16966 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16967 if (attr
!= nullptr && attr
->form_is_unsigned ())
16969 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
16970 TYPE_LENGTH (type
) = attr
->as_unsigned ();
16972 complaint (_("DW_AT_byte_size for array type smaller "
16973 "than the total size of elements"));
16976 name
= dwarf2_name (die
, cu
);
16978 type
->set_name (name
);
16980 maybe_set_alignment (cu
, die
, type
);
16982 struct type
*replacement_type
= nullptr;
16983 if (cu
->language
== language_ada
)
16985 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
16986 if (replacement_type
!= nullptr)
16987 type
= replacement_type
;
16990 /* Install the type in the die. */
16991 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
16993 /* set_die_type should be already done. */
16994 set_descriptive_type (type
, die
, cu
);
16999 static enum dwarf_array_dim_ordering
17000 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
17002 struct attribute
*attr
;
17004 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
17006 if (attr
!= nullptr)
17008 LONGEST val
= attr
->constant_value (-1);
17009 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
17010 return (enum dwarf_array_dim_ordering
) val
;
17013 /* GNU F77 is a special case, as at 08/2004 array type info is the
17014 opposite order to the dwarf2 specification, but data is still
17015 laid out as per normal fortran.
17017 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
17018 version checking. */
17020 if (cu
->language
== language_fortran
17021 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
17023 return DW_ORD_row_major
;
17026 switch (cu
->language_defn
->array_ordering ())
17028 case array_column_major
:
17029 return DW_ORD_col_major
;
17030 case array_row_major
:
17032 return DW_ORD_row_major
;
17036 /* Extract all information from a DW_TAG_set_type DIE and put it in
17037 the DIE's type field. */
17039 static struct type
*
17040 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17042 struct type
*domain_type
, *set_type
;
17043 struct attribute
*attr
;
17045 domain_type
= die_type (die
, cu
);
17047 /* The die_type call above may have already set the type for this DIE. */
17048 set_type
= get_die_type (die
, cu
);
17052 set_type
= create_set_type (NULL
, domain_type
);
17054 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17055 if (attr
!= nullptr && attr
->form_is_unsigned ())
17056 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
17058 maybe_set_alignment (cu
, die
, set_type
);
17060 return set_die_type (die
, set_type
, cu
);
17063 /* A helper for read_common_block that creates a locexpr baton.
17064 SYM is the symbol which we are marking as computed.
17065 COMMON_DIE is the DIE for the common block.
17066 COMMON_LOC is the location expression attribute for the common
17068 MEMBER_LOC is the location expression attribute for the particular
17069 member of the common block that we are processing.
17070 CU is the CU from which the above come. */
17073 mark_common_block_symbol_computed (struct symbol
*sym
,
17074 struct die_info
*common_die
,
17075 struct attribute
*common_loc
,
17076 struct attribute
*member_loc
,
17077 struct dwarf2_cu
*cu
)
17079 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17080 struct objfile
*objfile
= per_objfile
->objfile
;
17081 struct dwarf2_locexpr_baton
*baton
;
17083 unsigned int cu_off
;
17084 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
17085 LONGEST offset
= 0;
17087 gdb_assert (common_loc
&& member_loc
);
17088 gdb_assert (common_loc
->form_is_block ());
17089 gdb_assert (member_loc
->form_is_block ()
17090 || member_loc
->form_is_constant ());
17092 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
17093 baton
->per_objfile
= per_objfile
;
17094 baton
->per_cu
= cu
->per_cu
;
17095 gdb_assert (baton
->per_cu
);
17097 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
17099 if (member_loc
->form_is_constant ())
17101 offset
= member_loc
->constant_value (0);
17102 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
17105 baton
->size
+= member_loc
->as_block ()->size
;
17107 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
17110 *ptr
++ = DW_OP_call4
;
17111 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
17112 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
17115 if (member_loc
->form_is_constant ())
17117 *ptr
++ = DW_OP_addr
;
17118 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
17119 ptr
+= cu
->header
.addr_size
;
17123 /* We have to copy the data here, because DW_OP_call4 will only
17124 use a DW_AT_location attribute. */
17125 struct dwarf_block
*block
= member_loc
->as_block ();
17126 memcpy (ptr
, block
->data
, block
->size
);
17127 ptr
+= block
->size
;
17130 *ptr
++ = DW_OP_plus
;
17131 gdb_assert (ptr
- baton
->data
== baton
->size
);
17133 SYMBOL_LOCATION_BATON (sym
) = baton
;
17134 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
17137 /* Create appropriate locally-scoped variables for all the
17138 DW_TAG_common_block entries. Also create a struct common_block
17139 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
17140 is used to separate the common blocks name namespace from regular
17144 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
17146 struct attribute
*attr
;
17148 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17149 if (attr
!= nullptr)
17151 /* Support the .debug_loc offsets. */
17152 if (attr
->form_is_block ())
17156 else if (attr
->form_is_section_offset ())
17158 dwarf2_complex_location_expr_complaint ();
17163 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17164 "common block member");
17169 if (die
->child
!= NULL
)
17171 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17172 struct die_info
*child_die
;
17173 size_t n_entries
= 0, size
;
17174 struct common_block
*common_block
;
17175 struct symbol
*sym
;
17177 for (child_die
= die
->child
;
17178 child_die
&& child_die
->tag
;
17179 child_die
= child_die
->sibling
)
17182 size
= (sizeof (struct common_block
)
17183 + (n_entries
- 1) * sizeof (struct symbol
*));
17185 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17187 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17188 common_block
->n_entries
= 0;
17190 for (child_die
= die
->child
;
17191 child_die
&& child_die
->tag
;
17192 child_die
= child_die
->sibling
)
17194 /* Create the symbol in the DW_TAG_common_block block in the current
17196 sym
= new_symbol (child_die
, NULL
, cu
);
17199 struct attribute
*member_loc
;
17201 common_block
->contents
[common_block
->n_entries
++] = sym
;
17203 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17207 /* GDB has handled this for a long time, but it is
17208 not specified by DWARF. It seems to have been
17209 emitted by gfortran at least as recently as:
17210 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17211 complaint (_("Variable in common block has "
17212 "DW_AT_data_member_location "
17213 "- DIE at %s [in module %s]"),
17214 sect_offset_str (child_die
->sect_off
),
17215 objfile_name (objfile
));
17217 if (member_loc
->form_is_section_offset ())
17218 dwarf2_complex_location_expr_complaint ();
17219 else if (member_loc
->form_is_constant ()
17220 || member_loc
->form_is_block ())
17222 if (attr
!= nullptr)
17223 mark_common_block_symbol_computed (sym
, die
, attr
,
17227 dwarf2_complex_location_expr_complaint ();
17232 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17233 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17237 /* Create a type for a C++ namespace. */
17239 static struct type
*
17240 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17242 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17243 const char *previous_prefix
, *name
;
17247 /* For extensions, reuse the type of the original namespace. */
17248 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17250 struct die_info
*ext_die
;
17251 struct dwarf2_cu
*ext_cu
= cu
;
17253 ext_die
= dwarf2_extension (die
, &ext_cu
);
17254 type
= read_type_die (ext_die
, ext_cu
);
17256 /* EXT_CU may not be the same as CU.
17257 Ensure TYPE is recorded with CU in die_type_hash. */
17258 return set_die_type (die
, type
, cu
);
17261 name
= namespace_name (die
, &is_anonymous
, cu
);
17263 /* Now build the name of the current namespace. */
17265 previous_prefix
= determine_prefix (die
, cu
);
17266 if (previous_prefix
[0] != '\0')
17267 name
= typename_concat (&objfile
->objfile_obstack
,
17268 previous_prefix
, name
, 0, cu
);
17270 /* Create the type. */
17271 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17273 return set_die_type (die
, type
, cu
);
17276 /* Read a namespace scope. */
17279 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17281 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17284 /* Add a symbol associated to this if we haven't seen the namespace
17285 before. Also, add a using directive if it's an anonymous
17288 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17292 type
= read_type_die (die
, cu
);
17293 new_symbol (die
, type
, cu
);
17295 namespace_name (die
, &is_anonymous
, cu
);
17298 const char *previous_prefix
= determine_prefix (die
, cu
);
17300 std::vector
<const char *> excludes
;
17301 add_using_directive (using_directives (cu
),
17302 previous_prefix
, type
->name (), NULL
,
17303 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17307 if (die
->child
!= NULL
)
17309 struct die_info
*child_die
= die
->child
;
17311 while (child_die
&& child_die
->tag
)
17313 process_die (child_die
, cu
);
17314 child_die
= child_die
->sibling
;
17319 /* Read a Fortran module as type. This DIE can be only a declaration used for
17320 imported module. Still we need that type as local Fortran "use ... only"
17321 declaration imports depend on the created type in determine_prefix. */
17323 static struct type
*
17324 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17326 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17327 const char *module_name
;
17330 module_name
= dwarf2_name (die
, cu
);
17331 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17333 return set_die_type (die
, type
, cu
);
17336 /* Read a Fortran module. */
17339 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17341 struct die_info
*child_die
= die
->child
;
17344 type
= read_type_die (die
, cu
);
17345 new_symbol (die
, type
, cu
);
17347 while (child_die
&& child_die
->tag
)
17349 process_die (child_die
, cu
);
17350 child_die
= child_die
->sibling
;
17354 /* Return the name of the namespace represented by DIE. Set
17355 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17358 static const char *
17359 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17361 struct die_info
*current_die
;
17362 const char *name
= NULL
;
17364 /* Loop through the extensions until we find a name. */
17366 for (current_die
= die
;
17367 current_die
!= NULL
;
17368 current_die
= dwarf2_extension (die
, &cu
))
17370 /* We don't use dwarf2_name here so that we can detect the absence
17371 of a name -> anonymous namespace. */
17372 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17378 /* Is it an anonymous namespace? */
17380 *is_anonymous
= (name
== NULL
);
17382 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17387 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17388 the user defined type vector. */
17390 static struct type
*
17391 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17393 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17394 struct comp_unit_head
*cu_header
= &cu
->header
;
17396 struct attribute
*attr_byte_size
;
17397 struct attribute
*attr_address_class
;
17398 int byte_size
, addr_class
;
17399 struct type
*target_type
;
17401 target_type
= die_type (die
, cu
);
17403 /* The die_type call above may have already set the type for this DIE. */
17404 type
= get_die_type (die
, cu
);
17408 type
= lookup_pointer_type (target_type
);
17410 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17411 if (attr_byte_size
)
17412 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17414 byte_size
= cu_header
->addr_size
;
17416 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17417 if (attr_address_class
)
17418 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17420 addr_class
= DW_ADDR_none
;
17422 ULONGEST alignment
= get_alignment (cu
, die
);
17424 /* If the pointer size, alignment, or address class is different
17425 than the default, create a type variant marked as such and set
17426 the length accordingly. */
17427 if (TYPE_LENGTH (type
) != byte_size
17428 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17429 && alignment
!= TYPE_RAW_ALIGN (type
))
17430 || addr_class
!= DW_ADDR_none
)
17432 if (gdbarch_address_class_type_flags_p (gdbarch
))
17434 type_instance_flags type_flags
17435 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17437 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17439 type
= make_type_with_address_space (type
, type_flags
);
17441 else if (TYPE_LENGTH (type
) != byte_size
)
17443 complaint (_("invalid pointer size %d"), byte_size
);
17445 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17447 complaint (_("Invalid DW_AT_alignment"
17448 " - DIE at %s [in module %s]"),
17449 sect_offset_str (die
->sect_off
),
17450 objfile_name (cu
->per_objfile
->objfile
));
17454 /* Should we also complain about unhandled address classes? */
17458 TYPE_LENGTH (type
) = byte_size
;
17459 set_type_align (type
, alignment
);
17460 return set_die_type (die
, type
, cu
);
17463 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17464 the user defined type vector. */
17466 static struct type
*
17467 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17470 struct type
*to_type
;
17471 struct type
*domain
;
17473 to_type
= die_type (die
, cu
);
17474 domain
= die_containing_type (die
, cu
);
17476 /* The calls above may have already set the type for this DIE. */
17477 type
= get_die_type (die
, cu
);
17481 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17482 type
= lookup_methodptr_type (to_type
);
17483 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17485 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17487 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17488 to_type
->fields (), to_type
->num_fields (),
17489 to_type
->has_varargs ());
17490 type
= lookup_methodptr_type (new_type
);
17493 type
= lookup_memberptr_type (to_type
, domain
);
17495 return set_die_type (die
, type
, cu
);
17498 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17499 the user defined type vector. */
17501 static struct type
*
17502 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17503 enum type_code refcode
)
17505 struct comp_unit_head
*cu_header
= &cu
->header
;
17506 struct type
*type
, *target_type
;
17507 struct attribute
*attr
;
17509 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17511 target_type
= die_type (die
, cu
);
17513 /* The die_type call above may have already set the type for this DIE. */
17514 type
= get_die_type (die
, cu
);
17518 type
= lookup_reference_type (target_type
, refcode
);
17519 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17520 if (attr
!= nullptr)
17522 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17526 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17528 maybe_set_alignment (cu
, die
, type
);
17529 return set_die_type (die
, type
, cu
);
17532 /* Add the given cv-qualifiers to the element type of the array. GCC
17533 outputs DWARF type qualifiers that apply to an array, not the
17534 element type. But GDB relies on the array element type to carry
17535 the cv-qualifiers. This mimics section 6.7.3 of the C99
17538 static struct type
*
17539 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17540 struct type
*base_type
, int cnst
, int voltl
)
17542 struct type
*el_type
, *inner_array
;
17544 base_type
= copy_type (base_type
);
17545 inner_array
= base_type
;
17547 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17549 TYPE_TARGET_TYPE (inner_array
) =
17550 copy_type (TYPE_TARGET_TYPE (inner_array
));
17551 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17554 el_type
= TYPE_TARGET_TYPE (inner_array
);
17555 cnst
|= TYPE_CONST (el_type
);
17556 voltl
|= TYPE_VOLATILE (el_type
);
17557 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17559 return set_die_type (die
, base_type
, cu
);
17562 static struct type
*
17563 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17565 struct type
*base_type
, *cv_type
;
17567 base_type
= die_type (die
, cu
);
17569 /* The die_type call above may have already set the type for this DIE. */
17570 cv_type
= get_die_type (die
, cu
);
17574 /* In case the const qualifier is applied to an array type, the element type
17575 is so qualified, not the array type (section 6.7.3 of C99). */
17576 if (base_type
->code () == TYPE_CODE_ARRAY
)
17577 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17579 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17580 return set_die_type (die
, cv_type
, cu
);
17583 static struct type
*
17584 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17586 struct type
*base_type
, *cv_type
;
17588 base_type
= die_type (die
, cu
);
17590 /* The die_type call above may have already set the type for this DIE. */
17591 cv_type
= get_die_type (die
, cu
);
17595 /* In case the volatile qualifier is applied to an array type, the
17596 element type is so qualified, not the array type (section 6.7.3
17598 if (base_type
->code () == TYPE_CODE_ARRAY
)
17599 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17601 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17602 return set_die_type (die
, cv_type
, cu
);
17605 /* Handle DW_TAG_restrict_type. */
17607 static struct type
*
17608 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17610 struct type
*base_type
, *cv_type
;
17612 base_type
= die_type (die
, cu
);
17614 /* The die_type call above may have already set the type for this DIE. */
17615 cv_type
= get_die_type (die
, cu
);
17619 cv_type
= make_restrict_type (base_type
);
17620 return set_die_type (die
, cv_type
, cu
);
17623 /* Handle DW_TAG_atomic_type. */
17625 static struct type
*
17626 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17628 struct type
*base_type
, *cv_type
;
17630 base_type
= die_type (die
, cu
);
17632 /* The die_type call above may have already set the type for this DIE. */
17633 cv_type
= get_die_type (die
, cu
);
17637 cv_type
= make_atomic_type (base_type
);
17638 return set_die_type (die
, cv_type
, cu
);
17641 /* Extract all information from a DW_TAG_string_type DIE and add to
17642 the user defined type vector. It isn't really a user defined type,
17643 but it behaves like one, with other DIE's using an AT_user_def_type
17644 attribute to reference it. */
17646 static struct type
*
17647 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17649 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17650 struct gdbarch
*gdbarch
= objfile
->arch ();
17651 struct type
*type
, *range_type
, *index_type
, *char_type
;
17652 struct attribute
*attr
;
17653 struct dynamic_prop prop
;
17654 bool length_is_constant
= true;
17657 /* There are a couple of places where bit sizes might be made use of
17658 when parsing a DW_TAG_string_type, however, no producer that we know
17659 of make use of these. Handling bit sizes that are a multiple of the
17660 byte size is easy enough, but what about other bit sizes? Lets deal
17661 with that problem when we have to. Warn about these attributes being
17662 unsupported, then parse the type and ignore them like we always
17664 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17665 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17667 static bool warning_printed
= false;
17668 if (!warning_printed
)
17670 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17671 "currently supported on DW_TAG_string_type."));
17672 warning_printed
= true;
17676 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17677 if (attr
!= nullptr && !attr
->form_is_constant ())
17679 /* The string length describes the location at which the length of
17680 the string can be found. The size of the length field can be
17681 specified with one of the attributes below. */
17682 struct type
*prop_type
;
17683 struct attribute
*len
17684 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17685 if (len
== nullptr)
17686 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17687 if (len
!= nullptr && len
->form_is_constant ())
17689 /* Pass 0 as the default as we know this attribute is constant
17690 and the default value will not be returned. */
17691 LONGEST sz
= len
->constant_value (0);
17692 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17696 /* If the size is not specified then we assume it is the size of
17697 an address on this target. */
17698 prop_type
= cu
->addr_sized_int_type (true);
17701 /* Convert the attribute into a dynamic property. */
17702 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17705 length_is_constant
= false;
17707 else if (attr
!= nullptr)
17709 /* This DW_AT_string_length just contains the length with no
17710 indirection. There's no need to create a dynamic property in this
17711 case. Pass 0 for the default value as we know it will not be
17712 returned in this case. */
17713 length
= attr
->constant_value (0);
17715 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17717 /* We don't currently support non-constant byte sizes for strings. */
17718 length
= attr
->constant_value (1);
17722 /* Use 1 as a fallback length if we have nothing else. */
17726 index_type
= objfile_type (objfile
)->builtin_int
;
17727 if (length_is_constant
)
17728 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17731 struct dynamic_prop low_bound
;
17733 low_bound
.set_const_val (1);
17734 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17736 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17737 type
= create_string_type (NULL
, char_type
, range_type
);
17739 return set_die_type (die
, type
, cu
);
17742 /* Assuming that DIE corresponds to a function, returns nonzero
17743 if the function is prototyped. */
17746 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17748 struct attribute
*attr
;
17750 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17751 if (attr
&& attr
->as_boolean ())
17754 /* The DWARF standard implies that the DW_AT_prototyped attribute
17755 is only meaningful for C, but the concept also extends to other
17756 languages that allow unprototyped functions (Eg: Objective C).
17757 For all other languages, assume that functions are always
17759 if (cu
->language
!= language_c
17760 && cu
->language
!= language_objc
17761 && cu
->language
!= language_opencl
)
17764 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17765 prototyped and unprototyped functions; default to prototyped,
17766 since that is more common in modern code (and RealView warns
17767 about unprototyped functions). */
17768 if (producer_is_realview (cu
->producer
))
17774 /* Handle DIES due to C code like:
17778 int (*funcp)(int a, long l);
17782 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17784 static struct type
*
17785 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17787 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17788 struct type
*type
; /* Type that this function returns. */
17789 struct type
*ftype
; /* Function that returns above type. */
17790 struct attribute
*attr
;
17792 type
= die_type (die
, cu
);
17794 /* The die_type call above may have already set the type for this DIE. */
17795 ftype
= get_die_type (die
, cu
);
17799 ftype
= lookup_function_type (type
);
17801 if (prototyped_function_p (die
, cu
))
17802 ftype
->set_is_prototyped (true);
17804 /* Store the calling convention in the type if it's available in
17805 the subroutine die. Otherwise set the calling convention to
17806 the default value DW_CC_normal. */
17807 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17808 if (attr
!= nullptr
17809 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17810 TYPE_CALLING_CONVENTION (ftype
)
17811 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17812 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17813 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17815 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17817 /* Record whether the function returns normally to its caller or not
17818 if the DWARF producer set that information. */
17819 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17820 if (attr
&& attr
->as_boolean ())
17821 TYPE_NO_RETURN (ftype
) = 1;
17823 /* We need to add the subroutine type to the die immediately so
17824 we don't infinitely recurse when dealing with parameters
17825 declared as the same subroutine type. */
17826 set_die_type (die
, ftype
, cu
);
17828 if (die
->child
!= NULL
)
17830 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17831 struct die_info
*child_die
;
17832 int nparams
, iparams
;
17834 /* Count the number of parameters.
17835 FIXME: GDB currently ignores vararg functions, but knows about
17836 vararg member functions. */
17838 child_die
= die
->child
;
17839 while (child_die
&& child_die
->tag
)
17841 if (child_die
->tag
== DW_TAG_formal_parameter
)
17843 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17844 ftype
->set_has_varargs (true);
17846 child_die
= child_die
->sibling
;
17849 /* Allocate storage for parameters and fill them in. */
17850 ftype
->set_num_fields (nparams
);
17852 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17854 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17855 even if we error out during the parameters reading below. */
17856 for (iparams
= 0; iparams
< nparams
; iparams
++)
17857 ftype
->field (iparams
).set_type (void_type
);
17860 child_die
= die
->child
;
17861 while (child_die
&& child_die
->tag
)
17863 if (child_die
->tag
== DW_TAG_formal_parameter
)
17865 struct type
*arg_type
;
17867 /* DWARF version 2 has no clean way to discern C++
17868 static and non-static member functions. G++ helps
17869 GDB by marking the first parameter for non-static
17870 member functions (which is the this pointer) as
17871 artificial. We pass this information to
17872 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17874 DWARF version 3 added DW_AT_object_pointer, which GCC
17875 4.5 does not yet generate. */
17876 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17877 if (attr
!= nullptr)
17878 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17880 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17881 arg_type
= die_type (child_die
, cu
);
17883 /* RealView does not mark THIS as const, which the testsuite
17884 expects. GCC marks THIS as const in method definitions,
17885 but not in the class specifications (GCC PR 43053). */
17886 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17887 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17890 struct dwarf2_cu
*arg_cu
= cu
;
17891 const char *name
= dwarf2_name (child_die
, cu
);
17893 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17894 if (attr
!= nullptr)
17896 /* If the compiler emits this, use it. */
17897 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17900 else if (name
&& strcmp (name
, "this") == 0)
17901 /* Function definitions will have the argument names. */
17903 else if (name
== NULL
&& iparams
== 0)
17904 /* Declarations may not have the names, so like
17905 elsewhere in GDB, assume an artificial first
17906 argument is "this". */
17910 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17914 ftype
->field (iparams
).set_type (arg_type
);
17917 child_die
= child_die
->sibling
;
17924 static struct type
*
17925 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17927 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17928 const char *name
= NULL
;
17929 struct type
*this_type
, *target_type
;
17931 name
= dwarf2_full_name (NULL
, die
, cu
);
17932 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17933 this_type
->set_target_is_stub (true);
17934 set_die_type (die
, this_type
, cu
);
17935 target_type
= die_type (die
, cu
);
17936 if (target_type
!= this_type
)
17937 TYPE_TARGET_TYPE (this_type
) = target_type
;
17940 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17941 spec and cause infinite loops in GDB. */
17942 complaint (_("Self-referential DW_TAG_typedef "
17943 "- DIE at %s [in module %s]"),
17944 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17945 TYPE_TARGET_TYPE (this_type
) = NULL
;
17949 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17950 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17951 Handle these by just returning the target type, rather than
17952 constructing an anonymous typedef type and trying to handle this
17954 set_die_type (die
, target_type
, cu
);
17955 return target_type
;
17960 /* Helper for get_dwarf2_rational_constant that computes the value of
17961 a given gmp_mpz given an attribute. */
17964 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
17966 /* GCC will sometimes emit a 16-byte constant value as a DWARF
17967 location expression that pushes an implicit value. */
17968 if (attr
->form
== DW_FORM_exprloc
)
17970 dwarf_block
*blk
= attr
->as_block ();
17971 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
17974 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
17975 blk
->data
+ blk
->size
,
17977 if (ptr
- blk
->data
+ len
<= blk
->size
)
17979 mpz_import (value
->val
, len
,
17980 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17986 /* On failure set it to 1. */
17987 *value
= gdb_mpz (1);
17989 else if (attr
->form_is_block ())
17991 dwarf_block
*blk
= attr
->as_block ();
17992 mpz_import (value
->val
, blk
->size
,
17993 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17994 1, 0, 0, blk
->data
);
17997 *value
= gdb_mpz (attr
->constant_value (1));
18000 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
18001 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
18003 If the numerator and/or numerator attribute is missing,
18004 a complaint is filed, and NUMERATOR and DENOMINATOR are left
18008 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
18009 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
18011 struct attribute
*num_attr
, *denom_attr
;
18013 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
18014 if (num_attr
== nullptr)
18015 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
18016 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18018 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
18019 if (denom_attr
== nullptr)
18020 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
18021 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18023 if (num_attr
== nullptr || denom_attr
== nullptr)
18026 get_mpz (cu
, numerator
, num_attr
);
18027 get_mpz (cu
, denominator
, denom_attr
);
18030 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
18031 rational constant, rather than a signed one.
18033 If the rational constant has a negative value, a complaint
18034 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
18037 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
18038 struct dwarf2_cu
*cu
,
18039 gdb_mpz
*numerator
,
18040 gdb_mpz
*denominator
)
18045 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
18046 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
18048 mpz_neg (num
.val
, num
.val
);
18049 mpz_neg (denom
.val
, denom
.val
);
18051 else if (mpz_sgn (num
.val
) == -1)
18053 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
18055 sect_offset_str (die
->sect_off
));
18058 else if (mpz_sgn (denom
.val
) == -1)
18060 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
18062 sect_offset_str (die
->sect_off
));
18066 *numerator
= std::move (num
);
18067 *denominator
= std::move (denom
);
18070 /* Assuming that ENCODING is a string whose contents starting at the
18071 K'th character is "_nn" where "nn" is a decimal number, scan that
18072 number and set RESULT to the value. K is updated to point to the
18073 character immediately following the number.
18075 If the string does not conform to the format described above, false
18076 is returned, and K may or may not be changed. */
18079 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
18081 /* The next character should be an underscore ('_') followed
18083 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
18086 /* Skip the underscore. */
18090 /* Determine the number of digits for our number. */
18091 while (isdigit (encoding
[k
]))
18096 std::string
copy (&encoding
[start
], k
- start
);
18097 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
18103 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
18104 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
18105 DENOM, update OFFSET, and return true on success. Return false on
18109 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
18110 gdb_mpz
*num
, gdb_mpz
*denom
)
18112 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
18114 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
18117 /* Assuming DIE corresponds to a fixed point type, finish the creation
18118 of the corresponding TYPE by setting its type-specific data. CU is
18119 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
18120 encodings. It is nullptr if the GNAT encoding should be
18124 finish_fixed_point_type (struct type
*type
, const char *suffix
,
18125 struct die_info
*die
, struct dwarf2_cu
*cu
)
18127 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
18128 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
18130 /* If GNAT encodings are preferred, don't examine the
18132 struct attribute
*attr
= nullptr;
18133 if (suffix
== nullptr)
18135 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
18136 if (attr
== nullptr)
18137 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
18138 if (attr
== nullptr)
18139 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18142 /* Numerator and denominator of our fixed-point type's scaling factor.
18143 The default is a scaling factor of 1, which we use as a fallback
18144 when we are not able to decode it (problem with the debugging info,
18145 unsupported forms, bug in GDB, etc...). Using that as the default
18146 allows us to at least print the unscaled value, which might still
18147 be useful to a user. */
18148 gdb_mpz
scale_num (1);
18149 gdb_mpz
scale_denom (1);
18151 if (attr
== nullptr)
18154 if (suffix
!= nullptr
18155 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
18157 /* The number might be encoded as _nn_dd_nn_dd, where the
18158 second ratio is the 'small value. In this situation, we
18159 want the second value. */
18160 && (suffix
[offset
] != '_'
18161 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
18168 /* Scaling factor not found. Assume a scaling factor of 1,
18169 and hope for the best. At least the user will be able to
18170 see the encoded value. */
18173 complaint (_("no scale found for fixed-point type (DIE at %s)"),
18174 sect_offset_str (die
->sect_off
));
18177 else if (attr
->name
== DW_AT_binary_scale
)
18179 LONGEST scale_exp
= attr
->constant_value (0);
18180 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18182 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
18184 else if (attr
->name
== DW_AT_decimal_scale
)
18186 LONGEST scale_exp
= attr
->constant_value (0);
18187 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18189 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
18191 else if (attr
->name
== DW_AT_small
)
18193 struct die_info
*scale_die
;
18194 struct dwarf2_cu
*scale_cu
= cu
;
18196 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
18197 if (scale_die
->tag
== DW_TAG_constant
)
18198 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
18199 &scale_num
, &scale_denom
);
18201 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
18203 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18207 complaint (_("unsupported scale attribute %s for fixed-point type"
18209 dwarf_attr_name (attr
->name
),
18210 sect_offset_str (die
->sect_off
));
18213 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
18214 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
18215 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
18216 mpq_canonicalize (scaling_factor
.val
);
18219 /* The gnat-encoding suffix for fixed point. */
18221 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
18223 /* If NAME encodes an Ada fixed-point type, return a pointer to the
18224 "XF" suffix of the name. The text after this is what encodes the
18225 'small and 'delta information. Otherwise, return nullptr. */
18227 static const char *
18228 gnat_encoded_fixed_point_type_info (const char *name
)
18230 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
18233 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
18234 (which may be different from NAME) to the architecture back-end to allow
18235 it to guess the correct format if necessary. */
18237 static struct type
*
18238 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
18239 const char *name_hint
, enum bfd_endian byte_order
)
18241 struct gdbarch
*gdbarch
= objfile
->arch ();
18242 const struct floatformat
**format
;
18245 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
18247 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
18249 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18254 /* Allocate an integer type of size BITS and name NAME. */
18256 static struct type
*
18257 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
18258 int bits
, int unsigned_p
, const char *name
)
18262 /* Versions of Intel's C Compiler generate an integer type called "void"
18263 instead of using DW_TAG_unspecified_type. This has been seen on
18264 at least versions 14, 17, and 18. */
18265 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18266 && strcmp (name
, "void") == 0)
18267 type
= objfile_type (objfile
)->builtin_void
;
18269 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18274 /* Return true if DIE has a DW_AT_small attribute whose value is
18275 a constant rational, where both the numerator and denominator
18278 CU is the DIE's Compilation Unit. */
18281 has_zero_over_zero_small_attribute (struct die_info
*die
,
18282 struct dwarf2_cu
*cu
)
18284 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18285 if (attr
== nullptr)
18288 struct dwarf2_cu
*scale_cu
= cu
;
18289 struct die_info
*scale_die
18290 = follow_die_ref (die
, attr
, &scale_cu
);
18292 if (scale_die
->tag
!= DW_TAG_constant
)
18295 gdb_mpz
num (1), denom (1);
18296 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18297 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
18300 /* Initialise and return a floating point type of size BITS suitable for
18301 use as a component of a complex number. The NAME_HINT is passed through
18302 when initialising the floating point type and is the name of the complex
18305 As DWARF doesn't currently provide an explicit name for the components
18306 of a complex number, but it can be helpful to have these components
18307 named, we try to select a suitable name based on the size of the
18309 static struct type
*
18310 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18311 struct objfile
*objfile
,
18312 int bits
, const char *name_hint
,
18313 enum bfd_endian byte_order
)
18315 gdbarch
*gdbarch
= objfile
->arch ();
18316 struct type
*tt
= nullptr;
18318 /* Try to find a suitable floating point builtin type of size BITS.
18319 We're going to use the name of this type as the name for the complex
18320 target type that we are about to create. */
18321 switch (cu
->language
)
18323 case language_fortran
:
18327 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18330 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18332 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18334 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18342 tt
= builtin_type (gdbarch
)->builtin_float
;
18345 tt
= builtin_type (gdbarch
)->builtin_double
;
18347 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18349 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18355 /* If the type we found doesn't match the size we were looking for, then
18356 pretend we didn't find a type at all, the complex target type we
18357 create will then be nameless. */
18358 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18361 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18362 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18365 /* Find a representation of a given base type and install
18366 it in the TYPE field of the die. */
18368 static struct type
*
18369 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18371 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18373 struct attribute
*attr
;
18374 int encoding
= 0, bits
= 0;
18378 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18379 if (attr
!= nullptr && attr
->form_is_constant ())
18380 encoding
= attr
->constant_value (0);
18381 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18382 if (attr
!= nullptr)
18383 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18384 name
= dwarf2_name (die
, cu
);
18386 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18388 arch
= objfile
->arch ();
18389 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18391 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18392 if (attr
!= nullptr && attr
->form_is_constant ())
18394 int endianity
= attr
->constant_value (0);
18399 byte_order
= BFD_ENDIAN_BIG
;
18401 case DW_END_little
:
18402 byte_order
= BFD_ENDIAN_LITTLE
;
18405 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18410 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18411 && cu
->language
== language_ada
18412 && has_zero_over_zero_small_attribute (die
, cu
))
18414 /* brobecker/2018-02-24: This is a fixed point type for which
18415 the scaling factor is represented as fraction whose value
18416 does not make sense (zero divided by zero), so we should
18417 normally never see these. However, there is a small category
18418 of fixed point types for which GNAT is unable to provide
18419 the scaling factor via the standard DWARF mechanisms, and
18420 for which the info is provided via the GNAT encodings instead.
18421 This is likely what this DIE is about. */
18422 encoding
= (encoding
== DW_ATE_signed_fixed
18424 : DW_ATE_unsigned
);
18427 /* With GNAT encodings, fixed-point information will be encoded in
18428 the type name. Note that this can also occur with the above
18429 zero-over-zero case, which is why this is a separate "if" rather
18430 than an "else if". */
18431 const char *gnat_encoding_suffix
= nullptr;
18432 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18433 && cu
->language
== language_ada
18434 && name
!= nullptr)
18436 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18437 if (gnat_encoding_suffix
!= nullptr)
18439 gdb_assert (startswith (gnat_encoding_suffix
,
18440 GNAT_FIXED_POINT_SUFFIX
));
18441 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18442 name
, gnat_encoding_suffix
- name
);
18443 /* Use -1 here so that SUFFIX points at the "_" after the
18445 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18447 encoding
= (encoding
== DW_ATE_signed
18448 ? DW_ATE_signed_fixed
18449 : DW_ATE_unsigned_fixed
);
18455 case DW_ATE_address
:
18456 /* Turn DW_ATE_address into a void * pointer. */
18457 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18458 type
= init_pointer_type (objfile
, bits
, name
, type
);
18460 case DW_ATE_boolean
:
18461 type
= init_boolean_type (objfile
, bits
, 1, name
);
18463 case DW_ATE_complex_float
:
18464 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18466 if (type
->code () == TYPE_CODE_ERROR
)
18468 if (name
== nullptr)
18470 struct obstack
*obstack
18471 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18472 name
= obconcat (obstack
, "_Complex ", type
->name (),
18475 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18478 type
= init_complex_type (name
, type
);
18480 case DW_ATE_decimal_float
:
18481 type
= init_decfloat_type (objfile
, bits
, name
);
18484 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18486 case DW_ATE_signed
:
18487 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18489 case DW_ATE_unsigned
:
18490 if (cu
->language
== language_fortran
18492 && startswith (name
, "character("))
18493 type
= init_character_type (objfile
, bits
, 1, name
);
18495 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18497 case DW_ATE_signed_char
:
18498 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18499 || cu
->language
== language_pascal
18500 || cu
->language
== language_fortran
)
18501 type
= init_character_type (objfile
, bits
, 0, name
);
18503 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18505 case DW_ATE_unsigned_char
:
18506 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18507 || cu
->language
== language_pascal
18508 || cu
->language
== language_fortran
18509 || cu
->language
== language_rust
)
18510 type
= init_character_type (objfile
, bits
, 1, name
);
18512 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18517 type
= builtin_type (arch
)->builtin_char16
;
18518 else if (bits
== 32)
18519 type
= builtin_type (arch
)->builtin_char32
;
18522 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18524 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18526 return set_die_type (die
, type
, cu
);
18529 case DW_ATE_signed_fixed
:
18530 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18531 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18533 case DW_ATE_unsigned_fixed
:
18534 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18535 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18539 complaint (_("unsupported DW_AT_encoding: '%s'"),
18540 dwarf_type_encoding_name (encoding
));
18541 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18545 if (name
&& strcmp (name
, "char") == 0)
18546 type
->set_has_no_signedness (true);
18548 maybe_set_alignment (cu
, die
, type
);
18550 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18552 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18554 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18555 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18557 unsigned real_bit_size
= attr
->as_unsigned ();
18558 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18559 /* Only use the attributes if they make sense together. */
18560 if (attr
== nullptr
18561 || (attr
->as_unsigned () + real_bit_size
18562 <= 8 * TYPE_LENGTH (type
)))
18564 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18566 if (attr
!= nullptr)
18567 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18568 = attr
->as_unsigned ();
18573 return set_die_type (die
, type
, cu
);
18576 /* Parse dwarf attribute if it's a block, reference or constant and put the
18577 resulting value of the attribute into struct bound_prop.
18578 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18581 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18582 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18583 struct type
*default_type
)
18585 struct dwarf2_property_baton
*baton
;
18586 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18587 struct objfile
*objfile
= per_objfile
->objfile
;
18588 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18590 gdb_assert (default_type
!= NULL
);
18592 if (attr
== NULL
|| prop
== NULL
)
18595 if (attr
->form_is_block ())
18597 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18598 baton
->property_type
= default_type
;
18599 baton
->locexpr
.per_cu
= cu
->per_cu
;
18600 baton
->locexpr
.per_objfile
= per_objfile
;
18602 struct dwarf_block
*block
= attr
->as_block ();
18603 baton
->locexpr
.size
= block
->size
;
18604 baton
->locexpr
.data
= block
->data
;
18605 switch (attr
->name
)
18607 case DW_AT_string_length
:
18608 baton
->locexpr
.is_reference
= true;
18611 baton
->locexpr
.is_reference
= false;
18615 prop
->set_locexpr (baton
);
18616 gdb_assert (prop
->baton () != NULL
);
18618 else if (attr
->form_is_ref ())
18620 struct dwarf2_cu
*target_cu
= cu
;
18621 struct die_info
*target_die
;
18622 struct attribute
*target_attr
;
18624 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18625 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18626 if (target_attr
== NULL
)
18627 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18629 if (target_attr
== NULL
)
18632 switch (target_attr
->name
)
18634 case DW_AT_location
:
18635 if (target_attr
->form_is_section_offset ())
18637 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18638 baton
->property_type
= die_type (target_die
, target_cu
);
18639 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18640 prop
->set_loclist (baton
);
18641 gdb_assert (prop
->baton () != NULL
);
18643 else if (target_attr
->form_is_block ())
18645 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18646 baton
->property_type
= die_type (target_die
, target_cu
);
18647 baton
->locexpr
.per_cu
= cu
->per_cu
;
18648 baton
->locexpr
.per_objfile
= per_objfile
;
18649 struct dwarf_block
*block
= target_attr
->as_block ();
18650 baton
->locexpr
.size
= block
->size
;
18651 baton
->locexpr
.data
= block
->data
;
18652 baton
->locexpr
.is_reference
= true;
18653 prop
->set_locexpr (baton
);
18654 gdb_assert (prop
->baton () != NULL
);
18658 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18659 "dynamic property");
18663 case DW_AT_data_member_location
:
18667 if (!handle_data_member_location (target_die
, target_cu
,
18671 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18672 baton
->property_type
= read_type_die (target_die
->parent
,
18674 baton
->offset_info
.offset
= offset
;
18675 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18676 prop
->set_addr_offset (baton
);
18681 else if (attr
->form_is_constant ())
18682 prop
->set_const_val (attr
->constant_value (0));
18685 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18686 dwarf2_name (die
, cu
));
18696 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18698 struct type
*int_type
;
18700 /* Helper macro to examine the various builtin types. */
18701 #define TRY_TYPE(F) \
18702 int_type = (unsigned_p \
18703 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18704 : objfile_type (objfile)->builtin_ ## F); \
18705 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18712 TRY_TYPE (long_long
);
18716 gdb_assert_not_reached ("unable to find suitable integer type");
18722 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
18724 int addr_size
= this->per_cu
->addr_size ();
18725 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
18728 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18729 present (which is valid) then compute the default type based on the
18730 compilation units address size. */
18732 static struct type
*
18733 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18735 struct type
*index_type
= die_type (die
, cu
);
18737 /* Dwarf-2 specifications explicitly allows to create subrange types
18738 without specifying a base type.
18739 In that case, the base type must be set to the type of
18740 the lower bound, upper bound or count, in that order, if any of these
18741 three attributes references an object that has a type.
18742 If no base type is found, the Dwarf-2 specifications say that
18743 a signed integer type of size equal to the size of an address should
18745 For the following C code: `extern char gdb_int [];'
18746 GCC produces an empty range DIE.
18747 FIXME: muller/2010-05-28: Possible references to object for low bound,
18748 high bound or count are not yet handled by this code. */
18749 if (index_type
->code () == TYPE_CODE_VOID
)
18750 index_type
= cu
->addr_sized_int_type (false);
18755 /* Read the given DW_AT_subrange DIE. */
18757 static struct type
*
18758 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18760 struct type
*base_type
, *orig_base_type
;
18761 struct type
*range_type
;
18762 struct attribute
*attr
;
18763 struct dynamic_prop low
, high
;
18764 int low_default_is_valid
;
18765 int high_bound_is_count
= 0;
18767 ULONGEST negative_mask
;
18769 orig_base_type
= read_subrange_index_type (die
, cu
);
18771 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18772 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18773 creating the range type, but we use the result of check_typedef
18774 when examining properties of the type. */
18775 base_type
= check_typedef (orig_base_type
);
18777 /* The die_type call above may have already set the type for this DIE. */
18778 range_type
= get_die_type (die
, cu
);
18782 high
.set_const_val (0);
18784 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18785 omitting DW_AT_lower_bound. */
18786 switch (cu
->language
)
18789 case language_cplus
:
18790 low
.set_const_val (0);
18791 low_default_is_valid
= 1;
18793 case language_fortran
:
18794 low
.set_const_val (1);
18795 low_default_is_valid
= 1;
18798 case language_objc
:
18799 case language_rust
:
18800 low
.set_const_val (0);
18801 low_default_is_valid
= (cu
->header
.version
>= 4);
18805 case language_pascal
:
18806 low
.set_const_val (1);
18807 low_default_is_valid
= (cu
->header
.version
>= 4);
18810 low
.set_const_val (0);
18811 low_default_is_valid
= 0;
18815 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18816 if (attr
!= nullptr)
18817 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18818 else if (!low_default_is_valid
)
18819 complaint (_("Missing DW_AT_lower_bound "
18820 "- DIE at %s [in module %s]"),
18821 sect_offset_str (die
->sect_off
),
18822 objfile_name (cu
->per_objfile
->objfile
));
18824 struct attribute
*attr_ub
, *attr_count
;
18825 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18826 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18828 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18829 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18831 /* If bounds are constant do the final calculation here. */
18832 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18833 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18835 high_bound_is_count
= 1;
18839 if (attr_ub
!= NULL
)
18840 complaint (_("Unresolved DW_AT_upper_bound "
18841 "- DIE at %s [in module %s]"),
18842 sect_offset_str (die
->sect_off
),
18843 objfile_name (cu
->per_objfile
->objfile
));
18844 if (attr_count
!= NULL
)
18845 complaint (_("Unresolved DW_AT_count "
18846 "- DIE at %s [in module %s]"),
18847 sect_offset_str (die
->sect_off
),
18848 objfile_name (cu
->per_objfile
->objfile
));
18853 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18854 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18855 bias
= bias_attr
->constant_value (0);
18857 /* Normally, the DWARF producers are expected to use a signed
18858 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18859 But this is unfortunately not always the case, as witnessed
18860 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18861 is used instead. To work around that ambiguity, we treat
18862 the bounds as signed, and thus sign-extend their values, when
18863 the base type is signed. */
18865 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18866 if (low
.kind () == PROP_CONST
18867 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18868 low
.set_const_val (low
.const_val () | negative_mask
);
18869 if (high
.kind () == PROP_CONST
18870 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18871 high
.set_const_val (high
.const_val () | negative_mask
);
18873 /* Check for bit and byte strides. */
18874 struct dynamic_prop byte_stride_prop
;
18875 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18876 if (attr_byte_stride
!= nullptr)
18878 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18879 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18883 struct dynamic_prop bit_stride_prop
;
18884 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18885 if (attr_bit_stride
!= nullptr)
18887 /* It only makes sense to have either a bit or byte stride. */
18888 if (attr_byte_stride
!= nullptr)
18890 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18891 "- DIE at %s [in module %s]"),
18892 sect_offset_str (die
->sect_off
),
18893 objfile_name (cu
->per_objfile
->objfile
));
18894 attr_bit_stride
= nullptr;
18898 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18899 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18904 if (attr_byte_stride
!= nullptr
18905 || attr_bit_stride
!= nullptr)
18907 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18908 struct dynamic_prop
*stride
18909 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18912 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18913 &high
, bias
, stride
, byte_stride_p
);
18916 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18918 if (high_bound_is_count
)
18919 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18921 /* Ada expects an empty array on no boundary attributes. */
18922 if (attr
== NULL
&& cu
->language
!= language_ada
)
18923 range_type
->bounds ()->high
.set_undefined ();
18925 name
= dwarf2_name (die
, cu
);
18927 range_type
->set_name (name
);
18929 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18930 if (attr
!= nullptr)
18931 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18933 maybe_set_alignment (cu
, die
, range_type
);
18935 set_die_type (die
, range_type
, cu
);
18937 /* set_die_type should be already done. */
18938 set_descriptive_type (range_type
, die
, cu
);
18943 static struct type
*
18944 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18948 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18949 type
->set_name (dwarf2_name (die
, cu
));
18951 /* In Ada, an unspecified type is typically used when the description
18952 of the type is deferred to a different unit. When encountering
18953 such a type, we treat it as a stub, and try to resolve it later on,
18955 if (cu
->language
== language_ada
)
18956 type
->set_is_stub (true);
18958 return set_die_type (die
, type
, cu
);
18961 /* Read a single die and all its descendents. Set the die's sibling
18962 field to NULL; set other fields in the die correctly, and set all
18963 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18964 location of the info_ptr after reading all of those dies. PARENT
18965 is the parent of the die in question. */
18967 static struct die_info
*
18968 read_die_and_children (const struct die_reader_specs
*reader
,
18969 const gdb_byte
*info_ptr
,
18970 const gdb_byte
**new_info_ptr
,
18971 struct die_info
*parent
)
18973 struct die_info
*die
;
18974 const gdb_byte
*cur_ptr
;
18976 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18979 *new_info_ptr
= cur_ptr
;
18982 store_in_ref_table (die
, reader
->cu
);
18984 if (die
->has_children
)
18985 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18989 *new_info_ptr
= cur_ptr
;
18992 die
->sibling
= NULL
;
18993 die
->parent
= parent
;
18997 /* Read a die, all of its descendents, and all of its siblings; set
18998 all of the fields of all of the dies correctly. Arguments are as
18999 in read_die_and_children. */
19001 static struct die_info
*
19002 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
19003 const gdb_byte
*info_ptr
,
19004 const gdb_byte
**new_info_ptr
,
19005 struct die_info
*parent
)
19007 struct die_info
*first_die
, *last_sibling
;
19008 const gdb_byte
*cur_ptr
;
19010 cur_ptr
= info_ptr
;
19011 first_die
= last_sibling
= NULL
;
19015 struct die_info
*die
19016 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
19020 *new_info_ptr
= cur_ptr
;
19027 last_sibling
->sibling
= die
;
19029 last_sibling
= die
;
19033 /* Read a die, all of its descendents, and all of its siblings; set
19034 all of the fields of all of the dies correctly. Arguments are as
19035 in read_die_and_children.
19036 This the main entry point for reading a DIE and all its children. */
19038 static struct die_info
*
19039 read_die_and_siblings (const struct die_reader_specs
*reader
,
19040 const gdb_byte
*info_ptr
,
19041 const gdb_byte
**new_info_ptr
,
19042 struct die_info
*parent
)
19044 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
19045 new_info_ptr
, parent
);
19047 if (dwarf_die_debug
)
19049 fprintf_unfiltered (gdb_stdlog
,
19050 "Read die from %s@0x%x of %s:\n",
19051 reader
->die_section
->get_name (),
19052 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19053 bfd_get_filename (reader
->abfd
));
19054 dump_die (die
, dwarf_die_debug
);
19060 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
19062 The caller is responsible for filling in the extra attributes
19063 and updating (*DIEP)->num_attrs.
19064 Set DIEP to point to a newly allocated die with its information,
19065 except for its child, sibling, and parent fields. */
19067 static const gdb_byte
*
19068 read_full_die_1 (const struct die_reader_specs
*reader
,
19069 struct die_info
**diep
, const gdb_byte
*info_ptr
,
19070 int num_extra_attrs
)
19072 unsigned int abbrev_number
, bytes_read
, i
;
19073 const struct abbrev_info
*abbrev
;
19074 struct die_info
*die
;
19075 struct dwarf2_cu
*cu
= reader
->cu
;
19076 bfd
*abfd
= reader
->abfd
;
19078 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
19079 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19080 info_ptr
+= bytes_read
;
19081 if (!abbrev_number
)
19087 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
19089 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
19091 bfd_get_filename (abfd
));
19093 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
19094 die
->sect_off
= sect_off
;
19095 die
->tag
= abbrev
->tag
;
19096 die
->abbrev
= abbrev_number
;
19097 die
->has_children
= abbrev
->has_children
;
19099 /* Make the result usable.
19100 The caller needs to update num_attrs after adding the extra
19102 die
->num_attrs
= abbrev
->num_attrs
;
19104 bool any_need_reprocess
= false;
19105 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19107 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
19109 if (die
->attrs
[i
].requires_reprocessing_p ())
19110 any_need_reprocess
= true;
19113 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
19114 if (attr
!= nullptr && attr
->form_is_unsigned ())
19115 cu
->str_offsets_base
= attr
->as_unsigned ();
19117 attr
= die
->attr (DW_AT_loclists_base
);
19118 if (attr
!= nullptr)
19119 cu
->loclist_base
= attr
->as_unsigned ();
19121 auto maybe_addr_base
= die
->addr_base ();
19122 if (maybe_addr_base
.has_value ())
19123 cu
->addr_base
= *maybe_addr_base
;
19125 attr
= die
->attr (DW_AT_rnglists_base
);
19126 if (attr
!= nullptr)
19127 cu
->rnglists_base
= attr
->as_unsigned ();
19129 if (any_need_reprocess
)
19131 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19133 if (die
->attrs
[i
].requires_reprocessing_p ())
19134 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
19141 /* Read a die and all its attributes.
19142 Set DIEP to point to a newly allocated die with its information,
19143 except for its child, sibling, and parent fields. */
19145 static const gdb_byte
*
19146 read_full_die (const struct die_reader_specs
*reader
,
19147 struct die_info
**diep
, const gdb_byte
*info_ptr
)
19149 const gdb_byte
*result
;
19151 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
19153 if (dwarf_die_debug
)
19155 fprintf_unfiltered (gdb_stdlog
,
19156 "Read die from %s@0x%x of %s:\n",
19157 reader
->die_section
->get_name (),
19158 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19159 bfd_get_filename (reader
->abfd
));
19160 dump_die (*diep
, dwarf_die_debug
);
19167 /* Returns nonzero if TAG represents a type that we might generate a partial
19171 is_type_tag_for_partial (int tag
, enum language lang
)
19176 /* Some types that would be reasonable to generate partial symbols for,
19177 that we don't at present. Note that normally this does not
19178 matter, mainly because C compilers don't give names to these
19179 types, but instead emit DW_TAG_typedef. */
19180 case DW_TAG_file_type
:
19181 case DW_TAG_ptr_to_member_type
:
19182 case DW_TAG_set_type
:
19183 case DW_TAG_string_type
:
19184 case DW_TAG_subroutine_type
:
19187 /* GNAT may emit an array with a name, but no typedef, so we
19188 need to make a symbol in this case. */
19189 case DW_TAG_array_type
:
19190 return lang
== language_ada
;
19192 case DW_TAG_base_type
:
19193 case DW_TAG_class_type
:
19194 case DW_TAG_interface_type
:
19195 case DW_TAG_enumeration_type
:
19196 case DW_TAG_structure_type
:
19197 case DW_TAG_subrange_type
:
19198 case DW_TAG_typedef
:
19199 case DW_TAG_union_type
:
19206 /* Load all DIEs that are interesting for partial symbols into memory. */
19208 static struct partial_die_info
*
19209 load_partial_dies (const struct die_reader_specs
*reader
,
19210 const gdb_byte
*info_ptr
, int building_psymtab
)
19212 struct dwarf2_cu
*cu
= reader
->cu
;
19213 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19214 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
19215 unsigned int bytes_read
;
19216 unsigned int load_all
= 0;
19217 int nesting_level
= 1;
19222 gdb_assert (cu
->per_cu
!= NULL
);
19223 if (cu
->per_cu
->load_all_dies
)
19227 = htab_create_alloc_ex (cu
->header
.length
/ 12,
19231 &cu
->comp_unit_obstack
,
19232 hashtab_obstack_allocate
,
19233 dummy_obstack_deallocate
);
19237 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
19240 /* A NULL abbrev means the end of a series of children. */
19241 if (abbrev
== NULL
)
19243 if (--nesting_level
== 0)
19246 info_ptr
+= bytes_read
;
19247 last_die
= parent_die
;
19248 parent_die
= parent_die
->die_parent
;
19252 /* Check for template arguments. We never save these; if
19253 they're seen, we just mark the parent, and go on our way. */
19254 if (parent_die
!= NULL
19255 && cu
->language
== language_cplus
19256 && (abbrev
->tag
== DW_TAG_template_type_param
19257 || abbrev
->tag
== DW_TAG_template_value_param
))
19259 parent_die
->has_template_arguments
= 1;
19263 /* We don't need a partial DIE for the template argument. */
19264 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19269 /* We only recurse into c++ subprograms looking for template arguments.
19270 Skip their other children. */
19272 && cu
->language
== language_cplus
19273 && parent_die
!= NULL
19274 && parent_die
->tag
== DW_TAG_subprogram
19275 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19277 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19281 /* Check whether this DIE is interesting enough to save. Normally
19282 we would not be interested in members here, but there may be
19283 later variables referencing them via DW_AT_specification (for
19284 static members). */
19286 && !is_type_tag_for_partial (abbrev
->tag
, cu
->language
)
19287 && abbrev
->tag
!= DW_TAG_constant
19288 && abbrev
->tag
!= DW_TAG_enumerator
19289 && abbrev
->tag
!= DW_TAG_subprogram
19290 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19291 && abbrev
->tag
!= DW_TAG_lexical_block
19292 && abbrev
->tag
!= DW_TAG_variable
19293 && abbrev
->tag
!= DW_TAG_namespace
19294 && abbrev
->tag
!= DW_TAG_module
19295 && abbrev
->tag
!= DW_TAG_member
19296 && abbrev
->tag
!= DW_TAG_imported_unit
19297 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19299 /* Otherwise we skip to the next sibling, if any. */
19300 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19304 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19307 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19309 /* This two-pass algorithm for processing partial symbols has a
19310 high cost in cache pressure. Thus, handle some simple cases
19311 here which cover the majority of C partial symbols. DIEs
19312 which neither have specification tags in them, nor could have
19313 specification tags elsewhere pointing at them, can simply be
19314 processed and discarded.
19316 This segment is also optional; scan_partial_symbols and
19317 add_partial_symbol will handle these DIEs if we chain
19318 them in normally. When compilers which do not emit large
19319 quantities of duplicate debug information are more common,
19320 this code can probably be removed. */
19322 /* Any complete simple types at the top level (pretty much all
19323 of them, for a language without namespaces), can be processed
19325 if (parent_die
== NULL
19326 && pdi
.has_specification
== 0
19327 && pdi
.is_declaration
== 0
19328 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19329 || pdi
.tag
== DW_TAG_base_type
19330 || pdi
.tag
== DW_TAG_array_type
19331 || pdi
.tag
== DW_TAG_subrange_type
))
19333 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19334 add_partial_symbol (&pdi
, cu
);
19336 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19340 /* The exception for DW_TAG_typedef with has_children above is
19341 a workaround of GCC PR debug/47510. In the case of this complaint
19342 type_name_or_error will error on such types later.
19344 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19345 it could not find the child DIEs referenced later, this is checked
19346 above. In correct DWARF DW_TAG_typedef should have no children. */
19348 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19349 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19350 "- DIE at %s [in module %s]"),
19351 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19353 /* If we're at the second level, and we're an enumerator, and
19354 our parent has no specification (meaning possibly lives in a
19355 namespace elsewhere), then we can add the partial symbol now
19356 instead of queueing it. */
19357 if (pdi
.tag
== DW_TAG_enumerator
19358 && parent_die
!= NULL
19359 && parent_die
->die_parent
== NULL
19360 && parent_die
->tag
== DW_TAG_enumeration_type
19361 && parent_die
->has_specification
== 0)
19363 if (pdi
.raw_name
== NULL
)
19364 complaint (_("malformed enumerator DIE ignored"));
19365 else if (building_psymtab
)
19366 add_partial_symbol (&pdi
, cu
);
19368 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19372 struct partial_die_info
*part_die
19373 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19375 /* We'll save this DIE so link it in. */
19376 part_die
->die_parent
= parent_die
;
19377 part_die
->die_sibling
= NULL
;
19378 part_die
->die_child
= NULL
;
19380 if (last_die
&& last_die
== parent_die
)
19381 last_die
->die_child
= part_die
;
19383 last_die
->die_sibling
= part_die
;
19385 last_die
= part_die
;
19387 if (first_die
== NULL
)
19388 first_die
= part_die
;
19390 /* Maybe add the DIE to the hash table. Not all DIEs that we
19391 find interesting need to be in the hash table, because we
19392 also have the parent/sibling/child chains; only those that we
19393 might refer to by offset later during partial symbol reading.
19395 For now this means things that might have be the target of a
19396 DW_AT_specification, DW_AT_abstract_origin, or
19397 DW_AT_extension. DW_AT_extension will refer only to
19398 namespaces; DW_AT_abstract_origin refers to functions (and
19399 many things under the function DIE, but we do not recurse
19400 into function DIEs during partial symbol reading) and
19401 possibly variables as well; DW_AT_specification refers to
19402 declarations. Declarations ought to have the DW_AT_declaration
19403 flag. It happens that GCC forgets to put it in sometimes, but
19404 only for functions, not for types.
19406 Adding more things than necessary to the hash table is harmless
19407 except for the performance cost. Adding too few will result in
19408 wasted time in find_partial_die, when we reread the compilation
19409 unit with load_all_dies set. */
19412 || abbrev
->tag
== DW_TAG_constant
19413 || abbrev
->tag
== DW_TAG_subprogram
19414 || abbrev
->tag
== DW_TAG_variable
19415 || abbrev
->tag
== DW_TAG_namespace
19416 || part_die
->is_declaration
)
19420 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19421 to_underlying (part_die
->sect_off
),
19426 /* For some DIEs we want to follow their children (if any). For C
19427 we have no reason to follow the children of structures; for other
19428 languages we have to, so that we can get at method physnames
19429 to infer fully qualified class names, for DW_AT_specification,
19430 and for C++ template arguments. For C++, we also look one level
19431 inside functions to find template arguments (if the name of the
19432 function does not already contain the template arguments).
19434 For Ada and Fortran, we need to scan the children of subprograms
19435 and lexical blocks as well because these languages allow the
19436 definition of nested entities that could be interesting for the
19437 debugger, such as nested subprograms for instance. */
19438 if (last_die
->has_children
19440 || last_die
->tag
== DW_TAG_namespace
19441 || last_die
->tag
== DW_TAG_module
19442 || last_die
->tag
== DW_TAG_enumeration_type
19443 || (cu
->language
== language_cplus
19444 && last_die
->tag
== DW_TAG_subprogram
19445 && (last_die
->raw_name
== NULL
19446 || strchr (last_die
->raw_name
, '<') == NULL
))
19447 || (cu
->language
!= language_c
19448 && (last_die
->tag
== DW_TAG_class_type
19449 || last_die
->tag
== DW_TAG_interface_type
19450 || last_die
->tag
== DW_TAG_structure_type
19451 || last_die
->tag
== DW_TAG_union_type
))
19452 || ((cu
->language
== language_ada
19453 || cu
->language
== language_fortran
)
19454 && (last_die
->tag
== DW_TAG_subprogram
19455 || last_die
->tag
== DW_TAG_lexical_block
))))
19458 parent_die
= last_die
;
19462 /* Otherwise we skip to the next sibling, if any. */
19463 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19465 /* Back to the top, do it again. */
19469 partial_die_info::partial_die_info (sect_offset sect_off_
,
19470 const struct abbrev_info
*abbrev
)
19471 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19475 /* See class definition. */
19478 partial_die_info::name (dwarf2_cu
*cu
)
19480 if (!canonical_name
&& raw_name
!= nullptr)
19482 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19483 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19484 canonical_name
= 1;
19490 /* Read a minimal amount of information into the minimal die structure.
19491 INFO_PTR should point just after the initial uleb128 of a DIE. */
19494 partial_die_info::read (const struct die_reader_specs
*reader
,
19495 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19497 struct dwarf2_cu
*cu
= reader
->cu
;
19498 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19500 int has_low_pc_attr
= 0;
19501 int has_high_pc_attr
= 0;
19502 int high_pc_relative
= 0;
19504 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19507 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19508 /* String and address offsets that need to do the reprocessing have
19509 already been read at this point, so there is no need to wait until
19510 the loop terminates to do the reprocessing. */
19511 if (attr
.requires_reprocessing_p ())
19512 read_attribute_reprocess (reader
, &attr
, tag
);
19513 /* Store the data if it is of an attribute we want to keep in a
19514 partial symbol table. */
19520 case DW_TAG_compile_unit
:
19521 case DW_TAG_partial_unit
:
19522 case DW_TAG_type_unit
:
19523 /* Compilation units have a DW_AT_name that is a filename, not
19524 a source language identifier. */
19525 case DW_TAG_enumeration_type
:
19526 case DW_TAG_enumerator
:
19527 /* These tags always have simple identifiers already; no need
19528 to canonicalize them. */
19529 canonical_name
= 1;
19530 raw_name
= attr
.as_string ();
19533 canonical_name
= 0;
19534 raw_name
= attr
.as_string ();
19538 case DW_AT_linkage_name
:
19539 case DW_AT_MIPS_linkage_name
:
19540 /* Note that both forms of linkage name might appear. We
19541 assume they will be the same, and we only store the last
19543 linkage_name
= attr
.as_string ();
19546 has_low_pc_attr
= 1;
19547 lowpc
= attr
.as_address ();
19549 case DW_AT_high_pc
:
19550 has_high_pc_attr
= 1;
19551 highpc
= attr
.as_address ();
19552 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19553 high_pc_relative
= 1;
19555 case DW_AT_location
:
19556 /* Support the .debug_loc offsets. */
19557 if (attr
.form_is_block ())
19559 d
.locdesc
= attr
.as_block ();
19561 else if (attr
.form_is_section_offset ())
19563 dwarf2_complex_location_expr_complaint ();
19567 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19568 "partial symbol information");
19571 case DW_AT_external
:
19572 is_external
= attr
.as_boolean ();
19574 case DW_AT_declaration
:
19575 is_declaration
= attr
.as_boolean ();
19580 case DW_AT_abstract_origin
:
19581 case DW_AT_specification
:
19582 case DW_AT_extension
:
19583 has_specification
= 1;
19584 spec_offset
= attr
.get_ref_die_offset ();
19585 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19586 || cu
->per_cu
->is_dwz
);
19588 case DW_AT_sibling
:
19589 /* Ignore absolute siblings, they might point outside of
19590 the current compile unit. */
19591 if (attr
.form
== DW_FORM_ref_addr
)
19592 complaint (_("ignoring absolute DW_AT_sibling"));
19595 const gdb_byte
*buffer
= reader
->buffer
;
19596 sect_offset off
= attr
.get_ref_die_offset ();
19597 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19599 if (sibling_ptr
< info_ptr
)
19600 complaint (_("DW_AT_sibling points backwards"));
19601 else if (sibling_ptr
> reader
->buffer_end
)
19602 reader
->die_section
->overflow_complaint ();
19604 sibling
= sibling_ptr
;
19607 case DW_AT_byte_size
:
19610 case DW_AT_const_value
:
19611 has_const_value
= 1;
19613 case DW_AT_calling_convention
:
19614 /* DWARF doesn't provide a way to identify a program's source-level
19615 entry point. DW_AT_calling_convention attributes are only meant
19616 to describe functions' calling conventions.
19618 However, because it's a necessary piece of information in
19619 Fortran, and before DWARF 4 DW_CC_program was the only
19620 piece of debugging information whose definition refers to
19621 a 'main program' at all, several compilers marked Fortran
19622 main programs with DW_CC_program --- even when those
19623 functions use the standard calling conventions.
19625 Although DWARF now specifies a way to provide this
19626 information, we support this practice for backward
19628 if (attr
.constant_value (0) == DW_CC_program
19629 && cu
->language
== language_fortran
)
19630 main_subprogram
= 1;
19634 LONGEST value
= attr
.constant_value (-1);
19635 if (value
== DW_INL_inlined
19636 || value
== DW_INL_declared_inlined
)
19637 may_be_inlined
= 1;
19642 if (tag
== DW_TAG_imported_unit
)
19644 d
.sect_off
= attr
.get_ref_die_offset ();
19645 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19646 || cu
->per_cu
->is_dwz
);
19650 case DW_AT_main_subprogram
:
19651 main_subprogram
= attr
.as_boolean ();
19656 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19657 on DWARF version). */
19658 ULONGEST ranges_offset
= attr
.as_unsigned ();
19660 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19662 if (tag
!= DW_TAG_compile_unit
)
19663 ranges_offset
+= cu
->gnu_ranges_base
;
19665 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19676 /* For Ada, if both the name and the linkage name appear, we prefer
19677 the latter. This lets "catch exception" work better, regardless
19678 of the order in which the name and linkage name were emitted.
19679 Really, though, this is just a workaround for the fact that gdb
19680 doesn't store both the name and the linkage name. */
19681 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19682 raw_name
= linkage_name
;
19684 if (high_pc_relative
)
19687 if (has_low_pc_attr
&& has_high_pc_attr
)
19689 /* When using the GNU linker, .gnu.linkonce. sections are used to
19690 eliminate duplicate copies of functions and vtables and such.
19691 The linker will arbitrarily choose one and discard the others.
19692 The AT_*_pc values for such functions refer to local labels in
19693 these sections. If the section from that file was discarded, the
19694 labels are not in the output, so the relocs get a value of 0.
19695 If this is a discarded function, mark the pc bounds as invalid,
19696 so that GDB will ignore it. */
19697 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19699 struct objfile
*objfile
= per_objfile
->objfile
;
19700 struct gdbarch
*gdbarch
= objfile
->arch ();
19702 complaint (_("DW_AT_low_pc %s is zero "
19703 "for DIE at %s [in module %s]"),
19704 paddress (gdbarch
, lowpc
),
19705 sect_offset_str (sect_off
),
19706 objfile_name (objfile
));
19708 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19709 else if (lowpc
>= highpc
)
19711 struct objfile
*objfile
= per_objfile
->objfile
;
19712 struct gdbarch
*gdbarch
= objfile
->arch ();
19714 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19715 "for DIE at %s [in module %s]"),
19716 paddress (gdbarch
, lowpc
),
19717 paddress (gdbarch
, highpc
),
19718 sect_offset_str (sect_off
),
19719 objfile_name (objfile
));
19728 /* Find a cached partial DIE at OFFSET in CU. */
19730 struct partial_die_info
*
19731 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19733 struct partial_die_info
*lookup_die
= NULL
;
19734 struct partial_die_info
part_die (sect_off
);
19736 lookup_die
= ((struct partial_die_info
*)
19737 htab_find_with_hash (partial_dies
, &part_die
,
19738 to_underlying (sect_off
)));
19743 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19744 except in the case of .debug_types DIEs which do not reference
19745 outside their CU (they do however referencing other types via
19746 DW_FORM_ref_sig8). */
19748 static const struct cu_partial_die_info
19749 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19751 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19752 struct objfile
*objfile
= per_objfile
->objfile
;
19753 struct partial_die_info
*pd
= NULL
;
19755 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19756 && cu
->header
.offset_in_cu_p (sect_off
))
19758 pd
= cu
->find_partial_die (sect_off
);
19761 /* We missed recording what we needed.
19762 Load all dies and try again. */
19766 /* TUs don't reference other CUs/TUs (except via type signatures). */
19767 if (cu
->per_cu
->is_debug_types
)
19769 error (_("Dwarf Error: Type Unit at offset %s contains"
19770 " external reference to offset %s [in module %s].\n"),
19771 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19772 bfd_get_filename (objfile
->obfd
));
19774 dwarf2_per_cu_data
*per_cu
19775 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19778 cu
= per_objfile
->get_cu (per_cu
);
19779 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19780 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19782 cu
= per_objfile
->get_cu (per_cu
);
19785 pd
= cu
->find_partial_die (sect_off
);
19788 /* If we didn't find it, and not all dies have been loaded,
19789 load them all and try again. */
19791 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
19793 cu
->per_cu
->load_all_dies
= 1;
19795 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19796 THIS_CU->cu may already be in use. So we can't just free it and
19797 replace its DIEs with the ones we read in. Instead, we leave those
19798 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19799 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19801 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19803 pd
= cu
->find_partial_die (sect_off
);
19807 error (_("Dwarf Error: Cannot not find DIE at %s [from module %s]\n"),
19808 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19812 /* See if we can figure out if the class lives in a namespace. We do
19813 this by looking for a member function; its demangled name will
19814 contain namespace info, if there is any. */
19817 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19818 struct dwarf2_cu
*cu
)
19820 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19821 what template types look like, because the demangler
19822 frequently doesn't give the same name as the debug info. We
19823 could fix this by only using the demangled name to get the
19824 prefix (but see comment in read_structure_type). */
19826 struct partial_die_info
*real_pdi
;
19827 struct partial_die_info
*child_pdi
;
19829 /* If this DIE (this DIE's specification, if any) has a parent, then
19830 we should not do this. We'll prepend the parent's fully qualified
19831 name when we create the partial symbol. */
19833 real_pdi
= struct_pdi
;
19834 while (real_pdi
->has_specification
)
19836 auto res
= find_partial_die (real_pdi
->spec_offset
,
19837 real_pdi
->spec_is_dwz
, cu
);
19838 real_pdi
= res
.pdi
;
19842 if (real_pdi
->die_parent
!= NULL
)
19845 for (child_pdi
= struct_pdi
->die_child
;
19847 child_pdi
= child_pdi
->die_sibling
)
19849 if (child_pdi
->tag
== DW_TAG_subprogram
19850 && child_pdi
->linkage_name
!= NULL
)
19852 gdb::unique_xmalloc_ptr
<char> actual_class_name
19853 (cu
->language_defn
->class_name_from_physname
19854 (child_pdi
->linkage_name
));
19855 if (actual_class_name
!= NULL
)
19857 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19858 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19859 struct_pdi
->canonical_name
= 1;
19866 /* Return true if a DIE with TAG may have the DW_AT_const_value
19870 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19874 case DW_TAG_constant
:
19875 case DW_TAG_enumerator
:
19876 case DW_TAG_formal_parameter
:
19877 case DW_TAG_template_value_param
:
19878 case DW_TAG_variable
:
19886 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19888 /* Once we've fixed up a die, there's no point in doing so again.
19889 This also avoids a memory leak if we were to call
19890 guess_partial_die_structure_name multiple times. */
19894 /* If we found a reference attribute and the DIE has no name, try
19895 to find a name in the referred to DIE. */
19897 if (raw_name
== NULL
&& has_specification
)
19899 struct partial_die_info
*spec_die
;
19901 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19902 spec_die
= res
.pdi
;
19905 spec_die
->fixup (cu
);
19907 if (spec_die
->raw_name
)
19909 raw_name
= spec_die
->raw_name
;
19910 canonical_name
= spec_die
->canonical_name
;
19912 /* Copy DW_AT_external attribute if it is set. */
19913 if (spec_die
->is_external
)
19914 is_external
= spec_die
->is_external
;
19918 if (!has_const_value
&& has_specification
19919 && can_have_DW_AT_const_value_p (tag
))
19921 struct partial_die_info
*spec_die
;
19923 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19924 spec_die
= res
.pdi
;
19927 spec_die
->fixup (cu
);
19929 if (spec_die
->has_const_value
)
19931 /* Copy DW_AT_const_value attribute if it is set. */
19932 has_const_value
= spec_die
->has_const_value
;
19936 /* Set default names for some unnamed DIEs. */
19938 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19940 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19941 canonical_name
= 1;
19944 /* If there is no parent die to provide a namespace, and there are
19945 children, see if we can determine the namespace from their linkage
19947 if (cu
->language
== language_cplus
19948 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19949 && die_parent
== NULL
19951 && (tag
== DW_TAG_class_type
19952 || tag
== DW_TAG_structure_type
19953 || tag
== DW_TAG_union_type
))
19954 guess_partial_die_structure_name (this, cu
);
19956 /* GCC might emit a nameless struct or union that has a linkage
19957 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19958 if (raw_name
== NULL
19959 && (tag
== DW_TAG_class_type
19960 || tag
== DW_TAG_interface_type
19961 || tag
== DW_TAG_structure_type
19962 || tag
== DW_TAG_union_type
)
19963 && linkage_name
!= NULL
)
19965 gdb::unique_xmalloc_ptr
<char> demangled
19966 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19967 if (demangled
!= nullptr)
19971 /* Strip any leading namespaces/classes, keep only the base name.
19972 DW_AT_name for named DIEs does not contain the prefixes. */
19973 base
= strrchr (demangled
.get (), ':');
19974 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19977 base
= demangled
.get ();
19979 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19980 raw_name
= objfile
->intern (base
);
19981 canonical_name
= 1;
19988 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19989 contents from the given SECTION in the HEADER.
19991 HEADER_OFFSET is the offset of the header in the section. */
19993 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19994 struct dwarf2_section_info
*section
,
19995 sect_offset header_offset
)
19997 unsigned int bytes_read
;
19998 bfd
*abfd
= section
->get_bfd_owner ();
19999 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
20001 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
20002 info_ptr
+= bytes_read
;
20004 header
->version
= read_2_bytes (abfd
, info_ptr
);
20007 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
20010 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
20013 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
20016 /* Return the DW_AT_loclists_base value for the CU. */
20018 lookup_loclist_base (struct dwarf2_cu
*cu
)
20020 /* For the .dwo unit, the loclist_base points to the first offset following
20021 the header. The header consists of the following entities-
20022 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
20024 2. version (2 bytes)
20025 3. address size (1 byte)
20026 4. segment selector size (1 byte)
20027 5. offset entry count (4 bytes)
20028 These sizes are derived as per the DWARFv5 standard. */
20029 if (cu
->dwo_unit
!= nullptr)
20031 if (cu
->header
.initial_length_size
== 4)
20032 return LOCLIST_HEADER_SIZE32
;
20033 return LOCLIST_HEADER_SIZE64
;
20035 return cu
->loclist_base
;
20038 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
20039 array of offsets in the .debug_loclists section. */
20042 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
20044 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20045 struct objfile
*objfile
= per_objfile
->objfile
;
20046 bfd
*abfd
= objfile
->obfd
;
20047 ULONGEST loclist_header_size
=
20048 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
20049 : LOCLIST_HEADER_SIZE64
);
20050 ULONGEST loclist_base
= lookup_loclist_base (cu
);
20052 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
20053 ULONGEST start_offset
=
20054 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
20056 /* Get loclists section. */
20057 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
20059 /* Read the loclists section content. */
20060 section
->read (objfile
);
20061 if (section
->buffer
== NULL
)
20062 error (_("DW_FORM_loclistx used without .debug_loclists "
20063 "section [in module %s]"), objfile_name (objfile
));
20065 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
20066 so if loclist_base is smaller than the header size, we have a problem. */
20067 if (loclist_base
< loclist_header_size
)
20068 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
20069 objfile_name (objfile
));
20071 /* Read the header of the loclists contribution. */
20072 struct loclists_rnglists_header header
;
20073 read_loclists_rnglists_header (&header
, section
,
20074 (sect_offset
) (loclist_base
- loclist_header_size
));
20076 /* Verify the loclist index is valid. */
20077 if (loclist_index
>= header
.offset_entry_count
)
20078 error (_("DW_FORM_loclistx pointing outside of "
20079 ".debug_loclists offset array [in module %s]"),
20080 objfile_name (objfile
));
20082 /* Validate that reading won't go beyond the end of the section. */
20083 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
20084 error (_("Reading DW_FORM_loclistx index beyond end of"
20085 ".debug_loclists section [in module %s]"),
20086 objfile_name (objfile
));
20088 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20090 if (cu
->header
.offset_size
== 4)
20091 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
20093 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
20096 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
20097 array of offsets in the .debug_rnglists section. */
20100 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
20103 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
20104 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20105 bfd
*abfd
= objfile
->obfd
;
20106 ULONGEST rnglist_header_size
=
20107 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
20108 : RNGLIST_HEADER_SIZE64
);
20110 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
20111 .debug_rnglists.dwo section. The rnglists base given in the skeleton
20113 ULONGEST rnglist_base
=
20114 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
20116 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
20117 ULONGEST start_offset
=
20118 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
20120 /* Get rnglists section. */
20121 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
20123 /* Read the rnglists section content. */
20124 section
->read (objfile
);
20125 if (section
->buffer
== nullptr)
20126 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
20128 objfile_name (objfile
));
20130 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
20131 so if rnglist_base is smaller than the header size, we have a problem. */
20132 if (rnglist_base
< rnglist_header_size
)
20133 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
20134 objfile_name (objfile
));
20136 /* Read the header of the rnglists contribution. */
20137 struct loclists_rnglists_header header
;
20138 read_loclists_rnglists_header (&header
, section
,
20139 (sect_offset
) (rnglist_base
- rnglist_header_size
));
20141 /* Verify the rnglist index is valid. */
20142 if (rnglist_index
>= header
.offset_entry_count
)
20143 error (_("DW_FORM_rnglistx index pointing outside of "
20144 ".debug_rnglists offset array [in module %s]"),
20145 objfile_name (objfile
));
20147 /* Validate that reading won't go beyond the end of the section. */
20148 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
20149 error (_("Reading DW_FORM_rnglistx index beyond end of"
20150 ".debug_rnglists section [in module %s]"),
20151 objfile_name (objfile
));
20153 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20155 if (cu
->header
.offset_size
== 4)
20156 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
20158 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
20161 /* Process the attributes that had to be skipped in the first round. These
20162 attributes are the ones that need str_offsets_base or addr_base attributes.
20163 They could not have been processed in the first round, because at the time
20164 the values of str_offsets_base or addr_base may not have been known. */
20166 read_attribute_reprocess (const struct die_reader_specs
*reader
,
20167 struct attribute
*attr
, dwarf_tag tag
)
20169 struct dwarf2_cu
*cu
= reader
->cu
;
20170 switch (attr
->form
)
20172 case DW_FORM_addrx
:
20173 case DW_FORM_GNU_addr_index
:
20174 attr
->set_address (read_addr_index (cu
,
20175 attr
->as_unsigned_reprocess ()));
20177 case DW_FORM_loclistx
:
20179 sect_offset loclists_sect_off
20180 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
20182 attr
->set_unsigned (to_underlying (loclists_sect_off
));
20185 case DW_FORM_rnglistx
:
20187 sect_offset rnglists_sect_off
20188 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
20190 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
20194 case DW_FORM_strx1
:
20195 case DW_FORM_strx2
:
20196 case DW_FORM_strx3
:
20197 case DW_FORM_strx4
:
20198 case DW_FORM_GNU_str_index
:
20200 unsigned int str_index
= attr
->as_unsigned_reprocess ();
20201 gdb_assert (!attr
->canonical_string_p ());
20202 if (reader
->dwo_file
!= NULL
)
20203 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
20206 attr
->set_string_noncanonical (read_stub_str_index (cu
,
20211 gdb_assert_not_reached (_("Unexpected DWARF form."));
20215 /* Read an attribute value described by an attribute form. */
20217 static const gdb_byte
*
20218 read_attribute_value (const struct die_reader_specs
*reader
,
20219 struct attribute
*attr
, unsigned form
,
20220 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
20222 struct dwarf2_cu
*cu
= reader
->cu
;
20223 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20224 struct objfile
*objfile
= per_objfile
->objfile
;
20225 bfd
*abfd
= reader
->abfd
;
20226 struct comp_unit_head
*cu_header
= &cu
->header
;
20227 unsigned int bytes_read
;
20228 struct dwarf_block
*blk
;
20230 attr
->form
= (enum dwarf_form
) form
;
20233 case DW_FORM_ref_addr
:
20234 if (cu_header
->version
== 2)
20235 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
20238 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20240 info_ptr
+= bytes_read
;
20242 case DW_FORM_GNU_ref_alt
:
20243 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20245 info_ptr
+= bytes_read
;
20249 struct gdbarch
*gdbarch
= objfile
->arch ();
20250 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
20251 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
20252 attr
->set_address (addr
);
20253 info_ptr
+= bytes_read
;
20256 case DW_FORM_block2
:
20257 blk
= dwarf_alloc_block (cu
);
20258 blk
->size
= read_2_bytes (abfd
, info_ptr
);
20260 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20261 info_ptr
+= blk
->size
;
20262 attr
->set_block (blk
);
20264 case DW_FORM_block4
:
20265 blk
= dwarf_alloc_block (cu
);
20266 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20268 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20269 info_ptr
+= blk
->size
;
20270 attr
->set_block (blk
);
20272 case DW_FORM_data2
:
20273 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20276 case DW_FORM_data4
:
20277 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20280 case DW_FORM_data8
:
20281 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20284 case DW_FORM_data16
:
20285 blk
= dwarf_alloc_block (cu
);
20287 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20289 attr
->set_block (blk
);
20291 case DW_FORM_sec_offset
:
20292 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20294 info_ptr
+= bytes_read
;
20296 case DW_FORM_loclistx
:
20298 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20300 info_ptr
+= bytes_read
;
20303 case DW_FORM_string
:
20304 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20306 info_ptr
+= bytes_read
;
20309 if (!cu
->per_cu
->is_dwz
)
20311 attr
->set_string_noncanonical
20312 (read_indirect_string (per_objfile
,
20313 abfd
, info_ptr
, cu_header
,
20315 info_ptr
+= bytes_read
;
20319 case DW_FORM_line_strp
:
20320 if (!cu
->per_cu
->is_dwz
)
20322 attr
->set_string_noncanonical
20323 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20325 info_ptr
+= bytes_read
;
20329 case DW_FORM_GNU_strp_alt
:
20331 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20332 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20335 attr
->set_string_noncanonical
20336 (dwz
->read_string (objfile
, str_offset
));
20337 info_ptr
+= bytes_read
;
20340 case DW_FORM_exprloc
:
20341 case DW_FORM_block
:
20342 blk
= dwarf_alloc_block (cu
);
20343 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20344 info_ptr
+= bytes_read
;
20345 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20346 info_ptr
+= blk
->size
;
20347 attr
->set_block (blk
);
20349 case DW_FORM_block1
:
20350 blk
= dwarf_alloc_block (cu
);
20351 blk
->size
= read_1_byte (abfd
, info_ptr
);
20353 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20354 info_ptr
+= blk
->size
;
20355 attr
->set_block (blk
);
20357 case DW_FORM_data1
:
20359 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20362 case DW_FORM_flag_present
:
20363 attr
->set_unsigned (1);
20365 case DW_FORM_sdata
:
20366 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20367 info_ptr
+= bytes_read
;
20369 case DW_FORM_rnglistx
:
20371 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20373 info_ptr
+= bytes_read
;
20376 case DW_FORM_udata
:
20377 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20378 info_ptr
+= bytes_read
;
20381 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20382 + read_1_byte (abfd
, info_ptr
)));
20386 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20387 + read_2_bytes (abfd
, info_ptr
)));
20391 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20392 + read_4_bytes (abfd
, info_ptr
)));
20396 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20397 + read_8_bytes (abfd
, info_ptr
)));
20400 case DW_FORM_ref_sig8
:
20401 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20404 case DW_FORM_ref_udata
:
20405 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20406 + read_unsigned_leb128 (abfd
, info_ptr
,
20408 info_ptr
+= bytes_read
;
20410 case DW_FORM_indirect
:
20411 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20412 info_ptr
+= bytes_read
;
20413 if (form
== DW_FORM_implicit_const
)
20415 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20416 info_ptr
+= bytes_read
;
20418 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20421 case DW_FORM_implicit_const
:
20422 attr
->set_signed (implicit_const
);
20424 case DW_FORM_addrx
:
20425 case DW_FORM_GNU_addr_index
:
20426 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20428 info_ptr
+= bytes_read
;
20431 case DW_FORM_strx1
:
20432 case DW_FORM_strx2
:
20433 case DW_FORM_strx3
:
20434 case DW_FORM_strx4
:
20435 case DW_FORM_GNU_str_index
:
20437 ULONGEST str_index
;
20438 if (form
== DW_FORM_strx1
)
20440 str_index
= read_1_byte (abfd
, info_ptr
);
20443 else if (form
== DW_FORM_strx2
)
20445 str_index
= read_2_bytes (abfd
, info_ptr
);
20448 else if (form
== DW_FORM_strx3
)
20450 str_index
= read_3_bytes (abfd
, info_ptr
);
20453 else if (form
== DW_FORM_strx4
)
20455 str_index
= read_4_bytes (abfd
, info_ptr
);
20460 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20461 info_ptr
+= bytes_read
;
20463 attr
->set_unsigned_reprocess (str_index
);
20467 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20468 dwarf_form_name (form
),
20469 bfd_get_filename (abfd
));
20473 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20474 attr
->form
= DW_FORM_GNU_ref_alt
;
20476 /* We have seen instances where the compiler tried to emit a byte
20477 size attribute of -1 which ended up being encoded as an unsigned
20478 0xffffffff. Although 0xffffffff is technically a valid size value,
20479 an object of this size seems pretty unlikely so we can relatively
20480 safely treat these cases as if the size attribute was invalid and
20481 treat them as zero by default. */
20482 if (attr
->name
== DW_AT_byte_size
20483 && form
== DW_FORM_data4
20484 && attr
->as_unsigned () >= 0xffffffff)
20487 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20488 hex_string (attr
->as_unsigned ()));
20489 attr
->set_unsigned (0);
20495 /* Read an attribute described by an abbreviated attribute. */
20497 static const gdb_byte
*
20498 read_attribute (const struct die_reader_specs
*reader
,
20499 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20500 const gdb_byte
*info_ptr
)
20502 attr
->name
= abbrev
->name
;
20503 attr
->string_is_canonical
= 0;
20504 attr
->requires_reprocessing
= 0;
20505 return read_attribute_value (reader
, attr
, abbrev
->form
,
20506 abbrev
->implicit_const
, info_ptr
);
20509 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20511 static const char *
20512 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20513 LONGEST str_offset
)
20515 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20516 str_offset
, "DW_FORM_strp");
20519 /* Return pointer to string at .debug_str offset as read from BUF.
20520 BUF is assumed to be in a compilation unit described by CU_HEADER.
20521 Return *BYTES_READ_PTR count of bytes read from BUF. */
20523 static const char *
20524 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20525 const gdb_byte
*buf
,
20526 const struct comp_unit_head
*cu_header
,
20527 unsigned int *bytes_read_ptr
)
20529 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20531 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20537 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20538 const struct comp_unit_head
*cu_header
,
20539 unsigned int *bytes_read_ptr
)
20541 bfd
*abfd
= objfile
->obfd
;
20542 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20544 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20547 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20548 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20549 ADDR_SIZE is the size of addresses from the CU header. */
20552 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20553 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20555 struct objfile
*objfile
= per_objfile
->objfile
;
20556 bfd
*abfd
= objfile
->obfd
;
20557 const gdb_byte
*info_ptr
;
20558 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20560 per_objfile
->per_bfd
->addr
.read (objfile
);
20561 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20562 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20563 objfile_name (objfile
));
20564 if (addr_base_or_zero
+ addr_index
* addr_size
20565 >= per_objfile
->per_bfd
->addr
.size
)
20566 error (_("DW_FORM_addr_index pointing outside of "
20567 ".debug_addr section [in module %s]"),
20568 objfile_name (objfile
));
20569 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20570 + addr_index
* addr_size
);
20571 if (addr_size
== 4)
20572 return bfd_get_32 (abfd
, info_ptr
);
20574 return bfd_get_64 (abfd
, info_ptr
);
20577 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20580 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20582 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20583 cu
->addr_base
, cu
->header
.addr_size
);
20586 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20589 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20590 unsigned int *bytes_read
)
20592 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20593 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20595 return read_addr_index (cu
, addr_index
);
20601 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20602 dwarf2_per_objfile
*per_objfile
,
20603 unsigned int addr_index
)
20605 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20606 gdb::optional
<ULONGEST
> addr_base
;
20609 /* We need addr_base and addr_size.
20610 If we don't have PER_CU->cu, we have to get it.
20611 Nasty, but the alternative is storing the needed info in PER_CU,
20612 which at this point doesn't seem justified: it's not clear how frequently
20613 it would get used and it would increase the size of every PER_CU.
20614 Entry points like dwarf2_per_cu_addr_size do a similar thing
20615 so we're not in uncharted territory here.
20616 Alas we need to be a bit more complicated as addr_base is contained
20619 We don't need to read the entire CU(/TU).
20620 We just need the header and top level die.
20622 IWBN to use the aging mechanism to let us lazily later discard the CU.
20623 For now we skip this optimization. */
20627 addr_base
= cu
->addr_base
;
20628 addr_size
= cu
->header
.addr_size
;
20632 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20633 addr_base
= reader
.cu
->addr_base
;
20634 addr_size
= reader
.cu
->header
.addr_size
;
20637 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20640 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20641 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20644 static const char *
20645 read_str_index (struct dwarf2_cu
*cu
,
20646 struct dwarf2_section_info
*str_section
,
20647 struct dwarf2_section_info
*str_offsets_section
,
20648 ULONGEST str_offsets_base
, ULONGEST str_index
)
20650 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20651 struct objfile
*objfile
= per_objfile
->objfile
;
20652 const char *objf_name
= objfile_name (objfile
);
20653 bfd
*abfd
= objfile
->obfd
;
20654 const gdb_byte
*info_ptr
;
20655 ULONGEST str_offset
;
20656 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20658 str_section
->read (objfile
);
20659 str_offsets_section
->read (objfile
);
20660 if (str_section
->buffer
== NULL
)
20661 error (_("%s used without %s section"
20662 " in CU at offset %s [in module %s]"),
20663 form_name
, str_section
->get_name (),
20664 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20665 if (str_offsets_section
->buffer
== NULL
)
20666 error (_("%s used without %s section"
20667 " in CU at offset %s [in module %s]"),
20668 form_name
, str_section
->get_name (),
20669 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20670 info_ptr
= (str_offsets_section
->buffer
20672 + str_index
* cu
->header
.offset_size
);
20673 if (cu
->header
.offset_size
== 4)
20674 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20676 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20677 if (str_offset
>= str_section
->size
)
20678 error (_("Offset from %s pointing outside of"
20679 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20680 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20681 return (const char *) (str_section
->buffer
+ str_offset
);
20684 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20686 static const char *
20687 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20689 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20690 ? reader
->cu
->header
.addr_size
: 0;
20691 return read_str_index (reader
->cu
,
20692 &reader
->dwo_file
->sections
.str
,
20693 &reader
->dwo_file
->sections
.str_offsets
,
20694 str_offsets_base
, str_index
);
20697 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20699 static const char *
20700 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20702 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20703 const char *objf_name
= objfile_name (objfile
);
20704 static const char form_name
[] = "DW_FORM_GNU_str_index";
20705 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20707 if (!cu
->str_offsets_base
.has_value ())
20708 error (_("%s used in Fission stub without %s"
20709 " in CU at offset 0x%lx [in module %s]"),
20710 form_name
, str_offsets_attr_name
,
20711 (long) cu
->header
.offset_size
, objf_name
);
20713 return read_str_index (cu
,
20714 &cu
->per_objfile
->per_bfd
->str
,
20715 &cu
->per_objfile
->per_bfd
->str_offsets
,
20716 *cu
->str_offsets_base
, str_index
);
20719 /* Return the length of an LEB128 number in BUF. */
20722 leb128_size (const gdb_byte
*buf
)
20724 const gdb_byte
*begin
= buf
;
20730 if ((byte
& 128) == 0)
20731 return buf
- begin
;
20736 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20745 cu
->language
= language_c
;
20748 case DW_LANG_C_plus_plus
:
20749 case DW_LANG_C_plus_plus_11
:
20750 case DW_LANG_C_plus_plus_14
:
20751 cu
->language
= language_cplus
;
20754 cu
->language
= language_d
;
20756 case DW_LANG_Fortran77
:
20757 case DW_LANG_Fortran90
:
20758 case DW_LANG_Fortran95
:
20759 case DW_LANG_Fortran03
:
20760 case DW_LANG_Fortran08
:
20761 cu
->language
= language_fortran
;
20764 cu
->language
= language_go
;
20766 case DW_LANG_Mips_Assembler
:
20767 cu
->language
= language_asm
;
20769 case DW_LANG_Ada83
:
20770 case DW_LANG_Ada95
:
20771 cu
->language
= language_ada
;
20773 case DW_LANG_Modula2
:
20774 cu
->language
= language_m2
;
20776 case DW_LANG_Pascal83
:
20777 cu
->language
= language_pascal
;
20780 cu
->language
= language_objc
;
20783 case DW_LANG_Rust_old
:
20784 cu
->language
= language_rust
;
20786 case DW_LANG_Cobol74
:
20787 case DW_LANG_Cobol85
:
20789 cu
->language
= language_minimal
;
20792 cu
->language_defn
= language_def (cu
->language
);
20795 /* Return the named attribute or NULL if not there. */
20797 static struct attribute
*
20798 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20803 struct attribute
*spec
= NULL
;
20805 for (i
= 0; i
< die
->num_attrs
; ++i
)
20807 if (die
->attrs
[i
].name
== name
)
20808 return &die
->attrs
[i
];
20809 if (die
->attrs
[i
].name
== DW_AT_specification
20810 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20811 spec
= &die
->attrs
[i
];
20817 die
= follow_die_ref (die
, spec
, &cu
);
20823 /* Return the string associated with a string-typed attribute, or NULL if it
20824 is either not found or is of an incorrect type. */
20826 static const char *
20827 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20829 struct attribute
*attr
;
20830 const char *str
= NULL
;
20832 attr
= dwarf2_attr (die
, name
, cu
);
20836 str
= attr
->as_string ();
20837 if (str
== nullptr)
20838 complaint (_("string type expected for attribute %s for "
20839 "DIE at %s in module %s"),
20840 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20841 objfile_name (cu
->per_objfile
->objfile
));
20847 /* Return the dwo name or NULL if not present. If present, it is in either
20848 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20849 static const char *
20850 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20852 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20853 if (dwo_name
== nullptr)
20854 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20858 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20859 and holds a non-zero value. This function should only be used for
20860 DW_FORM_flag or DW_FORM_flag_present attributes. */
20863 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20865 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20867 return attr
!= nullptr && attr
->as_boolean ();
20871 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20873 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20874 which value is non-zero. However, we have to be careful with
20875 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20876 (via dwarf2_flag_true_p) follows this attribute. So we may
20877 end up accidently finding a declaration attribute that belongs
20878 to a different DIE referenced by the specification attribute,
20879 even though the given DIE does not have a declaration attribute. */
20880 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20881 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20884 /* Return the die giving the specification for DIE, if there is
20885 one. *SPEC_CU is the CU containing DIE on input, and the CU
20886 containing the return value on output. If there is no
20887 specification, but there is an abstract origin, that is
20890 static struct die_info
*
20891 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20893 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20896 if (spec_attr
== NULL
)
20897 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20899 if (spec_attr
== NULL
)
20902 return follow_die_ref (die
, spec_attr
, spec_cu
);
20905 /* Stub for free_line_header to match void * callback types. */
20908 free_line_header_voidp (void *arg
)
20910 struct line_header
*lh
= (struct line_header
*) arg
;
20915 /* A convenience function to find the proper .debug_line section for a CU. */
20917 static struct dwarf2_section_info
*
20918 get_debug_line_section (struct dwarf2_cu
*cu
)
20920 struct dwarf2_section_info
*section
;
20921 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20923 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20925 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20926 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20927 else if (cu
->per_cu
->is_dwz
)
20929 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20931 section
= &dwz
->line
;
20934 section
= &per_objfile
->per_bfd
->line
;
20939 /* Read the statement program header starting at OFFSET in
20940 .debug_line, or .debug_line.dwo. Return a pointer
20941 to a struct line_header, allocated using xmalloc.
20942 Returns NULL if there is a problem reading the header, e.g., if it
20943 has a version we don't understand.
20945 NOTE: the strings in the include directory and file name tables of
20946 the returned object point into the dwarf line section buffer,
20947 and must not be freed. */
20949 static line_header_up
20950 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20952 struct dwarf2_section_info
*section
;
20953 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20955 section
= get_debug_line_section (cu
);
20956 section
->read (per_objfile
->objfile
);
20957 if (section
->buffer
== NULL
)
20959 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20960 complaint (_("missing .debug_line.dwo section"));
20962 complaint (_("missing .debug_line section"));
20966 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20967 per_objfile
, section
, &cu
->header
);
20970 /* Subroutine of dwarf_decode_lines to simplify it.
20971 Return the file name of the psymtab for the given file_entry.
20972 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20973 If space for the result is malloc'd, *NAME_HOLDER will be set.
20974 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20976 static const char *
20977 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20978 const dwarf2_psymtab
*pst
,
20979 const char *comp_dir
,
20980 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20982 const char *include_name
= fe
.name
;
20983 const char *include_name_to_compare
= include_name
;
20984 const char *pst_filename
;
20987 const char *dir_name
= fe
.include_dir (lh
);
20989 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20990 if (!IS_ABSOLUTE_PATH (include_name
)
20991 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20993 /* Avoid creating a duplicate psymtab for PST.
20994 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20995 Before we do the comparison, however, we need to account
20996 for DIR_NAME and COMP_DIR.
20997 First prepend dir_name (if non-NULL). If we still don't
20998 have an absolute path prepend comp_dir (if non-NULL).
20999 However, the directory we record in the include-file's
21000 psymtab does not contain COMP_DIR (to match the
21001 corresponding symtab(s)).
21006 bash$ gcc -g ./hello.c
21007 include_name = "hello.c"
21009 DW_AT_comp_dir = comp_dir = "/tmp"
21010 DW_AT_name = "./hello.c"
21014 if (dir_name
!= NULL
)
21016 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
21017 include_name
, (char *) NULL
));
21018 include_name
= name_holder
->get ();
21019 include_name_to_compare
= include_name
;
21021 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
21023 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
21024 include_name
, (char *) NULL
));
21025 include_name_to_compare
= hold_compare
.get ();
21029 pst_filename
= pst
->filename
;
21030 gdb::unique_xmalloc_ptr
<char> copied_name
;
21031 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
21033 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
21034 pst_filename
, (char *) NULL
));
21035 pst_filename
= copied_name
.get ();
21038 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
21042 return include_name
;
21045 /* State machine to track the state of the line number program. */
21047 class lnp_state_machine
21050 /* Initialize a machine state for the start of a line number
21052 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
21053 bool record_lines_p
);
21055 file_entry
*current_file ()
21057 /* lh->file_names is 0-based, but the file name numbers in the
21058 statement program are 1-based. */
21059 return m_line_header
->file_name_at (m_file
);
21062 /* Record the line in the state machine. END_SEQUENCE is true if
21063 we're processing the end of a sequence. */
21064 void record_line (bool end_sequence
);
21066 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
21067 nop-out rest of the lines in this sequence. */
21068 void check_line_address (struct dwarf2_cu
*cu
,
21069 const gdb_byte
*line_ptr
,
21070 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
21072 void handle_set_discriminator (unsigned int discriminator
)
21074 m_discriminator
= discriminator
;
21075 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21078 /* Handle DW_LNE_set_address. */
21079 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21082 address
+= baseaddr
;
21083 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21086 /* Handle DW_LNS_advance_pc. */
21087 void handle_advance_pc (CORE_ADDR adjust
);
21089 /* Handle a special opcode. */
21090 void handle_special_opcode (unsigned char op_code
);
21092 /* Handle DW_LNS_advance_line. */
21093 void handle_advance_line (int line_delta
)
21095 advance_line (line_delta
);
21098 /* Handle DW_LNS_set_file. */
21099 void handle_set_file (file_name_index file
);
21101 /* Handle DW_LNS_negate_stmt. */
21102 void handle_negate_stmt ()
21104 m_is_stmt
= !m_is_stmt
;
21107 /* Handle DW_LNS_const_add_pc. */
21108 void handle_const_add_pc ();
21110 /* Handle DW_LNS_fixed_advance_pc. */
21111 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21113 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21117 /* Handle DW_LNS_copy. */
21118 void handle_copy ()
21120 record_line (false);
21121 m_discriminator
= 0;
21124 /* Handle DW_LNE_end_sequence. */
21125 void handle_end_sequence ()
21127 m_currently_recording_lines
= true;
21131 /* Advance the line by LINE_DELTA. */
21132 void advance_line (int line_delta
)
21134 m_line
+= line_delta
;
21136 if (line_delta
!= 0)
21137 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21140 struct dwarf2_cu
*m_cu
;
21142 gdbarch
*m_gdbarch
;
21144 /* True if we're recording lines.
21145 Otherwise we're building partial symtabs and are just interested in
21146 finding include files mentioned by the line number program. */
21147 bool m_record_lines_p
;
21149 /* The line number header. */
21150 line_header
*m_line_header
;
21152 /* These are part of the standard DWARF line number state machine,
21153 and initialized according to the DWARF spec. */
21155 unsigned char m_op_index
= 0;
21156 /* The line table index of the current file. */
21157 file_name_index m_file
= 1;
21158 unsigned int m_line
= 1;
21160 /* These are initialized in the constructor. */
21162 CORE_ADDR m_address
;
21164 unsigned int m_discriminator
;
21166 /* Additional bits of state we need to track. */
21168 /* The last file that we called dwarf2_start_subfile for.
21169 This is only used for TLLs. */
21170 unsigned int m_last_file
= 0;
21171 /* The last file a line number was recorded for. */
21172 struct subfile
*m_last_subfile
= NULL
;
21174 /* The address of the last line entry. */
21175 CORE_ADDR m_last_address
;
21177 /* Set to true when a previous line at the same address (using
21178 m_last_address) had m_is_stmt true. This is reset to false when a
21179 line entry at a new address (m_address different to m_last_address) is
21181 bool m_stmt_at_address
= false;
21183 /* When true, record the lines we decode. */
21184 bool m_currently_recording_lines
= false;
21186 /* The last line number that was recorded, used to coalesce
21187 consecutive entries for the same line. This can happen, for
21188 example, when discriminators are present. PR 17276. */
21189 unsigned int m_last_line
= 0;
21190 bool m_line_has_non_zero_discriminator
= false;
21194 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21196 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21197 / m_line_header
->maximum_ops_per_instruction
)
21198 * m_line_header
->minimum_instruction_length
);
21199 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21200 m_op_index
= ((m_op_index
+ adjust
)
21201 % m_line_header
->maximum_ops_per_instruction
);
21205 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21207 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21208 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
21209 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
21210 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
21211 / m_line_header
->maximum_ops_per_instruction
)
21212 * m_line_header
->minimum_instruction_length
);
21213 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21214 m_op_index
= ((m_op_index
+ adj_opcode_d
)
21215 % m_line_header
->maximum_ops_per_instruction
);
21217 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
21218 advance_line (line_delta
);
21219 record_line (false);
21220 m_discriminator
= 0;
21224 lnp_state_machine::handle_set_file (file_name_index file
)
21228 const file_entry
*fe
= current_file ();
21230 dwarf2_debug_line_missing_file_complaint ();
21231 else if (m_record_lines_p
)
21233 const char *dir
= fe
->include_dir (m_line_header
);
21235 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21236 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21237 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21242 lnp_state_machine::handle_const_add_pc ()
21245 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21248 = (((m_op_index
+ adjust
)
21249 / m_line_header
->maximum_ops_per_instruction
)
21250 * m_line_header
->minimum_instruction_length
);
21252 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21253 m_op_index
= ((m_op_index
+ adjust
)
21254 % m_line_header
->maximum_ops_per_instruction
);
21257 /* Return non-zero if we should add LINE to the line number table.
21258 LINE is the line to add, LAST_LINE is the last line that was added,
21259 LAST_SUBFILE is the subfile for LAST_LINE.
21260 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21261 had a non-zero discriminator.
21263 We have to be careful in the presence of discriminators.
21264 E.g., for this line:
21266 for (i = 0; i < 100000; i++);
21268 clang can emit four line number entries for that one line,
21269 each with a different discriminator.
21270 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21272 However, we want gdb to coalesce all four entries into one.
21273 Otherwise the user could stepi into the middle of the line and
21274 gdb would get confused about whether the pc really was in the
21275 middle of the line.
21277 Things are further complicated by the fact that two consecutive
21278 line number entries for the same line is a heuristic used by gcc
21279 to denote the end of the prologue. So we can't just discard duplicate
21280 entries, we have to be selective about it. The heuristic we use is
21281 that we only collapse consecutive entries for the same line if at least
21282 one of those entries has a non-zero discriminator. PR 17276.
21284 Note: Addresses in the line number state machine can never go backwards
21285 within one sequence, thus this coalescing is ok. */
21288 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21289 unsigned int line
, unsigned int last_line
,
21290 int line_has_non_zero_discriminator
,
21291 struct subfile
*last_subfile
)
21293 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21295 if (line
!= last_line
)
21297 /* Same line for the same file that we've seen already.
21298 As a last check, for pr 17276, only record the line if the line
21299 has never had a non-zero discriminator. */
21300 if (!line_has_non_zero_discriminator
)
21305 /* Use the CU's builder to record line number LINE beginning at
21306 address ADDRESS in the line table of subfile SUBFILE. */
21309 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21310 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
21311 struct dwarf2_cu
*cu
)
21313 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21315 if (dwarf_line_debug
)
21317 fprintf_unfiltered (gdb_stdlog
,
21318 "Recording line %u, file %s, address %s\n",
21319 line
, lbasename (subfile
->name
),
21320 paddress (gdbarch
, address
));
21324 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21327 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21328 Mark the end of a set of line number records.
21329 The arguments are the same as for dwarf_record_line_1.
21330 If SUBFILE is NULL the request is ignored. */
21333 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21334 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21336 if (subfile
== NULL
)
21339 if (dwarf_line_debug
)
21341 fprintf_unfiltered (gdb_stdlog
,
21342 "Finishing current line, file %s, address %s\n",
21343 lbasename (subfile
->name
),
21344 paddress (gdbarch
, address
));
21347 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21351 lnp_state_machine::record_line (bool end_sequence
)
21353 if (dwarf_line_debug
)
21355 fprintf_unfiltered (gdb_stdlog
,
21356 "Processing actual line %u: file %u,"
21357 " address %s, is_stmt %u, discrim %u%s\n",
21359 paddress (m_gdbarch
, m_address
),
21360 m_is_stmt
, m_discriminator
,
21361 (end_sequence
? "\t(end sequence)" : ""));
21364 file_entry
*fe
= current_file ();
21367 dwarf2_debug_line_missing_file_complaint ();
21368 /* For now we ignore lines not starting on an instruction boundary.
21369 But not when processing end_sequence for compatibility with the
21370 previous version of the code. */
21371 else if (m_op_index
== 0 || end_sequence
)
21373 fe
->included_p
= 1;
21374 if (m_record_lines_p
)
21376 /* When we switch files we insert an end maker in the first file,
21377 switch to the second file and add a new line entry. The
21378 problem is that the end marker inserted in the first file will
21379 discard any previous line entries at the same address. If the
21380 line entries in the first file are marked as is-stmt, while
21381 the new line in the second file is non-stmt, then this means
21382 the end marker will discard is-stmt lines so we can have a
21383 non-stmt line. This means that there are less addresses at
21384 which the user can insert a breakpoint.
21386 To improve this we track the last address in m_last_address,
21387 and whether we have seen an is-stmt at this address. Then
21388 when switching files, if we have seen a stmt at the current
21389 address, and we are switching to create a non-stmt line, then
21390 discard the new line. */
21392 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21393 bool ignore_this_line
21394 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21395 && !m_is_stmt
&& m_stmt_at_address
)
21396 || (!end_sequence
&& m_line
== 0));
21398 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21400 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21401 m_currently_recording_lines
? m_cu
: nullptr);
21404 if (!end_sequence
&& !ignore_this_line
)
21406 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21408 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21409 m_line_has_non_zero_discriminator
,
21412 buildsym_compunit
*builder
= m_cu
->get_builder ();
21413 dwarf_record_line_1 (m_gdbarch
,
21414 builder
->get_current_subfile (),
21415 m_line
, m_address
, is_stmt
,
21416 m_currently_recording_lines
? m_cu
: nullptr);
21418 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21419 m_last_line
= m_line
;
21424 /* Track whether we have seen any m_is_stmt true at m_address in case we
21425 have multiple line table entries all at m_address. */
21426 if (m_last_address
!= m_address
)
21428 m_stmt_at_address
= false;
21429 m_last_address
= m_address
;
21431 m_stmt_at_address
|= m_is_stmt
;
21434 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21435 line_header
*lh
, bool record_lines_p
)
21439 m_record_lines_p
= record_lines_p
;
21440 m_line_header
= lh
;
21442 m_currently_recording_lines
= true;
21444 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21445 was a line entry for it so that the backend has a chance to adjust it
21446 and also record it in case it needs it. This is currently used by MIPS
21447 code, cf. `mips_adjust_dwarf2_line'. */
21448 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21449 m_is_stmt
= lh
->default_is_stmt
;
21450 m_discriminator
= 0;
21452 m_last_address
= m_address
;
21453 m_stmt_at_address
= false;
21457 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21458 const gdb_byte
*line_ptr
,
21459 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21461 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21462 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21463 located at 0x0. In this case, additionally check that if
21464 ADDRESS < UNRELOCATED_LOWPC. */
21466 if ((address
== 0 && address
< unrelocated_lowpc
)
21467 || address
== (CORE_ADDR
) -1)
21469 /* This line table is for a function which has been
21470 GCd by the linker. Ignore it. PR gdb/12528 */
21472 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21473 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21475 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21476 line_offset
, objfile_name (objfile
));
21477 m_currently_recording_lines
= false;
21478 /* Note: m_currently_recording_lines is left as false until we see
21479 DW_LNE_end_sequence. */
21483 /* Subroutine of dwarf_decode_lines to simplify it.
21484 Process the line number information in LH.
21485 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21486 program in order to set included_p for every referenced header. */
21489 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21490 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21492 const gdb_byte
*line_ptr
, *extended_end
;
21493 const gdb_byte
*line_end
;
21494 unsigned int bytes_read
, extended_len
;
21495 unsigned char op_code
, extended_op
;
21496 CORE_ADDR baseaddr
;
21497 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21498 bfd
*abfd
= objfile
->obfd
;
21499 struct gdbarch
*gdbarch
= objfile
->arch ();
21500 /* True if we're recording line info (as opposed to building partial
21501 symtabs and just interested in finding include files mentioned by
21502 the line number program). */
21503 bool record_lines_p
= !decode_for_pst_p
;
21505 baseaddr
= objfile
->text_section_offset ();
21507 line_ptr
= lh
->statement_program_start
;
21508 line_end
= lh
->statement_program_end
;
21510 /* Read the statement sequences until there's nothing left. */
21511 while (line_ptr
< line_end
)
21513 /* The DWARF line number program state machine. Reset the state
21514 machine at the start of each sequence. */
21515 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21516 bool end_sequence
= false;
21518 if (record_lines_p
)
21520 /* Start a subfile for the current file of the state
21522 const file_entry
*fe
= state_machine
.current_file ();
21525 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21528 /* Decode the table. */
21529 while (line_ptr
< line_end
&& !end_sequence
)
21531 op_code
= read_1_byte (abfd
, line_ptr
);
21534 if (op_code
>= lh
->opcode_base
)
21536 /* Special opcode. */
21537 state_machine
.handle_special_opcode (op_code
);
21539 else switch (op_code
)
21541 case DW_LNS_extended_op
:
21542 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21544 line_ptr
+= bytes_read
;
21545 extended_end
= line_ptr
+ extended_len
;
21546 extended_op
= read_1_byte (abfd
, line_ptr
);
21548 if (DW_LNE_lo_user
<= extended_op
21549 && extended_op
<= DW_LNE_hi_user
)
21551 /* Vendor extension, ignore. */
21552 line_ptr
= extended_end
;
21555 switch (extended_op
)
21557 case DW_LNE_end_sequence
:
21558 state_machine
.handle_end_sequence ();
21559 end_sequence
= true;
21561 case DW_LNE_set_address
:
21564 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21565 line_ptr
+= bytes_read
;
21567 state_machine
.check_line_address (cu
, line_ptr
,
21568 lowpc
- baseaddr
, address
);
21569 state_machine
.handle_set_address (baseaddr
, address
);
21572 case DW_LNE_define_file
:
21574 const char *cur_file
;
21575 unsigned int mod_time
, length
;
21578 cur_file
= read_direct_string (abfd
, line_ptr
,
21580 line_ptr
+= bytes_read
;
21581 dindex
= (dir_index
)
21582 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21583 line_ptr
+= bytes_read
;
21585 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21586 line_ptr
+= bytes_read
;
21588 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21589 line_ptr
+= bytes_read
;
21590 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21593 case DW_LNE_set_discriminator
:
21595 /* The discriminator is not interesting to the
21596 debugger; just ignore it. We still need to
21597 check its value though:
21598 if there are consecutive entries for the same
21599 (non-prologue) line we want to coalesce them.
21602 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21603 line_ptr
+= bytes_read
;
21605 state_machine
.handle_set_discriminator (discr
);
21609 complaint (_("mangled .debug_line section"));
21612 /* Make sure that we parsed the extended op correctly. If e.g.
21613 we expected a different address size than the producer used,
21614 we may have read the wrong number of bytes. */
21615 if (line_ptr
!= extended_end
)
21617 complaint (_("mangled .debug_line section"));
21622 state_machine
.handle_copy ();
21624 case DW_LNS_advance_pc
:
21627 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21628 line_ptr
+= bytes_read
;
21630 state_machine
.handle_advance_pc (adjust
);
21633 case DW_LNS_advance_line
:
21636 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21637 line_ptr
+= bytes_read
;
21639 state_machine
.handle_advance_line (line_delta
);
21642 case DW_LNS_set_file
:
21644 file_name_index file
21645 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21647 line_ptr
+= bytes_read
;
21649 state_machine
.handle_set_file (file
);
21652 case DW_LNS_set_column
:
21653 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21654 line_ptr
+= bytes_read
;
21656 case DW_LNS_negate_stmt
:
21657 state_machine
.handle_negate_stmt ();
21659 case DW_LNS_set_basic_block
:
21661 /* Add to the address register of the state machine the
21662 address increment value corresponding to special opcode
21663 255. I.e., this value is scaled by the minimum
21664 instruction length since special opcode 255 would have
21665 scaled the increment. */
21666 case DW_LNS_const_add_pc
:
21667 state_machine
.handle_const_add_pc ();
21669 case DW_LNS_fixed_advance_pc
:
21671 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21674 state_machine
.handle_fixed_advance_pc (addr_adj
);
21679 /* Unknown standard opcode, ignore it. */
21682 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21684 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21685 line_ptr
+= bytes_read
;
21692 dwarf2_debug_line_missing_end_sequence_complaint ();
21694 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21695 in which case we still finish recording the last line). */
21696 state_machine
.record_line (true);
21700 /* Decode the Line Number Program (LNP) for the given line_header
21701 structure and CU. The actual information extracted and the type
21702 of structures created from the LNP depends on the value of PST.
21704 1. If PST is NULL, then this procedure uses the data from the program
21705 to create all necessary symbol tables, and their linetables.
21707 2. If PST is not NULL, this procedure reads the program to determine
21708 the list of files included by the unit represented by PST, and
21709 builds all the associated partial symbol tables.
21711 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21712 It is used for relative paths in the line table.
21713 NOTE: When processing partial symtabs (pst != NULL),
21714 comp_dir == pst->dirname.
21716 NOTE: It is important that psymtabs have the same file name (via strcmp)
21717 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21718 symtab we don't use it in the name of the psymtabs we create.
21719 E.g. expand_line_sal requires this when finding psymtabs to expand.
21720 A good testcase for this is mb-inline.exp.
21722 LOWPC is the lowest address in CU (or 0 if not known).
21724 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21725 for its PC<->lines mapping information. Otherwise only the filename
21726 table is read in. */
21729 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21730 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21731 CORE_ADDR lowpc
, int decode_mapping
)
21733 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21734 const int decode_for_pst_p
= (pst
!= NULL
);
21736 if (decode_mapping
)
21737 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21739 if (decode_for_pst_p
)
21741 /* Now that we're done scanning the Line Header Program, we can
21742 create the psymtab of each included file. */
21743 for (auto &file_entry
: lh
->file_names ())
21744 if (file_entry
.included_p
== 1)
21746 gdb::unique_xmalloc_ptr
<char> name_holder
;
21747 const char *include_name
=
21748 psymtab_include_file_name (lh
, file_entry
, pst
,
21749 comp_dir
, &name_holder
);
21750 if (include_name
!= NULL
)
21751 dwarf2_create_include_psymtab
21752 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
21753 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
21759 /* Make sure a symtab is created for every file, even files
21760 which contain only variables (i.e. no code with associated
21762 buildsym_compunit
*builder
= cu
->get_builder ();
21763 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21765 for (auto &fe
: lh
->file_names ())
21767 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21768 if (builder
->get_current_subfile ()->symtab
== NULL
)
21770 builder
->get_current_subfile ()->symtab
21771 = allocate_symtab (cust
,
21772 builder
->get_current_subfile ()->name
);
21774 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21779 /* Start a subfile for DWARF. FILENAME is the name of the file and
21780 DIRNAME the name of the source directory which contains FILENAME
21781 or NULL if not known.
21782 This routine tries to keep line numbers from identical absolute and
21783 relative file names in a common subfile.
21785 Using the `list' example from the GDB testsuite, which resides in
21786 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21787 of /srcdir/list0.c yields the following debugging information for list0.c:
21789 DW_AT_name: /srcdir/list0.c
21790 DW_AT_comp_dir: /compdir
21791 files.files[0].name: list0.h
21792 files.files[0].dir: /srcdir
21793 files.files[1].name: list0.c
21794 files.files[1].dir: /srcdir
21796 The line number information for list0.c has to end up in a single
21797 subfile, so that `break /srcdir/list0.c:1' works as expected.
21798 start_subfile will ensure that this happens provided that we pass the
21799 concatenation of files.files[1].dir and files.files[1].name as the
21803 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21804 const char *dirname
)
21806 gdb::unique_xmalloc_ptr
<char> copy
;
21808 /* In order not to lose the line information directory,
21809 we concatenate it to the filename when it makes sense.
21810 Note that the Dwarf3 standard says (speaking of filenames in line
21811 information): ``The directory index is ignored for file names
21812 that represent full path names''. Thus ignoring dirname in the
21813 `else' branch below isn't an issue. */
21815 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21817 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21818 filename
= copy
.get ();
21821 cu
->get_builder ()->start_subfile (filename
);
21824 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21825 buildsym_compunit constructor. */
21827 struct compunit_symtab
*
21828 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21831 gdb_assert (m_builder
== nullptr);
21833 m_builder
.reset (new struct buildsym_compunit
21834 (this->per_objfile
->objfile
,
21835 name
, comp_dir
, language
, low_pc
));
21837 list_in_scope
= get_builder ()->get_file_symbols ();
21839 get_builder ()->record_debugformat ("DWARF 2");
21840 get_builder ()->record_producer (producer
);
21842 processing_has_namespace_info
= false;
21844 return get_builder ()->get_compunit_symtab ();
21848 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21849 struct dwarf2_cu
*cu
)
21851 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21852 struct comp_unit_head
*cu_header
= &cu
->header
;
21854 /* NOTE drow/2003-01-30: There used to be a comment and some special
21855 code here to turn a symbol with DW_AT_external and a
21856 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21857 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21858 with some versions of binutils) where shared libraries could have
21859 relocations against symbols in their debug information - the
21860 minimal symbol would have the right address, but the debug info
21861 would not. It's no longer necessary, because we will explicitly
21862 apply relocations when we read in the debug information now. */
21864 /* A DW_AT_location attribute with no contents indicates that a
21865 variable has been optimized away. */
21866 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21868 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21872 /* Handle one degenerate form of location expression specially, to
21873 preserve GDB's previous behavior when section offsets are
21874 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21875 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21877 if (attr
->form_is_block ())
21879 struct dwarf_block
*block
= attr
->as_block ();
21881 if ((block
->data
[0] == DW_OP_addr
21882 && block
->size
== 1 + cu_header
->addr_size
)
21883 || ((block
->data
[0] == DW_OP_GNU_addr_index
21884 || block
->data
[0] == DW_OP_addrx
)
21886 == 1 + leb128_size (&block
->data
[1]))))
21888 unsigned int dummy
;
21890 if (block
->data
[0] == DW_OP_addr
)
21891 SET_SYMBOL_VALUE_ADDRESS
21892 (sym
, cu
->header
.read_address (objfile
->obfd
,
21896 SET_SYMBOL_VALUE_ADDRESS
21897 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21899 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21900 fixup_symbol_section (sym
, objfile
);
21901 SET_SYMBOL_VALUE_ADDRESS
21903 SYMBOL_VALUE_ADDRESS (sym
)
21904 + objfile
->section_offsets
[sym
->section_index ()]);
21909 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21910 expression evaluator, and use LOC_COMPUTED only when necessary
21911 (i.e. when the value of a register or memory location is
21912 referenced, or a thread-local block, etc.). Then again, it might
21913 not be worthwhile. I'm assuming that it isn't unless performance
21914 or memory numbers show me otherwise. */
21916 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21918 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21919 cu
->has_loclist
= true;
21922 /* Given a pointer to a DWARF information entry, figure out if we need
21923 to make a symbol table entry for it, and if so, create a new entry
21924 and return a pointer to it.
21925 If TYPE is NULL, determine symbol type from the die, otherwise
21926 used the passed type.
21927 If SPACE is not NULL, use it to hold the new symbol. If it is
21928 NULL, allocate a new symbol on the objfile's obstack. */
21930 static struct symbol
*
21931 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21932 struct symbol
*space
)
21934 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21935 struct objfile
*objfile
= per_objfile
->objfile
;
21936 struct gdbarch
*gdbarch
= objfile
->arch ();
21937 struct symbol
*sym
= NULL
;
21939 struct attribute
*attr
= NULL
;
21940 struct attribute
*attr2
= NULL
;
21941 CORE_ADDR baseaddr
;
21942 struct pending
**list_to_add
= NULL
;
21944 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21946 baseaddr
= objfile
->text_section_offset ();
21948 name
= dwarf2_name (die
, cu
);
21951 int suppress_add
= 0;
21956 sym
= new (&objfile
->objfile_obstack
) symbol
;
21957 OBJSTAT (objfile
, n_syms
++);
21959 /* Cache this symbol's name and the name's demangled form (if any). */
21960 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21961 /* Fortran does not have mangling standard and the mangling does differ
21962 between gfortran, iFort etc. */
21963 const char *physname
21964 = (cu
->language
== language_fortran
21965 ? dwarf2_full_name (name
, die
, cu
)
21966 : dwarf2_physname (name
, die
, cu
));
21967 const char *linkagename
= dw2_linkage_name (die
, cu
);
21969 if (linkagename
== nullptr || cu
->language
== language_ada
)
21970 sym
->set_linkage_name (physname
);
21973 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21974 sym
->set_linkage_name (linkagename
);
21977 /* Default assumptions.
21978 Use the passed type or decode it from the die. */
21979 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21980 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21982 SYMBOL_TYPE (sym
) = type
;
21984 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21985 attr
= dwarf2_attr (die
,
21986 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21988 if (attr
!= nullptr)
21989 SYMBOL_LINE (sym
) = attr
->constant_value (0);
21991 attr
= dwarf2_attr (die
,
21992 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21994 if (attr
!= nullptr && attr
->is_nonnegative ())
21996 file_name_index file_index
21997 = (file_name_index
) attr
->as_nonnegative ();
21998 struct file_entry
*fe
;
22000 if (cu
->line_header
!= NULL
)
22001 fe
= cu
->line_header
->file_name_at (file_index
);
22006 complaint (_("file index out of range"));
22008 symbol_set_symtab (sym
, fe
->symtab
);
22014 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
22015 if (attr
!= nullptr)
22019 addr
= attr
->as_address ();
22020 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
22021 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
22022 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
22025 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22026 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
22027 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
22028 add_symbol_to_list (sym
, cu
->list_in_scope
);
22030 case DW_TAG_subprogram
:
22031 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22033 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22034 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22035 if ((attr2
!= nullptr && attr2
->as_boolean ())
22036 || cu
->language
== language_ada
22037 || cu
->language
== language_fortran
)
22039 /* Subprograms marked external are stored as a global symbol.
22040 Ada and Fortran subprograms, whether marked external or
22041 not, are always stored as a global symbol, because we want
22042 to be able to access them globally. For instance, we want
22043 to be able to break on a nested subprogram without having
22044 to specify the context. */
22045 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22049 list_to_add
= cu
->list_in_scope
;
22052 case DW_TAG_inlined_subroutine
:
22053 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22055 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22056 SYMBOL_INLINED (sym
) = 1;
22057 list_to_add
= cu
->list_in_scope
;
22059 case DW_TAG_template_value_param
:
22061 /* Fall through. */
22062 case DW_TAG_constant
:
22063 case DW_TAG_variable
:
22064 case DW_TAG_member
:
22065 /* Compilation with minimal debug info may result in
22066 variables with missing type entries. Change the
22067 misleading `void' type to something sensible. */
22068 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
22069 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
22071 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22072 /* In the case of DW_TAG_member, we should only be called for
22073 static const members. */
22074 if (die
->tag
== DW_TAG_member
)
22076 /* dwarf2_add_field uses die_is_declaration,
22077 so we do the same. */
22078 gdb_assert (die_is_declaration (die
, cu
));
22081 if (attr
!= nullptr)
22083 dwarf2_const_value (attr
, sym
, cu
);
22084 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22087 if (attr2
!= nullptr && attr2
->as_boolean ())
22088 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22090 list_to_add
= cu
->list_in_scope
;
22094 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22095 if (attr
!= nullptr)
22097 var_decode_location (attr
, sym
, cu
);
22098 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22100 /* Fortran explicitly imports any global symbols to the local
22101 scope by DW_TAG_common_block. */
22102 if (cu
->language
== language_fortran
&& die
->parent
22103 && die
->parent
->tag
== DW_TAG_common_block
)
22106 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22107 && SYMBOL_VALUE_ADDRESS (sym
) == 0
22108 && !per_objfile
->per_bfd
->has_section_at_zero
)
22110 /* When a static variable is eliminated by the linker,
22111 the corresponding debug information is not stripped
22112 out, but the variable address is set to null;
22113 do not add such variables into symbol table. */
22115 else if (attr2
!= nullptr && attr2
->as_boolean ())
22117 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22118 && (objfile
->flags
& OBJF_MAINLINE
) == 0
22119 && per_objfile
->per_bfd
->can_copy
)
22121 /* A global static variable might be subject to
22122 copy relocation. We first check for a local
22123 minsym, though, because maybe the symbol was
22124 marked hidden, in which case this would not
22126 bound_minimal_symbol found
22127 = (lookup_minimal_symbol_linkage
22128 (sym
->linkage_name (), objfile
));
22129 if (found
.minsym
!= nullptr)
22130 sym
->maybe_copied
= 1;
22133 /* A variable with DW_AT_external is never static,
22134 but it may be block-scoped. */
22136 = ((cu
->list_in_scope
22137 == cu
->get_builder ()->get_file_symbols ())
22138 ? cu
->get_builder ()->get_global_symbols ()
22139 : cu
->list_in_scope
);
22142 list_to_add
= cu
->list_in_scope
;
22146 /* We do not know the address of this symbol.
22147 If it is an external symbol and we have type information
22148 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22149 The address of the variable will then be determined from
22150 the minimal symbol table whenever the variable is
22152 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22154 /* Fortran explicitly imports any global symbols to the local
22155 scope by DW_TAG_common_block. */
22156 if (cu
->language
== language_fortran
&& die
->parent
22157 && die
->parent
->tag
== DW_TAG_common_block
)
22159 /* SYMBOL_CLASS doesn't matter here because
22160 read_common_block is going to reset it. */
22162 list_to_add
= cu
->list_in_scope
;
22164 else if (attr2
!= nullptr && attr2
->as_boolean ()
22165 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22167 /* A variable with DW_AT_external is never static, but it
22168 may be block-scoped. */
22170 = ((cu
->list_in_scope
22171 == cu
->get_builder ()->get_file_symbols ())
22172 ? cu
->get_builder ()->get_global_symbols ()
22173 : cu
->list_in_scope
);
22175 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22177 else if (!die_is_declaration (die
, cu
))
22179 /* Use the default LOC_OPTIMIZED_OUT class. */
22180 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22182 list_to_add
= cu
->list_in_scope
;
22186 case DW_TAG_formal_parameter
:
22188 /* If we are inside a function, mark this as an argument. If
22189 not, we might be looking at an argument to an inlined function
22190 when we do not have enough information to show inlined frames;
22191 pretend it's a local variable in that case so that the user can
22193 struct context_stack
*curr
22194 = cu
->get_builder ()->get_current_context_stack ();
22195 if (curr
!= nullptr && curr
->name
!= nullptr)
22196 SYMBOL_IS_ARGUMENT (sym
) = 1;
22197 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22198 if (attr
!= nullptr)
22200 var_decode_location (attr
, sym
, cu
);
22202 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22203 if (attr
!= nullptr)
22205 dwarf2_const_value (attr
, sym
, cu
);
22208 list_to_add
= cu
->list_in_scope
;
22211 case DW_TAG_unspecified_parameters
:
22212 /* From varargs functions; gdb doesn't seem to have any
22213 interest in this information, so just ignore it for now.
22216 case DW_TAG_template_type_param
:
22218 /* Fall through. */
22219 case DW_TAG_class_type
:
22220 case DW_TAG_interface_type
:
22221 case DW_TAG_structure_type
:
22222 case DW_TAG_union_type
:
22223 case DW_TAG_set_type
:
22224 case DW_TAG_enumeration_type
:
22225 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22226 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22229 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22230 really ever be static objects: otherwise, if you try
22231 to, say, break of a class's method and you're in a file
22232 which doesn't mention that class, it won't work unless
22233 the check for all static symbols in lookup_symbol_aux
22234 saves you. See the OtherFileClass tests in
22235 gdb.c++/namespace.exp. */
22239 buildsym_compunit
*builder
= cu
->get_builder ();
22241 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22242 && cu
->language
== language_cplus
22243 ? builder
->get_global_symbols ()
22244 : cu
->list_in_scope
);
22246 /* The semantics of C++ state that "struct foo {
22247 ... }" also defines a typedef for "foo". */
22248 if (cu
->language
== language_cplus
22249 || cu
->language
== language_ada
22250 || cu
->language
== language_d
22251 || cu
->language
== language_rust
)
22253 /* The symbol's name is already allocated along
22254 with this objfile, so we don't need to
22255 duplicate it for the type. */
22256 if (SYMBOL_TYPE (sym
)->name () == 0)
22257 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
22262 case DW_TAG_typedef
:
22263 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22264 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22265 list_to_add
= cu
->list_in_scope
;
22267 case DW_TAG_array_type
:
22268 case DW_TAG_base_type
:
22269 case DW_TAG_subrange_type
:
22270 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22271 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22272 list_to_add
= cu
->list_in_scope
;
22274 case DW_TAG_enumerator
:
22275 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22276 if (attr
!= nullptr)
22278 dwarf2_const_value (attr
, sym
, cu
);
22281 /* NOTE: carlton/2003-11-10: See comment above in the
22282 DW_TAG_class_type, etc. block. */
22285 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22286 && cu
->language
== language_cplus
22287 ? cu
->get_builder ()->get_global_symbols ()
22288 : cu
->list_in_scope
);
22291 case DW_TAG_imported_declaration
:
22292 case DW_TAG_namespace
:
22293 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22294 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22296 case DW_TAG_module
:
22297 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22298 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22299 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22301 case DW_TAG_common_block
:
22302 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22303 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22304 add_symbol_to_list (sym
, cu
->list_in_scope
);
22307 /* Not a tag we recognize. Hopefully we aren't processing
22308 trash data, but since we must specifically ignore things
22309 we don't recognize, there is nothing else we should do at
22311 complaint (_("unsupported tag: '%s'"),
22312 dwarf_tag_name (die
->tag
));
22318 sym
->hash_next
= objfile
->template_symbols
;
22319 objfile
->template_symbols
= sym
;
22320 list_to_add
= NULL
;
22323 if (list_to_add
!= NULL
)
22324 add_symbol_to_list (sym
, list_to_add
);
22326 /* For the benefit of old versions of GCC, check for anonymous
22327 namespaces based on the demangled name. */
22328 if (!cu
->processing_has_namespace_info
22329 && cu
->language
== language_cplus
)
22330 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22335 /* Given an attr with a DW_FORM_dataN value in host byte order,
22336 zero-extend it as appropriate for the symbol's type. The DWARF
22337 standard (v4) is not entirely clear about the meaning of using
22338 DW_FORM_dataN for a constant with a signed type, where the type is
22339 wider than the data. The conclusion of a discussion on the DWARF
22340 list was that this is unspecified. We choose to always zero-extend
22341 because that is the interpretation long in use by GCC. */
22344 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22345 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22347 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22348 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22349 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22350 LONGEST l
= attr
->constant_value (0);
22352 if (bits
< sizeof (*value
) * 8)
22354 l
&= ((LONGEST
) 1 << bits
) - 1;
22357 else if (bits
== sizeof (*value
) * 8)
22361 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22362 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22369 /* Read a constant value from an attribute. Either set *VALUE, or if
22370 the value does not fit in *VALUE, set *BYTES - either already
22371 allocated on the objfile obstack, or newly allocated on OBSTACK,
22372 or, set *BATON, if we translated the constant to a location
22376 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22377 const char *name
, struct obstack
*obstack
,
22378 struct dwarf2_cu
*cu
,
22379 LONGEST
*value
, const gdb_byte
**bytes
,
22380 struct dwarf2_locexpr_baton
**baton
)
22382 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22383 struct objfile
*objfile
= per_objfile
->objfile
;
22384 struct comp_unit_head
*cu_header
= &cu
->header
;
22385 struct dwarf_block
*blk
;
22386 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22387 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22393 switch (attr
->form
)
22396 case DW_FORM_addrx
:
22397 case DW_FORM_GNU_addr_index
:
22401 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22402 dwarf2_const_value_length_mismatch_complaint (name
,
22403 cu_header
->addr_size
,
22404 TYPE_LENGTH (type
));
22405 /* Symbols of this form are reasonably rare, so we just
22406 piggyback on the existing location code rather than writing
22407 a new implementation of symbol_computed_ops. */
22408 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22409 (*baton
)->per_objfile
= per_objfile
;
22410 (*baton
)->per_cu
= cu
->per_cu
;
22411 gdb_assert ((*baton
)->per_cu
);
22413 (*baton
)->size
= 2 + cu_header
->addr_size
;
22414 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22415 (*baton
)->data
= data
;
22417 data
[0] = DW_OP_addr
;
22418 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22419 byte_order
, attr
->as_address ());
22420 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22423 case DW_FORM_string
:
22426 case DW_FORM_GNU_str_index
:
22427 case DW_FORM_GNU_strp_alt
:
22428 /* The string is already allocated on the objfile obstack, point
22430 *bytes
= (const gdb_byte
*) attr
->as_string ();
22432 case DW_FORM_block1
:
22433 case DW_FORM_block2
:
22434 case DW_FORM_block4
:
22435 case DW_FORM_block
:
22436 case DW_FORM_exprloc
:
22437 case DW_FORM_data16
:
22438 blk
= attr
->as_block ();
22439 if (TYPE_LENGTH (type
) != blk
->size
)
22440 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22441 TYPE_LENGTH (type
));
22442 *bytes
= blk
->data
;
22445 /* The DW_AT_const_value attributes are supposed to carry the
22446 symbol's value "represented as it would be on the target
22447 architecture." By the time we get here, it's already been
22448 converted to host endianness, so we just need to sign- or
22449 zero-extend it as appropriate. */
22450 case DW_FORM_data1
:
22451 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22453 case DW_FORM_data2
:
22454 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22456 case DW_FORM_data4
:
22457 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22459 case DW_FORM_data8
:
22460 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22463 case DW_FORM_sdata
:
22464 case DW_FORM_implicit_const
:
22465 *value
= attr
->as_signed ();
22468 case DW_FORM_udata
:
22469 *value
= attr
->as_unsigned ();
22473 complaint (_("unsupported const value attribute form: '%s'"),
22474 dwarf_form_name (attr
->form
));
22481 /* Copy constant value from an attribute to a symbol. */
22484 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22485 struct dwarf2_cu
*cu
)
22487 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22489 const gdb_byte
*bytes
;
22490 struct dwarf2_locexpr_baton
*baton
;
22492 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22493 sym
->print_name (),
22494 &objfile
->objfile_obstack
, cu
,
22495 &value
, &bytes
, &baton
);
22499 SYMBOL_LOCATION_BATON (sym
) = baton
;
22500 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22502 else if (bytes
!= NULL
)
22504 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22505 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22509 SYMBOL_VALUE (sym
) = value
;
22510 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22514 /* Return the type of the die in question using its DW_AT_type attribute. */
22516 static struct type
*
22517 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22519 struct attribute
*type_attr
;
22521 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22524 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22525 /* A missing DW_AT_type represents a void type. */
22526 return objfile_type (objfile
)->builtin_void
;
22529 return lookup_die_type (die
, type_attr
, cu
);
22532 /* True iff CU's producer generates GNAT Ada auxiliary information
22533 that allows to find parallel types through that information instead
22534 of having to do expensive parallel lookups by type name. */
22537 need_gnat_info (struct dwarf2_cu
*cu
)
22539 /* Assume that the Ada compiler was GNAT, which always produces
22540 the auxiliary information. */
22541 return (cu
->language
== language_ada
);
22544 /* Return the auxiliary type of the die in question using its
22545 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22546 attribute is not present. */
22548 static struct type
*
22549 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22551 struct attribute
*type_attr
;
22553 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22557 return lookup_die_type (die
, type_attr
, cu
);
22560 /* If DIE has a descriptive_type attribute, then set the TYPE's
22561 descriptive type accordingly. */
22564 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22565 struct dwarf2_cu
*cu
)
22567 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22569 if (descriptive_type
)
22571 ALLOCATE_GNAT_AUX_TYPE (type
);
22572 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22576 /* Return the containing type of the die in question using its
22577 DW_AT_containing_type attribute. */
22579 static struct type
*
22580 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22582 struct attribute
*type_attr
;
22583 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22585 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22587 error (_("Dwarf Error: Problem turning containing type into gdb type "
22588 "[in module %s]"), objfile_name (objfile
));
22590 return lookup_die_type (die
, type_attr
, cu
);
22593 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22595 static struct type
*
22596 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22598 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22599 struct objfile
*objfile
= per_objfile
->objfile
;
22602 std::string message
22603 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22604 objfile_name (objfile
),
22605 sect_offset_str (cu
->header
.sect_off
),
22606 sect_offset_str (die
->sect_off
));
22607 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22609 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22612 /* Look up the type of DIE in CU using its type attribute ATTR.
22613 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22614 DW_AT_containing_type.
22615 If there is no type substitute an error marker. */
22617 static struct type
*
22618 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22619 struct dwarf2_cu
*cu
)
22621 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22622 struct objfile
*objfile
= per_objfile
->objfile
;
22623 struct type
*this_type
;
22625 gdb_assert (attr
->name
== DW_AT_type
22626 || attr
->name
== DW_AT_GNAT_descriptive_type
22627 || attr
->name
== DW_AT_containing_type
);
22629 /* First see if we have it cached. */
22631 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22633 struct dwarf2_per_cu_data
*per_cu
;
22634 sect_offset sect_off
= attr
->get_ref_die_offset ();
22636 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22637 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22639 else if (attr
->form_is_ref ())
22641 sect_offset sect_off
= attr
->get_ref_die_offset ();
22643 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22645 else if (attr
->form
== DW_FORM_ref_sig8
)
22647 ULONGEST signature
= attr
->as_signature ();
22649 return get_signatured_type (die
, signature
, cu
);
22653 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22654 " at %s [in module %s]"),
22655 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22656 objfile_name (objfile
));
22657 return build_error_marker_type (cu
, die
);
22660 /* If not cached we need to read it in. */
22662 if (this_type
== NULL
)
22664 struct die_info
*type_die
= NULL
;
22665 struct dwarf2_cu
*type_cu
= cu
;
22667 if (attr
->form_is_ref ())
22668 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22669 if (type_die
== NULL
)
22670 return build_error_marker_type (cu
, die
);
22671 /* If we find the type now, it's probably because the type came
22672 from an inter-CU reference and the type's CU got expanded before
22674 this_type
= read_type_die (type_die
, type_cu
);
22677 /* If we still don't have a type use an error marker. */
22679 if (this_type
== NULL
)
22680 return build_error_marker_type (cu
, die
);
22685 /* Return the type in DIE, CU.
22686 Returns NULL for invalid types.
22688 This first does a lookup in die_type_hash,
22689 and only reads the die in if necessary.
22691 NOTE: This can be called when reading in partial or full symbols. */
22693 static struct type
*
22694 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22696 struct type
*this_type
;
22698 this_type
= get_die_type (die
, cu
);
22702 return read_type_die_1 (die
, cu
);
22705 /* Read the type in DIE, CU.
22706 Returns NULL for invalid types. */
22708 static struct type
*
22709 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22711 struct type
*this_type
= NULL
;
22715 case DW_TAG_class_type
:
22716 case DW_TAG_interface_type
:
22717 case DW_TAG_structure_type
:
22718 case DW_TAG_union_type
:
22719 this_type
= read_structure_type (die
, cu
);
22721 case DW_TAG_enumeration_type
:
22722 this_type
= read_enumeration_type (die
, cu
);
22724 case DW_TAG_subprogram
:
22725 case DW_TAG_subroutine_type
:
22726 case DW_TAG_inlined_subroutine
:
22727 this_type
= read_subroutine_type (die
, cu
);
22729 case DW_TAG_array_type
:
22730 this_type
= read_array_type (die
, cu
);
22732 case DW_TAG_set_type
:
22733 this_type
= read_set_type (die
, cu
);
22735 case DW_TAG_pointer_type
:
22736 this_type
= read_tag_pointer_type (die
, cu
);
22738 case DW_TAG_ptr_to_member_type
:
22739 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22741 case DW_TAG_reference_type
:
22742 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22744 case DW_TAG_rvalue_reference_type
:
22745 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22747 case DW_TAG_const_type
:
22748 this_type
= read_tag_const_type (die
, cu
);
22750 case DW_TAG_volatile_type
:
22751 this_type
= read_tag_volatile_type (die
, cu
);
22753 case DW_TAG_restrict_type
:
22754 this_type
= read_tag_restrict_type (die
, cu
);
22756 case DW_TAG_string_type
:
22757 this_type
= read_tag_string_type (die
, cu
);
22759 case DW_TAG_typedef
:
22760 this_type
= read_typedef (die
, cu
);
22762 case DW_TAG_subrange_type
:
22763 this_type
= read_subrange_type (die
, cu
);
22765 case DW_TAG_base_type
:
22766 this_type
= read_base_type (die
, cu
);
22768 case DW_TAG_unspecified_type
:
22769 this_type
= read_unspecified_type (die
, cu
);
22771 case DW_TAG_namespace
:
22772 this_type
= read_namespace_type (die
, cu
);
22774 case DW_TAG_module
:
22775 this_type
= read_module_type (die
, cu
);
22777 case DW_TAG_atomic_type
:
22778 this_type
= read_tag_atomic_type (die
, cu
);
22781 complaint (_("unexpected tag in read_type_die: '%s'"),
22782 dwarf_tag_name (die
->tag
));
22789 /* See if we can figure out if the class lives in a namespace. We do
22790 this by looking for a member function; its demangled name will
22791 contain namespace info, if there is any.
22792 Return the computed name or NULL.
22793 Space for the result is allocated on the objfile's obstack.
22794 This is the full-die version of guess_partial_die_structure_name.
22795 In this case we know DIE has no useful parent. */
22797 static const char *
22798 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22800 struct die_info
*spec_die
;
22801 struct dwarf2_cu
*spec_cu
;
22802 struct die_info
*child
;
22803 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22806 spec_die
= die_specification (die
, &spec_cu
);
22807 if (spec_die
!= NULL
)
22813 for (child
= die
->child
;
22815 child
= child
->sibling
)
22817 if (child
->tag
== DW_TAG_subprogram
)
22819 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22821 if (linkage_name
!= NULL
)
22823 gdb::unique_xmalloc_ptr
<char> actual_name
22824 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22825 const char *name
= NULL
;
22827 if (actual_name
!= NULL
)
22829 const char *die_name
= dwarf2_name (die
, cu
);
22831 if (die_name
!= NULL
22832 && strcmp (die_name
, actual_name
.get ()) != 0)
22834 /* Strip off the class name from the full name.
22835 We want the prefix. */
22836 int die_name_len
= strlen (die_name
);
22837 int actual_name_len
= strlen (actual_name
.get ());
22838 const char *ptr
= actual_name
.get ();
22840 /* Test for '::' as a sanity check. */
22841 if (actual_name_len
> die_name_len
+ 2
22842 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22843 name
= obstack_strndup (
22844 &objfile
->per_bfd
->storage_obstack
,
22845 ptr
, actual_name_len
- die_name_len
- 2);
22856 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22857 prefix part in such case. See
22858 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22860 static const char *
22861 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22863 struct attribute
*attr
;
22866 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22867 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22870 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22873 attr
= dw2_linkage_name_attr (die
, cu
);
22874 const char *attr_name
= attr
->as_string ();
22875 if (attr
== NULL
|| attr_name
== NULL
)
22878 /* dwarf2_name had to be already called. */
22879 gdb_assert (attr
->canonical_string_p ());
22881 /* Strip the base name, keep any leading namespaces/classes. */
22882 base
= strrchr (attr_name
, ':');
22883 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22886 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22887 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22889 &base
[-1] - attr_name
);
22892 /* Return the name of the namespace/class that DIE is defined within,
22893 or "" if we can't tell. The caller should not xfree the result.
22895 For example, if we're within the method foo() in the following
22905 then determine_prefix on foo's die will return "N::C". */
22907 static const char *
22908 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22910 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22911 struct die_info
*parent
, *spec_die
;
22912 struct dwarf2_cu
*spec_cu
;
22913 struct type
*parent_type
;
22914 const char *retval
;
22916 if (cu
->language
!= language_cplus
22917 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22918 && cu
->language
!= language_rust
)
22921 retval
= anonymous_struct_prefix (die
, cu
);
22925 /* We have to be careful in the presence of DW_AT_specification.
22926 For example, with GCC 3.4, given the code
22930 // Definition of N::foo.
22934 then we'll have a tree of DIEs like this:
22936 1: DW_TAG_compile_unit
22937 2: DW_TAG_namespace // N
22938 3: DW_TAG_subprogram // declaration of N::foo
22939 4: DW_TAG_subprogram // definition of N::foo
22940 DW_AT_specification // refers to die #3
22942 Thus, when processing die #4, we have to pretend that we're in
22943 the context of its DW_AT_specification, namely the contex of die
22946 spec_die
= die_specification (die
, &spec_cu
);
22947 if (spec_die
== NULL
)
22948 parent
= die
->parent
;
22951 parent
= spec_die
->parent
;
22955 if (parent
== NULL
)
22957 else if (parent
->building_fullname
)
22960 const char *parent_name
;
22962 /* It has been seen on RealView 2.2 built binaries,
22963 DW_TAG_template_type_param types actually _defined_ as
22964 children of the parent class:
22967 template class <class Enum> Class{};
22968 Class<enum E> class_e;
22970 1: DW_TAG_class_type (Class)
22971 2: DW_TAG_enumeration_type (E)
22972 3: DW_TAG_enumerator (enum1:0)
22973 3: DW_TAG_enumerator (enum2:1)
22975 2: DW_TAG_template_type_param
22976 DW_AT_type DW_FORM_ref_udata (E)
22978 Besides being broken debug info, it can put GDB into an
22979 infinite loop. Consider:
22981 When we're building the full name for Class<E>, we'll start
22982 at Class, and go look over its template type parameters,
22983 finding E. We'll then try to build the full name of E, and
22984 reach here. We're now trying to build the full name of E,
22985 and look over the parent DIE for containing scope. In the
22986 broken case, if we followed the parent DIE of E, we'd again
22987 find Class, and once again go look at its template type
22988 arguments, etc., etc. Simply don't consider such parent die
22989 as source-level parent of this die (it can't be, the language
22990 doesn't allow it), and break the loop here. */
22991 name
= dwarf2_name (die
, cu
);
22992 parent_name
= dwarf2_name (parent
, cu
);
22993 complaint (_("template param type '%s' defined within parent '%s'"),
22994 name
? name
: "<unknown>",
22995 parent_name
? parent_name
: "<unknown>");
22999 switch (parent
->tag
)
23001 case DW_TAG_namespace
:
23002 parent_type
= read_type_die (parent
, cu
);
23003 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
23004 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
23005 Work around this problem here. */
23006 if (cu
->language
== language_cplus
23007 && strcmp (parent_type
->name (), "::") == 0)
23009 /* We give a name to even anonymous namespaces. */
23010 return parent_type
->name ();
23011 case DW_TAG_class_type
:
23012 case DW_TAG_interface_type
:
23013 case DW_TAG_structure_type
:
23014 case DW_TAG_union_type
:
23015 case DW_TAG_module
:
23016 parent_type
= read_type_die (parent
, cu
);
23017 if (parent_type
->name () != NULL
)
23018 return parent_type
->name ();
23020 /* An anonymous structure is only allowed non-static data
23021 members; no typedefs, no member functions, et cetera.
23022 So it does not need a prefix. */
23024 case DW_TAG_compile_unit
:
23025 case DW_TAG_partial_unit
:
23026 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
23027 if (cu
->language
== language_cplus
23028 && !per_objfile
->per_bfd
->types
.empty ()
23029 && die
->child
!= NULL
23030 && (die
->tag
== DW_TAG_class_type
23031 || die
->tag
== DW_TAG_structure_type
23032 || die
->tag
== DW_TAG_union_type
))
23034 const char *name
= guess_full_die_structure_name (die
, cu
);
23039 case DW_TAG_subprogram
:
23040 /* Nested subroutines in Fortran get a prefix with the name
23041 of the parent's subroutine. */
23042 if (cu
->language
== language_fortran
)
23044 if ((die
->tag
== DW_TAG_subprogram
)
23045 && (dwarf2_name (parent
, cu
) != NULL
))
23046 return dwarf2_name (parent
, cu
);
23048 return determine_prefix (parent
, cu
);
23049 case DW_TAG_enumeration_type
:
23050 parent_type
= read_type_die (parent
, cu
);
23051 if (parent_type
->is_declared_class ())
23053 if (parent_type
->name () != NULL
)
23054 return parent_type
->name ();
23057 /* Fall through. */
23059 return determine_prefix (parent
, cu
);
23063 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
23064 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
23065 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
23066 an obconcat, otherwise allocate storage for the result. The CU argument is
23067 used to determine the language and hence, the appropriate separator. */
23069 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
23072 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
23073 int physname
, struct dwarf2_cu
*cu
)
23075 const char *lead
= "";
23078 if (suffix
== NULL
|| suffix
[0] == '\0'
23079 || prefix
== NULL
|| prefix
[0] == '\0')
23081 else if (cu
->language
== language_d
)
23083 /* For D, the 'main' function could be defined in any module, but it
23084 should never be prefixed. */
23085 if (strcmp (suffix
, "D main") == 0)
23093 else if (cu
->language
== language_fortran
&& physname
)
23095 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
23096 DW_AT_MIPS_linkage_name is preferred and used instead. */
23104 if (prefix
== NULL
)
23106 if (suffix
== NULL
)
23113 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
23115 strcpy (retval
, lead
);
23116 strcat (retval
, prefix
);
23117 strcat (retval
, sep
);
23118 strcat (retval
, suffix
);
23123 /* We have an obstack. */
23124 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
23128 /* Get name of a die, return NULL if not found. */
23130 static const char *
23131 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
23132 struct objfile
*objfile
)
23134 if (name
&& cu
->language
== language_cplus
)
23136 gdb::unique_xmalloc_ptr
<char> canon_name
23137 = cp_canonicalize_string (name
);
23139 if (canon_name
!= nullptr)
23140 name
= objfile
->intern (canon_name
.get ());
23146 /* Get name of a die, return NULL if not found.
23147 Anonymous namespaces are converted to their magic string. */
23149 static const char *
23150 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23152 struct attribute
*attr
;
23153 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23155 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23156 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23157 if (attr_name
== nullptr
23158 && die
->tag
!= DW_TAG_namespace
23159 && die
->tag
!= DW_TAG_class_type
23160 && die
->tag
!= DW_TAG_interface_type
23161 && die
->tag
!= DW_TAG_structure_type
23162 && die
->tag
!= DW_TAG_union_type
)
23167 case DW_TAG_compile_unit
:
23168 case DW_TAG_partial_unit
:
23169 /* Compilation units have a DW_AT_name that is a filename, not
23170 a source language identifier. */
23171 case DW_TAG_enumeration_type
:
23172 case DW_TAG_enumerator
:
23173 /* These tags always have simple identifiers already; no need
23174 to canonicalize them. */
23177 case DW_TAG_namespace
:
23178 if (attr_name
!= nullptr)
23180 return CP_ANONYMOUS_NAMESPACE_STR
;
23182 case DW_TAG_class_type
:
23183 case DW_TAG_interface_type
:
23184 case DW_TAG_structure_type
:
23185 case DW_TAG_union_type
:
23186 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23187 structures or unions. These were of the form "._%d" in GCC 4.1,
23188 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23189 and GCC 4.4. We work around this problem by ignoring these. */
23190 if (attr_name
!= nullptr
23191 && (startswith (attr_name
, "._")
23192 || startswith (attr_name
, "<anonymous")))
23195 /* GCC might emit a nameless typedef that has a linkage name. See
23196 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23197 if (!attr
|| attr_name
== NULL
)
23199 attr
= dw2_linkage_name_attr (die
, cu
);
23200 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23201 if (attr
== NULL
|| attr_name
== NULL
)
23204 /* Avoid demangling attr_name the second time on a second
23205 call for the same DIE. */
23206 if (!attr
->canonical_string_p ())
23208 gdb::unique_xmalloc_ptr
<char> demangled
23209 (gdb_demangle (attr_name
, DMGL_TYPES
));
23210 if (demangled
== nullptr)
23213 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
23214 attr_name
= attr
->as_string ();
23217 /* Strip any leading namespaces/classes, keep only the
23218 base name. DW_AT_name for named DIEs does not
23219 contain the prefixes. */
23220 const char *base
= strrchr (attr_name
, ':');
23221 if (base
&& base
> attr_name
&& base
[-1] == ':')
23232 if (!attr
->canonical_string_p ())
23233 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
23235 return attr
->as_string ();
23238 /* Return the die that this die in an extension of, or NULL if there
23239 is none. *EXT_CU is the CU containing DIE on input, and the CU
23240 containing the return value on output. */
23242 static struct die_info
*
23243 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23245 struct attribute
*attr
;
23247 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23251 return follow_die_ref (die
, attr
, ext_cu
);
23255 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23259 print_spaces (indent
, f
);
23260 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23261 dwarf_tag_name (die
->tag
), die
->abbrev
,
23262 sect_offset_str (die
->sect_off
));
23264 if (die
->parent
!= NULL
)
23266 print_spaces (indent
, f
);
23267 fprintf_unfiltered (f
, " parent at offset: %s\n",
23268 sect_offset_str (die
->parent
->sect_off
));
23271 print_spaces (indent
, f
);
23272 fprintf_unfiltered (f
, " has children: %s\n",
23273 dwarf_bool_name (die
->child
!= NULL
));
23275 print_spaces (indent
, f
);
23276 fprintf_unfiltered (f
, " attributes:\n");
23278 for (i
= 0; i
< die
->num_attrs
; ++i
)
23280 print_spaces (indent
, f
);
23281 fprintf_unfiltered (f
, " %s (%s) ",
23282 dwarf_attr_name (die
->attrs
[i
].name
),
23283 dwarf_form_name (die
->attrs
[i
].form
));
23285 switch (die
->attrs
[i
].form
)
23288 case DW_FORM_addrx
:
23289 case DW_FORM_GNU_addr_index
:
23290 fprintf_unfiltered (f
, "address: ");
23291 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
23293 case DW_FORM_block2
:
23294 case DW_FORM_block4
:
23295 case DW_FORM_block
:
23296 case DW_FORM_block1
:
23297 fprintf_unfiltered (f
, "block: size %s",
23298 pulongest (die
->attrs
[i
].as_block ()->size
));
23300 case DW_FORM_exprloc
:
23301 fprintf_unfiltered (f
, "expression: size %s",
23302 pulongest (die
->attrs
[i
].as_block ()->size
));
23304 case DW_FORM_data16
:
23305 fprintf_unfiltered (f
, "constant of 16 bytes");
23307 case DW_FORM_ref_addr
:
23308 fprintf_unfiltered (f
, "ref address: ");
23309 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23311 case DW_FORM_GNU_ref_alt
:
23312 fprintf_unfiltered (f
, "alt ref address: ");
23313 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23319 case DW_FORM_ref_udata
:
23320 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23321 (long) (die
->attrs
[i
].as_unsigned ()));
23323 case DW_FORM_data1
:
23324 case DW_FORM_data2
:
23325 case DW_FORM_data4
:
23326 case DW_FORM_data8
:
23327 case DW_FORM_udata
:
23328 fprintf_unfiltered (f
, "constant: %s",
23329 pulongest (die
->attrs
[i
].as_unsigned ()));
23331 case DW_FORM_sec_offset
:
23332 fprintf_unfiltered (f
, "section offset: %s",
23333 pulongest (die
->attrs
[i
].as_unsigned ()));
23335 case DW_FORM_ref_sig8
:
23336 fprintf_unfiltered (f
, "signature: %s",
23337 hex_string (die
->attrs
[i
].as_signature ()));
23339 case DW_FORM_string
:
23341 case DW_FORM_line_strp
:
23343 case DW_FORM_GNU_str_index
:
23344 case DW_FORM_GNU_strp_alt
:
23345 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23346 die
->attrs
[i
].as_string ()
23347 ? die
->attrs
[i
].as_string () : "",
23348 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23351 if (die
->attrs
[i
].as_boolean ())
23352 fprintf_unfiltered (f
, "flag: TRUE");
23354 fprintf_unfiltered (f
, "flag: FALSE");
23356 case DW_FORM_flag_present
:
23357 fprintf_unfiltered (f
, "flag: TRUE");
23359 case DW_FORM_indirect
:
23360 /* The reader will have reduced the indirect form to
23361 the "base form" so this form should not occur. */
23362 fprintf_unfiltered (f
,
23363 "unexpected attribute form: DW_FORM_indirect");
23365 case DW_FORM_sdata
:
23366 case DW_FORM_implicit_const
:
23367 fprintf_unfiltered (f
, "constant: %s",
23368 plongest (die
->attrs
[i
].as_signed ()));
23371 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23372 die
->attrs
[i
].form
);
23375 fprintf_unfiltered (f
, "\n");
23380 dump_die_for_error (struct die_info
*die
)
23382 dump_die_shallow (gdb_stderr
, 0, die
);
23386 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23388 int indent
= level
* 4;
23390 gdb_assert (die
!= NULL
);
23392 if (level
>= max_level
)
23395 dump_die_shallow (f
, indent
, die
);
23397 if (die
->child
!= NULL
)
23399 print_spaces (indent
, f
);
23400 fprintf_unfiltered (f
, " Children:");
23401 if (level
+ 1 < max_level
)
23403 fprintf_unfiltered (f
, "\n");
23404 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23408 fprintf_unfiltered (f
,
23409 " [not printed, max nesting level reached]\n");
23413 if (die
->sibling
!= NULL
&& level
> 0)
23415 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23419 /* This is called from the pdie macro in gdbinit.in.
23420 It's not static so gcc will keep a copy callable from gdb. */
23423 dump_die (struct die_info
*die
, int max_level
)
23425 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23429 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23433 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23434 to_underlying (die
->sect_off
),
23440 /* Follow reference or signature attribute ATTR of SRC_DIE.
23441 On entry *REF_CU is the CU of SRC_DIE.
23442 On exit *REF_CU is the CU of the result. */
23444 static struct die_info
*
23445 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23446 struct dwarf2_cu
**ref_cu
)
23448 struct die_info
*die
;
23450 if (attr
->form_is_ref ())
23451 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23452 else if (attr
->form
== DW_FORM_ref_sig8
)
23453 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23456 dump_die_for_error (src_die
);
23457 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23458 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23464 /* Follow reference OFFSET.
23465 On entry *REF_CU is the CU of the source die referencing OFFSET.
23466 On exit *REF_CU is the CU of the result.
23467 Returns NULL if OFFSET is invalid. */
23469 static struct die_info
*
23470 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23471 struct dwarf2_cu
**ref_cu
)
23473 struct die_info temp_die
;
23474 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23475 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23477 gdb_assert (cu
->per_cu
!= NULL
);
23481 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23482 "source CU contains target offset: %d",
23483 sect_offset_str (cu
->per_cu
->sect_off
),
23484 sect_offset_str (sect_off
),
23485 cu
->header
.offset_in_cu_p (sect_off
));
23487 if (cu
->per_cu
->is_debug_types
)
23489 /* .debug_types CUs cannot reference anything outside their CU.
23490 If they need to, they have to reference a signatured type via
23491 DW_FORM_ref_sig8. */
23492 if (!cu
->header
.offset_in_cu_p (sect_off
))
23495 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23496 || !cu
->header
.offset_in_cu_p (sect_off
))
23498 struct dwarf2_per_cu_data
*per_cu
;
23500 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23503 dwarf_read_debug_printf_v ("target CU offset: %s, "
23504 "target CU DIEs loaded: %d",
23505 sect_offset_str (per_cu
->sect_off
),
23506 per_objfile
->get_cu (per_cu
) != nullptr);
23508 /* If necessary, add it to the queue and load its DIEs.
23510 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23511 it doesn't mean they are currently loaded. Since we require them
23512 to be loaded, we must check for ourselves. */
23513 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
)
23514 || per_objfile
->get_cu (per_cu
) == nullptr)
23515 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23516 false, cu
->language
);
23518 target_cu
= per_objfile
->get_cu (per_cu
);
23519 gdb_assert (target_cu
!= nullptr);
23521 else if (cu
->dies
== NULL
)
23523 /* We're loading full DIEs during partial symbol reading. */
23524 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23525 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23529 *ref_cu
= target_cu
;
23530 temp_die
.sect_off
= sect_off
;
23532 if (target_cu
!= cu
)
23533 target_cu
->ancestor
= cu
;
23535 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23537 to_underlying (sect_off
));
23540 /* Follow reference attribute ATTR of SRC_DIE.
23541 On entry *REF_CU is the CU of SRC_DIE.
23542 On exit *REF_CU is the CU of the result. */
23544 static struct die_info
*
23545 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23546 struct dwarf2_cu
**ref_cu
)
23548 sect_offset sect_off
= attr
->get_ref_die_offset ();
23549 struct dwarf2_cu
*cu
= *ref_cu
;
23550 struct die_info
*die
;
23552 die
= follow_die_offset (sect_off
,
23553 (attr
->form
== DW_FORM_GNU_ref_alt
23554 || cu
->per_cu
->is_dwz
),
23557 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23558 "at %s [in module %s]"),
23559 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23560 objfile_name (cu
->per_objfile
->objfile
));
23567 struct dwarf2_locexpr_baton
23568 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23569 dwarf2_per_cu_data
*per_cu
,
23570 dwarf2_per_objfile
*per_objfile
,
23571 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23572 bool resolve_abstract_p
)
23574 struct die_info
*die
;
23575 struct attribute
*attr
;
23576 struct dwarf2_locexpr_baton retval
;
23577 struct objfile
*objfile
= per_objfile
->objfile
;
23579 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23581 cu
= load_cu (per_cu
, per_objfile
, false);
23585 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23586 Instead just throw an error, not much else we can do. */
23587 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23588 sect_offset_str (sect_off
), objfile_name (objfile
));
23591 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23593 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23594 sect_offset_str (sect_off
), objfile_name (objfile
));
23596 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23597 if (!attr
&& resolve_abstract_p
23598 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23599 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23601 CORE_ADDR pc
= get_frame_pc ();
23602 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23603 struct gdbarch
*gdbarch
= objfile
->arch ();
23605 for (const auto &cand_off
23606 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23608 struct dwarf2_cu
*cand_cu
= cu
;
23609 struct die_info
*cand
23610 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23613 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23616 CORE_ADDR pc_low
, pc_high
;
23617 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23618 if (pc_low
== ((CORE_ADDR
) -1))
23620 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23621 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23622 if (!(pc_low
<= pc
&& pc
< pc_high
))
23626 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23633 /* DWARF: "If there is no such attribute, then there is no effect.".
23634 DATA is ignored if SIZE is 0. */
23636 retval
.data
= NULL
;
23639 else if (attr
->form_is_section_offset ())
23641 struct dwarf2_loclist_baton loclist_baton
;
23642 CORE_ADDR pc
= get_frame_pc ();
23645 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23647 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23649 retval
.size
= size
;
23653 if (!attr
->form_is_block ())
23654 error (_("Dwarf Error: DIE at %s referenced in module %s "
23655 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23656 sect_offset_str (sect_off
), objfile_name (objfile
));
23658 struct dwarf_block
*block
= attr
->as_block ();
23659 retval
.data
= block
->data
;
23660 retval
.size
= block
->size
;
23662 retval
.per_objfile
= per_objfile
;
23663 retval
.per_cu
= cu
->per_cu
;
23665 per_objfile
->age_comp_units ();
23672 struct dwarf2_locexpr_baton
23673 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23674 dwarf2_per_cu_data
*per_cu
,
23675 dwarf2_per_objfile
*per_objfile
,
23676 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23678 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23680 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23684 /* Write a constant of a given type as target-ordered bytes into
23687 static const gdb_byte
*
23688 write_constant_as_bytes (struct obstack
*obstack
,
23689 enum bfd_endian byte_order
,
23696 *len
= TYPE_LENGTH (type
);
23697 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23698 store_unsigned_integer (result
, *len
, byte_order
, value
);
23706 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23707 dwarf2_per_cu_data
*per_cu
,
23708 dwarf2_per_objfile
*per_objfile
,
23712 struct die_info
*die
;
23713 struct attribute
*attr
;
23714 const gdb_byte
*result
= NULL
;
23717 enum bfd_endian byte_order
;
23718 struct objfile
*objfile
= per_objfile
->objfile
;
23720 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23722 cu
= load_cu (per_cu
, per_objfile
, false);
23726 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23727 Instead just throw an error, not much else we can do. */
23728 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23729 sect_offset_str (sect_off
), objfile_name (objfile
));
23732 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23734 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23735 sect_offset_str (sect_off
), objfile_name (objfile
));
23737 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23741 byte_order
= (bfd_big_endian (objfile
->obfd
)
23742 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23744 switch (attr
->form
)
23747 case DW_FORM_addrx
:
23748 case DW_FORM_GNU_addr_index
:
23752 *len
= cu
->header
.addr_size
;
23753 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23754 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23758 case DW_FORM_string
:
23761 case DW_FORM_GNU_str_index
:
23762 case DW_FORM_GNU_strp_alt
:
23763 /* The string is already allocated on the objfile obstack, point
23766 const char *attr_name
= attr
->as_string ();
23767 result
= (const gdb_byte
*) attr_name
;
23768 *len
= strlen (attr_name
);
23771 case DW_FORM_block1
:
23772 case DW_FORM_block2
:
23773 case DW_FORM_block4
:
23774 case DW_FORM_block
:
23775 case DW_FORM_exprloc
:
23776 case DW_FORM_data16
:
23778 struct dwarf_block
*block
= attr
->as_block ();
23779 result
= block
->data
;
23780 *len
= block
->size
;
23784 /* The DW_AT_const_value attributes are supposed to carry the
23785 symbol's value "represented as it would be on the target
23786 architecture." By the time we get here, it's already been
23787 converted to host endianness, so we just need to sign- or
23788 zero-extend it as appropriate. */
23789 case DW_FORM_data1
:
23790 type
= die_type (die
, cu
);
23791 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23792 if (result
== NULL
)
23793 result
= write_constant_as_bytes (obstack
, byte_order
,
23796 case DW_FORM_data2
:
23797 type
= die_type (die
, cu
);
23798 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23799 if (result
== NULL
)
23800 result
= write_constant_as_bytes (obstack
, byte_order
,
23803 case DW_FORM_data4
:
23804 type
= die_type (die
, cu
);
23805 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23806 if (result
== NULL
)
23807 result
= write_constant_as_bytes (obstack
, byte_order
,
23810 case DW_FORM_data8
:
23811 type
= die_type (die
, cu
);
23812 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23813 if (result
== NULL
)
23814 result
= write_constant_as_bytes (obstack
, byte_order
,
23818 case DW_FORM_sdata
:
23819 case DW_FORM_implicit_const
:
23820 type
= die_type (die
, cu
);
23821 result
= write_constant_as_bytes (obstack
, byte_order
,
23822 type
, attr
->as_signed (), len
);
23825 case DW_FORM_udata
:
23826 type
= die_type (die
, cu
);
23827 result
= write_constant_as_bytes (obstack
, byte_order
,
23828 type
, attr
->as_unsigned (), len
);
23832 complaint (_("unsupported const value attribute form: '%s'"),
23833 dwarf_form_name (attr
->form
));
23843 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23844 dwarf2_per_cu_data
*per_cu
,
23845 dwarf2_per_objfile
*per_objfile
)
23847 struct die_info
*die
;
23849 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23851 cu
= load_cu (per_cu
, per_objfile
, false);
23856 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23860 return die_type (die
, cu
);
23866 dwarf2_get_die_type (cu_offset die_offset
,
23867 dwarf2_per_cu_data
*per_cu
,
23868 dwarf2_per_objfile
*per_objfile
)
23870 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23871 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23874 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23875 On entry *REF_CU is the CU of SRC_DIE.
23876 On exit *REF_CU is the CU of the result.
23877 Returns NULL if the referenced DIE isn't found. */
23879 static struct die_info
*
23880 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23881 struct dwarf2_cu
**ref_cu
)
23883 struct die_info temp_die
;
23884 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23885 struct die_info
*die
;
23886 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23889 /* While it might be nice to assert sig_type->type == NULL here,
23890 we can get here for DW_AT_imported_declaration where we need
23891 the DIE not the type. */
23893 /* If necessary, add it to the queue and load its DIEs.
23895 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23896 it doesn't mean they are currently loaded. Since we require them
23897 to be loaded, we must check for ourselves. */
23898 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
23900 || per_objfile
->get_cu (&sig_type
->per_cu
) == nullptr)
23901 read_signatured_type (sig_type
, per_objfile
);
23903 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
23904 gdb_assert (sig_cu
!= NULL
);
23905 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23906 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23907 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23908 to_underlying (temp_die
.sect_off
));
23911 /* For .gdb_index version 7 keep track of included TUs.
23912 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23913 if (per_objfile
->per_bfd
->index_table
!= NULL
23914 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23916 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23921 sig_cu
->ancestor
= cu
;
23929 /* Follow signatured type referenced by ATTR in SRC_DIE.
23930 On entry *REF_CU is the CU of SRC_DIE.
23931 On exit *REF_CU is the CU of the result.
23932 The result is the DIE of the type.
23933 If the referenced type cannot be found an error is thrown. */
23935 static struct die_info
*
23936 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23937 struct dwarf2_cu
**ref_cu
)
23939 ULONGEST signature
= attr
->as_signature ();
23940 struct signatured_type
*sig_type
;
23941 struct die_info
*die
;
23943 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23945 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23946 /* sig_type will be NULL if the signatured type is missing from
23948 if (sig_type
== NULL
)
23950 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23951 " from DIE at %s [in module %s]"),
23952 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23953 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23956 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23959 dump_die_for_error (src_die
);
23960 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23961 " from DIE at %s [in module %s]"),
23962 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23963 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23969 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23970 reading in and processing the type unit if necessary. */
23972 static struct type
*
23973 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23974 struct dwarf2_cu
*cu
)
23976 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23977 struct signatured_type
*sig_type
;
23978 struct dwarf2_cu
*type_cu
;
23979 struct die_info
*type_die
;
23982 sig_type
= lookup_signatured_type (cu
, signature
);
23983 /* sig_type will be NULL if the signatured type is missing from
23985 if (sig_type
== NULL
)
23987 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23988 " from DIE at %s [in module %s]"),
23989 hex_string (signature
), sect_offset_str (die
->sect_off
),
23990 objfile_name (per_objfile
->objfile
));
23991 return build_error_marker_type (cu
, die
);
23994 /* If we already know the type we're done. */
23995 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23996 if (type
!= nullptr)
24000 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
24001 if (type_die
!= NULL
)
24003 /* N.B. We need to call get_die_type to ensure only one type for this DIE
24004 is created. This is important, for example, because for c++ classes
24005 we need TYPE_NAME set which is only done by new_symbol. Blech. */
24006 type
= read_type_die (type_die
, type_cu
);
24009 complaint (_("Dwarf Error: Cannot build signatured type %s"
24010 " referenced from DIE at %s [in module %s]"),
24011 hex_string (signature
), sect_offset_str (die
->sect_off
),
24012 objfile_name (per_objfile
->objfile
));
24013 type
= build_error_marker_type (cu
, die
);
24018 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24019 " from DIE at %s [in module %s]"),
24020 hex_string (signature
), sect_offset_str (die
->sect_off
),
24021 objfile_name (per_objfile
->objfile
));
24022 type
= build_error_marker_type (cu
, die
);
24025 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
24030 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
24031 reading in and processing the type unit if necessary. */
24033 static struct type
*
24034 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
24035 struct dwarf2_cu
*cu
) /* ARI: editCase function */
24037 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
24038 if (attr
->form_is_ref ())
24040 struct dwarf2_cu
*type_cu
= cu
;
24041 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24043 return read_type_die (type_die
, type_cu
);
24045 else if (attr
->form
== DW_FORM_ref_sig8
)
24047 return get_signatured_type (die
, attr
->as_signature (), cu
);
24051 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24053 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24054 " at %s [in module %s]"),
24055 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24056 objfile_name (per_objfile
->objfile
));
24057 return build_error_marker_type (cu
, die
);
24061 /* Load the DIEs associated with type unit PER_CU into memory. */
24064 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
24065 dwarf2_per_objfile
*per_objfile
)
24067 struct signatured_type
*sig_type
;
24069 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24070 gdb_assert (! per_cu
->type_unit_group_p ());
24072 /* We have the per_cu, but we need the signatured_type.
24073 Fortunately this is an easy translation. */
24074 gdb_assert (per_cu
->is_debug_types
);
24075 sig_type
= (struct signatured_type
*) per_cu
;
24077 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
24079 read_signatured_type (sig_type
, per_objfile
);
24081 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
24084 /* Read in a signatured type and build its CU and DIEs.
24085 If the type is a stub for the real type in a DWO file,
24086 read in the real type from the DWO file as well. */
24089 read_signatured_type (signatured_type
*sig_type
,
24090 dwarf2_per_objfile
*per_objfile
)
24092 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24094 gdb_assert (per_cu
->is_debug_types
);
24095 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
24097 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
24099 if (!reader
.dummy_p
)
24101 struct dwarf2_cu
*cu
= reader
.cu
;
24102 const gdb_byte
*info_ptr
= reader
.info_ptr
;
24104 gdb_assert (cu
->die_hash
== NULL
);
24106 htab_create_alloc_ex (cu
->header
.length
/ 12,
24110 &cu
->comp_unit_obstack
,
24111 hashtab_obstack_allocate
,
24112 dummy_obstack_deallocate
);
24114 if (reader
.comp_unit_die
->has_children
)
24115 reader
.comp_unit_die
->child
24116 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
24117 reader
.comp_unit_die
);
24118 cu
->dies
= reader
.comp_unit_die
;
24119 /* comp_unit_die is not stored in die_hash, no need. */
24121 /* We try not to read any attributes in this function, because
24122 not all CUs needed for references have been loaded yet, and
24123 symbol table processing isn't initialized. But we have to
24124 set the CU language, or we won't be able to build types
24125 correctly. Similarly, if we do not read the producer, we can
24126 not apply producer-specific interpretation. */
24127 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24132 sig_type
->per_cu
.tu_read
= 1;
24135 /* Decode simple location descriptions.
24136 Given a pointer to a dwarf block that defines a location, compute
24137 the location and return the value. If COMPUTED is non-null, it is
24138 set to true to indicate that decoding was successful, and false
24139 otherwise. If COMPUTED is null, then this function may emit a
24143 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
24145 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
24147 size_t size
= blk
->size
;
24148 const gdb_byte
*data
= blk
->data
;
24149 CORE_ADDR stack
[64];
24151 unsigned int bytes_read
, unsnd
;
24154 if (computed
!= nullptr)
24160 stack
[++stacki
] = 0;
24199 stack
[++stacki
] = op
- DW_OP_lit0
;
24234 stack
[++stacki
] = op
- DW_OP_reg0
;
24237 if (computed
== nullptr)
24238 dwarf2_complex_location_expr_complaint ();
24245 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24247 stack
[++stacki
] = unsnd
;
24250 if (computed
== nullptr)
24251 dwarf2_complex_location_expr_complaint ();
24258 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
24263 case DW_OP_const1u
:
24264 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24268 case DW_OP_const1s
:
24269 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24273 case DW_OP_const2u
:
24274 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24278 case DW_OP_const2s
:
24279 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24283 case DW_OP_const4u
:
24284 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24288 case DW_OP_const4s
:
24289 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24293 case DW_OP_const8u
:
24294 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24299 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24305 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24310 stack
[stacki
+ 1] = stack
[stacki
];
24315 stack
[stacki
- 1] += stack
[stacki
];
24319 case DW_OP_plus_uconst
:
24320 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24326 stack
[stacki
- 1] -= stack
[stacki
];
24331 /* If we're not the last op, then we definitely can't encode
24332 this using GDB's address_class enum. This is valid for partial
24333 global symbols, although the variable's address will be bogus
24337 if (computed
== nullptr)
24338 dwarf2_complex_location_expr_complaint ();
24344 case DW_OP_GNU_push_tls_address
:
24345 case DW_OP_form_tls_address
:
24346 /* The top of the stack has the offset from the beginning
24347 of the thread control block at which the variable is located. */
24348 /* Nothing should follow this operator, so the top of stack would
24350 /* This is valid for partial global symbols, but the variable's
24351 address will be bogus in the psymtab. Make it always at least
24352 non-zero to not look as a variable garbage collected by linker
24353 which have DW_OP_addr 0. */
24356 if (computed
== nullptr)
24357 dwarf2_complex_location_expr_complaint ();
24364 case DW_OP_GNU_uninit
:
24365 if (computed
!= nullptr)
24370 case DW_OP_GNU_addr_index
:
24371 case DW_OP_GNU_const_index
:
24372 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24378 if (computed
== nullptr)
24380 const char *name
= get_DW_OP_name (op
);
24383 complaint (_("unsupported stack op: '%s'"),
24386 complaint (_("unsupported stack op: '%02x'"),
24390 return (stack
[stacki
]);
24393 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24394 outside of the allocated space. Also enforce minimum>0. */
24395 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24397 if (computed
== nullptr)
24398 complaint (_("location description stack overflow"));
24404 if (computed
== nullptr)
24405 complaint (_("location description stack underflow"));
24410 if (computed
!= nullptr)
24412 return (stack
[stacki
]);
24415 /* memory allocation interface */
24417 static struct dwarf_block
*
24418 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24420 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24423 static struct die_info
*
24424 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24426 struct die_info
*die
;
24427 size_t size
= sizeof (struct die_info
);
24430 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24432 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24433 memset (die
, 0, sizeof (struct die_info
));
24439 /* Macro support. */
24441 /* An overload of dwarf_decode_macros that finds the correct section
24442 and ensures it is read in before calling the other overload. */
24445 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24446 int section_is_gnu
)
24448 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24449 struct objfile
*objfile
= per_objfile
->objfile
;
24450 const struct line_header
*lh
= cu
->line_header
;
24451 unsigned int offset_size
= cu
->header
.offset_size
;
24452 struct dwarf2_section_info
*section
;
24453 const char *section_name
;
24455 if (cu
->dwo_unit
!= nullptr)
24457 if (section_is_gnu
)
24459 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24460 section_name
= ".debug_macro.dwo";
24464 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24465 section_name
= ".debug_macinfo.dwo";
24470 if (section_is_gnu
)
24472 section
= &per_objfile
->per_bfd
->macro
;
24473 section_name
= ".debug_macro";
24477 section
= &per_objfile
->per_bfd
->macinfo
;
24478 section_name
= ".debug_macinfo";
24482 section
->read (objfile
);
24483 if (section
->buffer
== nullptr)
24485 complaint (_("missing %s section"), section_name
);
24489 buildsym_compunit
*builder
= cu
->get_builder ();
24491 struct dwarf2_section_info
*str_offsets_section
;
24492 struct dwarf2_section_info
*str_section
;
24493 ULONGEST str_offsets_base
;
24495 if (cu
->dwo_unit
!= nullptr)
24497 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24498 ->sections
.str_offsets
;
24499 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24500 str_offsets_base
= cu
->header
.addr_size
;
24504 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24505 str_section
= &per_objfile
->per_bfd
->str
;
24506 str_offsets_base
= *cu
->str_offsets_base
;
24509 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24510 offset_size
, offset
, str_section
, str_offsets_section
,
24511 str_offsets_base
, section_is_gnu
);
24514 /* Return the .debug_loc section to use for CU.
24515 For DWO files use .debug_loc.dwo. */
24517 static struct dwarf2_section_info
*
24518 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24520 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24524 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24526 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24528 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24529 : &per_objfile
->per_bfd
->loc
);
24532 /* Return the .debug_rnglists section to use for CU. */
24533 static struct dwarf2_section_info
*
24534 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24536 if (cu
->header
.version
< 5)
24537 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24538 cu
->header
.version
);
24539 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24541 /* Make sure we read the .debug_rnglists section from the file that
24542 contains the DW_AT_ranges attribute we are reading. Normally that
24543 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24544 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24546 if (cu
->dwo_unit
!= nullptr
24547 && tag
!= DW_TAG_compile_unit
24548 && tag
!= DW_TAG_skeleton_unit
)
24550 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24552 if (sections
->rnglists
.size
> 0)
24553 return §ions
->rnglists
;
24555 error (_(".debug_rnglists section is missing from .dwo file."));
24557 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24560 /* A helper function that fills in a dwarf2_loclist_baton. */
24563 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24564 struct dwarf2_loclist_baton
*baton
,
24565 const struct attribute
*attr
)
24567 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24568 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24570 section
->read (per_objfile
->objfile
);
24572 baton
->per_objfile
= per_objfile
;
24573 baton
->per_cu
= cu
->per_cu
;
24574 gdb_assert (baton
->per_cu
);
24575 /* We don't know how long the location list is, but make sure we
24576 don't run off the edge of the section. */
24577 baton
->size
= section
->size
- attr
->as_unsigned ();
24578 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24579 if (cu
->base_address
.has_value ())
24580 baton
->base_address
= *cu
->base_address
;
24582 baton
->base_address
= 0;
24583 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24587 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24588 struct dwarf2_cu
*cu
, int is_block
)
24590 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24591 struct objfile
*objfile
= per_objfile
->objfile
;
24592 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24594 if (attr
->form_is_section_offset ()
24595 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24596 the section. If so, fall through to the complaint in the
24598 && attr
->as_unsigned () < section
->get_size (objfile
))
24600 struct dwarf2_loclist_baton
*baton
;
24602 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24604 fill_in_loclist_baton (cu
, baton
, attr
);
24606 if (!cu
->base_address
.has_value ())
24607 complaint (_("Location list used without "
24608 "specifying the CU base address."));
24610 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24611 ? dwarf2_loclist_block_index
24612 : dwarf2_loclist_index
);
24613 SYMBOL_LOCATION_BATON (sym
) = baton
;
24617 struct dwarf2_locexpr_baton
*baton
;
24619 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24620 baton
->per_objfile
= per_objfile
;
24621 baton
->per_cu
= cu
->per_cu
;
24622 gdb_assert (baton
->per_cu
);
24624 if (attr
->form_is_block ())
24626 /* Note that we're just copying the block's data pointer
24627 here, not the actual data. We're still pointing into the
24628 info_buffer for SYM's objfile; right now we never release
24629 that buffer, but when we do clean up properly this may
24631 struct dwarf_block
*block
= attr
->as_block ();
24632 baton
->size
= block
->size
;
24633 baton
->data
= block
->data
;
24637 dwarf2_invalid_attrib_class_complaint ("location description",
24638 sym
->natural_name ());
24642 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24643 ? dwarf2_locexpr_block_index
24644 : dwarf2_locexpr_index
);
24645 SYMBOL_LOCATION_BATON (sym
) = baton
;
24651 const comp_unit_head
*
24652 dwarf2_per_cu_data::get_header () const
24654 if (!m_header_read_in
)
24656 const gdb_byte
*info_ptr
24657 = this->section
->buffer
+ to_underlying (this->sect_off
);
24659 memset (&m_header
, 0, sizeof (m_header
));
24661 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24662 rcuh_kind::COMPILE
);
24664 m_header_read_in
= true;
24673 dwarf2_per_cu_data::addr_size () const
24675 return this->get_header ()->addr_size
;
24681 dwarf2_per_cu_data::offset_size () const
24683 return this->get_header ()->offset_size
;
24689 dwarf2_per_cu_data::ref_addr_size () const
24691 const comp_unit_head
*header
= this->get_header ();
24693 if (header
->version
== 2)
24694 return header
->addr_size
;
24696 return header
->offset_size
;
24702 dwarf2_cu::addr_type () const
24704 struct objfile
*objfile
= this->per_objfile
->objfile
;
24705 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24706 struct type
*addr_type
= lookup_pointer_type (void_type
);
24707 int addr_size
= this->per_cu
->addr_size ();
24709 if (TYPE_LENGTH (addr_type
) == addr_size
)
24712 addr_type
= addr_sized_int_type (addr_type
->is_unsigned ());
24716 /* A helper function for dwarf2_find_containing_comp_unit that returns
24717 the index of the result, and that searches a vector. It will
24718 return a result even if the offset in question does not actually
24719 occur in any CU. This is separate so that it can be unit
24723 dwarf2_find_containing_comp_unit
24724 (sect_offset sect_off
,
24725 unsigned int offset_in_dwz
,
24726 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
24731 high
= all_comp_units
.size () - 1;
24734 struct dwarf2_per_cu_data
*mid_cu
;
24735 int mid
= low
+ (high
- low
) / 2;
24737 mid_cu
= all_comp_units
[mid
];
24738 if (mid_cu
->is_dwz
> offset_in_dwz
24739 || (mid_cu
->is_dwz
== offset_in_dwz
24740 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24745 gdb_assert (low
== high
);
24749 /* Locate the .debug_info compilation unit from CU's objfile which contains
24750 the DIE at OFFSET. Raises an error on failure. */
24752 static struct dwarf2_per_cu_data
*
24753 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24754 unsigned int offset_in_dwz
,
24755 dwarf2_per_objfile
*per_objfile
)
24757 int low
= dwarf2_find_containing_comp_unit
24758 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24759 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
24761 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24763 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24764 error (_("Dwarf Error: could not find partial DIE containing "
24765 "offset %s [in module %s]"),
24766 sect_offset_str (sect_off
),
24767 bfd_get_filename (per_objfile
->objfile
->obfd
));
24769 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24771 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
24775 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24776 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24777 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24778 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24785 namespace selftests
{
24786 namespace find_containing_comp_unit
{
24791 struct dwarf2_per_cu_data one
{};
24792 struct dwarf2_per_cu_data two
{};
24793 struct dwarf2_per_cu_data three
{};
24794 struct dwarf2_per_cu_data four
{};
24797 two
.sect_off
= sect_offset (one
.length
);
24802 four
.sect_off
= sect_offset (three
.length
);
24806 std::vector
<dwarf2_per_cu_data
*> units
;
24807 units
.push_back (&one
);
24808 units
.push_back (&two
);
24809 units
.push_back (&three
);
24810 units
.push_back (&four
);
24814 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24815 SELF_CHECK (units
[result
] == &one
);
24816 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24817 SELF_CHECK (units
[result
] == &one
);
24818 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24819 SELF_CHECK (units
[result
] == &two
);
24821 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24822 SELF_CHECK (units
[result
] == &three
);
24823 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24824 SELF_CHECK (units
[result
] == &three
);
24825 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24826 SELF_CHECK (units
[result
] == &four
);
24832 #endif /* GDB_SELF_TEST */
24834 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
24836 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
24837 dwarf2_per_objfile
*per_objfile
)
24839 per_objfile (per_objfile
),
24841 has_loclist (false),
24842 checked_producer (false),
24843 producer_is_gxx_lt_4_6 (false),
24844 producer_is_gcc_lt_4_3 (false),
24845 producer_is_icc (false),
24846 producer_is_icc_lt_14 (false),
24847 producer_is_codewarrior (false),
24848 processing_has_namespace_info (false)
24852 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24855 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24856 enum language pretend_language
)
24858 struct attribute
*attr
;
24860 /* Set the language we're debugging. */
24861 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24862 if (attr
!= nullptr)
24863 set_cu_language (attr
->constant_value (0), cu
);
24866 cu
->language
= pretend_language
;
24867 cu
->language_defn
= language_def (cu
->language
);
24870 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24876 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24878 auto it
= m_dwarf2_cus
.find (per_cu
);
24879 if (it
== m_dwarf2_cus
.end ())
24888 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24890 gdb_assert (this->get_cu (per_cu
) == nullptr);
24892 m_dwarf2_cus
[per_cu
] = cu
;
24898 dwarf2_per_objfile::age_comp_units ()
24900 dwarf_read_debug_printf_v ("running");
24902 /* This is not expected to be called in the middle of CU expansion. There is
24903 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
24904 loaded in memory. Calling age_comp_units while the queue is in use could
24905 make us free the DIEs for a CU that is in the queue and therefore break
24907 gdb_assert (!this->per_bfd
->queue
.has_value ());
24909 /* Start by clearing all marks. */
24910 for (auto pair
: m_dwarf2_cus
)
24911 pair
.second
->mark
= false;
24913 /* Traverse all CUs, mark them and their dependencies if used recently
24915 for (auto pair
: m_dwarf2_cus
)
24917 dwarf2_cu
*cu
= pair
.second
;
24920 if (cu
->last_used
<= dwarf_max_cache_age
)
24924 /* Delete all CUs still not marked. */
24925 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24927 dwarf2_cu
*cu
= it
->second
;
24931 dwarf_read_debug_printf_v ("deleting old CU %s",
24932 sect_offset_str (cu
->per_cu
->sect_off
));
24934 it
= m_dwarf2_cus
.erase (it
);
24944 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24946 auto it
= m_dwarf2_cus
.find (per_cu
);
24947 if (it
== m_dwarf2_cus
.end ())
24952 m_dwarf2_cus
.erase (it
);
24955 dwarf2_per_objfile::~dwarf2_per_objfile ()
24960 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24961 We store these in a hash table separate from the DIEs, and preserve them
24962 when the DIEs are flushed out of cache.
24964 The CU "per_cu" pointer is needed because offset alone is not enough to
24965 uniquely identify the type. A file may have multiple .debug_types sections,
24966 or the type may come from a DWO file. Furthermore, while it's more logical
24967 to use per_cu->section+offset, with Fission the section with the data is in
24968 the DWO file but we don't know that section at the point we need it.
24969 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24970 because we can enter the lookup routine, get_die_type_at_offset, from
24971 outside this file, and thus won't necessarily have PER_CU->cu.
24972 Fortunately, PER_CU is stable for the life of the objfile. */
24974 struct dwarf2_per_cu_offset_and_type
24976 const struct dwarf2_per_cu_data
*per_cu
;
24977 sect_offset sect_off
;
24981 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24984 per_cu_offset_and_type_hash (const void *item
)
24986 const struct dwarf2_per_cu_offset_and_type
*ofs
24987 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24989 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24992 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24995 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24997 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24998 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24999 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25000 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25002 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25003 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25006 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25007 table if necessary. For convenience, return TYPE.
25009 The DIEs reading must have careful ordering to:
25010 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25011 reading current DIE.
25012 * Not trying to dereference contents of still incompletely read in types
25013 while reading in other DIEs.
25014 * Enable referencing still incompletely read in types just by a pointer to
25015 the type without accessing its fields.
25017 Therefore caller should follow these rules:
25018 * Try to fetch any prerequisite types we may need to build this DIE type
25019 before building the type and calling set_die_type.
25020 * After building type call set_die_type for current DIE as soon as
25021 possible before fetching more types to complete the current type.
25022 * Make the type as complete as possible before fetching more types. */
25024 static struct type
*
25025 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
25026 bool skip_data_location
)
25028 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
25029 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25030 struct objfile
*objfile
= per_objfile
->objfile
;
25031 struct attribute
*attr
;
25032 struct dynamic_prop prop
;
25034 /* For Ada types, make sure that the gnat-specific data is always
25035 initialized (if not already set). There are a few types where
25036 we should not be doing so, because the type-specific area is
25037 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25038 where the type-specific area is used to store the floatformat).
25039 But this is not a problem, because the gnat-specific information
25040 is actually not needed for these types. */
25041 if (need_gnat_info (cu
)
25042 && type
->code () != TYPE_CODE_FUNC
25043 && type
->code () != TYPE_CODE_FLT
25044 && type
->code () != TYPE_CODE_METHODPTR
25045 && type
->code () != TYPE_CODE_MEMBERPTR
25046 && type
->code () != TYPE_CODE_METHOD
25047 && type
->code () != TYPE_CODE_FIXED_POINT
25048 && !HAVE_GNAT_AUX_INFO (type
))
25049 INIT_GNAT_SPECIFIC (type
);
25051 /* Read DW_AT_allocated and set in type. */
25052 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25055 struct type
*prop_type
= cu
->addr_sized_int_type (false);
25056 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25057 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
25060 /* Read DW_AT_associated and set in type. */
25061 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25064 struct type
*prop_type
= cu
->addr_sized_int_type (false);
25065 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25066 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
25069 /* Read DW_AT_data_location and set in type. */
25070 if (!skip_data_location
)
25072 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25073 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
25074 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
25077 if (per_objfile
->die_type_hash
== NULL
)
25078 per_objfile
->die_type_hash
25079 = htab_up (htab_create_alloc (127,
25080 per_cu_offset_and_type_hash
,
25081 per_cu_offset_and_type_eq
,
25082 NULL
, xcalloc
, xfree
));
25084 ofs
.per_cu
= cu
->per_cu
;
25085 ofs
.sect_off
= die
->sect_off
;
25087 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25088 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
25090 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25091 sect_offset_str (die
->sect_off
));
25092 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25093 struct dwarf2_per_cu_offset_and_type
);
25098 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25099 or return NULL if the die does not have a saved type. */
25101 static struct type
*
25102 get_die_type_at_offset (sect_offset sect_off
,
25103 dwarf2_per_cu_data
*per_cu
,
25104 dwarf2_per_objfile
*per_objfile
)
25106 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25108 if (per_objfile
->die_type_hash
== NULL
)
25111 ofs
.per_cu
= per_cu
;
25112 ofs
.sect_off
= sect_off
;
25113 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25114 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
25121 /* Look up the type for DIE in CU in die_type_hash,
25122 or return NULL if DIE does not have a saved type. */
25124 static struct type
*
25125 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25127 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
25130 /* Add a dependence relationship from CU to REF_PER_CU. */
25133 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25134 struct dwarf2_per_cu_data
*ref_per_cu
)
25138 if (cu
->dependencies
== NULL
)
25140 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25141 NULL
, &cu
->comp_unit_obstack
,
25142 hashtab_obstack_allocate
,
25143 dummy_obstack_deallocate
);
25145 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25147 *slot
= ref_per_cu
;
25150 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25151 Set the mark field in every compilation unit in the
25152 cache that we must keep because we are keeping CU.
25154 DATA is the dwarf2_per_objfile object in which to look up CUs. */
25157 dwarf2_mark_helper (void **slot
, void *data
)
25159 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
25160 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
25161 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
25163 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25164 reading of the chain. As such dependencies remain valid it is not much
25165 useful to track and undo them during QUIT cleanups. */
25174 if (cu
->dependencies
!= nullptr)
25175 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
25180 /* Set the mark field in CU and in every other compilation unit in the
25181 cache that we must keep because we are keeping CU. */
25184 dwarf2_mark (struct dwarf2_cu
*cu
)
25191 if (cu
->dependencies
!= nullptr)
25192 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
25195 /* Trivial hash function for partial_die_info: the hash value of a DIE
25196 is its offset in .debug_info for this objfile. */
25199 partial_die_hash (const void *item
)
25201 const struct partial_die_info
*part_die
25202 = (const struct partial_die_info
*) item
;
25204 return to_underlying (part_die
->sect_off
);
25207 /* Trivial comparison function for partial_die_info structures: two DIEs
25208 are equal if they have the same offset. */
25211 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25213 const struct partial_die_info
*part_die_lhs
25214 = (const struct partial_die_info
*) item_lhs
;
25215 const struct partial_die_info
*part_die_rhs
25216 = (const struct partial_die_info
*) item_rhs
;
25218 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25221 struct cmd_list_element
*set_dwarf_cmdlist
;
25222 struct cmd_list_element
*show_dwarf_cmdlist
;
25225 show_check_physname (struct ui_file
*file
, int from_tty
,
25226 struct cmd_list_element
*c
, const char *value
)
25228 fprintf_filtered (file
,
25229 _("Whether to check \"physname\" is %s.\n"),
25233 void _initialize_dwarf2_read ();
25235 _initialize_dwarf2_read ()
25237 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
25238 Set DWARF specific variables.\n\
25239 Configure DWARF variables such as the cache size."),
25240 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25241 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25243 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
25244 Show DWARF specific variables.\n\
25245 Show DWARF variables such as the cache size."),
25246 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25247 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25249 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25250 &dwarf_max_cache_age
, _("\
25251 Set the upper bound on the age of cached DWARF compilation units."), _("\
25252 Show the upper bound on the age of cached DWARF compilation units."), _("\
25253 A higher limit means that cached compilation units will be stored\n\
25254 in memory longer, and more total memory will be used. Zero disables\n\
25255 caching, which can slow down startup."),
25257 show_dwarf_max_cache_age
,
25258 &set_dwarf_cmdlist
,
25259 &show_dwarf_cmdlist
);
25261 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25262 Set debugging of the DWARF reader."), _("\
25263 Show debugging of the DWARF reader."), _("\
25264 When enabled (non-zero), debugging messages are printed during DWARF\n\
25265 reading and symtab expansion. A value of 1 (one) provides basic\n\
25266 information. A value greater than 1 provides more verbose information."),
25269 &setdebuglist
, &showdebuglist
);
25271 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25272 Set debugging of the DWARF DIE reader."), _("\
25273 Show debugging of the DWARF DIE reader."), _("\
25274 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25275 The value is the maximum depth to print."),
25278 &setdebuglist
, &showdebuglist
);
25280 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25281 Set debugging of the dwarf line reader."), _("\
25282 Show debugging of the dwarf line reader."), _("\
25283 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25284 A value of 1 (one) provides basic information.\n\
25285 A value greater than 1 provides more verbose information."),
25288 &setdebuglist
, &showdebuglist
);
25290 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25291 Set cross-checking of \"physname\" code against demangler."), _("\
25292 Show cross-checking of \"physname\" code against demangler."), _("\
25293 When enabled, GDB's internal \"physname\" code is checked against\n\
25295 NULL
, show_check_physname
,
25296 &setdebuglist
, &showdebuglist
);
25298 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25299 no_class
, &use_deprecated_index_sections
, _("\
25300 Set whether to use deprecated gdb_index sections."), _("\
25301 Show whether to use deprecated gdb_index sections."), _("\
25302 When enabled, deprecated .gdb_index sections are used anyway.\n\
25303 Normally they are ignored either because of a missing feature or\n\
25304 performance issue.\n\
25305 Warning: This option must be enabled before gdb reads the file."),
25308 &setlist
, &showlist
);
25310 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25311 &dwarf2_locexpr_funcs
);
25312 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25313 &dwarf2_loclist_funcs
);
25315 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25316 &dwarf2_block_frame_base_locexpr_funcs
);
25317 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25318 &dwarf2_block_frame_base_loclist_funcs
);
25321 selftests::register_test ("dw2_expand_symtabs_matching",
25322 selftests::dw2_expand_symtabs_matching::run_test
);
25323 selftests::register_test ("dwarf2_find_containing_comp_unit",
25324 selftests::find_containing_comp_unit::run_test
);