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"
91 #include <unordered_set>
93 /* When == 1, print basic high level tracing messages.
94 When > 1, be more verbose.
95 This is in contrast to the low level DIE reading of dwarf_die_debug. */
96 static unsigned int dwarf_read_debug
= 0;
98 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
100 #define dwarf_read_debug_printf(fmt, ...) \
101 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
104 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
106 #define dwarf_read_debug_printf_v(fmt, ...) \
107 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
110 /* When non-zero, dump DIEs after they are read in. */
111 static unsigned int dwarf_die_debug
= 0;
113 /* When non-zero, dump line number entries as they are read in. */
114 unsigned int dwarf_line_debug
= 0;
116 /* When true, cross-check physname against demangler. */
117 static bool check_physname
= false;
119 /* When true, do not reject deprecated .gdb_index sections. */
120 static bool use_deprecated_index_sections
= false;
122 /* This is used to store the data that is always per objfile. */
123 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
125 /* These are used to store the dwarf2_per_bfd objects.
127 objfiles having the same BFD, which doesn't require relocations, are going to
128 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
130 Other objfiles are not going to share a dwarf2_per_bfd with any other
131 objfiles, so they'll have their own version kept in the _objfile_data_key
133 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
134 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
136 /* The "aclass" indices for various kinds of computed DWARF symbols. */
138 static int dwarf2_locexpr_index
;
139 static int dwarf2_loclist_index
;
140 static int dwarf2_locexpr_block_index
;
141 static int dwarf2_loclist_block_index
;
143 /* Size of .debug_loclists section header for 32-bit DWARF format. */
144 #define LOCLIST_HEADER_SIZE32 12
146 /* Size of .debug_loclists section header for 64-bit DWARF format. */
147 #define LOCLIST_HEADER_SIZE64 20
149 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
150 #define RNGLIST_HEADER_SIZE32 12
152 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
153 #define RNGLIST_HEADER_SIZE64 20
155 /* An index into a (C++) symbol name component in a symbol name as
156 recorded in the mapped_index's symbol table. For each C++ symbol
157 in the symbol table, we record one entry for the start of each
158 component in the symbol in a table of name components, and then
159 sort the table, in order to be able to binary search symbol names,
160 ignoring leading namespaces, both completion and regular look up.
161 For example, for symbol "A::B::C", we'll have an entry that points
162 to "A::B::C", another that points to "B::C", and another for "C".
163 Note that function symbols in GDB index have no parameter
164 information, just the function/method names. You can convert a
165 name_component to a "const char *" using the
166 'mapped_index::symbol_name_at(offset_type)' method. */
168 struct name_component
170 /* Offset in the symbol name where the component starts. Stored as
171 a (32-bit) offset instead of a pointer to save memory and improve
172 locality on 64-bit architectures. */
173 offset_type name_offset
;
175 /* The symbol's index in the symbol and constant pool tables of a
180 /* Base class containing bits shared by both .gdb_index and
181 .debug_name indexes. */
183 struct mapped_index_base
185 mapped_index_base () = default;
186 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
188 /* The name_component table (a sorted vector). See name_component's
189 description above. */
190 std::vector
<name_component
> name_components
;
192 /* How NAME_COMPONENTS is sorted. */
193 enum case_sensitivity name_components_casing
;
195 /* Return the number of names in the symbol table. */
196 virtual size_t symbol_name_count () const = 0;
198 /* Get the name of the symbol at IDX in the symbol table. */
199 virtual const char *symbol_name_at
200 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
202 /* Return whether the name at IDX in the symbol table should be
204 virtual bool symbol_name_slot_invalid (offset_type idx
) const
209 /* Build the symbol name component sorted vector, if we haven't
211 void build_name_components (dwarf2_per_objfile
*per_objfile
);
213 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
214 possible matches for LN_NO_PARAMS in the name component
216 std::pair
<std::vector
<name_component
>::const_iterator
,
217 std::vector
<name_component
>::const_iterator
>
218 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
220 dwarf2_per_objfile
*per_objfile
) const;
222 /* Prevent deleting/destroying via a base class pointer. */
224 ~mapped_index_base() = default;
227 /* This is a view into the index that converts from bytes to an
228 offset_type, and allows indexing. Unaligned bytes are specifically
229 allowed here, and handled via unpacking. */
234 offset_view () = default;
236 explicit offset_view (gdb::array_view
<const gdb_byte
> bytes
)
241 /* Extract the INDEXth offset_type from the array. */
242 offset_type
operator[] (size_t index
) const
244 const gdb_byte
*bytes
= &m_bytes
[index
* sizeof (offset_type
)];
245 return (offset_type
) extract_unsigned_integer (bytes
,
246 sizeof (offset_type
),
250 /* Return the number of offset_types in this array. */
253 return m_bytes
.size () / sizeof (offset_type
);
256 /* Return true if this view is empty. */
259 return m_bytes
.empty ();
263 /* The underlying bytes. */
264 gdb::array_view
<const gdb_byte
> m_bytes
;
267 /* A description of the mapped index. The file format is described in
268 a comment by the code that writes the index. */
269 struct mapped_index final
: public mapped_index_base
271 /* Index data format version. */
274 /* The address table data. */
275 gdb::array_view
<const gdb_byte
> address_table
;
277 /* The symbol table, implemented as a hash table. */
278 offset_view symbol_table
;
280 /* A pointer to the constant pool. */
281 gdb::array_view
<const gdb_byte
> constant_pool
;
283 /* Return the index into the constant pool of the name of the IDXth
284 symbol in the symbol table. */
285 offset_type
symbol_name_index (offset_type idx
) const
287 return symbol_table
[2 * idx
];
290 /* Return the index into the constant pool of the CU vector of the
291 IDXth symbol in the symbol table. */
292 offset_type
symbol_vec_index (offset_type idx
) const
294 return symbol_table
[2 * idx
+ 1];
297 bool symbol_name_slot_invalid (offset_type idx
) const override
299 return (symbol_name_index (idx
) == 0
300 && symbol_vec_index (idx
) == 0);
303 /* Convenience method to get at the name of the symbol at IDX in the
305 const char *symbol_name_at
306 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
308 return (const char *) (this->constant_pool
.data ()
309 + symbol_name_index (idx
));
312 size_t symbol_name_count () const override
313 { return this->symbol_table
.size () / 2; }
316 /* A description of the mapped .debug_names.
317 Uninitialized map has CU_COUNT 0. */
318 struct mapped_debug_names final
: public mapped_index_base
320 bfd_endian dwarf5_byte_order
;
321 bool dwarf5_is_dwarf64
;
322 bool augmentation_is_gdb
;
324 uint32_t cu_count
= 0;
325 uint32_t tu_count
, bucket_count
, name_count
;
326 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
327 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
328 const gdb_byte
*name_table_string_offs_reordered
;
329 const gdb_byte
*name_table_entry_offs_reordered
;
330 const gdb_byte
*entry_pool
;
337 /* Attribute name DW_IDX_*. */
340 /* Attribute form DW_FORM_*. */
343 /* Value if FORM is DW_FORM_implicit_const. */
344 LONGEST implicit_const
;
346 std::vector
<attr
> attr_vec
;
349 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
351 const char *namei_to_name
352 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
354 /* Implementation of the mapped_index_base virtual interface, for
355 the name_components cache. */
357 const char *symbol_name_at
358 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
359 { return namei_to_name (idx
, per_objfile
); }
361 size_t symbol_name_count () const override
362 { return this->name_count
; }
365 /* See dwarf2read.h. */
368 get_dwarf2_per_objfile (struct objfile
*objfile
)
370 return dwarf2_objfile_data_key
.get (objfile
);
373 /* Default names of the debugging sections. */
375 /* Note that if the debugging section has been compressed, it might
376 have a name like .zdebug_info. */
378 const struct dwarf2_debug_sections dwarf2_elf_names
=
380 { ".debug_info", ".zdebug_info" },
381 { ".debug_abbrev", ".zdebug_abbrev" },
382 { ".debug_line", ".zdebug_line" },
383 { ".debug_loc", ".zdebug_loc" },
384 { ".debug_loclists", ".zdebug_loclists" },
385 { ".debug_macinfo", ".zdebug_macinfo" },
386 { ".debug_macro", ".zdebug_macro" },
387 { ".debug_str", ".zdebug_str" },
388 { ".debug_str_offsets", ".zdebug_str_offsets" },
389 { ".debug_line_str", ".zdebug_line_str" },
390 { ".debug_ranges", ".zdebug_ranges" },
391 { ".debug_rnglists", ".zdebug_rnglists" },
392 { ".debug_types", ".zdebug_types" },
393 { ".debug_addr", ".zdebug_addr" },
394 { ".debug_frame", ".zdebug_frame" },
395 { ".eh_frame", NULL
},
396 { ".gdb_index", ".zgdb_index" },
397 { ".debug_names", ".zdebug_names" },
398 { ".debug_aranges", ".zdebug_aranges" },
402 /* List of DWO/DWP sections. */
404 static const struct dwop_section_names
406 struct dwarf2_section_names abbrev_dwo
;
407 struct dwarf2_section_names info_dwo
;
408 struct dwarf2_section_names line_dwo
;
409 struct dwarf2_section_names loc_dwo
;
410 struct dwarf2_section_names loclists_dwo
;
411 struct dwarf2_section_names macinfo_dwo
;
412 struct dwarf2_section_names macro_dwo
;
413 struct dwarf2_section_names rnglists_dwo
;
414 struct dwarf2_section_names str_dwo
;
415 struct dwarf2_section_names str_offsets_dwo
;
416 struct dwarf2_section_names types_dwo
;
417 struct dwarf2_section_names cu_index
;
418 struct dwarf2_section_names tu_index
;
422 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
423 { ".debug_info.dwo", ".zdebug_info.dwo" },
424 { ".debug_line.dwo", ".zdebug_line.dwo" },
425 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
426 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
427 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
428 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
429 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
430 { ".debug_str.dwo", ".zdebug_str.dwo" },
431 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
432 { ".debug_types.dwo", ".zdebug_types.dwo" },
433 { ".debug_cu_index", ".zdebug_cu_index" },
434 { ".debug_tu_index", ".zdebug_tu_index" },
437 /* local data types */
439 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
440 begin with a header, which contains the following information. */
441 struct loclists_rnglists_header
443 /* A 4-byte or 12-byte length containing the length of the
444 set of entries for this compilation unit, not including the
445 length field itself. */
448 /* A 2-byte version identifier. */
451 /* A 1-byte unsigned integer containing the size in bytes of an address on
452 the target system. */
453 unsigned char addr_size
;
455 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
456 on the target system. */
457 unsigned char segment_collector_size
;
459 /* A 4-byte count of the number of offsets that follow the header. */
460 unsigned int offset_entry_count
;
463 /* Type used for delaying computation of method physnames.
464 See comments for compute_delayed_physnames. */
465 struct delayed_method_info
467 /* The type to which the method is attached, i.e., its parent class. */
470 /* The index of the method in the type's function fieldlists. */
473 /* The index of the method in the fieldlist. */
476 /* The name of the DIE. */
479 /* The DIE associated with this method. */
480 struct die_info
*die
;
483 /* Internal state when decoding a particular compilation unit. */
486 explicit dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
487 dwarf2_per_objfile
*per_objfile
);
489 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
491 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
492 Create the set of symtabs used by this TU, or if this TU is sharing
493 symtabs with another TU and the symtabs have already been created
494 then restore those symtabs in the line header.
495 We don't need the pc/line-number mapping for type units. */
496 void setup_type_unit_groups (struct die_info
*die
);
498 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
499 buildsym_compunit constructor. */
500 struct compunit_symtab
*start_symtab (const char *name
,
501 const char *comp_dir
,
504 /* Reset the builder. */
505 void reset_builder () { m_builder
.reset (); }
507 /* Return a type that is a generic pointer type, the size of which
508 matches the address size given in the compilation unit header for
510 struct type
*addr_type () const;
512 /* Find an integer type the same size as the address size given in
513 the compilation unit header for this CU. UNSIGNED_P controls if
514 the integer is unsigned or not. */
515 struct type
*addr_sized_int_type (bool unsigned_p
) const;
517 /* The header of the compilation unit. */
518 struct comp_unit_head header
{};
520 /* Base address of this compilation unit. */
521 gdb::optional
<CORE_ADDR
> base_address
;
523 /* The language we are debugging. */
524 enum language language
= language_unknown
;
525 const struct language_defn
*language_defn
= nullptr;
527 const char *producer
= nullptr;
530 /* The symtab builder for this CU. This is only non-NULL when full
531 symbols are being read. */
532 std::unique_ptr
<buildsym_compunit
> m_builder
;
535 /* The generic symbol table building routines have separate lists for
536 file scope symbols and all all other scopes (local scopes). So
537 we need to select the right one to pass to add_symbol_to_list().
538 We do it by keeping a pointer to the correct list in list_in_scope.
540 FIXME: The original dwarf code just treated the file scope as the
541 first local scope, and all other local scopes as nested local
542 scopes, and worked fine. Check to see if we really need to
543 distinguish these in buildsym.c. */
544 struct pending
**list_in_scope
= nullptr;
546 /* Hash table holding all the loaded partial DIEs
547 with partial_die->offset.SECT_OFF as hash. */
548 htab_t partial_dies
= nullptr;
550 /* Storage for things with the same lifetime as this read-in compilation
551 unit, including partial DIEs. */
552 auto_obstack comp_unit_obstack
;
554 /* Backlink to our per_cu entry. */
555 struct dwarf2_per_cu_data
*per_cu
;
557 /* The dwarf2_per_objfile that owns this. */
558 dwarf2_per_objfile
*per_objfile
;
560 /* How many compilation units ago was this CU last referenced? */
563 /* A hash table of DIE cu_offset for following references with
564 die_info->offset.sect_off as hash. */
565 htab_t die_hash
= nullptr;
567 /* Full DIEs if read in. */
568 struct die_info
*dies
= nullptr;
570 /* A set of pointers to dwarf2_per_cu_data objects for compilation
571 units referenced by this one. Only set during full symbol processing;
572 partial symbol tables do not have dependencies. */
573 htab_t dependencies
= nullptr;
575 /* Header data from the line table, during full symbol processing. */
576 struct line_header
*line_header
= nullptr;
577 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
578 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
579 this is the DW_TAG_compile_unit die for this CU. We'll hold on
580 to the line header as long as this DIE is being processed. See
581 process_die_scope. */
582 die_info
*line_header_die_owner
= nullptr;
584 /* A list of methods which need to have physnames computed
585 after all type information has been read. */
586 std::vector
<delayed_method_info
> method_list
;
588 /* To be copied to symtab->call_site_htab. */
589 htab_t call_site_htab
= nullptr;
591 /* Non-NULL if this CU came from a DWO file.
592 There is an invariant here that is important to remember:
593 Except for attributes copied from the top level DIE in the "main"
594 (or "stub") file in preparation for reading the DWO file
595 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
596 Either there isn't a DWO file (in which case this is NULL and the point
597 is moot), or there is and either we're not going to read it (in which
598 case this is NULL) or there is and we are reading it (in which case this
600 struct dwo_unit
*dwo_unit
= nullptr;
602 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
603 Note this value comes from the Fission stub CU/TU's DIE. */
604 gdb::optional
<ULONGEST
> addr_base
;
606 /* The DW_AT_GNU_ranges_base attribute, if present.
608 This is only relevant in the context of pre-DWARF 5 split units. In this
609 context, there is a .debug_ranges section in the linked executable,
610 containing all the ranges data for all the compilation units. Each
611 skeleton/stub unit has (if needed) a DW_AT_GNU_ranges_base attribute that
612 indicates the base of its contribution to that section. The DW_AT_ranges
613 attributes in the split-unit are of the form DW_FORM_sec_offset and point
614 into the .debug_ranges section of the linked file. However, they are not
615 "true" DW_FORM_sec_offset, because they are relative to the base of their
616 compilation unit's contribution, rather than relative to the beginning of
617 the section. The DW_AT_GNU_ranges_base value must be added to it to make
618 it relative to the beginning of the section.
620 Note that the value is zero when we are not in a pre-DWARF 5 split-unit
621 case, so this value can be added without needing to know whether we are in
624 N.B. If a DW_AT_ranges attribute is found on the DW_TAG_compile_unit in the
625 skeleton/stub, it must not have the base added, as it already points to the
626 right place. And since the DW_TAG_compile_unit DIE in the split-unit can't
627 have a DW_AT_ranges attribute, we can use the
629 die->tag != DW_AT_compile_unit
631 to determine whether the base should be added or not. */
632 ULONGEST gnu_ranges_base
= 0;
634 /* The DW_AT_rnglists_base attribute, if present.
636 This is used when processing attributes of form DW_FORM_rnglistx in
637 non-split units. Attributes of this form found in a split unit don't
638 use it, as split-unit files have their own non-shared .debug_rnglists.dwo
640 ULONGEST rnglists_base
= 0;
642 /* The DW_AT_loclists_base attribute if present. */
643 ULONGEST loclist_base
= 0;
645 /* When reading debug info generated by older versions of rustc, we
646 have to rewrite some union types to be struct types with a
647 variant part. This rewriting must be done after the CU is fully
648 read in, because otherwise at the point of rewriting some struct
649 type might not have been fully processed. So, we keep a list of
650 all such types here and process them after expansion. */
651 std::vector
<struct type
*> rust_unions
;
653 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
654 files, the value is implicitly zero. For DWARF 5 version DWO files, the
655 value is often implicit and is the size of the header of
656 .debug_str_offsets section (8 or 4, depending on the address size). */
657 gdb::optional
<ULONGEST
> str_offsets_base
;
659 /* Mark used when releasing cached dies. */
662 /* This CU references .debug_loc. See the symtab->locations_valid field.
663 This test is imperfect as there may exist optimized debug code not using
664 any location list and still facing inlining issues if handled as
665 unoptimized code. For a future better test see GCC PR other/32998. */
666 bool has_loclist
: 1;
668 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
669 if all the producer_is_* fields are valid. This information is cached
670 because profiling CU expansion showed excessive time spent in
671 producer_is_gxx_lt_4_6. */
672 bool checked_producer
: 1;
673 bool producer_is_gxx_lt_4_6
: 1;
674 bool producer_is_gcc_lt_4_3
: 1;
675 bool producer_is_icc
: 1;
676 bool producer_is_icc_lt_14
: 1;
677 bool producer_is_codewarrior
: 1;
679 /* When true, the file that we're processing is known to have
680 debugging info for C++ namespaces. GCC 3.3.x did not produce
681 this information, but later versions do. */
683 bool processing_has_namespace_info
: 1;
685 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
687 /* Get the buildsym_compunit for this CU. */
688 buildsym_compunit
*get_builder ()
690 /* If this CU has a builder associated with it, use that. */
691 if (m_builder
!= nullptr)
692 return m_builder
.get ();
698 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
699 This includes type_unit_group and quick_file_names. */
701 struct stmt_list_hash
703 /* The DWO unit this table is from or NULL if there is none. */
704 struct dwo_unit
*dwo_unit
;
706 /* Offset in .debug_line or .debug_line.dwo. */
707 sect_offset line_sect_off
;
710 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
711 an object of this type. This contains elements of type unit groups
712 that can be shared across objfiles. The non-shareable parts are in
713 type_unit_group_unshareable. */
715 struct type_unit_group
: public dwarf2_per_cu_data
717 /* The TUs that share this DW_AT_stmt_list entry.
718 This is added to while parsing type units to build partial symtabs,
719 and is deleted afterwards and not used again. */
720 std::vector
<signatured_type
*> *tus
= nullptr;
722 /* The data used to construct the hash key. */
723 struct stmt_list_hash hash
{};
726 /* These sections are what may appear in a (real or virtual) DWO file. */
730 struct dwarf2_section_info abbrev
;
731 struct dwarf2_section_info line
;
732 struct dwarf2_section_info loc
;
733 struct dwarf2_section_info loclists
;
734 struct dwarf2_section_info macinfo
;
735 struct dwarf2_section_info macro
;
736 struct dwarf2_section_info rnglists
;
737 struct dwarf2_section_info str
;
738 struct dwarf2_section_info str_offsets
;
739 /* In the case of a virtual DWO file, these two are unused. */
740 struct dwarf2_section_info info
;
741 std::vector
<dwarf2_section_info
> types
;
744 /* CUs/TUs in DWP/DWO files. */
748 /* Backlink to the containing struct dwo_file. */
749 struct dwo_file
*dwo_file
;
751 /* The "id" that distinguishes this CU/TU.
752 .debug_info calls this "dwo_id", .debug_types calls this "signature".
753 Since signatures came first, we stick with it for consistency. */
756 /* The section this CU/TU lives in, in the DWO file. */
757 struct dwarf2_section_info
*section
;
759 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
760 sect_offset sect_off
;
763 /* For types, offset in the type's DIE of the type defined by this TU. */
764 cu_offset type_offset_in_tu
;
767 /* include/dwarf2.h defines the DWP section codes.
768 It defines a max value but it doesn't define a min value, which we
769 use for error checking, so provide one. */
771 enum dwp_v2_section_ids
776 /* Data for one DWO file.
778 This includes virtual DWO files (a virtual DWO file is a DWO file as it
779 appears in a DWP file). DWP files don't really have DWO files per se -
780 comdat folding of types "loses" the DWO file they came from, and from
781 a high level view DWP files appear to contain a mass of random types.
782 However, to maintain consistency with the non-DWP case we pretend DWP
783 files contain virtual DWO files, and we assign each TU with one virtual
784 DWO file (generally based on the line and abbrev section offsets -
785 a heuristic that seems to work in practice). */
789 dwo_file () = default;
790 DISABLE_COPY_AND_ASSIGN (dwo_file
);
792 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
793 For virtual DWO files the name is constructed from the section offsets
794 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
795 from related CU+TUs. */
796 const char *dwo_name
= nullptr;
798 /* The DW_AT_comp_dir attribute. */
799 const char *comp_dir
= nullptr;
801 /* The bfd, when the file is open. Otherwise this is NULL.
802 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
803 gdb_bfd_ref_ptr dbfd
;
805 /* The sections that make up this DWO file.
806 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
807 sections (for lack of a better name). */
808 struct dwo_sections sections
{};
810 /* The CUs in the file.
811 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
812 an extension to handle LLVM's Link Time Optimization output (where
813 multiple source files may be compiled into a single object/dwo pair). */
816 /* Table of TUs in the file.
817 Each element is a struct dwo_unit. */
821 /* These sections are what may appear in a DWP file. */
825 /* These are used by all DWP versions (1, 2 and 5). */
826 struct dwarf2_section_info str
;
827 struct dwarf2_section_info cu_index
;
828 struct dwarf2_section_info tu_index
;
830 /* These are only used by DWP version 2 and version 5 files.
831 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
832 sections are referenced by section number, and are not recorded here.
833 In DWP version 2 or 5 there is at most one copy of all these sections,
834 each section being (effectively) comprised of the concatenation of all of
835 the individual sections that exist in the version 1 format.
836 To keep the code simple we treat each of these concatenated pieces as a
837 section itself (a virtual section?). */
838 struct dwarf2_section_info abbrev
;
839 struct dwarf2_section_info info
;
840 struct dwarf2_section_info line
;
841 struct dwarf2_section_info loc
;
842 struct dwarf2_section_info loclists
;
843 struct dwarf2_section_info macinfo
;
844 struct dwarf2_section_info macro
;
845 struct dwarf2_section_info rnglists
;
846 struct dwarf2_section_info str_offsets
;
847 struct dwarf2_section_info types
;
850 /* These sections are what may appear in a virtual DWO file in DWP version 1.
851 A virtual DWO file is a DWO file as it appears in a DWP file. */
853 struct virtual_v1_dwo_sections
855 struct dwarf2_section_info abbrev
;
856 struct dwarf2_section_info line
;
857 struct dwarf2_section_info loc
;
858 struct dwarf2_section_info macinfo
;
859 struct dwarf2_section_info macro
;
860 struct dwarf2_section_info str_offsets
;
861 /* Each DWP hash table entry records one CU or one TU.
862 That is recorded here, and copied to dwo_unit.section. */
863 struct dwarf2_section_info info_or_types
;
866 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
867 In version 2, the sections of the DWO files are concatenated together
868 and stored in one section of that name. Thus each ELF section contains
869 several "virtual" sections. */
871 struct virtual_v2_or_v5_dwo_sections
873 bfd_size_type abbrev_offset
;
874 bfd_size_type abbrev_size
;
876 bfd_size_type line_offset
;
877 bfd_size_type line_size
;
879 bfd_size_type loc_offset
;
880 bfd_size_type loc_size
;
882 bfd_size_type loclists_offset
;
883 bfd_size_type loclists_size
;
885 bfd_size_type macinfo_offset
;
886 bfd_size_type macinfo_size
;
888 bfd_size_type macro_offset
;
889 bfd_size_type macro_size
;
891 bfd_size_type rnglists_offset
;
892 bfd_size_type rnglists_size
;
894 bfd_size_type str_offsets_offset
;
895 bfd_size_type str_offsets_size
;
897 /* Each DWP hash table entry records one CU or one TU.
898 That is recorded here, and copied to dwo_unit.section. */
899 bfd_size_type info_or_types_offset
;
900 bfd_size_type info_or_types_size
;
903 /* Contents of DWP hash tables. */
905 struct dwp_hash_table
907 uint32_t version
, nr_columns
;
908 uint32_t nr_units
, nr_slots
;
909 const gdb_byte
*hash_table
, *unit_table
;
914 const gdb_byte
*indices
;
918 /* This is indexed by column number and gives the id of the section
920 #define MAX_NR_V2_DWO_SECTIONS \
921 (1 /* .debug_info or .debug_types */ \
922 + 1 /* .debug_abbrev */ \
923 + 1 /* .debug_line */ \
924 + 1 /* .debug_loc */ \
925 + 1 /* .debug_str_offsets */ \
926 + 1 /* .debug_macro or .debug_macinfo */)
927 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
928 const gdb_byte
*offsets
;
929 const gdb_byte
*sizes
;
933 /* This is indexed by column number and gives the id of the section
935 #define MAX_NR_V5_DWO_SECTIONS \
936 (1 /* .debug_info */ \
937 + 1 /* .debug_abbrev */ \
938 + 1 /* .debug_line */ \
939 + 1 /* .debug_loclists */ \
940 + 1 /* .debug_str_offsets */ \
941 + 1 /* .debug_macro */ \
942 + 1 /* .debug_rnglists */)
943 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
944 const gdb_byte
*offsets
;
945 const gdb_byte
*sizes
;
950 /* Data for one DWP file. */
954 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
956 dbfd (std::move (abfd
))
960 /* Name of the file. */
963 /* File format version. */
967 gdb_bfd_ref_ptr dbfd
;
969 /* Section info for this file. */
970 struct dwp_sections sections
{};
972 /* Table of CUs in the file. */
973 const struct dwp_hash_table
*cus
= nullptr;
975 /* Table of TUs in the file. */
976 const struct dwp_hash_table
*tus
= nullptr;
978 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
982 /* Table to map ELF section numbers to their sections.
983 This is only needed for the DWP V1 file format. */
984 unsigned int num_sections
= 0;
985 asection
**elf_sections
= nullptr;
988 /* Struct used to pass misc. parameters to read_die_and_children, et
989 al. which are used for both .debug_info and .debug_types dies.
990 All parameters here are unchanging for the life of the call. This
991 struct exists to abstract away the constant parameters of die reading. */
993 struct die_reader_specs
995 /* The bfd of die_section. */
998 /* The CU of the DIE we are parsing. */
999 struct dwarf2_cu
*cu
;
1001 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1002 struct dwo_file
*dwo_file
;
1004 /* The section the die comes from.
1005 This is either .debug_info or .debug_types, or the .dwo variants. */
1006 struct dwarf2_section_info
*die_section
;
1008 /* die_section->buffer. */
1009 const gdb_byte
*buffer
;
1011 /* The end of the buffer. */
1012 const gdb_byte
*buffer_end
;
1014 /* The abbreviation table to use when reading the DIEs. */
1015 struct abbrev_table
*abbrev_table
;
1018 /* A subclass of die_reader_specs that holds storage and has complex
1019 constructor and destructor behavior. */
1021 class cutu_reader
: public die_reader_specs
1025 cutu_reader (dwarf2_per_cu_data
*this_cu
,
1026 dwarf2_per_objfile
*per_objfile
,
1027 struct abbrev_table
*abbrev_table
,
1028 dwarf2_cu
*existing_cu
,
1031 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
1032 dwarf2_per_objfile
*per_objfile
,
1033 struct dwarf2_cu
*parent_cu
= nullptr,
1034 struct dwo_file
*dwo_file
= nullptr);
1036 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
1038 const gdb_byte
*info_ptr
= nullptr;
1039 struct die_info
*comp_unit_die
= nullptr;
1040 bool dummy_p
= false;
1042 /* Release the new CU, putting it on the chain. This cannot be done
1047 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
1048 dwarf2_per_objfile
*per_objfile
,
1049 dwarf2_cu
*existing_cu
);
1051 struct dwarf2_per_cu_data
*m_this_cu
;
1052 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
1054 /* The ordinary abbreviation table. */
1055 abbrev_table_up m_abbrev_table_holder
;
1057 /* The DWO abbreviation table. */
1058 abbrev_table_up m_dwo_abbrev_table
;
1061 /* When we construct a partial symbol table entry we only
1062 need this much information. */
1063 struct partial_die_info
: public allocate_on_obstack
1065 partial_die_info (sect_offset sect_off
, const struct abbrev_info
*abbrev
);
1067 /* Disable assign but still keep copy ctor, which is needed
1068 load_partial_dies. */
1069 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1071 /* Adjust the partial die before generating a symbol for it. This
1072 function may set the is_external flag or change the DIE's
1074 void fixup (struct dwarf2_cu
*cu
);
1076 /* Read a minimal amount of information into the minimal die
1078 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1079 const struct abbrev_info
&abbrev
,
1080 const gdb_byte
*info_ptr
);
1082 /* Compute the name of this partial DIE. This memoizes the
1083 result, so it is safe to call multiple times. */
1084 const char *name (dwarf2_cu
*cu
);
1086 /* Offset of this DIE. */
1087 const sect_offset sect_off
;
1089 /* DWARF-2 tag for this DIE. */
1090 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1092 /* Assorted flags describing the data found in this DIE. */
1093 const unsigned int has_children
: 1;
1095 unsigned int is_external
: 1;
1096 unsigned int is_declaration
: 1;
1097 unsigned int has_type
: 1;
1098 unsigned int has_specification
: 1;
1099 unsigned int has_pc_info
: 1;
1100 unsigned int may_be_inlined
: 1;
1102 /* This DIE has been marked DW_AT_main_subprogram. */
1103 unsigned int main_subprogram
: 1;
1105 /* Flag set if the SCOPE field of this structure has been
1107 unsigned int scope_set
: 1;
1109 /* Flag set if the DIE has a byte_size attribute. */
1110 unsigned int has_byte_size
: 1;
1112 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1113 unsigned int has_const_value
: 1;
1115 /* Flag set if any of the DIE's children are template arguments. */
1116 unsigned int has_template_arguments
: 1;
1118 /* Flag set if fixup has been called on this die. */
1119 unsigned int fixup_called
: 1;
1121 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1122 unsigned int is_dwz
: 1;
1124 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1125 unsigned int spec_is_dwz
: 1;
1127 unsigned int canonical_name
: 1;
1129 /* The name of this DIE. Normally the value of DW_AT_name, but
1130 sometimes a default name for unnamed DIEs. */
1131 const char *raw_name
= nullptr;
1133 /* The linkage name, if present. */
1134 const char *linkage_name
= nullptr;
1136 /* The scope to prepend to our children. This is generally
1137 allocated on the comp_unit_obstack, so will disappear
1138 when this compilation unit leaves the cache. */
1139 const char *scope
= nullptr;
1141 /* Some data associated with the partial DIE. The tag determines
1142 which field is live. */
1145 /* The location description associated with this DIE, if any. */
1146 struct dwarf_block
*locdesc
;
1147 /* The offset of an import, for DW_TAG_imported_unit. */
1148 sect_offset sect_off
;
1151 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1152 CORE_ADDR lowpc
= 0;
1153 CORE_ADDR highpc
= 0;
1155 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1156 DW_AT_sibling, if any. */
1157 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1158 could return DW_AT_sibling values to its caller load_partial_dies. */
1159 const gdb_byte
*sibling
= nullptr;
1161 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1162 DW_AT_specification (or DW_AT_abstract_origin or
1163 DW_AT_extension). */
1164 sect_offset spec_offset
{};
1166 /* Pointers to this DIE's parent, first child, and next sibling,
1168 struct partial_die_info
*die_parent
= nullptr;
1169 struct partial_die_info
*die_child
= nullptr;
1170 struct partial_die_info
*die_sibling
= nullptr;
1172 friend struct partial_die_info
*
1173 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1176 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1177 partial_die_info (sect_offset sect_off
)
1178 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1182 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1184 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1189 has_specification
= 0;
1192 main_subprogram
= 0;
1195 has_const_value
= 0;
1196 has_template_arguments
= 0;
1204 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1205 but this would require a corresponding change in unpack_field_as_long
1207 static int bits_per_byte
= 8;
1209 struct variant_part_builder
;
1211 /* When reading a variant, we track a bit more information about the
1212 field, and store it in an object of this type. */
1214 struct variant_field
1216 int first_field
= -1;
1217 int last_field
= -1;
1219 /* A variant can contain other variant parts. */
1220 std::vector
<variant_part_builder
> variant_parts
;
1222 /* If we see a DW_TAG_variant, then this will be set if this is the
1224 bool default_branch
= false;
1225 /* If we see a DW_AT_discr_value, then this will be the discriminant
1227 ULONGEST discriminant_value
= 0;
1228 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1230 struct dwarf_block
*discr_list_data
= nullptr;
1233 /* This represents a DW_TAG_variant_part. */
1235 struct variant_part_builder
1237 /* The offset of the discriminant field. */
1238 sect_offset discriminant_offset
{};
1240 /* Variants that are direct children of this variant part. */
1241 std::vector
<variant_field
> variants
;
1243 /* True if we're currently reading a variant. */
1244 bool processing_variant
= false;
1249 int accessibility
= 0;
1251 /* Variant parts need to find the discriminant, which is a DIE
1252 reference. We track the section offset of each field to make
1255 struct field field
{};
1260 const char *name
= nullptr;
1261 std::vector
<struct fn_field
> fnfields
;
1264 /* The routines that read and process dies for a C struct or C++ class
1265 pass lists of data member fields and lists of member function fields
1266 in an instance of a field_info structure, as defined below. */
1269 /* List of data member and baseclasses fields. */
1270 std::vector
<struct nextfield
> fields
;
1271 std::vector
<struct nextfield
> baseclasses
;
1273 /* Set if the accessibility of one of the fields is not public. */
1274 bool non_public_fields
= false;
1276 /* Member function fieldlist array, contains name of possibly overloaded
1277 member function, number of overloaded member functions and a pointer
1278 to the head of the member function field chain. */
1279 std::vector
<struct fnfieldlist
> fnfieldlists
;
1281 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1282 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1283 std::vector
<struct decl_field
> typedef_field_list
;
1285 /* Nested types defined by this class and the number of elements in this
1287 std::vector
<struct decl_field
> nested_types_list
;
1289 /* If non-null, this is the variant part we are currently
1291 variant_part_builder
*current_variant_part
= nullptr;
1292 /* This holds all the top-level variant parts attached to the type
1294 std::vector
<variant_part_builder
> variant_parts
;
1296 /* Return the total number of fields (including baseclasses). */
1297 int nfields () const
1299 return fields
.size () + baseclasses
.size ();
1303 /* Loaded secondary compilation units are kept in memory until they
1304 have not been referenced for the processing of this many
1305 compilation units. Set this to zero to disable caching. Cache
1306 sizes of up to at least twenty will improve startup time for
1307 typical inter-CU-reference binaries, at an obvious memory cost. */
1308 static int dwarf_max_cache_age
= 5;
1310 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1311 struct cmd_list_element
*c
, const char *value
)
1313 fprintf_filtered (file
, _("The upper bound on the age of cached "
1314 "DWARF compilation units is %s.\n"),
1318 /* local function prototypes */
1320 static void dwarf2_find_base_address (struct die_info
*die
,
1321 struct dwarf2_cu
*cu
);
1323 static dwarf2_psymtab
*create_partial_symtab
1324 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1327 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1328 const gdb_byte
*info_ptr
,
1329 struct die_info
*type_unit_die
);
1331 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1333 static void scan_partial_symbols (struct partial_die_info
*,
1334 CORE_ADDR
*, CORE_ADDR
*,
1335 int, struct dwarf2_cu
*);
1337 static void add_partial_symbol (struct partial_die_info
*,
1338 struct dwarf2_cu
*);
1340 static void add_partial_namespace (struct partial_die_info
*pdi
,
1341 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1342 int set_addrmap
, struct dwarf2_cu
*cu
);
1344 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1345 CORE_ADDR
*highpc
, int set_addrmap
,
1346 struct dwarf2_cu
*cu
);
1348 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1349 struct dwarf2_cu
*cu
);
1351 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1352 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1353 int need_pc
, struct dwarf2_cu
*cu
);
1355 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1357 static struct partial_die_info
*load_partial_dies
1358 (const struct die_reader_specs
*, const gdb_byte
*, int);
1360 /* A pair of partial_die_info and compilation unit. */
1361 struct cu_partial_die_info
1363 /* The compilation unit of the partial_die_info. */
1364 struct dwarf2_cu
*cu
;
1365 /* A partial_die_info. */
1366 struct partial_die_info
*pdi
;
1368 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1374 cu_partial_die_info () = delete;
1377 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1378 struct dwarf2_cu
*);
1380 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1382 const struct attr_abbrev
*,
1385 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1386 struct attribute
*attr
, dwarf_tag tag
);
1388 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1390 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1391 dwarf2_section_info
*, sect_offset
);
1393 static const char *read_indirect_string
1394 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1395 const struct comp_unit_head
*, unsigned int *);
1397 static const char *read_indirect_string_at_offset
1398 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1400 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1404 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1405 ULONGEST str_index
);
1407 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1408 ULONGEST str_index
);
1410 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1412 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1413 struct dwarf2_cu
*);
1415 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1416 struct dwarf2_cu
*cu
);
1418 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1420 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1421 struct dwarf2_cu
*cu
);
1423 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1425 static struct die_info
*die_specification (struct die_info
*die
,
1426 struct dwarf2_cu
**);
1428 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1429 struct dwarf2_cu
*cu
);
1431 static void dwarf_decode_lines (struct line_header
*, const char *,
1432 struct dwarf2_cu
*, dwarf2_psymtab
*,
1433 CORE_ADDR
, int decode_mapping
);
1435 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1438 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1439 struct dwarf2_cu
*, struct symbol
* = NULL
);
1441 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1442 struct dwarf2_cu
*);
1444 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1447 struct obstack
*obstack
,
1448 struct dwarf2_cu
*cu
, LONGEST
*value
,
1449 const gdb_byte
**bytes
,
1450 struct dwarf2_locexpr_baton
**baton
);
1452 static struct type
*read_subrange_index_type (struct die_info
*die
,
1453 struct dwarf2_cu
*cu
);
1455 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1457 static int need_gnat_info (struct dwarf2_cu
*);
1459 static struct type
*die_descriptive_type (struct die_info
*,
1460 struct dwarf2_cu
*);
1462 static void set_descriptive_type (struct type
*, struct die_info
*,
1463 struct dwarf2_cu
*);
1465 static struct type
*die_containing_type (struct die_info
*,
1466 struct dwarf2_cu
*);
1468 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1469 struct dwarf2_cu
*);
1471 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1473 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1475 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1477 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1478 const char *suffix
, int physname
,
1479 struct dwarf2_cu
*cu
);
1481 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1483 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1485 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1487 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1489 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1491 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1493 /* Return the .debug_loclists section to use for cu. */
1494 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1496 /* Return the .debug_rnglists section to use for cu. */
1497 static struct dwarf2_section_info
*cu_debug_rnglists_section
1498 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1500 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1501 values. Keep the items ordered with increasing constraints compliance. */
1504 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1505 PC_BOUNDS_NOT_PRESENT
,
1507 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1508 were present but they do not form a valid range of PC addresses. */
1511 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1514 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1518 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1519 CORE_ADDR
*, CORE_ADDR
*,
1523 static void get_scope_pc_bounds (struct die_info
*,
1524 CORE_ADDR
*, CORE_ADDR
*,
1525 struct dwarf2_cu
*);
1527 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1528 CORE_ADDR
, struct dwarf2_cu
*);
1530 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1531 struct dwarf2_cu
*);
1533 static void dwarf2_attach_fields_to_type (struct field_info
*,
1534 struct type
*, struct dwarf2_cu
*);
1536 static void dwarf2_add_member_fn (struct field_info
*,
1537 struct die_info
*, struct type
*,
1538 struct dwarf2_cu
*);
1540 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1542 struct dwarf2_cu
*);
1544 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1546 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1548 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1550 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1552 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1554 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1556 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1558 static struct type
*read_module_type (struct die_info
*die
,
1559 struct dwarf2_cu
*cu
);
1561 static const char *namespace_name (struct die_info
*die
,
1562 int *is_anonymous
, struct dwarf2_cu
*);
1564 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1566 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1569 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1570 struct dwarf2_cu
*);
1572 static struct die_info
*read_die_and_siblings_1
1573 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1576 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1577 const gdb_byte
*info_ptr
,
1578 const gdb_byte
**new_info_ptr
,
1579 struct die_info
*parent
);
1581 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1582 struct die_info
**, const gdb_byte
*,
1585 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1586 struct die_info
**, const gdb_byte
*);
1588 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1590 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1593 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1595 static const char *dwarf2_full_name (const char *name
,
1596 struct die_info
*die
,
1597 struct dwarf2_cu
*cu
);
1599 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1600 struct dwarf2_cu
*cu
);
1602 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1603 struct dwarf2_cu
**);
1605 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1607 static void dump_die_for_error (struct die_info
*);
1609 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1612 /*static*/ void dump_die (struct die_info
*, int max_level
);
1614 static void store_in_ref_table (struct die_info
*,
1615 struct dwarf2_cu
*);
1617 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1618 const struct attribute
*,
1619 struct dwarf2_cu
**);
1621 static struct die_info
*follow_die_ref (struct die_info
*,
1622 const struct attribute
*,
1623 struct dwarf2_cu
**);
1625 static struct die_info
*follow_die_sig (struct die_info
*,
1626 const struct attribute
*,
1627 struct dwarf2_cu
**);
1629 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1630 struct dwarf2_cu
*);
1632 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1633 const struct attribute
*,
1634 struct dwarf2_cu
*);
1636 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1637 dwarf2_per_objfile
*per_objfile
);
1639 static void read_signatured_type (signatured_type
*sig_type
,
1640 dwarf2_per_objfile
*per_objfile
);
1642 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1643 struct die_info
*die
, struct dwarf2_cu
*cu
,
1644 struct dynamic_prop
*prop
, struct type
*type
);
1646 /* memory allocation interface */
1648 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1650 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1652 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1654 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1655 struct dwarf2_loclist_baton
*baton
,
1656 const struct attribute
*attr
);
1658 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1660 struct dwarf2_cu
*cu
,
1663 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1664 const gdb_byte
*info_ptr
,
1665 const struct abbrev_info
*abbrev
);
1667 static hashval_t
partial_die_hash (const void *item
);
1669 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1671 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1672 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1673 dwarf2_per_objfile
*per_objfile
);
1675 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1676 struct die_info
*comp_unit_die
,
1677 enum language pretend_language
);
1679 static struct type
*set_die_type (struct die_info
*, struct type
*,
1680 struct dwarf2_cu
*, bool = false);
1682 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1684 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1685 dwarf2_per_objfile
*per_objfile
,
1686 dwarf2_cu
*existing_cu
,
1688 enum language pretend_language
);
1690 static void process_full_comp_unit (dwarf2_cu
*cu
,
1691 enum language pretend_language
);
1693 static void process_full_type_unit (dwarf2_cu
*cu
,
1694 enum language pretend_language
);
1696 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1697 struct dwarf2_per_cu_data
*);
1699 static void dwarf2_mark (struct dwarf2_cu
*);
1701 static struct type
*get_die_type_at_offset (sect_offset
,
1702 dwarf2_per_cu_data
*per_cu
,
1703 dwarf2_per_objfile
*per_objfile
);
1705 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1707 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1708 dwarf2_per_objfile
*per_objfile
,
1709 enum language pretend_language
);
1711 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1713 /* Class, the destructor of which frees all allocated queue entries. This
1714 will only have work to do if an error was thrown while processing the
1715 dwarf. If no error was thrown then the queue entries should have all
1716 been processed, and freed, as we went along. */
1718 class dwarf2_queue_guard
1721 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1722 : m_per_objfile (per_objfile
)
1724 gdb_assert (!m_per_objfile
->per_bfd
->queue
.has_value ());
1726 m_per_objfile
->per_bfd
->queue
.emplace ();
1729 /* Free any entries remaining on the queue. There should only be
1730 entries left if we hit an error while processing the dwarf. */
1731 ~dwarf2_queue_guard ()
1733 gdb_assert (m_per_objfile
->per_bfd
->queue
.has_value ());
1735 m_per_objfile
->per_bfd
->queue
.reset ();
1738 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1741 dwarf2_per_objfile
*m_per_objfile
;
1744 dwarf2_queue_item::~dwarf2_queue_item ()
1746 /* Anything still marked queued is likely to be in an
1747 inconsistent state, so discard it. */
1750 per_objfile
->remove_cu (per_cu
);
1755 /* The return type of find_file_and_directory. Note, the enclosed
1756 string pointers are only valid while this object is valid. */
1758 struct file_and_directory
1760 /* The filename. This is never NULL. */
1763 /* The compilation directory. NULL if not known. If we needed to
1764 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1765 points directly to the DW_AT_comp_dir string attribute owned by
1766 the obstack that owns the DIE. */
1767 const char *comp_dir
;
1769 /* If we needed to build a new string for comp_dir, this is what
1770 owns the storage. */
1771 std::string comp_dir_storage
;
1774 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1775 struct dwarf2_cu
*cu
);
1777 static htab_up
allocate_signatured_type_table ();
1779 static htab_up
allocate_dwo_unit_table ();
1781 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1782 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1783 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1785 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1787 static struct dwo_unit
*lookup_dwo_comp_unit
1788 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1789 ULONGEST signature
);
1791 static struct dwo_unit
*lookup_dwo_type_unit
1792 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1794 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1796 /* A unique pointer to a dwo_file. */
1798 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1800 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1802 static void check_producer (struct dwarf2_cu
*cu
);
1804 static void free_line_header_voidp (void *arg
);
1806 /* Various complaints about symbol reading that don't abort the process. */
1809 dwarf2_debug_line_missing_file_complaint (void)
1811 complaint (_(".debug_line section has line data without a file"));
1815 dwarf2_debug_line_missing_end_sequence_complaint (void)
1817 complaint (_(".debug_line section has line "
1818 "program sequence without an end"));
1822 dwarf2_complex_location_expr_complaint (void)
1824 complaint (_("location expression too complex"));
1828 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1831 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1836 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1838 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1842 /* Hash function for line_header_hash. */
1845 line_header_hash (const struct line_header
*ofs
)
1847 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1850 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1853 line_header_hash_voidp (const void *item
)
1855 const struct line_header
*ofs
= (const struct line_header
*) item
;
1857 return line_header_hash (ofs
);
1860 /* Equality function for line_header_hash. */
1863 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1865 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1866 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1868 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1869 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1874 /* See declaration. */
1876 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1879 can_copy (can_copy_
)
1882 names
= &dwarf2_elf_names
;
1884 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1885 locate_sections (obfd
, sec
, *names
);
1888 dwarf2_per_bfd::~dwarf2_per_bfd ()
1890 for (auto &per_cu
: all_comp_units
)
1891 per_cu
->imported_symtabs_free ();
1893 /* Everything else should be on this->obstack. */
1899 dwarf2_per_objfile::remove_all_cus ()
1901 gdb_assert (!this->per_bfd
->queue
.has_value ());
1903 for (auto pair
: m_dwarf2_cus
)
1906 m_dwarf2_cus
.clear ();
1909 /* A helper class that calls free_cached_comp_units on
1912 class free_cached_comp_units
1916 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1917 : m_per_objfile (per_objfile
)
1921 ~free_cached_comp_units ()
1923 m_per_objfile
->remove_all_cus ();
1926 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1930 dwarf2_per_objfile
*m_per_objfile
;
1936 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1938 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1940 return this->m_symtabs
[per_cu
->index
] != nullptr;
1946 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1948 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1950 return this->m_symtabs
[per_cu
->index
];
1956 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1957 compunit_symtab
*symtab
)
1959 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1960 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1962 this->m_symtabs
[per_cu
->index
] = symtab
;
1965 /* Try to locate the sections we need for DWARF 2 debugging
1966 information and return true if we have enough to do something.
1967 NAMES points to the dwarf2 section names, or is NULL if the standard
1968 ELF names are used. CAN_COPY is true for formats where symbol
1969 interposition is possible and so symbol values must follow copy
1970 relocation rules. */
1973 dwarf2_has_info (struct objfile
*objfile
,
1974 const struct dwarf2_debug_sections
*names
,
1977 if (objfile
->flags
& OBJF_READNEVER
)
1980 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1982 if (per_objfile
== NULL
)
1984 dwarf2_per_bfd
*per_bfd
;
1986 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1987 BFD doesn't require relocations.
1989 We don't share with objfiles for which -readnow was requested,
1990 because it would complicate things when loading the same BFD with
1991 -readnow and then without -readnow. */
1992 if (!gdb_bfd_requires_relocations (objfile
->obfd
)
1993 && (objfile
->flags
& OBJF_READNOW
) == 0)
1995 /* See if one has been created for this BFD yet. */
1996 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1998 if (per_bfd
== nullptr)
2000 /* No, create it now. */
2001 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
2002 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
2007 /* No sharing possible, create one specifically for this objfile. */
2008 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
2009 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
2012 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
2015 return (!per_objfile
->per_bfd
->info
.is_virtual
2016 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
2017 && !per_objfile
->per_bfd
->abbrev
.is_virtual
2018 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
2021 /* See declaration. */
2024 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
2025 const dwarf2_debug_sections
&names
)
2027 flagword aflag
= bfd_section_flags (sectp
);
2029 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2032 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2033 > bfd_get_file_size (abfd
))
2035 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2036 warning (_("Discarding section %s which has a section size (%s"
2037 ") larger than the file size [in module %s]"),
2038 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2039 bfd_get_filename (abfd
));
2041 else if (names
.info
.matches (sectp
->name
))
2043 this->info
.s
.section
= sectp
;
2044 this->info
.size
= bfd_section_size (sectp
);
2046 else if (names
.abbrev
.matches (sectp
->name
))
2048 this->abbrev
.s
.section
= sectp
;
2049 this->abbrev
.size
= bfd_section_size (sectp
);
2051 else if (names
.line
.matches (sectp
->name
))
2053 this->line
.s
.section
= sectp
;
2054 this->line
.size
= bfd_section_size (sectp
);
2056 else if (names
.loc
.matches (sectp
->name
))
2058 this->loc
.s
.section
= sectp
;
2059 this->loc
.size
= bfd_section_size (sectp
);
2061 else if (names
.loclists
.matches (sectp
->name
))
2063 this->loclists
.s
.section
= sectp
;
2064 this->loclists
.size
= bfd_section_size (sectp
);
2066 else if (names
.macinfo
.matches (sectp
->name
))
2068 this->macinfo
.s
.section
= sectp
;
2069 this->macinfo
.size
= bfd_section_size (sectp
);
2071 else if (names
.macro
.matches (sectp
->name
))
2073 this->macro
.s
.section
= sectp
;
2074 this->macro
.size
= bfd_section_size (sectp
);
2076 else if (names
.str
.matches (sectp
->name
))
2078 this->str
.s
.section
= sectp
;
2079 this->str
.size
= bfd_section_size (sectp
);
2081 else if (names
.str_offsets
.matches (sectp
->name
))
2083 this->str_offsets
.s
.section
= sectp
;
2084 this->str_offsets
.size
= bfd_section_size (sectp
);
2086 else if (names
.line_str
.matches (sectp
->name
))
2088 this->line_str
.s
.section
= sectp
;
2089 this->line_str
.size
= bfd_section_size (sectp
);
2091 else if (names
.addr
.matches (sectp
->name
))
2093 this->addr
.s
.section
= sectp
;
2094 this->addr
.size
= bfd_section_size (sectp
);
2096 else if (names
.frame
.matches (sectp
->name
))
2098 this->frame
.s
.section
= sectp
;
2099 this->frame
.size
= bfd_section_size (sectp
);
2101 else if (names
.eh_frame
.matches (sectp
->name
))
2103 this->eh_frame
.s
.section
= sectp
;
2104 this->eh_frame
.size
= bfd_section_size (sectp
);
2106 else if (names
.ranges
.matches (sectp
->name
))
2108 this->ranges
.s
.section
= sectp
;
2109 this->ranges
.size
= bfd_section_size (sectp
);
2111 else if (names
.rnglists
.matches (sectp
->name
))
2113 this->rnglists
.s
.section
= sectp
;
2114 this->rnglists
.size
= bfd_section_size (sectp
);
2116 else if (names
.types
.matches (sectp
->name
))
2118 struct dwarf2_section_info type_section
;
2120 memset (&type_section
, 0, sizeof (type_section
));
2121 type_section
.s
.section
= sectp
;
2122 type_section
.size
= bfd_section_size (sectp
);
2124 this->types
.push_back (type_section
);
2126 else if (names
.gdb_index
.matches (sectp
->name
))
2128 this->gdb_index
.s
.section
= sectp
;
2129 this->gdb_index
.size
= bfd_section_size (sectp
);
2131 else if (names
.debug_names
.matches (sectp
->name
))
2133 this->debug_names
.s
.section
= sectp
;
2134 this->debug_names
.size
= bfd_section_size (sectp
);
2136 else if (names
.debug_aranges
.matches (sectp
->name
))
2138 this->debug_aranges
.s
.section
= sectp
;
2139 this->debug_aranges
.size
= bfd_section_size (sectp
);
2142 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2143 && bfd_section_vma (sectp
) == 0)
2144 this->has_section_at_zero
= true;
2147 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2151 dwarf2_get_section_info (struct objfile
*objfile
,
2152 enum dwarf2_section_enum sect
,
2153 asection
**sectp
, const gdb_byte
**bufp
,
2154 bfd_size_type
*sizep
)
2156 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2157 struct dwarf2_section_info
*info
;
2159 /* We may see an objfile without any DWARF, in which case we just
2161 if (per_objfile
== NULL
)
2170 case DWARF2_DEBUG_FRAME
:
2171 info
= &per_objfile
->per_bfd
->frame
;
2173 case DWARF2_EH_FRAME
:
2174 info
= &per_objfile
->per_bfd
->eh_frame
;
2177 gdb_assert_not_reached ("unexpected section");
2180 info
->read (objfile
);
2182 *sectp
= info
->get_bfd_section ();
2183 *bufp
= info
->buffer
;
2184 *sizep
= info
->size
;
2188 /* DWARF quick_symbol_functions support. */
2190 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2191 unique line tables, so we maintain a separate table of all .debug_line
2192 derived entries to support the sharing.
2193 All the quick functions need is the list of file names. We discard the
2194 line_header when we're done and don't need to record it here. */
2195 struct quick_file_names
2197 /* The data used to construct the hash key. */
2198 struct stmt_list_hash hash
;
2200 /* The number of entries in file_names, real_names. */
2201 unsigned int num_file_names
;
2203 /* The file names from the line table, after being run through
2205 const char **file_names
;
2207 /* The file names from the line table after being run through
2208 gdb_realpath. These are computed lazily. */
2209 const char **real_names
;
2212 /* When using the index (and thus not using psymtabs), each CU has an
2213 object of this type. This is used to hold information needed by
2214 the various "quick" methods. */
2215 struct dwarf2_per_cu_quick_data
2217 /* The file table. This can be NULL if there was no file table
2218 or it's currently not read in.
2219 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2220 struct quick_file_names
*file_names
;
2222 /* A temporary mark bit used when iterating over all CUs in
2223 expand_symtabs_matching. */
2224 unsigned int mark
: 1;
2226 /* True if we've tried to read the file table and found there isn't one.
2227 There will be no point in trying to read it again next time. */
2228 unsigned int no_file_data
: 1;
2231 /* A subclass of psymbol_functions that arranges to read the DWARF
2232 partial symbols when needed. */
2233 struct lazy_dwarf_reader
: public psymbol_functions
2235 using psymbol_functions::psymbol_functions
;
2237 bool can_lazily_read_symbols () override
2242 void read_partial_symbols (struct objfile
*objfile
) override
2244 if (dwarf2_has_info (objfile
, nullptr))
2245 dwarf2_build_psymtabs (objfile
, this);
2249 static quick_symbol_functions_up
2250 make_lazy_dwarf_reader ()
2252 return quick_symbol_functions_up (new lazy_dwarf_reader
);
2255 struct dwarf2_base_index_functions
: public quick_symbol_functions
2257 bool has_symbols (struct objfile
*objfile
) override
;
2259 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
2261 void forget_cached_source_info (struct objfile
*objfile
) override
;
2263 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
2266 bool *symbol_found_p
) override
2268 *symbol_found_p
= false;
2269 return language_unknown
;
2272 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
2274 void expand_all_symtabs (struct objfile
*objfile
) override
;
2276 struct compunit_symtab
*find_pc_sect_compunit_symtab
2277 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
2278 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
2280 struct compunit_symtab
*find_compunit_symtab_by_address
2281 (struct objfile
*objfile
, CORE_ADDR address
) override
2286 void map_symbol_filenames (struct objfile
*objfile
,
2287 gdb::function_view
<symbol_filename_ftype
> fun
,
2288 bool need_fullname
) override
;
2291 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
2293 void dump (struct objfile
*objfile
) override
;
2295 void expand_matching_symbols
2297 const lookup_name_info
&lookup_name
,
2300 symbol_compare_ftype
*ordered_compare
) override
;
2302 bool expand_symtabs_matching
2303 (struct objfile
*objfile
,
2304 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2305 const lookup_name_info
*lookup_name
,
2306 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2307 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2308 block_search_flags search_flags
,
2310 enum search_domain kind
) override
;
2313 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
2315 void dump (struct objfile
*objfile
) override
;
2317 void expand_matching_symbols
2319 const lookup_name_info
&lookup_name
,
2322 symbol_compare_ftype
*ordered_compare
) override
;
2324 bool expand_symtabs_matching
2325 (struct objfile
*objfile
,
2326 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2327 const lookup_name_info
*lookup_name
,
2328 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2329 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2330 block_search_flags search_flags
,
2332 enum search_domain kind
) override
;
2335 static quick_symbol_functions_up
2336 make_dwarf_gdb_index ()
2338 return quick_symbol_functions_up (new dwarf2_gdb_index
);
2341 static quick_symbol_functions_up
2342 make_dwarf_debug_names ()
2344 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
2347 /* Utility hash function for a stmt_list_hash. */
2350 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2354 if (stmt_list_hash
->dwo_unit
!= NULL
)
2355 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2356 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2360 /* Utility equality function for a stmt_list_hash. */
2363 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2364 const struct stmt_list_hash
*rhs
)
2366 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2368 if (lhs
->dwo_unit
!= NULL
2369 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2372 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2375 /* Hash function for a quick_file_names. */
2378 hash_file_name_entry (const void *e
)
2380 const struct quick_file_names
*file_data
2381 = (const struct quick_file_names
*) e
;
2383 return hash_stmt_list_entry (&file_data
->hash
);
2386 /* Equality function for a quick_file_names. */
2389 eq_file_name_entry (const void *a
, const void *b
)
2391 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2392 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2394 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2397 /* Delete function for a quick_file_names. */
2400 delete_file_name_entry (void *e
)
2402 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2405 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2407 xfree ((void*) file_data
->file_names
[i
]);
2408 if (file_data
->real_names
)
2409 xfree ((void*) file_data
->real_names
[i
]);
2412 /* The space for the struct itself lives on the obstack, so we don't
2416 /* Create a quick_file_names hash table. */
2419 create_quick_file_names_table (unsigned int nr_initial_entries
)
2421 return htab_up (htab_create_alloc (nr_initial_entries
,
2422 hash_file_name_entry
, eq_file_name_entry
,
2423 delete_file_name_entry
, xcalloc
, xfree
));
2426 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2427 function is unrelated to symtabs, symtab would have to be created afterwards.
2428 You should call age_cached_comp_units after processing the CU. */
2431 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2434 if (per_cu
->is_debug_types
)
2435 load_full_type_unit (per_cu
, per_objfile
);
2437 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2438 skip_partial
, language_minimal
);
2440 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2442 return nullptr; /* Dummy CU. */
2444 dwarf2_find_base_address (cu
->dies
, cu
);
2449 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2452 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2453 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2455 /* Skip type_unit_groups, reading the type units they contain
2456 is handled elsewhere. */
2457 if (per_cu
->type_unit_group_p ())
2461 /* The destructor of dwarf2_queue_guard frees any entries left on
2462 the queue. After this point we're guaranteed to leave this function
2463 with the dwarf queue empty. */
2464 dwarf2_queue_guard
q_guard (per_objfile
);
2466 if (!per_objfile
->symtab_set_p (per_cu
))
2468 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2469 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2471 /* If we just loaded a CU from a DWO, and we're working with an index
2472 that may badly handle TUs, load all the TUs in that DWO as well.
2473 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2474 if (!per_cu
->is_debug_types
2476 && cu
->dwo_unit
!= NULL
2477 && per_objfile
->per_bfd
->index_table
!= NULL
2478 && per_objfile
->per_bfd
->index_table
->version
<= 7
2479 /* DWP files aren't supported yet. */
2480 && get_dwp_file (per_objfile
) == NULL
)
2481 queue_and_load_all_dwo_tus (cu
);
2484 process_queue (per_objfile
);
2487 /* Age the cache, releasing compilation units that have not
2488 been used recently. */
2489 per_objfile
->age_comp_units ();
2492 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2493 the per-objfile for which this symtab is instantiated.
2495 Returns the resulting symbol table. */
2497 static struct compunit_symtab
*
2498 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2499 dwarf2_per_objfile
*per_objfile
,
2502 gdb_assert (per_objfile
->per_bfd
->using_index
);
2504 if (!per_objfile
->symtab_set_p (per_cu
))
2506 free_cached_comp_units
freer (per_objfile
);
2507 scoped_restore decrementer
= increment_reading_symtab ();
2508 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2509 process_cu_includes (per_objfile
);
2512 return per_objfile
->get_symtab (per_cu
);
2517 std::unique_ptr
<dwarf2_per_cu_data
>
2518 dwarf2_per_bfd::allocate_per_cu ()
2520 std::unique_ptr
<dwarf2_per_cu_data
> result (new dwarf2_per_cu_data
);
2521 result
->per_bfd
= this;
2522 result
->index
= m_num_psymtabs
++;
2528 std::unique_ptr
<signatured_type
>
2529 dwarf2_per_bfd::allocate_signatured_type ()
2531 std::unique_ptr
<signatured_type
> result (new signatured_type
);
2532 result
->per_bfd
= this;
2533 result
->index
= m_num_psymtabs
++;
2538 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2539 obstack, and constructed with the specified field values. */
2541 static std::unique_ptr
<dwarf2_per_cu_data
>
2542 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2543 struct dwarf2_section_info
*section
,
2545 sect_offset sect_off
, ULONGEST length
)
2547 std::unique_ptr
<dwarf2_per_cu_data
> the_cu
= per_bfd
->allocate_per_cu ();
2548 the_cu
->sect_off
= sect_off
;
2549 the_cu
->length
= length
;
2550 the_cu
->section
= section
;
2551 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2552 struct dwarf2_per_cu_quick_data
);
2553 the_cu
->is_dwz
= is_dwz
;
2557 /* A helper for create_cus_from_index that handles a given list of
2561 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2562 const gdb_byte
*cu_list
, offset_type n_elements
,
2563 struct dwarf2_section_info
*section
,
2566 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2568 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2570 sect_offset sect_off
2571 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2572 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2575 std::unique_ptr
<dwarf2_per_cu_data
> per_cu
2576 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2578 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
2582 /* Read the CU list from the mapped index, and use it to create all
2583 the CU objects for PER_BFD. */
2586 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2587 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2588 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2590 gdb_assert (per_bfd
->all_comp_units
.empty ());
2591 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2593 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2596 if (dwz_elements
== 0)
2599 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2600 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2604 /* Create the signatured type hash table from the index. */
2607 create_signatured_type_table_from_index
2608 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2609 const gdb_byte
*bytes
, offset_type elements
)
2611 htab_up sig_types_hash
= allocate_signatured_type_table ();
2613 for (offset_type i
= 0; i
< elements
; i
+= 3)
2615 std::unique_ptr
<signatured_type
> sig_type
;
2618 cu_offset type_offset_in_tu
;
2620 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2621 sect_offset sect_off
2622 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2624 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2626 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2629 sig_type
= per_bfd
->allocate_signatured_type ();
2630 sig_type
->signature
= signature
;
2631 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2632 sig_type
->is_debug_types
= 1;
2633 sig_type
->section
= section
;
2634 sig_type
->sect_off
= sect_off
;
2636 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2637 struct dwarf2_per_cu_quick_data
);
2639 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2640 *slot
= sig_type
.get ();
2642 per_bfd
->all_comp_units
.push_back (std::move (sig_type
));
2645 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2648 /* Create the signatured type hash table from .debug_names. */
2651 create_signatured_type_table_from_debug_names
2652 (dwarf2_per_objfile
*per_objfile
,
2653 const mapped_debug_names
&map
,
2654 struct dwarf2_section_info
*section
,
2655 struct dwarf2_section_info
*abbrev_section
)
2657 struct objfile
*objfile
= per_objfile
->objfile
;
2659 section
->read (objfile
);
2660 abbrev_section
->read (objfile
);
2662 htab_up sig_types_hash
= allocate_signatured_type_table ();
2664 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2666 std::unique_ptr
<signatured_type
> sig_type
;
2669 sect_offset sect_off
2670 = (sect_offset
) (extract_unsigned_integer
2671 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2673 map
.dwarf5_byte_order
));
2675 comp_unit_head cu_header
;
2676 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2678 section
->buffer
+ to_underlying (sect_off
),
2681 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2682 sig_type
->signature
= cu_header
.signature
;
2683 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2684 sig_type
->is_debug_types
= 1;
2685 sig_type
->section
= section
;
2686 sig_type
->sect_off
= sect_off
;
2688 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2689 struct dwarf2_per_cu_quick_data
);
2691 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2692 *slot
= sig_type
.get ();
2694 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (sig_type
));
2697 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2700 /* Read the address map data from the mapped index, and use it to
2701 populate the psymtabs_addrmap. */
2704 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2705 struct mapped_index
*index
)
2707 struct objfile
*objfile
= per_objfile
->objfile
;
2708 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2709 struct gdbarch
*gdbarch
= objfile
->arch ();
2710 const gdb_byte
*iter
, *end
;
2711 struct addrmap
*mutable_map
;
2714 auto_obstack temp_obstack
;
2716 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2718 iter
= index
->address_table
.data ();
2719 end
= iter
+ index
->address_table
.size ();
2721 baseaddr
= objfile
->text_section_offset ();
2725 ULONGEST hi
, lo
, cu_index
;
2726 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2728 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2730 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2735 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2736 hex_string (lo
), hex_string (hi
));
2740 if (cu_index
>= per_bfd
->all_comp_units
.size ())
2742 complaint (_(".gdb_index address table has invalid CU number %u"),
2743 (unsigned) cu_index
);
2747 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2748 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2749 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2750 per_bfd
->get_cu (cu_index
));
2753 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2757 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2758 populate the psymtabs_addrmap. */
2761 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2762 struct dwarf2_section_info
*section
)
2764 struct objfile
*objfile
= per_objfile
->objfile
;
2765 bfd
*abfd
= objfile
->obfd
;
2766 struct gdbarch
*gdbarch
= objfile
->arch ();
2767 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2768 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2770 auto_obstack temp_obstack
;
2771 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2773 std::unordered_map
<sect_offset
,
2774 dwarf2_per_cu_data
*,
2775 gdb::hash_enum
<sect_offset
>>
2776 debug_info_offset_to_per_cu
;
2777 for (const auto &per_cu
: per_bfd
->all_comp_units
)
2779 const auto insertpair
2780 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
,
2782 if (!insertpair
.second
)
2784 warning (_("Section .debug_aranges in %s has duplicate "
2785 "debug_info_offset %s, ignoring .debug_aranges."),
2786 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2791 section
->read (objfile
);
2793 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2795 const gdb_byte
*addr
= section
->buffer
;
2797 while (addr
< section
->buffer
+ section
->size
)
2799 const gdb_byte
*const entry_addr
= addr
;
2800 unsigned int bytes_read
;
2802 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2806 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2807 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2808 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2809 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2811 warning (_("Section .debug_aranges in %s entry at offset %s "
2812 "length %s exceeds section length %s, "
2813 "ignoring .debug_aranges."),
2814 objfile_name (objfile
),
2815 plongest (entry_addr
- section
->buffer
),
2816 plongest (bytes_read
+ entry_length
),
2817 pulongest (section
->size
));
2821 /* The version number. */
2822 const uint16_t version
= read_2_bytes (abfd
, addr
);
2826 warning (_("Section .debug_aranges in %s entry at offset %s "
2827 "has unsupported version %d, ignoring .debug_aranges."),
2828 objfile_name (objfile
),
2829 plongest (entry_addr
- section
->buffer
), version
);
2833 const uint64_t debug_info_offset
2834 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2835 addr
+= offset_size
;
2836 const auto per_cu_it
2837 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2838 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2840 warning (_("Section .debug_aranges in %s entry at offset %s "
2841 "debug_info_offset %s does not exists, "
2842 "ignoring .debug_aranges."),
2843 objfile_name (objfile
),
2844 plongest (entry_addr
- section
->buffer
),
2845 pulongest (debug_info_offset
));
2848 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2850 const uint8_t address_size
= *addr
++;
2851 if (address_size
< 1 || address_size
> 8)
2853 warning (_("Section .debug_aranges in %s entry at offset %s "
2854 "address_size %u is invalid, ignoring .debug_aranges."),
2855 objfile_name (objfile
),
2856 plongest (entry_addr
- section
->buffer
), address_size
);
2860 const uint8_t segment_selector_size
= *addr
++;
2861 if (segment_selector_size
!= 0)
2863 warning (_("Section .debug_aranges in %s entry at offset %s "
2864 "segment_selector_size %u is not supported, "
2865 "ignoring .debug_aranges."),
2866 objfile_name (objfile
),
2867 plongest (entry_addr
- section
->buffer
),
2868 segment_selector_size
);
2872 /* Must pad to an alignment boundary that is twice the address
2873 size. It is undocumented by the DWARF standard but GCC does
2875 for (size_t padding
= ((-(addr
- section
->buffer
))
2876 & (2 * address_size
- 1));
2877 padding
> 0; padding
--)
2880 warning (_("Section .debug_aranges in %s entry at offset %s "
2881 "padding is not zero, ignoring .debug_aranges."),
2882 objfile_name (objfile
),
2883 plongest (entry_addr
- section
->buffer
));
2889 if (addr
+ 2 * address_size
> entry_end
)
2891 warning (_("Section .debug_aranges in %s entry at offset %s "
2892 "address list is not properly terminated, "
2893 "ignoring .debug_aranges."),
2894 objfile_name (objfile
),
2895 plongest (entry_addr
- section
->buffer
));
2898 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2900 addr
+= address_size
;
2901 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2903 addr
+= address_size
;
2904 if (start
== 0 && length
== 0)
2906 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2908 /* Symbol was eliminated due to a COMDAT group. */
2911 ULONGEST end
= start
+ length
;
2912 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2914 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2916 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2920 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2924 /* A helper function that reads the .gdb_index from BUFFER and fills
2925 in MAP. FILENAME is the name of the file containing the data;
2926 it is used for error reporting. DEPRECATED_OK is true if it is
2927 ok to use deprecated sections.
2929 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2930 out parameters that are filled in with information about the CU and
2931 TU lists in the section.
2933 Returns true if all went well, false otherwise. */
2936 read_gdb_index_from_buffer (const char *filename
,
2938 gdb::array_view
<const gdb_byte
> buffer
,
2939 struct mapped_index
*map
,
2940 const gdb_byte
**cu_list
,
2941 offset_type
*cu_list_elements
,
2942 const gdb_byte
**types_list
,
2943 offset_type
*types_list_elements
)
2945 const gdb_byte
*addr
= &buffer
[0];
2946 offset_view
metadata (buffer
);
2948 /* Version check. */
2949 offset_type version
= metadata
[0];
2950 /* Versions earlier than 3 emitted every copy of a psymbol. This
2951 causes the index to behave very poorly for certain requests. Version 3
2952 contained incomplete addrmap. So, it seems better to just ignore such
2956 static int warning_printed
= 0;
2957 if (!warning_printed
)
2959 warning (_("Skipping obsolete .gdb_index section in %s."),
2961 warning_printed
= 1;
2965 /* Index version 4 uses a different hash function than index version
2968 Versions earlier than 6 did not emit psymbols for inlined
2969 functions. Using these files will cause GDB not to be able to
2970 set breakpoints on inlined functions by name, so we ignore these
2971 indices unless the user has done
2972 "set use-deprecated-index-sections on". */
2973 if (version
< 6 && !deprecated_ok
)
2975 static int warning_printed
= 0;
2976 if (!warning_printed
)
2979 Skipping deprecated .gdb_index section in %s.\n\
2980 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2981 to use the section anyway."),
2983 warning_printed
= 1;
2987 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2988 of the TU (for symbols coming from TUs),
2989 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2990 Plus gold-generated indices can have duplicate entries for global symbols,
2991 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2992 These are just performance bugs, and we can't distinguish gdb-generated
2993 indices from gold-generated ones, so issue no warning here. */
2995 /* Indexes with higher version than the one supported by GDB may be no
2996 longer backward compatible. */
3000 map
->version
= version
;
3003 *cu_list
= addr
+ metadata
[i
];
3004 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
3007 *types_list
= addr
+ metadata
[i
];
3008 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
3011 const gdb_byte
*address_table
= addr
+ metadata
[i
];
3012 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
3014 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3017 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
3018 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
3020 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
3024 map
->constant_pool
= buffer
.slice (metadata
[i
]);
3029 /* Callback types for dwarf2_read_gdb_index. */
3031 typedef gdb::function_view
3032 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3033 get_gdb_index_contents_ftype
;
3034 typedef gdb::function_view
3035 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3036 get_gdb_index_contents_dwz_ftype
;
3038 /* Read .gdb_index. If everything went ok, initialize the "quick"
3039 elements of all the CUs and return 1. Otherwise, return 0. */
3042 dwarf2_read_gdb_index
3043 (dwarf2_per_objfile
*per_objfile
,
3044 get_gdb_index_contents_ftype get_gdb_index_contents
,
3045 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3047 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3048 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3049 struct dwz_file
*dwz
;
3050 struct objfile
*objfile
= per_objfile
->objfile
;
3051 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3053 gdb::array_view
<const gdb_byte
> main_index_contents
3054 = get_gdb_index_contents (objfile
, per_bfd
);
3056 if (main_index_contents
.empty ())
3059 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3060 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3061 use_deprecated_index_sections
,
3062 main_index_contents
, map
.get (), &cu_list
,
3063 &cu_list_elements
, &types_list
,
3064 &types_list_elements
))
3067 /* Don't use the index if it's empty. */
3068 if (map
->symbol_table
.empty ())
3071 /* If there is a .dwz file, read it so we can get its CU list as
3073 dwz
= dwarf2_get_dwz_file (per_bfd
);
3076 struct mapped_index dwz_map
;
3077 const gdb_byte
*dwz_types_ignore
;
3078 offset_type dwz_types_elements_ignore
;
3080 gdb::array_view
<const gdb_byte
> dwz_index_content
3081 = get_gdb_index_contents_dwz (objfile
, dwz
);
3083 if (dwz_index_content
.empty ())
3086 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3087 1, dwz_index_content
, &dwz_map
,
3088 &dwz_list
, &dwz_list_elements
,
3090 &dwz_types_elements_ignore
))
3092 warning (_("could not read '.gdb_index' section from %s; skipping"),
3093 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3098 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
3101 if (types_list_elements
)
3103 /* We can only handle a single .debug_types when we have an
3105 if (per_bfd
->types
.size () != 1)
3108 dwarf2_section_info
*section
= &per_bfd
->types
[0];
3110 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
3111 types_list_elements
);
3114 create_addrmap_from_index (per_objfile
, map
.get ());
3116 per_bfd
->index_table
= std::move (map
);
3117 per_bfd
->using_index
= 1;
3118 per_bfd
->quick_file_names_table
=
3119 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
3124 /* die_reader_func for dw2_get_file_names. */
3127 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3128 struct die_info
*comp_unit_die
)
3130 struct dwarf2_cu
*cu
= reader
->cu
;
3131 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3132 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3133 struct dwarf2_per_cu_data
*lh_cu
;
3134 struct attribute
*attr
;
3136 struct quick_file_names
*qfn
;
3138 gdb_assert (! this_cu
->is_debug_types
);
3140 /* Our callers never want to match partial units -- instead they
3141 will match the enclosing full CU. */
3142 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3144 this_cu
->v
.quick
->no_file_data
= 1;
3152 sect_offset line_offset
{};
3154 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3155 if (attr
!= nullptr && attr
->form_is_unsigned ())
3157 struct quick_file_names find_entry
;
3159 line_offset
= (sect_offset
) attr
->as_unsigned ();
3161 /* We may have already read in this line header (TU line header sharing).
3162 If we have we're done. */
3163 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3164 find_entry
.hash
.line_sect_off
= line_offset
;
3165 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3166 &find_entry
, INSERT
);
3169 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3173 lh
= dwarf_decode_line_header (line_offset
, cu
);
3177 lh_cu
->v
.quick
->no_file_data
= 1;
3181 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3182 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3183 qfn
->hash
.line_sect_off
= line_offset
;
3184 gdb_assert (slot
!= NULL
);
3187 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3190 if (strcmp (fnd
.name
, "<unknown>") != 0)
3193 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3195 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3196 qfn
->num_file_names
);
3198 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3199 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3200 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3201 fnd
.comp_dir
).release ();
3202 qfn
->real_names
= NULL
;
3204 lh_cu
->v
.quick
->file_names
= qfn
;
3207 /* A helper for the "quick" functions which attempts to read the line
3208 table for THIS_CU. */
3210 static struct quick_file_names
*
3211 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3212 dwarf2_per_objfile
*per_objfile
)
3214 /* This should never be called for TUs. */
3215 gdb_assert (! this_cu
->is_debug_types
);
3216 /* Nor type unit groups. */
3217 gdb_assert (! this_cu
->type_unit_group_p ());
3219 if (this_cu
->v
.quick
->file_names
!= NULL
)
3220 return this_cu
->v
.quick
->file_names
;
3221 /* If we know there is no line data, no point in looking again. */
3222 if (this_cu
->v
.quick
->no_file_data
)
3225 cutu_reader
reader (this_cu
, per_objfile
);
3226 if (!reader
.dummy_p
)
3227 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
3229 if (this_cu
->v
.quick
->no_file_data
)
3231 return this_cu
->v
.quick
->file_names
;
3234 /* A helper for the "quick" functions which computes and caches the
3235 real path for a given file name from the line table. */
3238 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3239 struct quick_file_names
*qfn
, int index
)
3241 if (qfn
->real_names
== NULL
)
3242 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3243 qfn
->num_file_names
, const char *);
3245 if (qfn
->real_names
[index
] == NULL
)
3246 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3248 return qfn
->real_names
[index
];
3252 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3254 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3255 dwarf2_per_cu_data
*dwarf_cu
3256 = per_objfile
->per_bfd
->all_comp_units
.back ().get ();
3257 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3262 return compunit_primary_filetab (cust
);
3265 /* Traversal function for dw2_forget_cached_source_info. */
3268 dw2_free_cached_file_names (void **slot
, void *info
)
3270 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3272 if (file_data
->real_names
)
3276 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3278 xfree ((void*) file_data
->real_names
[i
]);
3279 file_data
->real_names
[i
] = NULL
;
3287 dwarf2_base_index_functions::forget_cached_source_info
3288 (struct objfile
*objfile
)
3290 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3292 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3293 dw2_free_cached_file_names
, NULL
);
3296 /* Struct used to manage iterating over all CUs looking for a symbol. */
3298 struct dw2_symtab_iterator
3300 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3301 dwarf2_per_objfile
*per_objfile
;
3302 /* If set, only look for symbols that match that block. Valid values are
3303 GLOBAL_BLOCK and STATIC_BLOCK. */
3304 gdb::optional
<block_enum
> block_index
;
3305 /* The kind of symbol we're looking for. */
3307 /* The list of CUs from the index entry of the symbol,
3308 or NULL if not found. */
3310 /* The next element in VEC to look at. */
3312 /* The number of elements in VEC, or zero if there is no match. */
3314 /* Have we seen a global version of the symbol?
3315 If so we can ignore all further global instances.
3316 This is to work around gold/15646, inefficient gold-generated
3321 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3324 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3325 dwarf2_per_objfile
*per_objfile
,
3326 gdb::optional
<block_enum
> block_index
,
3327 domain_enum domain
, offset_type namei
)
3329 iter
->per_objfile
= per_objfile
;
3330 iter
->block_index
= block_index
;
3331 iter
->domain
= domain
;
3333 iter
->global_seen
= 0;
3337 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3338 /* index is NULL if OBJF_READNOW. */
3342 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3343 offset_type vec_idx
= index
->symbol_vec_index (namei
);
3345 iter
->vec
= offset_view (index
->constant_pool
.slice (vec_idx
));
3346 iter
->length
= iter
->vec
[0];
3349 /* Return the next matching CU or NULL if there are no more. */
3351 static struct dwarf2_per_cu_data
*
3352 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3354 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3356 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3358 offset_type cu_index_and_attrs
= iter
->vec
[iter
->next
+ 1];
3359 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3360 gdb_index_symbol_kind symbol_kind
=
3361 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3362 /* Only check the symbol attributes if they're present.
3363 Indices prior to version 7 don't record them,
3364 and indices >= 7 may elide them for certain symbols
3365 (gold does this). */
3367 (per_objfile
->per_bfd
->index_table
->version
>= 7
3368 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3370 /* Don't crash on bad data. */
3371 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
3373 complaint (_(".gdb_index entry has bad CU index"
3374 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3378 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
3380 /* Skip if already read in. */
3381 if (per_objfile
->symtab_set_p (per_cu
))
3384 /* Check static vs global. */
3387 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3389 if (iter
->block_index
.has_value ())
3391 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3393 if (is_static
!= want_static
)
3397 /* Work around gold/15646. */
3399 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3401 if (iter
->global_seen
)
3404 iter
->global_seen
= 1;
3408 /* Only check the symbol's kind if it has one. */
3411 switch (iter
->domain
)
3414 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3415 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3416 /* Some types are also in VAR_DOMAIN. */
3417 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3421 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3425 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3429 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3445 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
3451 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3452 int total
= per_objfile
->per_bfd
->all_comp_units
.size ();
3455 for (int i
= 0; i
< total
; ++i
)
3457 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3459 if (!per_objfile
->symtab_set_p (per_cu
))
3462 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3463 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3466 /* This dumps minimal information about the index.
3467 It is called via "mt print objfiles".
3468 One use is to verify .gdb_index has been loaded by the
3469 gdb.dwarf2/gdb-index.exp testcase. */
3472 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3474 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3476 gdb_assert (per_objfile
->per_bfd
->using_index
);
3477 printf_filtered (".gdb_index:");
3478 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3480 printf_filtered (" version %d\n",
3481 per_objfile
->per_bfd
->index_table
->version
);
3484 printf_filtered (" faked for \"readnow\"\n");
3485 printf_filtered ("\n");
3489 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3491 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3492 int total_units
= per_objfile
->per_bfd
->all_comp_units
.size ();
3494 for (int i
= 0; i
< total_units
; ++i
)
3496 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3498 /* We don't want to directly expand a partial CU, because if we
3499 read it with the wrong language, then assertion failures can
3500 be triggered later on. See PR symtab/23010. So, tell
3501 dw2_instantiate_symtab to skip partial CUs -- any important
3502 partial CU will be read via DW_TAG_imported_unit anyway. */
3503 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3508 dw2_expand_symtabs_matching_symbol
3509 (mapped_index_base
&index
,
3510 const lookup_name_info
&lookup_name_in
,
3511 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3512 gdb::function_view
<bool (offset_type
)> match_callback
,
3513 dwarf2_per_objfile
*per_objfile
);
3516 dw2_expand_symtabs_matching_one
3517 (dwarf2_per_cu_data
*per_cu
,
3518 dwarf2_per_objfile
*per_objfile
,
3519 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3520 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3523 dwarf2_gdb_index::expand_matching_symbols
3524 (struct objfile
*objfile
,
3525 const lookup_name_info
&name
, domain_enum domain
,
3527 symbol_compare_ftype
*ordered_compare
)
3530 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3532 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3534 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3536 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3538 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3539 auto matcher
= [&] (const char *symname
)
3541 if (ordered_compare
== nullptr)
3543 return ordered_compare (symname
, match_name
) == 0;
3546 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
3547 [&] (offset_type namei
)
3549 struct dw2_symtab_iterator iter
;
3550 struct dwarf2_per_cu_data
*per_cu
;
3552 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3554 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3555 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3562 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3563 proceed assuming all symtabs have been read in. */
3567 /* Starting from a search name, return the string that finds the upper
3568 bound of all strings that start with SEARCH_NAME in a sorted name
3569 list. Returns the empty string to indicate that the upper bound is
3570 the end of the list. */
3573 make_sort_after_prefix_name (const char *search_name
)
3575 /* When looking to complete "func", we find the upper bound of all
3576 symbols that start with "func" by looking for where we'd insert
3577 the closest string that would follow "func" in lexicographical
3578 order. Usually, that's "func"-with-last-character-incremented,
3579 i.e. "fund". Mind non-ASCII characters, though. Usually those
3580 will be UTF-8 multi-byte sequences, but we can't be certain.
3581 Especially mind the 0xff character, which is a valid character in
3582 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3583 rule out compilers allowing it in identifiers. Note that
3584 conveniently, strcmp/strcasecmp are specified to compare
3585 characters interpreted as unsigned char. So what we do is treat
3586 the whole string as a base 256 number composed of a sequence of
3587 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3588 to 0, and carries 1 to the following more-significant position.
3589 If the very first character in SEARCH_NAME ends up incremented
3590 and carries/overflows, then the upper bound is the end of the
3591 list. The string after the empty string is also the empty
3594 Some examples of this operation:
3596 SEARCH_NAME => "+1" RESULT
3600 "\xff" "a" "\xff" => "\xff" "b"
3605 Then, with these symbols for example:
3611 completing "func" looks for symbols between "func" and
3612 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3613 which finds "func" and "func1", but not "fund".
3617 funcÿ (Latin1 'ÿ' [0xff])
3621 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3622 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3626 ÿÿ (Latin1 'ÿ' [0xff])
3629 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3630 the end of the list.
3632 std::string after
= search_name
;
3633 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3635 if (!after
.empty ())
3636 after
.back () = (unsigned char) after
.back () + 1;
3640 /* See declaration. */
3642 std::pair
<std::vector
<name_component
>::const_iterator
,
3643 std::vector
<name_component
>::const_iterator
>
3644 mapped_index_base::find_name_components_bounds
3645 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3646 dwarf2_per_objfile
*per_objfile
) const
3649 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3651 const char *lang_name
3652 = lookup_name_without_params
.language_lookup_name (lang
);
3654 /* Comparison function object for lower_bound that matches against a
3655 given symbol name. */
3656 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3659 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3660 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3661 return name_cmp (elem_name
, name
) < 0;
3664 /* Comparison function object for upper_bound that matches against a
3665 given symbol name. */
3666 auto lookup_compare_upper
= [&] (const char *name
,
3667 const name_component
&elem
)
3669 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3670 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3671 return name_cmp (name
, elem_name
) < 0;
3674 auto begin
= this->name_components
.begin ();
3675 auto end
= this->name_components
.end ();
3677 /* Find the lower bound. */
3680 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3683 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3686 /* Find the upper bound. */
3689 if (lookup_name_without_params
.completion_mode ())
3691 /* In completion mode, we want UPPER to point past all
3692 symbols names that have the same prefix. I.e., with
3693 these symbols, and completing "func":
3695 function << lower bound
3697 other_function << upper bound
3699 We find the upper bound by looking for the insertion
3700 point of "func"-with-last-character-incremented,
3702 std::string after
= make_sort_after_prefix_name (lang_name
);
3705 return std::lower_bound (lower
, end
, after
.c_str (),
3706 lookup_compare_lower
);
3709 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3712 return {lower
, upper
};
3715 /* See declaration. */
3718 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3720 if (!this->name_components
.empty ())
3723 this->name_components_casing
= case_sensitivity
;
3725 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3727 /* The code below only knows how to break apart components of C++
3728 symbol names (and other languages that use '::' as
3729 namespace/module separator) and Ada symbol names. */
3730 auto count
= this->symbol_name_count ();
3731 for (offset_type idx
= 0; idx
< count
; idx
++)
3733 if (this->symbol_name_slot_invalid (idx
))
3736 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3738 /* Add each name component to the name component table. */
3739 unsigned int previous_len
= 0;
3741 if (strstr (name
, "::") != nullptr)
3743 for (unsigned int current_len
= cp_find_first_component (name
);
3744 name
[current_len
] != '\0';
3745 current_len
+= cp_find_first_component (name
+ current_len
))
3747 gdb_assert (name
[current_len
] == ':');
3748 this->name_components
.push_back ({previous_len
, idx
});
3749 /* Skip the '::'. */
3751 previous_len
= current_len
;
3756 /* Handle the Ada encoded (aka mangled) form here. */
3757 for (const char *iter
= strstr (name
, "__");
3759 iter
= strstr (iter
, "__"))
3761 this->name_components
.push_back ({previous_len
, idx
});
3763 previous_len
= iter
- name
;
3767 this->name_components
.push_back ({previous_len
, idx
});
3770 /* Sort name_components elements by name. */
3771 auto name_comp_compare
= [&] (const name_component
&left
,
3772 const name_component
&right
)
3774 const char *left_qualified
3775 = this->symbol_name_at (left
.idx
, per_objfile
);
3776 const char *right_qualified
3777 = this->symbol_name_at (right
.idx
, per_objfile
);
3779 const char *left_name
= left_qualified
+ left
.name_offset
;
3780 const char *right_name
= right_qualified
+ right
.name_offset
;
3782 return name_cmp (left_name
, right_name
) < 0;
3785 std::sort (this->name_components
.begin (),
3786 this->name_components
.end (),
3790 /* Helper for dw2_expand_symtabs_matching that works with a
3791 mapped_index_base instead of the containing objfile. This is split
3792 to a separate function in order to be able to unit test the
3793 name_components matching using a mock mapped_index_base. For each
3794 symbol name that matches, calls MATCH_CALLBACK, passing it the
3795 symbol's index in the mapped_index_base symbol table. */
3798 dw2_expand_symtabs_matching_symbol
3799 (mapped_index_base
&index
,
3800 const lookup_name_info
&lookup_name_in
,
3801 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3802 gdb::function_view
<bool (offset_type
)> match_callback
,
3803 dwarf2_per_objfile
*per_objfile
)
3805 lookup_name_info lookup_name_without_params
3806 = lookup_name_in
.make_ignore_params ();
3808 /* Build the symbol name component sorted vector, if we haven't
3810 index
.build_name_components (per_objfile
);
3812 /* The same symbol may appear more than once in the range though.
3813 E.g., if we're looking for symbols that complete "w", and we have
3814 a symbol named "w1::w2", we'll find the two name components for
3815 that same symbol in the range. To be sure we only call the
3816 callback once per symbol, we first collect the symbol name
3817 indexes that matched in a temporary vector and ignore
3819 std::vector
<offset_type
> matches
;
3821 struct name_and_matcher
3823 symbol_name_matcher_ftype
*matcher
;
3826 bool operator== (const name_and_matcher
&other
) const
3828 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3832 /* A vector holding all the different symbol name matchers, for all
3834 std::vector
<name_and_matcher
> matchers
;
3836 for (int i
= 0; i
< nr_languages
; i
++)
3838 enum language lang_e
= (enum language
) i
;
3840 const language_defn
*lang
= language_def (lang_e
);
3841 symbol_name_matcher_ftype
*name_matcher
3842 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
3844 name_and_matcher key
{
3846 lookup_name_without_params
.language_lookup_name (lang_e
)
3849 /* Don't insert the same comparison routine more than once.
3850 Note that we do this linear walk. This is not a problem in
3851 practice because the number of supported languages is
3853 if (std::find (matchers
.begin (), matchers
.end (), key
)
3856 matchers
.push_back (std::move (key
));
3859 = index
.find_name_components_bounds (lookup_name_without_params
,
3860 lang_e
, per_objfile
);
3862 /* Now for each symbol name in range, check to see if we have a name
3863 match, and if so, call the MATCH_CALLBACK callback. */
3865 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3867 const char *qualified
3868 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
3870 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3871 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3874 matches
.push_back (bounds
.first
->idx
);
3878 std::sort (matches
.begin (), matches
.end ());
3880 /* Finally call the callback, once per match. */
3883 for (offset_type idx
: matches
)
3887 if (!match_callback (idx
))
3896 /* Above we use a type wider than idx's for 'prev', since 0 and
3897 (offset_type)-1 are both possible values. */
3898 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3905 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3907 /* A mock .gdb_index/.debug_names-like name index table, enough to
3908 exercise dw2_expand_symtabs_matching_symbol, which works with the
3909 mapped_index_base interface. Builds an index from the symbol list
3910 passed as parameter to the constructor. */
3911 class mock_mapped_index
: public mapped_index_base
3914 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3915 : m_symbol_table (symbols
)
3918 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3920 /* Return the number of names in the symbol table. */
3921 size_t symbol_name_count () const override
3923 return m_symbol_table
.size ();
3926 /* Get the name of the symbol at IDX in the symbol table. */
3927 const char *symbol_name_at
3928 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
3930 return m_symbol_table
[idx
];
3934 gdb::array_view
<const char *> m_symbol_table
;
3937 /* Convenience function that converts a NULL pointer to a "<null>"
3938 string, to pass to print routines. */
3941 string_or_null (const char *str
)
3943 return str
!= NULL
? str
: "<null>";
3946 /* Check if a lookup_name_info built from
3947 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3948 index. EXPECTED_LIST is the list of expected matches, in expected
3949 matching order. If no match expected, then an empty list is
3950 specified. Returns true on success. On failure prints a warning
3951 indicating the file:line that failed, and returns false. */
3954 check_match (const char *file
, int line
,
3955 mock_mapped_index
&mock_index
,
3956 const char *name
, symbol_name_match_type match_type
,
3957 bool completion_mode
,
3958 std::initializer_list
<const char *> expected_list
,
3959 dwarf2_per_objfile
*per_objfile
)
3961 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3963 bool matched
= true;
3965 auto mismatch
= [&] (const char *expected_str
,
3968 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3969 "expected=\"%s\", got=\"%s\"\n"),
3971 (match_type
== symbol_name_match_type::FULL
3973 name
, string_or_null (expected_str
), string_or_null (got
));
3977 auto expected_it
= expected_list
.begin ();
3978 auto expected_end
= expected_list
.end ();
3980 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
3982 [&] (offset_type idx
)
3984 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
3985 const char *expected_str
3986 = expected_it
== expected_end
? NULL
: *expected_it
++;
3988 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
3989 mismatch (expected_str
, matched_name
);
3993 const char *expected_str
3994 = expected_it
== expected_end
? NULL
: *expected_it
++;
3995 if (expected_str
!= NULL
)
3996 mismatch (expected_str
, NULL
);
4001 /* The symbols added to the mock mapped_index for testing (in
4003 static const char *test_symbols
[] = {
4012 "ns2::tmpl<int>::foo2",
4013 "(anonymous namespace)::A::B::C",
4015 /* These are used to check that the increment-last-char in the
4016 matching algorithm for completion doesn't match "t1_fund" when
4017 completing "t1_func". */
4023 /* A UTF-8 name with multi-byte sequences to make sure that
4024 cp-name-parser understands this as a single identifier ("função"
4025 is "function" in PT). */
4028 /* \377 (0xff) is Latin1 'ÿ'. */
4031 /* \377 (0xff) is Latin1 'ÿ'. */
4035 /* A name with all sorts of complications. Starts with "z" to make
4036 it easier for the completion tests below. */
4037 #define Z_SYM_NAME \
4038 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4039 "::tuple<(anonymous namespace)::ui*, " \
4040 "std::default_delete<(anonymous namespace)::ui>, void>"
4045 /* Returns true if the mapped_index_base::find_name_component_bounds
4046 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4047 in completion mode. */
4050 check_find_bounds_finds (mapped_index_base
&index
,
4051 const char *search_name
,
4052 gdb::array_view
<const char *> expected_syms
,
4053 dwarf2_per_objfile
*per_objfile
)
4055 lookup_name_info
lookup_name (search_name
,
4056 symbol_name_match_type::FULL
, true);
4058 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4062 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4063 if (distance
!= expected_syms
.size ())
4066 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4068 auto nc_elem
= bounds
.first
+ exp_elem
;
4069 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4070 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4077 /* Test the lower-level mapped_index::find_name_component_bounds
4081 test_mapped_index_find_name_component_bounds ()
4083 mock_mapped_index
mock_index (test_symbols
);
4085 mock_index
.build_name_components (NULL
/* per_objfile */);
4087 /* Test the lower-level mapped_index::find_name_component_bounds
4088 method in completion mode. */
4090 static const char *expected_syms
[] = {
4095 SELF_CHECK (check_find_bounds_finds
4096 (mock_index
, "t1_func", expected_syms
,
4097 NULL
/* per_objfile */));
4100 /* Check that the increment-last-char in the name matching algorithm
4101 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4103 static const char *expected_syms1
[] = {
4107 SELF_CHECK (check_find_bounds_finds
4108 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4110 static const char *expected_syms2
[] = {
4113 SELF_CHECK (check_find_bounds_finds
4114 (mock_index
, "\377\377", expected_syms2
,
4115 NULL
/* per_objfile */));
4119 /* Test dw2_expand_symtabs_matching_symbol. */
4122 test_dw2_expand_symtabs_matching_symbol ()
4124 mock_mapped_index
mock_index (test_symbols
);
4126 /* We let all tests run until the end even if some fails, for debug
4128 bool any_mismatch
= false;
4130 /* Create the expected symbols list (an initializer_list). Needed
4131 because lists have commas, and we need to pass them to CHECK,
4132 which is a macro. */
4133 #define EXPECT(...) { __VA_ARGS__ }
4135 /* Wrapper for check_match that passes down the current
4136 __FILE__/__LINE__. */
4137 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4138 any_mismatch |= !check_match (__FILE__, __LINE__, \
4140 NAME, MATCH_TYPE, COMPLETION_MODE, \
4141 EXPECTED_LIST, NULL)
4143 /* Identity checks. */
4144 for (const char *sym
: test_symbols
)
4146 /* Should be able to match all existing symbols. */
4147 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4150 /* Should be able to match all existing symbols with
4152 std::string with_params
= std::string (sym
) + "(int)";
4153 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4156 /* Should be able to match all existing symbols with
4157 parameters and qualifiers. */
4158 with_params
= std::string (sym
) + " ( int ) const";
4159 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4162 /* This should really find sym, but cp-name-parser.y doesn't
4163 know about lvalue/rvalue qualifiers yet. */
4164 with_params
= std::string (sym
) + " ( int ) &&";
4165 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4169 /* Check that the name matching algorithm for completion doesn't get
4170 confused with Latin1 'ÿ' / 0xff. */
4172 static const char str
[] = "\377";
4173 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4174 EXPECT ("\377", "\377\377123"));
4177 /* Check that the increment-last-char in the matching algorithm for
4178 completion doesn't match "t1_fund" when completing "t1_func". */
4180 static const char str
[] = "t1_func";
4181 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4182 EXPECT ("t1_func", "t1_func1"));
4185 /* Check that completion mode works at each prefix of the expected
4188 static const char str
[] = "function(int)";
4189 size_t len
= strlen (str
);
4192 for (size_t i
= 1; i
< len
; i
++)
4194 lookup
.assign (str
, i
);
4195 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4196 EXPECT ("function"));
4200 /* While "w" is a prefix of both components, the match function
4201 should still only be called once. */
4203 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4205 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4209 /* Same, with a "complicated" symbol. */
4211 static const char str
[] = Z_SYM_NAME
;
4212 size_t len
= strlen (str
);
4215 for (size_t i
= 1; i
< len
; i
++)
4217 lookup
.assign (str
, i
);
4218 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4219 EXPECT (Z_SYM_NAME
));
4223 /* In FULL mode, an incomplete symbol doesn't match. */
4225 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4229 /* A complete symbol with parameters matches any overload, since the
4230 index has no overload info. */
4232 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4233 EXPECT ("std::zfunction", "std::zfunction2"));
4234 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4235 EXPECT ("std::zfunction", "std::zfunction2"));
4236 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4237 EXPECT ("std::zfunction", "std::zfunction2"));
4240 /* Check that whitespace is ignored appropriately. A symbol with a
4241 template argument list. */
4243 static const char expected
[] = "ns::foo<int>";
4244 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4246 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4250 /* Check that whitespace is ignored appropriately. A symbol with a
4251 template argument list that includes a pointer. */
4253 static const char expected
[] = "ns::foo<char*>";
4254 /* Try both completion and non-completion modes. */
4255 static const bool completion_mode
[2] = {false, true};
4256 for (size_t i
= 0; i
< 2; i
++)
4258 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4259 completion_mode
[i
], EXPECT (expected
));
4260 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4261 completion_mode
[i
], EXPECT (expected
));
4263 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4264 completion_mode
[i
], EXPECT (expected
));
4265 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4266 completion_mode
[i
], EXPECT (expected
));
4271 /* Check method qualifiers are ignored. */
4272 static const char expected
[] = "ns::foo<char*>";
4273 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4274 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4275 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4276 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4277 CHECK_MATCH ("foo < char * > ( int ) const",
4278 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4279 CHECK_MATCH ("foo < char * > ( int ) &&",
4280 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4283 /* Test lookup names that don't match anything. */
4285 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4288 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4292 /* Some wild matching tests, exercising "(anonymous namespace)",
4293 which should not be confused with a parameter list. */
4295 static const char *syms
[] = {
4299 "A :: B :: C ( int )",
4304 for (const char *s
: syms
)
4306 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4307 EXPECT ("(anonymous namespace)::A::B::C"));
4312 static const char expected
[] = "ns2::tmpl<int>::foo2";
4313 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4315 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4319 SELF_CHECK (!any_mismatch
);
4328 test_mapped_index_find_name_component_bounds ();
4329 test_dw2_expand_symtabs_matching_symbol ();
4332 }} // namespace selftests::dw2_expand_symtabs_matching
4334 #endif /* GDB_SELF_TEST */
4336 /* If FILE_MATCHER is NULL or if PER_CU has
4337 dwarf2_per_cu_quick_data::MARK set (see
4338 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4339 EXPANSION_NOTIFY on it. */
4342 dw2_expand_symtabs_matching_one
4343 (dwarf2_per_cu_data
*per_cu
,
4344 dwarf2_per_objfile
*per_objfile
,
4345 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4346 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4348 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4350 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4352 compunit_symtab
*symtab
4353 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4354 gdb_assert (symtab
!= nullptr);
4356 if (expansion_notify
!= NULL
&& symtab_was_null
)
4357 return expansion_notify (symtab
);
4362 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4363 matched, to expand corresponding CUs that were marked. IDX is the
4364 index of the symbol name that matched. */
4367 dw2_expand_marked_cus
4368 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4369 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4370 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4371 block_search_flags search_flags
,
4374 offset_type vec_len
, vec_idx
;
4375 bool global_seen
= false;
4376 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4378 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
4380 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4382 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
4383 /* This value is only valid for index versions >= 7. */
4384 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4385 gdb_index_symbol_kind symbol_kind
=
4386 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4387 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4388 /* Only check the symbol attributes if they're present.
4389 Indices prior to version 7 don't record them,
4390 and indices >= 7 may elide them for certain symbols
4391 (gold does this). */
4394 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4396 /* Work around gold/15646. */
4399 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4407 /* Only check the symbol's kind if it has one. */
4412 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
4417 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
4423 case VARIABLES_DOMAIN
:
4424 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4427 case FUNCTIONS_DOMAIN
:
4428 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4432 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4435 case MODULES_DOMAIN
:
4436 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4444 /* Don't crash on bad data. */
4445 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
4447 complaint (_(".gdb_index entry has bad CU index"
4448 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4452 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
4453 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4461 /* If FILE_MATCHER is non-NULL, set all the
4462 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4463 that match FILE_MATCHER. */
4466 dw_expand_symtabs_matching_file_matcher
4467 (dwarf2_per_objfile
*per_objfile
,
4468 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4470 if (file_matcher
== NULL
)
4473 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4475 NULL
, xcalloc
, xfree
));
4476 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4478 NULL
, xcalloc
, xfree
));
4480 /* The rule is CUs specify all the files, including those used by
4481 any TU, so there's no need to scan TUs here. */
4483 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4487 if (per_cu
->is_debug_types
)
4489 per_cu
->v
.quick
->mark
= 0;
4491 /* We only need to look at symtabs not already expanded. */
4492 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4495 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4497 if (file_data
== NULL
)
4500 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4502 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4504 per_cu
->v
.quick
->mark
= 1;
4508 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4510 const char *this_real_name
;
4512 if (file_matcher (file_data
->file_names
[j
], false))
4514 per_cu
->v
.quick
->mark
= 1;
4518 /* Before we invoke realpath, which can get expensive when many
4519 files are involved, do a quick comparison of the basenames. */
4520 if (!basenames_may_differ
4521 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4525 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4526 if (file_matcher (this_real_name
, false))
4528 per_cu
->v
.quick
->mark
= 1;
4533 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4534 ? visited_found
.get ()
4535 : visited_not_found
.get (),
4542 dwarf2_gdb_index::expand_symtabs_matching
4543 (struct objfile
*objfile
,
4544 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4545 const lookup_name_info
*lookup_name
,
4546 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4547 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4548 block_search_flags search_flags
,
4550 enum search_domain kind
)
4552 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4554 /* index_table is NULL if OBJF_READNOW. */
4555 if (!per_objfile
->per_bfd
->index_table
)
4558 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4560 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4562 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4566 if (!dw2_expand_symtabs_matching_one (per_cu
.get (), per_objfile
,
4574 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4577 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4579 [&] (offset_type idx
)
4581 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
4582 expansion_notify
, search_flags
, kind
))
4590 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4593 static struct compunit_symtab
*
4594 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4599 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4600 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4603 if (cust
->includes
== NULL
)
4606 for (i
= 0; cust
->includes
[i
]; ++i
)
4608 struct compunit_symtab
*s
= cust
->includes
[i
];
4610 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4618 struct compunit_symtab
*
4619 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4620 (struct objfile
*objfile
,
4621 struct bound_minimal_symbol msymbol
,
4623 struct obj_section
*section
,
4626 struct dwarf2_per_cu_data
*data
;
4627 struct compunit_symtab
*result
;
4629 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4630 if (per_objfile
->per_bfd
->index_addrmap
== nullptr)
4633 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4634 data
= ((struct dwarf2_per_cu_data
*)
4635 addrmap_find (per_objfile
->per_bfd
->index_addrmap
,
4640 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4641 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4642 paddress (objfile
->arch (), pc
));
4644 result
= recursively_find_pc_sect_compunit_symtab
4645 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4647 gdb_assert (result
!= NULL
);
4652 dwarf2_base_index_functions::map_symbol_filenames
4653 (struct objfile
*objfile
,
4654 gdb::function_view
<symbol_filename_ftype
> fun
,
4657 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4659 /* Use caches to ensure we only call FUN once for each filename. */
4660 filename_seen_cache filenames_cache
;
4661 std::unordered_set
<quick_file_names
*> qfn_cache
;
4663 /* The rule is CUs specify all the files, including those used by any TU,
4664 so there's no need to scan TUs here. We can ignore file names coming
4665 from already-expanded CUs. It is possible that an expanded CU might
4666 reuse the file names data from a currently unexpanded CU, in this
4667 case we don't want to report the files from the unexpanded CU. */
4669 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4671 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4673 if (per_cu
->v
.quick
->file_names
!= nullptr)
4674 qfn_cache
.insert (per_cu
->v
.quick
->file_names
);
4678 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4680 /* We only need to look at symtabs not already expanded. */
4681 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4684 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4686 if (file_data
== nullptr
4687 || qfn_cache
.find (file_data
) != qfn_cache
.end ())
4690 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4692 const char *filename
= file_data
->file_names
[j
];
4693 filenames_cache
.seen (filename
);
4697 filenames_cache
.traverse ([&] (const char *filename
)
4699 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4702 this_real_name
= gdb_realpath (filename
);
4703 fun (filename
, this_real_name
.get ());
4708 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
4713 /* DWARF-5 debug_names reader. */
4715 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4716 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4718 /* A helper function that reads the .debug_names section in SECTION
4719 and fills in MAP. FILENAME is the name of the file containing the
4720 section; it is used for error reporting.
4722 Returns true if all went well, false otherwise. */
4725 read_debug_names_from_section (struct objfile
*objfile
,
4726 const char *filename
,
4727 struct dwarf2_section_info
*section
,
4728 mapped_debug_names
&map
)
4730 if (section
->empty ())
4733 /* Older elfutils strip versions could keep the section in the main
4734 executable while splitting it for the separate debug info file. */
4735 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4738 section
->read (objfile
);
4740 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4742 const gdb_byte
*addr
= section
->buffer
;
4744 bfd
*const abfd
= section
->get_bfd_owner ();
4746 unsigned int bytes_read
;
4747 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4750 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4751 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4752 if (bytes_read
+ length
!= section
->size
)
4754 /* There may be multiple per-CU indices. */
4755 warning (_("Section .debug_names in %s length %s does not match "
4756 "section length %s, ignoring .debug_names."),
4757 filename
, plongest (bytes_read
+ length
),
4758 pulongest (section
->size
));
4762 /* The version number. */
4763 uint16_t version
= read_2_bytes (abfd
, addr
);
4767 warning (_("Section .debug_names in %s has unsupported version %d, "
4768 "ignoring .debug_names."),
4774 uint16_t padding
= read_2_bytes (abfd
, addr
);
4778 warning (_("Section .debug_names in %s has unsupported padding %d, "
4779 "ignoring .debug_names."),
4784 /* comp_unit_count - The number of CUs in the CU list. */
4785 map
.cu_count
= read_4_bytes (abfd
, addr
);
4788 /* local_type_unit_count - The number of TUs in the local TU
4790 map
.tu_count
= read_4_bytes (abfd
, addr
);
4793 /* foreign_type_unit_count - The number of TUs in the foreign TU
4795 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4797 if (foreign_tu_count
!= 0)
4799 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4800 "ignoring .debug_names."),
4801 filename
, static_cast<unsigned long> (foreign_tu_count
));
4805 /* bucket_count - The number of hash buckets in the hash lookup
4807 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4810 /* name_count - The number of unique names in the index. */
4811 map
.name_count
= read_4_bytes (abfd
, addr
);
4814 /* abbrev_table_size - The size in bytes of the abbreviations
4816 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4819 /* augmentation_string_size - The size in bytes of the augmentation
4820 string. This value is rounded up to a multiple of 4. */
4821 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4823 map
.augmentation_is_gdb
= ((augmentation_string_size
4824 == sizeof (dwarf5_augmentation
))
4825 && memcmp (addr
, dwarf5_augmentation
,
4826 sizeof (dwarf5_augmentation
)) == 0);
4827 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4828 addr
+= augmentation_string_size
;
4831 map
.cu_table_reordered
= addr
;
4832 addr
+= map
.cu_count
* map
.offset_size
;
4834 /* List of Local TUs */
4835 map
.tu_table_reordered
= addr
;
4836 addr
+= map
.tu_count
* map
.offset_size
;
4838 /* Hash Lookup Table */
4839 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4840 addr
+= map
.bucket_count
* 4;
4841 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4842 addr
+= map
.name_count
* 4;
4845 map
.name_table_string_offs_reordered
= addr
;
4846 addr
+= map
.name_count
* map
.offset_size
;
4847 map
.name_table_entry_offs_reordered
= addr
;
4848 addr
+= map
.name_count
* map
.offset_size
;
4850 const gdb_byte
*abbrev_table_start
= addr
;
4853 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4858 const auto insertpair
4859 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4860 if (!insertpair
.second
)
4862 warning (_("Section .debug_names in %s has duplicate index %s, "
4863 "ignoring .debug_names."),
4864 filename
, pulongest (index_num
));
4867 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4868 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4873 mapped_debug_names::index_val::attr attr
;
4874 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4876 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4878 if (attr
.form
== DW_FORM_implicit_const
)
4880 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4884 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4886 indexval
.attr_vec
.push_back (std::move (attr
));
4889 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4891 warning (_("Section .debug_names in %s has abbreviation_table "
4892 "of size %s vs. written as %u, ignoring .debug_names."),
4893 filename
, plongest (addr
- abbrev_table_start
),
4897 map
.entry_pool
= addr
;
4902 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4906 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
4907 const mapped_debug_names
&map
,
4908 dwarf2_section_info
§ion
,
4911 if (!map
.augmentation_is_gdb
)
4913 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
4915 sect_offset sect_off
4916 = (sect_offset
) (extract_unsigned_integer
4917 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4919 map
.dwarf5_byte_order
));
4920 /* We don't know the length of the CU, because the CU list in a
4921 .debug_names index can be incomplete, so we can't use the start
4922 of the next CU as end of this CU. We create the CUs here with
4923 length 0, and in cutu_reader::cutu_reader we'll fill in the
4925 std::unique_ptr
<dwarf2_per_cu_data
> per_cu
4926 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4928 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4933 sect_offset sect_off_prev
;
4934 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4936 sect_offset sect_off_next
;
4937 if (i
< map
.cu_count
)
4940 = (sect_offset
) (extract_unsigned_integer
4941 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4943 map
.dwarf5_byte_order
));
4946 sect_off_next
= (sect_offset
) section
.size
;
4949 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4950 std::unique_ptr
<dwarf2_per_cu_data
> per_cu
4951 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4952 sect_off_prev
, length
);
4953 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4955 sect_off_prev
= sect_off_next
;
4959 /* Read the CU list from the mapped index, and use it to create all
4960 the CU objects for this dwarf2_per_objfile. */
4963 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
4964 const mapped_debug_names
&map
,
4965 const mapped_debug_names
&dwz_map
)
4967 gdb_assert (per_bfd
->all_comp_units
.empty ());
4968 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4970 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
4971 false /* is_dwz */);
4973 if (dwz_map
.cu_count
== 0)
4976 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4977 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
4981 /* Read .debug_names. If everything went ok, initialize the "quick"
4982 elements of all the CUs and return true. Otherwise, return false. */
4985 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
4987 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
4988 mapped_debug_names dwz_map
;
4989 struct objfile
*objfile
= per_objfile
->objfile
;
4990 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
4992 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4993 &per_bfd
->debug_names
, *map
))
4996 /* Don't use the index if it's empty. */
4997 if (map
->name_count
== 0)
5000 /* If there is a .dwz file, read it so we can get its CU list as
5002 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5005 if (!read_debug_names_from_section (objfile
,
5006 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5007 &dwz
->debug_names
, dwz_map
))
5009 warning (_("could not read '.debug_names' section from %s; skipping"),
5010 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5015 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
5017 if (map
->tu_count
!= 0)
5019 /* We can only handle a single .debug_types when we have an
5021 if (per_bfd
->types
.size () != 1)
5024 dwarf2_section_info
*section
= &per_bfd
->types
[0];
5026 create_signatured_type_table_from_debug_names
5027 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
5030 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
5032 per_bfd
->debug_names_table
= std::move (map
);
5033 per_bfd
->using_index
= 1;
5034 per_bfd
->quick_file_names_table
=
5035 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5040 /* Type used to manage iterating over all CUs looking for a symbol for
5043 class dw2_debug_names_iterator
5046 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5047 block_search_flags block_index
,
5049 const char *name
, dwarf2_per_objfile
*per_objfile
)
5050 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5051 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5052 m_per_objfile (per_objfile
)
5055 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5056 search_domain search
, uint32_t namei
,
5057 dwarf2_per_objfile
*per_objfile
,
5058 domain_enum domain
= UNDEF_DOMAIN
)
5062 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5063 m_per_objfile (per_objfile
)
5066 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5067 block_search_flags block_index
, domain_enum domain
,
5068 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5069 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5070 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5071 m_per_objfile (per_objfile
)
5074 /* Return the next matching CU or NULL if there are no more. */
5075 dwarf2_per_cu_data
*next ();
5078 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5080 dwarf2_per_objfile
*per_objfile
);
5081 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5083 dwarf2_per_objfile
*per_objfile
);
5085 /* The internalized form of .debug_names. */
5086 const mapped_debug_names
&m_map
;
5088 /* Restrict the search to these blocks. */
5089 block_search_flags m_block_index
= (SEARCH_GLOBAL_BLOCK
5090 | SEARCH_STATIC_BLOCK
);
5092 /* The kind of symbol we're looking for. */
5093 const domain_enum m_domain
= UNDEF_DOMAIN
;
5094 const search_domain m_search
= ALL_DOMAIN
;
5096 /* The list of CUs from the index entry of the symbol, or NULL if
5098 const gdb_byte
*m_addr
;
5100 dwarf2_per_objfile
*m_per_objfile
;
5104 mapped_debug_names::namei_to_name
5105 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5107 const ULONGEST namei_string_offs
5108 = extract_unsigned_integer ((name_table_string_offs_reordered
5109 + namei
* offset_size
),
5112 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5115 /* Find a slot in .debug_names for the object named NAME. If NAME is
5116 found, return pointer to its pool data. If NAME cannot be found,
5120 dw2_debug_names_iterator::find_vec_in_debug_names
5121 (const mapped_debug_names
&map
, const char *name
,
5122 dwarf2_per_objfile
*per_objfile
)
5124 int (*cmp
) (const char *, const char *);
5126 gdb::unique_xmalloc_ptr
<char> without_params
;
5127 if (current_language
->la_language
== language_cplus
5128 || current_language
->la_language
== language_fortran
5129 || current_language
->la_language
== language_d
)
5131 /* NAME is already canonical. Drop any qualifiers as
5132 .debug_names does not contain any. */
5134 if (strchr (name
, '(') != NULL
)
5136 without_params
= cp_remove_params (name
);
5137 if (without_params
!= NULL
)
5138 name
= without_params
.get ();
5142 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5144 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5146 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5147 (map
.bucket_table_reordered
5148 + (full_hash
% map
.bucket_count
)), 4,
5149 map
.dwarf5_byte_order
);
5153 if (namei
>= map
.name_count
)
5155 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5157 namei
, map
.name_count
,
5158 objfile_name (per_objfile
->objfile
));
5164 const uint32_t namei_full_hash
5165 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5166 (map
.hash_table_reordered
+ namei
), 4,
5167 map
.dwarf5_byte_order
);
5168 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5171 if (full_hash
== namei_full_hash
)
5173 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5175 #if 0 /* An expensive sanity check. */
5176 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5178 complaint (_("Wrong .debug_names hash for string at index %u "
5180 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5185 if (cmp (namei_string
, name
) == 0)
5187 const ULONGEST namei_entry_offs
5188 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5189 + namei
* map
.offset_size
),
5190 map
.offset_size
, map
.dwarf5_byte_order
);
5191 return map
.entry_pool
+ namei_entry_offs
;
5196 if (namei
>= map
.name_count
)
5202 dw2_debug_names_iterator::find_vec_in_debug_names
5203 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5205 if (namei
>= map
.name_count
)
5207 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5209 namei
, map
.name_count
,
5210 objfile_name (per_objfile
->objfile
));
5214 const ULONGEST namei_entry_offs
5215 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5216 + namei
* map
.offset_size
),
5217 map
.offset_size
, map
.dwarf5_byte_order
);
5218 return map
.entry_pool
+ namei_entry_offs
;
5221 /* See dw2_debug_names_iterator. */
5223 dwarf2_per_cu_data
*
5224 dw2_debug_names_iterator::next ()
5229 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5230 struct objfile
*objfile
= m_per_objfile
->objfile
;
5231 bfd
*const abfd
= objfile
->obfd
;
5235 unsigned int bytes_read
;
5236 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5237 m_addr
+= bytes_read
;
5241 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5242 if (indexval_it
== m_map
.abbrev_map
.cend ())
5244 complaint (_("Wrong .debug_names undefined abbrev code %s "
5246 pulongest (abbrev
), objfile_name (objfile
));
5249 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5250 enum class symbol_linkage
{
5254 } symbol_linkage_
= symbol_linkage::unknown
;
5255 dwarf2_per_cu_data
*per_cu
= NULL
;
5256 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5261 case DW_FORM_implicit_const
:
5262 ull
= attr
.implicit_const
;
5264 case DW_FORM_flag_present
:
5268 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5269 m_addr
+= bytes_read
;
5272 ull
= read_4_bytes (abfd
, m_addr
);
5276 ull
= read_8_bytes (abfd
, m_addr
);
5279 case DW_FORM_ref_sig8
:
5280 ull
= read_8_bytes (abfd
, m_addr
);
5284 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5285 dwarf_form_name (attr
.form
),
5286 objfile_name (objfile
));
5289 switch (attr
.dw_idx
)
5291 case DW_IDX_compile_unit
:
5292 /* Don't crash on bad data. */
5293 if (ull
>= per_bfd
->all_comp_units
.size ())
5295 complaint (_(".debug_names entry has bad CU index %s"
5298 objfile_name (objfile
));
5301 per_cu
= per_bfd
->get_cu (ull
);
5303 case DW_IDX_type_unit
:
5304 /* Don't crash on bad data. */
5305 if (ull
>= per_bfd
->tu_stats
.nr_tus
)
5307 complaint (_(".debug_names entry has bad TU index %s"
5310 objfile_name (objfile
));
5313 per_cu
= per_bfd
->get_cu (ull
+ per_bfd
->tu_stats
.nr_tus
);
5315 case DW_IDX_die_offset
:
5316 /* In a per-CU index (as opposed to a per-module index), index
5317 entries without CU attribute implicitly refer to the single CU. */
5319 per_cu
= per_bfd
->get_cu (0);
5321 case DW_IDX_GNU_internal
:
5322 if (!m_map
.augmentation_is_gdb
)
5324 symbol_linkage_
= symbol_linkage::static_
;
5326 case DW_IDX_GNU_external
:
5327 if (!m_map
.augmentation_is_gdb
)
5329 symbol_linkage_
= symbol_linkage::extern_
;
5334 /* Skip if already read in. */
5335 if (m_per_objfile
->symtab_set_p (per_cu
))
5338 /* Check static vs global. */
5339 if (symbol_linkage_
!= symbol_linkage::unknown
)
5341 if (symbol_linkage_
== symbol_linkage::static_
)
5343 if ((m_block_index
& SEARCH_STATIC_BLOCK
) == 0)
5348 if ((m_block_index
& SEARCH_GLOBAL_BLOCK
) == 0)
5353 /* Match dw2_symtab_iter_next, symbol_kind
5354 and debug_names::psymbol_tag. */
5358 switch (indexval
.dwarf_tag
)
5360 case DW_TAG_variable
:
5361 case DW_TAG_subprogram
:
5362 /* Some types are also in VAR_DOMAIN. */
5363 case DW_TAG_typedef
:
5364 case DW_TAG_structure_type
:
5371 switch (indexval
.dwarf_tag
)
5373 case DW_TAG_typedef
:
5374 case DW_TAG_structure_type
:
5381 switch (indexval
.dwarf_tag
)
5384 case DW_TAG_variable
:
5391 switch (indexval
.dwarf_tag
)
5403 /* Match dw2_expand_symtabs_matching, symbol_kind and
5404 debug_names::psymbol_tag. */
5407 case VARIABLES_DOMAIN
:
5408 switch (indexval
.dwarf_tag
)
5410 case DW_TAG_variable
:
5416 case FUNCTIONS_DOMAIN
:
5417 switch (indexval
.dwarf_tag
)
5419 case DW_TAG_subprogram
:
5426 switch (indexval
.dwarf_tag
)
5428 case DW_TAG_typedef
:
5429 case DW_TAG_structure_type
:
5435 case MODULES_DOMAIN
:
5436 switch (indexval
.dwarf_tag
)
5450 /* This dumps minimal information about .debug_names. It is called
5451 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5452 uses this to verify that .debug_names has been loaded. */
5455 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5457 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5459 gdb_assert (per_objfile
->per_bfd
->using_index
);
5460 printf_filtered (".debug_names:");
5461 if (per_objfile
->per_bfd
->debug_names_table
)
5462 printf_filtered (" exists\n");
5464 printf_filtered (" faked for \"readnow\"\n");
5465 printf_filtered ("\n");
5469 dwarf2_debug_names_index::expand_matching_symbols
5470 (struct objfile
*objfile
,
5471 const lookup_name_info
&name
, domain_enum domain
,
5473 symbol_compare_ftype
*ordered_compare
)
5475 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5477 /* debug_names_table is NULL if OBJF_READNOW. */
5478 if (!per_objfile
->per_bfd
->debug_names_table
)
5481 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5482 const block_search_flags block_flags
5483 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
5485 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5486 auto matcher
= [&] (const char *symname
)
5488 if (ordered_compare
== nullptr)
5490 return ordered_compare (symname
, match_name
) == 0;
5493 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
5494 [&] (offset_type namei
)
5496 /* The name was matched, now expand corresponding CUs that were
5498 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
5501 struct dwarf2_per_cu_data
*per_cu
;
5502 while ((per_cu
= iter
.next ()) != NULL
)
5503 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5510 dwarf2_debug_names_index::expand_symtabs_matching
5511 (struct objfile
*objfile
,
5512 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5513 const lookup_name_info
*lookup_name
,
5514 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5515 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5516 block_search_flags search_flags
,
5518 enum search_domain kind
)
5520 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5522 /* debug_names_table is NULL if OBJF_READNOW. */
5523 if (!per_objfile
->per_bfd
->debug_names_table
)
5526 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5528 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5530 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5534 if (!dw2_expand_symtabs_matching_one (per_cu
.get (), per_objfile
,
5542 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5545 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5547 [&] (offset_type namei
)
5549 /* The name was matched, now expand corresponding CUs that were
5551 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
5553 struct dwarf2_per_cu_data
*per_cu
;
5554 while ((per_cu
= iter
.next ()) != NULL
)
5555 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5565 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5566 to either a dwarf2_per_bfd or dwz_file object. */
5568 template <typename T
>
5569 static gdb::array_view
<const gdb_byte
>
5570 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5572 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5574 if (section
->empty ())
5577 /* Older elfutils strip versions could keep the section in the main
5578 executable while splitting it for the separate debug info file. */
5579 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5582 section
->read (obj
);
5584 /* dwarf2_section_info::size is a bfd_size_type, while
5585 gdb::array_view works with size_t. On 32-bit hosts, with
5586 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5587 is 32-bit. So we need an explicit narrowing conversion here.
5588 This is fine, because it's impossible to allocate or mmap an
5589 array/buffer larger than what size_t can represent. */
5590 return gdb::make_array_view (section
->buffer
, section
->size
);
5593 /* Lookup the index cache for the contents of the index associated to
5596 static gdb::array_view
<const gdb_byte
>
5597 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5599 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5600 if (build_id
== nullptr)
5603 return global_index_cache
.lookup_gdb_index (build_id
,
5604 &dwarf2_per_bfd
->index_cache_res
);
5607 /* Same as the above, but for DWZ. */
5609 static gdb::array_view
<const gdb_byte
>
5610 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5612 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5613 if (build_id
== nullptr)
5616 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5619 /* See dwarf2/public.h. */
5622 dwarf2_initialize_objfile (struct objfile
*objfile
)
5624 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5625 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5627 dwarf_read_debug_printf ("called");
5629 /* If we're about to read full symbols, don't bother with the
5630 indices. In this case we also don't care if some other debug
5631 format is making psymtabs, because they are all about to be
5633 if ((objfile
->flags
& OBJF_READNOW
))
5635 dwarf_read_debug_printf ("readnow requested");
5637 /* When using READNOW, the using_index flag (set below) indicates that
5638 PER_BFD was already initialized, when we loaded some other objfile. */
5639 if (per_bfd
->using_index
)
5641 dwarf_read_debug_printf ("using_index already set");
5642 per_objfile
->resize_symtabs ();
5643 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5647 per_bfd
->using_index
= 1;
5648 create_all_comp_units (per_objfile
);
5649 per_bfd
->quick_file_names_table
5650 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5651 per_objfile
->resize_symtabs ();
5653 for (int i
= 0; i
< per_bfd
->all_comp_units
.size (); ++i
)
5655 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cu (i
);
5657 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5658 struct dwarf2_per_cu_quick_data
);
5661 /* Arrange for gdb to see the "quick" functions. However, these
5662 functions will be no-ops because we will have expanded all
5664 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5668 /* Was a debug names index already read when we processed an objfile sharing
5670 if (per_bfd
->debug_names_table
!= nullptr)
5672 dwarf_read_debug_printf ("re-using shared debug names table");
5673 per_objfile
->resize_symtabs ();
5674 objfile
->qf
.push_front (make_dwarf_debug_names ());
5678 /* Was a GDB index already read when we processed an objfile sharing
5680 if (per_bfd
->index_table
!= nullptr)
5682 dwarf_read_debug_printf ("re-using shared index table");
5683 per_objfile
->resize_symtabs ();
5684 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5688 /* There might already be partial symtabs built for this BFD. This happens
5689 when loading the same binary twice with the index-cache enabled. If so,
5690 don't try to read an index. The objfile / per_objfile initialization will
5691 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
5693 if (per_bfd
->partial_symtabs
!= nullptr)
5695 dwarf_read_debug_printf ("re-using shared partial symtabs");
5696 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5700 if (dwarf2_read_debug_names (per_objfile
))
5702 dwarf_read_debug_printf ("found debug names");
5703 per_objfile
->resize_symtabs ();
5704 objfile
->qf
.push_front (make_dwarf_debug_names ());
5708 if (dwarf2_read_gdb_index (per_objfile
,
5709 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5710 get_gdb_index_contents_from_section
<dwz_file
>))
5712 dwarf_read_debug_printf ("found gdb index from file");
5713 per_objfile
->resize_symtabs ();
5714 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5718 /* ... otherwise, try to find the index in the index cache. */
5719 if (dwarf2_read_gdb_index (per_objfile
,
5720 get_gdb_index_contents_from_cache
,
5721 get_gdb_index_contents_from_cache_dwz
))
5723 dwarf_read_debug_printf ("found gdb index from cache");
5724 global_index_cache
.hit ();
5725 per_objfile
->resize_symtabs ();
5726 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5730 global_index_cache
.miss ();
5731 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5736 /* Build a partial symbol table. */
5739 dwarf2_build_psymtabs (struct objfile
*objfile
, psymbol_functions
*psf
)
5741 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5742 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5744 if (per_bfd
->partial_symtabs
!= nullptr)
5746 /* Partial symbols were already read, so now we can simply
5750 psf
= new psymbol_functions (per_bfd
->partial_symtabs
);
5751 objfile
->qf
.emplace_front (psf
);
5754 psf
->set_partial_symtabs (per_bfd
->partial_symtabs
);
5755 per_objfile
->resize_symtabs ();
5761 psf
= new psymbol_functions
;
5762 objfile
->qf
.emplace_front (psf
);
5764 const std::shared_ptr
<psymtab_storage
> &partial_symtabs
5765 = psf
->get_partial_symtabs ();
5767 /* Set the local reference to partial symtabs, so that we don't try
5768 to read them again if reading another objfile with the same BFD.
5769 If we can't in fact share, this won't make a difference anyway as
5770 the dwarf2_per_bfd object won't be shared. */
5771 per_bfd
->partial_symtabs
= partial_symtabs
;
5775 /* This isn't really ideal: all the data we allocate on the
5776 objfile's obstack is still uselessly kept around. However,
5777 freeing it seems unsafe. */
5778 psymtab_discarder
psymtabs (partial_symtabs
.get ());
5779 dwarf2_build_psymtabs_hard (per_objfile
);
5782 per_objfile
->resize_symtabs ();
5784 /* (maybe) store an index in the cache. */
5785 global_index_cache
.store (per_objfile
);
5787 catch (const gdb_exception_error
&except
)
5789 exception_print (gdb_stderr
, except
);
5793 /* Find the base address of the compilation unit for range lists and
5794 location lists. It will normally be specified by DW_AT_low_pc.
5795 In DWARF-3 draft 4, the base address could be overridden by
5796 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5797 compilation units with discontinuous ranges. */
5800 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5802 struct attribute
*attr
;
5804 cu
->base_address
.reset ();
5806 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5807 if (attr
!= nullptr)
5808 cu
->base_address
= attr
->as_address ();
5811 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5812 if (attr
!= nullptr)
5813 cu
->base_address
= attr
->as_address ();
5817 /* Helper function that returns the proper abbrev section for
5820 static struct dwarf2_section_info
*
5821 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5823 struct dwarf2_section_info
*abbrev
;
5824 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
5826 if (this_cu
->is_dwz
)
5827 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
5829 abbrev
= &per_bfd
->abbrev
;
5834 /* Fetch the abbreviation table offset from a comp or type unit header. */
5837 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
5838 struct dwarf2_section_info
*section
,
5839 sect_offset sect_off
)
5841 bfd
*abfd
= section
->get_bfd_owner ();
5842 const gdb_byte
*info_ptr
;
5843 unsigned int initial_length_size
, offset_size
;
5846 section
->read (per_objfile
->objfile
);
5847 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5848 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5849 offset_size
= initial_length_size
== 4 ? 4 : 8;
5850 info_ptr
+= initial_length_size
;
5852 version
= read_2_bytes (abfd
, info_ptr
);
5856 /* Skip unit type and address size. */
5860 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5863 /* A partial symtab that is used only for include files. */
5864 struct dwarf2_include_psymtab
: public partial_symtab
5866 dwarf2_include_psymtab (const char *filename
,
5867 psymtab_storage
*partial_symtabs
,
5868 objfile_per_bfd_storage
*objfile_per_bfd
)
5869 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
5873 void read_symtab (struct objfile
*objfile
) override
5875 /* It's an include file, no symbols to read for it.
5876 Everything is in the includer symtab. */
5878 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5879 expansion of the includer psymtab. We use the dependencies[0] field to
5880 model the includer. But if we go the regular route of calling
5881 expand_psymtab here, and having expand_psymtab call expand_dependencies
5882 to expand the includer, we'll only use expand_psymtab on the includer
5883 (making it a non-toplevel psymtab), while if we expand the includer via
5884 another path, we'll use read_symtab (making it a toplevel psymtab).
5885 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5886 psymtab, and trigger read_symtab on the includer here directly. */
5887 includer ()->read_symtab (objfile
);
5890 void expand_psymtab (struct objfile
*objfile
) override
5892 /* This is not called by read_symtab, and should not be called by any
5893 expand_dependencies. */
5897 bool readin_p (struct objfile
*objfile
) const override
5899 return includer ()->readin_p (objfile
);
5902 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
5908 partial_symtab
*includer () const
5910 /* An include psymtab has exactly one dependency: the psymtab that
5912 gdb_assert (this->number_of_dependencies
== 1);
5913 return this->dependencies
[0];
5917 /* Allocate a new partial symtab for file named NAME and mark this new
5918 partial symtab as being an include of PST. */
5921 dwarf2_create_include_psymtab (dwarf2_per_bfd
*per_bfd
,
5923 dwarf2_psymtab
*pst
,
5924 psymtab_storage
*partial_symtabs
,
5925 objfile_per_bfd_storage
*objfile_per_bfd
)
5927 dwarf2_include_psymtab
*subpst
5928 = new dwarf2_include_psymtab (name
, partial_symtabs
, objfile_per_bfd
);
5930 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5931 subpst
->dirname
= pst
->dirname
;
5933 subpst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (1);
5934 subpst
->dependencies
[0] = pst
;
5935 subpst
->number_of_dependencies
= 1;
5938 /* Read the Line Number Program data and extract the list of files
5939 included by the source file represented by PST. Build an include
5940 partial symtab for each of these included files. */
5943 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5944 struct die_info
*die
,
5945 dwarf2_psymtab
*pst
)
5948 struct attribute
*attr
;
5950 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5951 if (attr
!= nullptr && attr
->form_is_unsigned ())
5952 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
5954 return; /* No linetable, so no includes. */
5956 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5957 that we pass in the raw text_low here; that is ok because we're
5958 only decoding the line table to make include partial symtabs, and
5959 so the addresses aren't really used. */
5960 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5961 pst
->raw_text_low (), 1);
5965 hash_signatured_type (const void *item
)
5967 const struct signatured_type
*sig_type
5968 = (const struct signatured_type
*) item
;
5970 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5971 return sig_type
->signature
;
5975 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5977 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5978 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5980 return lhs
->signature
== rhs
->signature
;
5983 /* Allocate a hash table for signatured types. */
5986 allocate_signatured_type_table ()
5988 return htab_up (htab_create_alloc (41,
5989 hash_signatured_type
,
5991 NULL
, xcalloc
, xfree
));
5994 /* A helper for create_debug_types_hash_table. Read types from SECTION
5995 and fill them into TYPES_HTAB. It will process only type units,
5996 therefore DW_UT_type. */
5999 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6000 struct dwo_file
*dwo_file
,
6001 dwarf2_section_info
*section
, htab_up
&types_htab
,
6002 rcuh_kind section_kind
)
6004 struct objfile
*objfile
= per_objfile
->objfile
;
6005 struct dwarf2_section_info
*abbrev_section
;
6007 const gdb_byte
*info_ptr
, *end_ptr
;
6009 abbrev_section
= &dwo_file
->sections
.abbrev
;
6011 dwarf_read_debug_printf ("Reading %s for %s",
6012 section
->get_name (),
6013 abbrev_section
->get_file_name ());
6015 section
->read (objfile
);
6016 info_ptr
= section
->buffer
;
6018 if (info_ptr
== NULL
)
6021 /* We can't set abfd until now because the section may be empty or
6022 not present, in which case the bfd is unknown. */
6023 abfd
= section
->get_bfd_owner ();
6025 /* We don't use cutu_reader here because we don't need to read
6026 any dies: the signature is in the header. */
6028 end_ptr
= info_ptr
+ section
->size
;
6029 while (info_ptr
< end_ptr
)
6031 std::unique_ptr
<signatured_type
> sig_type
;
6032 struct dwo_unit
*dwo_tu
;
6034 const gdb_byte
*ptr
= info_ptr
;
6035 struct comp_unit_head header
;
6036 unsigned int length
;
6038 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6040 /* Initialize it due to a false compiler warning. */
6041 header
.signature
= -1;
6042 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6044 /* We need to read the type's signature in order to build the hash
6045 table, but we don't need anything else just yet. */
6047 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6048 abbrev_section
, ptr
, section_kind
);
6050 length
= header
.get_length ();
6052 /* Skip dummy type units. */
6053 if (ptr
>= info_ptr
+ length
6054 || peek_abbrev_code (abfd
, ptr
) == 0
6055 || (header
.unit_type
!= DW_UT_type
6056 && header
.unit_type
!= DW_UT_split_type
))
6062 if (types_htab
== NULL
)
6063 types_htab
= allocate_dwo_unit_table ();
6065 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6066 dwo_tu
->dwo_file
= dwo_file
;
6067 dwo_tu
->signature
= header
.signature
;
6068 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6069 dwo_tu
->section
= section
;
6070 dwo_tu
->sect_off
= sect_off
;
6071 dwo_tu
->length
= length
;
6073 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
6074 gdb_assert (slot
!= NULL
);
6076 complaint (_("debug type entry at offset %s is duplicate to"
6077 " the entry at offset %s, signature %s"),
6078 sect_offset_str (sect_off
),
6079 sect_offset_str (dwo_tu
->sect_off
),
6080 hex_string (header
.signature
));
6083 dwarf_read_debug_printf_v (" offset %s, signature %s",
6084 sect_offset_str (sect_off
),
6085 hex_string (header
.signature
));
6091 /* Create the hash table of all entries in the .debug_types
6092 (or .debug_types.dwo) section(s).
6093 DWO_FILE is a pointer to the DWO file object.
6095 The result is a pointer to the hash table or NULL if there are no types.
6097 Note: This function processes DWO files only, not DWP files. */
6100 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6101 struct dwo_file
*dwo_file
,
6102 gdb::array_view
<dwarf2_section_info
> type_sections
,
6103 htab_up
&types_htab
)
6105 for (dwarf2_section_info
§ion
: type_sections
)
6106 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6110 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6111 If SLOT is non-NULL, it is the entry to use in the hash table.
6112 Otherwise we find one. */
6114 static struct signatured_type
*
6115 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6117 if (per_objfile
->per_bfd
->all_comp_units
.size ()
6118 == per_objfile
->per_bfd
->all_comp_units
.capacity ())
6119 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6121 std::unique_ptr
<signatured_type
> sig_type_holder
6122 = per_objfile
->per_bfd
->allocate_signatured_type ();
6123 signatured_type
*sig_type
= sig_type_holder
.get ();
6125 per_objfile
->resize_symtabs ();
6127 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (sig_type_holder
));
6128 sig_type
->signature
= sig
;
6129 sig_type
->is_debug_types
= 1;
6130 if (per_objfile
->per_bfd
->using_index
)
6133 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6134 struct dwarf2_per_cu_quick_data
);
6139 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6142 gdb_assert (*slot
== NULL
);
6144 /* The rest of sig_type must be filled in by the caller. */
6148 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6149 Fill in SIG_ENTRY with DWO_ENTRY. */
6152 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6153 struct signatured_type
*sig_entry
,
6154 struct dwo_unit
*dwo_entry
)
6156 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6158 /* Make sure we're not clobbering something we don't expect to. */
6159 gdb_assert (! sig_entry
->queued
);
6160 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
6161 if (per_bfd
->using_index
)
6163 gdb_assert (sig_entry
->v
.quick
!= NULL
);
6164 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
6167 gdb_assert (sig_entry
->v
.psymtab
== NULL
);
6168 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6169 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6170 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6171 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6173 sig_entry
->section
= dwo_entry
->section
;
6174 sig_entry
->sect_off
= dwo_entry
->sect_off
;
6175 sig_entry
->length
= dwo_entry
->length
;
6176 sig_entry
->reading_dwo_directly
= 1;
6177 sig_entry
->per_bfd
= per_bfd
;
6178 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6179 sig_entry
->dwo_unit
= dwo_entry
;
6182 /* Subroutine of lookup_signatured_type.
6183 If we haven't read the TU yet, create the signatured_type data structure
6184 for a TU to be read in directly from a DWO file, bypassing the stub.
6185 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6186 using .gdb_index, then when reading a CU we want to stay in the DWO file
6187 containing that CU. Otherwise we could end up reading several other DWO
6188 files (due to comdat folding) to process the transitive closure of all the
6189 mentioned TUs, and that can be slow. The current DWO file will have every
6190 type signature that it needs.
6191 We only do this for .gdb_index because in the psymtab case we already have
6192 to read all the DWOs to build the type unit groups. */
6194 static struct signatured_type
*
6195 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6197 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6198 struct dwo_file
*dwo_file
;
6199 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6200 struct signatured_type find_sig_entry
, *sig_entry
;
6203 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6205 /* If TU skeletons have been removed then we may not have read in any
6207 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6208 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6210 /* We only ever need to read in one copy of a signatured type.
6211 Use the global signatured_types array to do our own comdat-folding
6212 of types. If this is the first time we're reading this TU, and
6213 the TU has an entry in .gdb_index, replace the recorded data from
6214 .gdb_index with this TU. */
6216 find_sig_entry
.signature
= sig
;
6217 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6218 &find_sig_entry
, INSERT
);
6219 sig_entry
= (struct signatured_type
*) *slot
;
6221 /* We can get here with the TU already read, *or* in the process of being
6222 read. Don't reassign the global entry to point to this DWO if that's
6223 the case. Also note that if the TU is already being read, it may not
6224 have come from a DWO, the program may be a mix of Fission-compiled
6225 code and non-Fission-compiled code. */
6227 /* Have we already tried to read this TU?
6228 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6229 needn't exist in the global table yet). */
6230 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
6233 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6234 dwo_unit of the TU itself. */
6235 dwo_file
= cu
->dwo_unit
->dwo_file
;
6237 /* Ok, this is the first time we're reading this TU. */
6238 if (dwo_file
->tus
== NULL
)
6240 find_dwo_entry
.signature
= sig
;
6241 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6243 if (dwo_entry
== NULL
)
6246 /* If the global table doesn't have an entry for this TU, add one. */
6247 if (sig_entry
== NULL
)
6248 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6250 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6251 sig_entry
->tu_read
= 1;
6255 /* Subroutine of lookup_signatured_type.
6256 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6257 then try the DWP file. If the TU stub (skeleton) has been removed then
6258 it won't be in .gdb_index. */
6260 static struct signatured_type
*
6261 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6263 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6264 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6265 struct dwo_unit
*dwo_entry
;
6266 struct signatured_type find_sig_entry
, *sig_entry
;
6269 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6270 gdb_assert (dwp_file
!= NULL
);
6272 /* If TU skeletons have been removed then we may not have read in any
6274 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6275 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6277 find_sig_entry
.signature
= sig
;
6278 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6279 &find_sig_entry
, INSERT
);
6280 sig_entry
= (struct signatured_type
*) *slot
;
6282 /* Have we already tried to read this TU?
6283 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6284 needn't exist in the global table yet). */
6285 if (sig_entry
!= NULL
)
6288 if (dwp_file
->tus
== NULL
)
6290 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6291 1 /* is_debug_types */);
6292 if (dwo_entry
== NULL
)
6295 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6296 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6301 /* Lookup a signature based type for DW_FORM_ref_sig8.
6302 Returns NULL if signature SIG is not present in the table.
6303 It is up to the caller to complain about this. */
6305 static struct signatured_type
*
6306 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6308 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6310 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6312 /* We're in a DWO/DWP file, and we're using .gdb_index.
6313 These cases require special processing. */
6314 if (get_dwp_file (per_objfile
) == NULL
)
6315 return lookup_dwo_signatured_type (cu
, sig
);
6317 return lookup_dwp_signatured_type (cu
, sig
);
6321 struct signatured_type find_entry
, *entry
;
6323 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6325 find_entry
.signature
= sig
;
6326 entry
= ((struct signatured_type
*)
6327 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6333 /* Low level DIE reading support. */
6335 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6338 init_cu_die_reader (struct die_reader_specs
*reader
,
6339 struct dwarf2_cu
*cu
,
6340 struct dwarf2_section_info
*section
,
6341 struct dwo_file
*dwo_file
,
6342 struct abbrev_table
*abbrev_table
)
6344 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6345 reader
->abfd
= section
->get_bfd_owner ();
6347 reader
->dwo_file
= dwo_file
;
6348 reader
->die_section
= section
;
6349 reader
->buffer
= section
->buffer
;
6350 reader
->buffer_end
= section
->buffer
+ section
->size
;
6351 reader
->abbrev_table
= abbrev_table
;
6354 /* Subroutine of cutu_reader to simplify it.
6355 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6356 There's just a lot of work to do, and cutu_reader is big enough
6359 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6360 from it to the DIE in the DWO. If NULL we are skipping the stub.
6361 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6362 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6363 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6364 STUB_COMP_DIR may be non-NULL.
6365 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6366 are filled in with the info of the DIE from the DWO file.
6367 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6368 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6369 kept around for at least as long as *RESULT_READER.
6371 The result is non-zero if a valid (non-dummy) DIE was found. */
6374 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6375 struct dwo_unit
*dwo_unit
,
6376 struct die_info
*stub_comp_unit_die
,
6377 const char *stub_comp_dir
,
6378 struct die_reader_specs
*result_reader
,
6379 const gdb_byte
**result_info_ptr
,
6380 struct die_info
**result_comp_unit_die
,
6381 abbrev_table_up
*result_dwo_abbrev_table
)
6383 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6384 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6385 struct objfile
*objfile
= per_objfile
->objfile
;
6387 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6388 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6389 int i
,num_extra_attrs
;
6390 struct dwarf2_section_info
*dwo_abbrev_section
;
6391 struct die_info
*comp_unit_die
;
6393 /* At most one of these may be provided. */
6394 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6396 /* These attributes aren't processed until later:
6397 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6398 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6399 referenced later. However, these attributes are found in the stub
6400 which we won't have later. In order to not impose this complication
6401 on the rest of the code, we read them here and copy them to the
6410 if (stub_comp_unit_die
!= NULL
)
6412 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6414 if (!per_cu
->is_debug_types
)
6415 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6416 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6417 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6418 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6419 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6421 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6423 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6424 We need the value before we can process DW_AT_ranges values from the
6426 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6428 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6429 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6430 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6431 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6433 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6435 else if (stub_comp_dir
!= NULL
)
6437 /* Reconstruct the comp_dir attribute to simplify the code below. */
6438 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6439 comp_dir
->name
= DW_AT_comp_dir
;
6440 comp_dir
->form
= DW_FORM_string
;
6441 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6444 /* Set up for reading the DWO CU/TU. */
6445 cu
->dwo_unit
= dwo_unit
;
6446 dwarf2_section_info
*section
= dwo_unit
->section
;
6447 section
->read (objfile
);
6448 abfd
= section
->get_bfd_owner ();
6449 begin_info_ptr
= info_ptr
= (section
->buffer
6450 + to_underlying (dwo_unit
->sect_off
));
6451 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6453 if (per_cu
->is_debug_types
)
6455 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6457 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6458 section
, dwo_abbrev_section
,
6459 info_ptr
, rcuh_kind::TYPE
);
6460 /* This is not an assert because it can be caused by bad debug info. */
6461 if (sig_type
->signature
!= cu
->header
.signature
)
6463 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6464 " TU at offset %s [in module %s]"),
6465 hex_string (sig_type
->signature
),
6466 hex_string (cu
->header
.signature
),
6467 sect_offset_str (dwo_unit
->sect_off
),
6468 bfd_get_filename (abfd
));
6470 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6471 /* For DWOs coming from DWP files, we don't know the CU length
6472 nor the type's offset in the TU until now. */
6473 dwo_unit
->length
= cu
->header
.get_length ();
6474 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6476 /* Establish the type offset that can be used to lookup the type.
6477 For DWO files, we don't know it until now. */
6478 sig_type
->type_offset_in_section
6479 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6483 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6484 section
, dwo_abbrev_section
,
6485 info_ptr
, rcuh_kind::COMPILE
);
6486 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6487 /* For DWOs coming from DWP files, we don't know the CU length
6489 dwo_unit
->length
= cu
->header
.get_length ();
6492 dwo_abbrev_section
->read (objfile
);
6493 *result_dwo_abbrev_table
6494 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6495 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6496 result_dwo_abbrev_table
->get ());
6498 /* Read in the die, but leave space to copy over the attributes
6499 from the stub. This has the benefit of simplifying the rest of
6500 the code - all the work to maintain the illusion of a single
6501 DW_TAG_{compile,type}_unit DIE is done here. */
6502 num_extra_attrs
= ((stmt_list
!= NULL
)
6506 + (comp_dir
!= NULL
));
6507 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6510 /* Copy over the attributes from the stub to the DIE we just read in. */
6511 comp_unit_die
= *result_comp_unit_die
;
6512 i
= comp_unit_die
->num_attrs
;
6513 if (stmt_list
!= NULL
)
6514 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6516 comp_unit_die
->attrs
[i
++] = *low_pc
;
6517 if (high_pc
!= NULL
)
6518 comp_unit_die
->attrs
[i
++] = *high_pc
;
6520 comp_unit_die
->attrs
[i
++] = *ranges
;
6521 if (comp_dir
!= NULL
)
6522 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6523 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6525 if (dwarf_die_debug
)
6527 fprintf_unfiltered (gdb_stdlog
,
6528 "Read die from %s@0x%x of %s:\n",
6529 section
->get_name (),
6530 (unsigned) (begin_info_ptr
- section
->buffer
),
6531 bfd_get_filename (abfd
));
6532 dump_die (comp_unit_die
, dwarf_die_debug
);
6535 /* Skip dummy compilation units. */
6536 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6537 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6540 *result_info_ptr
= info_ptr
;
6544 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6545 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6546 signature is part of the header. */
6547 static gdb::optional
<ULONGEST
>
6548 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6550 if (cu
->header
.version
>= 5)
6551 return cu
->header
.signature
;
6552 struct attribute
*attr
;
6553 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6554 if (attr
== nullptr || !attr
->form_is_unsigned ())
6555 return gdb::optional
<ULONGEST
> ();
6556 return attr
->as_unsigned ();
6559 /* Subroutine of cutu_reader to simplify it.
6560 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6561 Returns NULL if the specified DWO unit cannot be found. */
6563 static struct dwo_unit
*
6564 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6566 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6567 struct dwo_unit
*dwo_unit
;
6568 const char *comp_dir
;
6570 gdb_assert (cu
!= NULL
);
6572 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6573 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6574 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6576 if (per_cu
->is_debug_types
)
6577 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6580 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6582 if (!signature
.has_value ())
6583 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6585 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6587 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6593 /* Subroutine of cutu_reader to simplify it.
6594 See it for a description of the parameters.
6595 Read a TU directly from a DWO file, bypassing the stub. */
6598 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6599 dwarf2_per_objfile
*per_objfile
,
6600 dwarf2_cu
*existing_cu
)
6602 struct signatured_type
*sig_type
;
6604 /* Verify we can do the following downcast, and that we have the
6606 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6607 sig_type
= (struct signatured_type
*) this_cu
;
6608 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6612 if (existing_cu
!= nullptr)
6615 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6616 /* There's no need to do the rereading_dwo_cu handling that
6617 cutu_reader does since we don't read the stub. */
6621 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6622 in per_objfile yet. */
6623 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6624 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6625 cu
= m_new_cu
.get ();
6628 /* A future optimization, if needed, would be to use an existing
6629 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6630 could share abbrev tables. */
6632 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6633 NULL
/* stub_comp_unit_die */,
6634 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6637 &m_dwo_abbrev_table
) == 0)
6644 /* Initialize a CU (or TU) and read its DIEs.
6645 If the CU defers to a DWO file, read the DWO file as well.
6647 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6648 Otherwise the table specified in the comp unit header is read in and used.
6649 This is an optimization for when we already have the abbrev table.
6651 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6654 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6655 dwarf2_per_objfile
*per_objfile
,
6656 struct abbrev_table
*abbrev_table
,
6657 dwarf2_cu
*existing_cu
,
6659 : die_reader_specs
{},
6662 struct objfile
*objfile
= per_objfile
->objfile
;
6663 struct dwarf2_section_info
*section
= this_cu
->section
;
6664 bfd
*abfd
= section
->get_bfd_owner ();
6665 const gdb_byte
*begin_info_ptr
;
6666 struct signatured_type
*sig_type
= NULL
;
6667 struct dwarf2_section_info
*abbrev_section
;
6668 /* Non-zero if CU currently points to a DWO file and we need to
6669 reread it. When this happens we need to reread the skeleton die
6670 before we can reread the DWO file (this only applies to CUs, not TUs). */
6671 int rereading_dwo_cu
= 0;
6673 if (dwarf_die_debug
)
6674 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6675 this_cu
->is_debug_types
? "type" : "comp",
6676 sect_offset_str (this_cu
->sect_off
));
6678 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6679 file (instead of going through the stub), short-circuit all of this. */
6680 if (this_cu
->reading_dwo_directly
)
6682 /* Narrow down the scope of possibilities to have to understand. */
6683 gdb_assert (this_cu
->is_debug_types
);
6684 gdb_assert (abbrev_table
== NULL
);
6685 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
6689 /* This is cheap if the section is already read in. */
6690 section
->read (objfile
);
6692 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6694 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6698 if (existing_cu
!= nullptr)
6701 /* If this CU is from a DWO file we need to start over, we need to
6702 refetch the attributes from the skeleton CU.
6703 This could be optimized by retrieving those attributes from when we
6704 were here the first time: the previous comp_unit_die was stored in
6705 comp_unit_obstack. But there's no data yet that we need this
6707 if (cu
->dwo_unit
!= NULL
)
6708 rereading_dwo_cu
= 1;
6712 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6713 in per_objfile yet. */
6714 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6715 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6716 cu
= m_new_cu
.get ();
6719 /* Get the header. */
6720 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6722 /* We already have the header, there's no need to read it in again. */
6723 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6727 if (this_cu
->is_debug_types
)
6729 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6730 section
, abbrev_section
,
6731 info_ptr
, rcuh_kind::TYPE
);
6733 /* Since per_cu is the first member of struct signatured_type,
6734 we can go from a pointer to one to a pointer to the other. */
6735 sig_type
= (struct signatured_type
*) this_cu
;
6736 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6737 gdb_assert (sig_type
->type_offset_in_tu
6738 == cu
->header
.type_cu_offset_in_tu
);
6739 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6741 /* LENGTH has not been set yet for type units if we're
6742 using .gdb_index. */
6743 this_cu
->length
= cu
->header
.get_length ();
6745 /* Establish the type offset that can be used to lookup the type. */
6746 sig_type
->type_offset_in_section
=
6747 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6749 this_cu
->dwarf_version
= cu
->header
.version
;
6753 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6754 section
, abbrev_section
,
6756 rcuh_kind::COMPILE
);
6758 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6759 if (this_cu
->length
== 0)
6760 this_cu
->length
= cu
->header
.get_length ();
6762 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6763 this_cu
->dwarf_version
= cu
->header
.version
;
6767 /* Skip dummy compilation units. */
6768 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6769 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6775 /* If we don't have them yet, read the abbrevs for this compilation unit.
6776 And if we need to read them now, make sure they're freed when we're
6778 if (abbrev_table
!= NULL
)
6779 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6782 abbrev_section
->read (objfile
);
6783 m_abbrev_table_holder
6784 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
6785 abbrev_table
= m_abbrev_table_holder
.get ();
6788 /* Read the top level CU/TU die. */
6789 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6790 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6792 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6798 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6799 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6800 table from the DWO file and pass the ownership over to us. It will be
6801 referenced from READER, so we must make sure to free it after we're done
6804 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6805 DWO CU, that this test will fail (the attribute will not be present). */
6806 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6807 if (dwo_name
!= nullptr)
6809 struct dwo_unit
*dwo_unit
;
6810 struct die_info
*dwo_comp_unit_die
;
6812 if (comp_unit_die
->has_children
)
6814 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6815 " has children (offset %s) [in module %s]"),
6816 sect_offset_str (this_cu
->sect_off
),
6817 bfd_get_filename (abfd
));
6819 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
6820 if (dwo_unit
!= NULL
)
6822 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
6823 comp_unit_die
, NULL
,
6826 &m_dwo_abbrev_table
) == 0)
6832 comp_unit_die
= dwo_comp_unit_die
;
6836 /* Yikes, we couldn't find the rest of the DIE, we only have
6837 the stub. A complaint has already been logged. There's
6838 not much more we can do except pass on the stub DIE to
6839 die_reader_func. We don't want to throw an error on bad
6846 cutu_reader::keep ()
6848 /* Done, clean up. */
6849 gdb_assert (!dummy_p
);
6850 if (m_new_cu
!= NULL
)
6852 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
6854 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
6855 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
6859 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6860 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6861 assumed to have already done the lookup to find the DWO file).
6863 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6864 THIS_CU->is_debug_types, but nothing else.
6866 We fill in THIS_CU->length.
6868 THIS_CU->cu is always freed when done.
6869 This is done in order to not leave THIS_CU->cu in a state where we have
6870 to care whether it refers to the "main" CU or the DWO CU.
6872 When parent_cu is passed, it is used to provide a default value for
6873 str_offsets_base and addr_base from the parent. */
6875 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6876 dwarf2_per_objfile
*per_objfile
,
6877 struct dwarf2_cu
*parent_cu
,
6878 struct dwo_file
*dwo_file
)
6879 : die_reader_specs
{},
6882 struct objfile
*objfile
= per_objfile
->objfile
;
6883 struct dwarf2_section_info
*section
= this_cu
->section
;
6884 bfd
*abfd
= section
->get_bfd_owner ();
6885 struct dwarf2_section_info
*abbrev_section
;
6886 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6888 if (dwarf_die_debug
)
6889 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6890 this_cu
->is_debug_types
? "type" : "comp",
6891 sect_offset_str (this_cu
->sect_off
));
6893 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6895 abbrev_section
= (dwo_file
!= NULL
6896 ? &dwo_file
->sections
.abbrev
6897 : get_abbrev_section_for_cu (this_cu
));
6899 /* This is cheap if the section is already read in. */
6900 section
->read (objfile
);
6902 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6904 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6905 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
6906 section
, abbrev_section
, info_ptr
,
6907 (this_cu
->is_debug_types
6909 : rcuh_kind::COMPILE
));
6911 if (parent_cu
!= nullptr)
6913 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6914 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6916 this_cu
->length
= m_new_cu
->header
.get_length ();
6918 /* Skip dummy compilation units. */
6919 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6920 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6926 abbrev_section
->read (objfile
);
6927 m_abbrev_table_holder
6928 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
6930 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6931 m_abbrev_table_holder
.get ());
6932 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6936 /* Type Unit Groups.
6938 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6939 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6940 so that all types coming from the same compilation (.o file) are grouped
6941 together. A future step could be to put the types in the same symtab as
6942 the CU the types ultimately came from. */
6945 hash_type_unit_group (const void *item
)
6947 const struct type_unit_group
*tu_group
6948 = (const struct type_unit_group
*) item
;
6950 return hash_stmt_list_entry (&tu_group
->hash
);
6954 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6956 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6957 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6959 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6962 /* Allocate a hash table for type unit groups. */
6965 allocate_type_unit_groups_table ()
6967 return htab_up (htab_create_alloc (3,
6968 hash_type_unit_group
,
6972 type_unit_group
*grp
6973 = (type_unit_group
*) arg
;
6979 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6980 partial symtabs. We combine several TUs per psymtab to not let the size
6981 of any one psymtab grow too big. */
6982 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6983 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6985 /* Helper routine for get_type_unit_group.
6986 Create the type_unit_group object used to hold one or more TUs. */
6988 static std::unique_ptr
<type_unit_group
>
6989 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6991 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6992 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6994 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
6995 tu_group
->per_bfd
= per_bfd
;
6997 if (per_bfd
->using_index
)
6999 tu_group
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7000 struct dwarf2_per_cu_quick_data
);
7004 unsigned int line_offset
= to_underlying (line_offset_struct
);
7005 dwarf2_psymtab
*pst
;
7008 /* Give the symtab a useful name for debug purposes. */
7009 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7010 name
= string_printf ("<type_units_%d>",
7011 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7013 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7015 pst
= create_partial_symtab (tu_group
.get (), per_objfile
,
7017 pst
->anonymous
= true;
7020 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7021 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7026 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7027 STMT_LIST is a DW_AT_stmt_list attribute. */
7029 static struct type_unit_group
*
7030 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7032 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7033 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7034 struct type_unit_group
*tu_group
;
7036 unsigned int line_offset
;
7037 struct type_unit_group type_unit_group_for_lookup
;
7039 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7040 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7042 /* Do we need to create a new group, or can we use an existing one? */
7044 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
7046 line_offset
= stmt_list
->as_unsigned ();
7047 ++tu_stats
->nr_symtab_sharers
;
7051 /* Ugh, no stmt_list. Rare, but we have to handle it.
7052 We can do various things here like create one group per TU or
7053 spread them over multiple groups to split up the expansion work.
7054 To avoid worst case scenarios (too many groups or too large groups)
7055 we, umm, group them in bunches. */
7056 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7057 | (tu_stats
->nr_stmt_less_type_units
7058 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7059 ++tu_stats
->nr_stmt_less_type_units
;
7062 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7063 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7064 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7065 &type_unit_group_for_lookup
, INSERT
);
7066 if (*slot
== nullptr)
7068 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7069 std::unique_ptr
<type_unit_group
> grp
7070 = create_type_unit_group (cu
, line_offset_struct
);
7071 *slot
= grp
.release ();
7072 ++tu_stats
->nr_symtabs
;
7075 tu_group
= (struct type_unit_group
*) *slot
;
7076 gdb_assert (tu_group
!= nullptr);
7080 /* Partial symbol tables. */
7082 /* Create a psymtab named NAME and assign it to PER_CU.
7084 The caller must fill in the following details:
7085 dirname, textlow, texthigh. */
7087 static dwarf2_psymtab
*
7088 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7089 dwarf2_per_objfile
*per_objfile
,
7093 = new dwarf2_psymtab (name
, per_objfile
->per_bfd
->partial_symtabs
.get (),
7094 per_objfile
->objfile
->per_bfd
, per_cu
);
7096 pst
->psymtabs_addrmap_supported
= true;
7098 /* This is the glue that links PST into GDB's symbol API. */
7099 per_cu
->v
.psymtab
= pst
;
7104 /* DIE reader function for process_psymtab_comp_unit. */
7107 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7108 const gdb_byte
*info_ptr
,
7109 struct die_info
*comp_unit_die
,
7110 enum language pretend_language
)
7112 struct dwarf2_cu
*cu
= reader
->cu
;
7113 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7114 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7115 struct objfile
*objfile
= per_objfile
->objfile
;
7116 struct gdbarch
*gdbarch
= objfile
->arch ();
7117 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7119 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7120 dwarf2_psymtab
*pst
;
7121 enum pc_bounds_kind cu_bounds_kind
;
7122 const char *filename
;
7124 gdb_assert (! per_cu
->is_debug_types
);
7126 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7128 /* Allocate a new partial symbol table structure. */
7129 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7130 static const char artificial
[] = "<artificial>";
7131 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7132 if (filename
== NULL
)
7134 else if (strcmp (filename
, artificial
) == 0)
7136 debug_filename
.reset (concat (artificial
, "@",
7137 sect_offset_str (per_cu
->sect_off
),
7139 filename
= debug_filename
.get ();
7142 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7144 /* This must be done before calling dwarf2_build_include_psymtabs. */
7145 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7147 baseaddr
= objfile
->text_section_offset ();
7149 dwarf2_find_base_address (comp_unit_die
, cu
);
7151 /* Possibly set the default values of LOWPC and HIGHPC from
7153 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7154 &best_highpc
, cu
, pst
);
7155 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7158 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7161 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7163 /* Store the contiguous range if it is not empty; it can be
7164 empty for CUs with no code. */
7165 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7169 /* Check if comp unit has_children.
7170 If so, read the rest of the partial symbols from this comp unit.
7171 If not, there's no more debug_info for this comp unit. */
7172 if (comp_unit_die
->has_children
)
7174 struct partial_die_info
*first_die
;
7175 CORE_ADDR lowpc
, highpc
;
7177 lowpc
= ((CORE_ADDR
) -1);
7178 highpc
= ((CORE_ADDR
) 0);
7180 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7182 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7183 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7185 /* If we didn't find a lowpc, set it to highpc to avoid
7186 complaints from `maint check'. */
7187 if (lowpc
== ((CORE_ADDR
) -1))
7190 /* If the compilation unit didn't have an explicit address range,
7191 then use the information extracted from its child dies. */
7192 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7195 best_highpc
= highpc
;
7198 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7199 best_lowpc
+ baseaddr
)
7201 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7202 best_highpc
+ baseaddr
)
7207 if (!cu
->per_cu
->imported_symtabs_empty ())
7210 int len
= cu
->per_cu
->imported_symtabs_size ();
7212 /* Fill in 'dependencies' here; we fill in 'users' in a
7214 pst
->number_of_dependencies
= len
;
7216 = per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7217 for (i
= 0; i
< len
; ++i
)
7219 pst
->dependencies
[i
]
7220 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7223 cu
->per_cu
->imported_symtabs_free ();
7226 /* Get the list of files included in the current compilation unit,
7227 and build a psymtab for each of them. */
7228 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7230 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7231 ", %d global, %d static syms",
7232 per_cu
->is_debug_types
? "type" : "comp",
7233 sect_offset_str (per_cu
->sect_off
),
7234 paddress (gdbarch
, pst
->text_low (objfile
)),
7235 paddress (gdbarch
, pst
->text_high (objfile
)),
7236 (int) pst
->global_psymbols
.size (),
7237 (int) pst
->static_psymbols
.size ());
7240 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7241 Process compilation unit THIS_CU for a psymtab. */
7244 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7245 dwarf2_per_objfile
*per_objfile
,
7246 bool want_partial_unit
,
7247 enum language pretend_language
)
7249 /* If this compilation unit was already read in, free the
7250 cached copy in order to read it in again. This is
7251 necessary because we skipped some symbols when we first
7252 read in the compilation unit (see load_partial_dies).
7253 This problem could be avoided, but the benefit is unclear. */
7254 per_objfile
->remove_cu (this_cu
);
7256 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7258 switch (reader
.comp_unit_die
->tag
)
7260 case DW_TAG_compile_unit
:
7261 this_cu
->unit_type
= DW_UT_compile
;
7263 case DW_TAG_partial_unit
:
7264 this_cu
->unit_type
= DW_UT_partial
;
7266 case DW_TAG_type_unit
:
7267 this_cu
->unit_type
= DW_UT_type
;
7270 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
7271 dwarf_tag_name (reader
.comp_unit_die
->tag
),
7272 sect_offset_str (reader
.cu
->per_cu
->sect_off
),
7273 objfile_name (per_objfile
->objfile
));
7280 else if (this_cu
->is_debug_types
)
7281 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7282 reader
.comp_unit_die
);
7283 else if (want_partial_unit
7284 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7285 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7286 reader
.comp_unit_die
,
7289 this_cu
->lang
= reader
.cu
->language
;
7291 /* Age out any secondary CUs. */
7292 per_objfile
->age_comp_units ();
7295 /* Reader function for build_type_psymtabs. */
7298 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7299 const gdb_byte
*info_ptr
,
7300 struct die_info
*type_unit_die
)
7302 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7303 struct dwarf2_cu
*cu
= reader
->cu
;
7304 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7305 struct signatured_type
*sig_type
;
7306 struct type_unit_group
*tu_group
;
7307 struct attribute
*attr
;
7308 struct partial_die_info
*first_die
;
7309 CORE_ADDR lowpc
, highpc
;
7310 dwarf2_psymtab
*pst
;
7312 gdb_assert (per_cu
->is_debug_types
);
7313 sig_type
= (struct signatured_type
*) per_cu
;
7315 if (! type_unit_die
->has_children
)
7318 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7319 tu_group
= get_type_unit_group (cu
, attr
);
7321 if (tu_group
->tus
== nullptr)
7322 tu_group
->tus
= new std::vector
<signatured_type
*>;
7323 tu_group
->tus
->push_back (sig_type
);
7325 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7326 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7327 pst
->anonymous
= true;
7329 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7331 lowpc
= (CORE_ADDR
) -1;
7332 highpc
= (CORE_ADDR
) 0;
7333 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7338 /* Struct used to sort TUs by their abbreviation table offset. */
7340 struct tu_abbrev_offset
7342 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7343 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7346 signatured_type
*sig_type
;
7347 sect_offset abbrev_offset
;
7350 /* Helper routine for build_type_psymtabs, passed to std::sort. */
7353 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7354 const struct tu_abbrev_offset
&b
)
7356 return a
.abbrev_offset
< b
.abbrev_offset
;
7359 /* Efficiently read all the type units.
7361 The efficiency is because we sort TUs by the abbrev table they use and
7362 only read each abbrev table once. In one program there are 200K TUs
7363 sharing 8K abbrev tables.
7365 The main purpose of this function is to support building the
7366 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7367 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7368 can collapse the search space by grouping them by stmt_list.
7369 The savings can be significant, in the same program from above the 200K TUs
7370 share 8K stmt_list tables.
7372 FUNC is expected to call get_type_unit_group, which will create the
7373 struct type_unit_group if necessary and add it to
7374 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7377 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7379 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7380 abbrev_table_up abbrev_table
;
7381 sect_offset abbrev_offset
;
7383 /* It's up to the caller to not call us multiple times. */
7384 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7386 if (per_objfile
->per_bfd
->tu_stats
.nr_tus
== 0)
7389 /* TUs typically share abbrev tables, and there can be way more TUs than
7390 abbrev tables. Sort by abbrev table to reduce the number of times we
7391 read each abbrev table in.
7392 Alternatives are to punt or to maintain a cache of abbrev tables.
7393 This is simpler and efficient enough for now.
7395 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7396 symtab to use). Typically TUs with the same abbrev offset have the same
7397 stmt_list value too so in practice this should work well.
7399 The basic algorithm here is:
7401 sort TUs by abbrev table
7402 for each TU with same abbrev table:
7403 read abbrev table if first user
7404 read TU top level DIE
7405 [IWBN if DWO skeletons had DW_AT_stmt_list]
7408 dwarf_read_debug_printf ("Building type unit groups ...");
7410 /* Sort in a separate table to maintain the order of all_comp_units
7411 for .gdb_index: TU indices directly index all_type_units. */
7412 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7413 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->tu_stats
.nr_tus
);
7415 for (const auto &cu
: per_objfile
->per_bfd
->all_comp_units
)
7417 if (cu
->is_debug_types
)
7419 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
7420 sorted_by_abbrev
.emplace_back
7421 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
7422 sig_type
->sect_off
));
7426 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7427 sort_tu_by_abbrev_offset
);
7429 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7431 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7433 /* Switch to the next abbrev table if necessary. */
7434 if (abbrev_table
== NULL
7435 || tu
.abbrev_offset
!= abbrev_offset
)
7437 abbrev_offset
= tu
.abbrev_offset
;
7438 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7440 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7441 ++tu_stats
->nr_uniq_abbrev_tables
;
7444 cutu_reader
reader (tu
.sig_type
, per_objfile
,
7445 abbrev_table
.get (), nullptr, false);
7446 if (!reader
.dummy_p
)
7447 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7448 reader
.comp_unit_die
);
7452 /* Print collected type unit statistics. */
7455 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7457 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7459 dwarf_read_debug_printf ("Type unit statistics:");
7460 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
7461 dwarf_read_debug_printf (" %d uniq abbrev tables",
7462 tu_stats
->nr_uniq_abbrev_tables
);
7463 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7464 tu_stats
->nr_symtabs
);
7465 dwarf_read_debug_printf (" %d symtab sharers",
7466 tu_stats
->nr_symtab_sharers
);
7467 dwarf_read_debug_printf (" %d type units without a stmt_list",
7468 tu_stats
->nr_stmt_less_type_units
);
7469 dwarf_read_debug_printf (" %d all_type_units reallocs",
7470 tu_stats
->nr_all_type_units_reallocs
);
7473 /* Traversal function for build_type_psymtabs. */
7476 build_type_psymtab_dependencies (void **slot
, void *info
)
7478 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7479 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7480 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7481 dwarf2_psymtab
*pst
= tu_group
->v
.psymtab
;
7482 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7485 gdb_assert (len
> 0);
7486 gdb_assert (tu_group
->type_unit_group_p ());
7488 pst
->number_of_dependencies
= len
;
7489 pst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7490 for (i
= 0; i
< len
; ++i
)
7492 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7493 gdb_assert (iter
->is_debug_types
);
7494 pst
->dependencies
[i
] = iter
->v
.psymtab
;
7495 iter
->type_unit_group
= tu_group
;
7498 delete tu_group
->tus
;
7499 tu_group
->tus
= nullptr;
7504 /* Traversal function for process_skeletonless_type_unit.
7505 Read a TU in a DWO file and build partial symbols for it. */
7508 process_skeletonless_type_unit (void **slot
, void *info
)
7510 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7511 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7512 struct signatured_type find_entry
, *entry
;
7514 /* If this TU doesn't exist in the global table, add it and read it in. */
7516 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7517 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7519 find_entry
.signature
= dwo_unit
->signature
;
7520 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7521 &find_entry
, INSERT
);
7522 /* If we've already seen this type there's nothing to do. What's happening
7523 is we're doing our own version of comdat-folding here. */
7527 /* This does the job that create_all_comp_units would have done for
7529 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7530 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7533 /* This does the job that build_type_psymtabs would have done. */
7534 cutu_reader
reader (entry
, per_objfile
, nullptr, nullptr, false);
7535 if (!reader
.dummy_p
)
7536 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7537 reader
.comp_unit_die
);
7542 /* Traversal function for process_skeletonless_type_units. */
7545 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7547 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7549 if (dwo_file
->tus
!= NULL
)
7550 htab_traverse_noresize (dwo_file
->tus
.get (),
7551 process_skeletonless_type_unit
, info
);
7556 /* Scan all TUs of DWO files, verifying we've processed them.
7557 This is needed in case a TU was emitted without its skeleton.
7558 Note: This can't be done until we know what all the DWO files are. */
7561 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7563 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7564 if (get_dwp_file (per_objfile
) == NULL
7565 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7567 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7568 process_dwo_file_for_skeletonless_type_units
,
7573 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7576 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7578 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7580 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7585 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7587 /* Set the 'user' field only if it is not already set. */
7588 if (pst
->dependencies
[j
]->user
== NULL
)
7589 pst
->dependencies
[j
]->user
= pst
;
7594 /* Build the partial symbol table by doing a quick pass through the
7595 .debug_info and .debug_abbrev sections. */
7598 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7600 struct objfile
*objfile
= per_objfile
->objfile
;
7601 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7603 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7604 objfile_name (objfile
));
7606 scoped_restore restore_reading_psyms
7607 = make_scoped_restore (&per_bfd
->reading_partial_symbols
, true);
7609 per_bfd
->info
.read (objfile
);
7611 /* Any cached compilation units will be linked by the per-objfile
7612 read_in_chain. Make sure to free them when we're done. */
7613 free_cached_comp_units
freer (per_objfile
);
7615 create_all_comp_units (per_objfile
);
7616 build_type_psymtabs (per_objfile
);
7618 /* Create a temporary address map on a temporary obstack. We later
7619 copy this to the final obstack. */
7620 auto_obstack temp_obstack
;
7622 scoped_restore save_psymtabs_addrmap
7623 = make_scoped_restore (&per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7624 addrmap_create_mutable (&temp_obstack
));
7626 for (const auto &per_cu
: per_bfd
->all_comp_units
)
7628 if (per_cu
->v
.psymtab
!= NULL
)
7629 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7631 process_psymtab_comp_unit (per_cu
.get (), per_objfile
, false,
7635 /* This has to wait until we read the CUs, we need the list of DWOs. */
7636 process_skeletonless_type_units (per_objfile
);
7638 /* Now that all TUs have been processed we can fill in the dependencies. */
7639 if (per_bfd
->type_unit_groups
!= NULL
)
7641 htab_traverse_noresize (per_bfd
->type_unit_groups
.get (),
7642 build_type_psymtab_dependencies
, per_objfile
);
7645 if (dwarf_read_debug
> 0)
7646 print_tu_stats (per_objfile
);
7648 set_partial_user (per_objfile
);
7650 per_bfd
->partial_symtabs
->psymtabs_addrmap
7651 = addrmap_create_fixed (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7652 per_bfd
->partial_symtabs
->obstack ());
7653 /* At this point we want to keep the address map. */
7654 save_psymtabs_addrmap
.release ();
7656 dwarf_read_debug_printf ("Done building psymtabs of %s",
7657 objfile_name (objfile
));
7660 /* Load the partial DIEs for a secondary CU into memory.
7661 This is also used when rereading a primary CU with load_all_dies. */
7664 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7665 dwarf2_per_objfile
*per_objfile
,
7666 dwarf2_cu
*existing_cu
)
7668 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
7670 if (!reader
.dummy_p
)
7672 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7675 /* Check if comp unit has_children.
7676 If so, read the rest of the partial symbols from this comp unit.
7677 If not, there's no more debug_info for this comp unit. */
7678 if (reader
.comp_unit_die
->has_children
)
7679 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7686 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
7687 struct dwarf2_section_info
*section
,
7688 struct dwarf2_section_info
*abbrev_section
,
7689 unsigned int is_dwz
,
7690 htab_up
&types_htab
,
7691 rcuh_kind section_kind
)
7693 const gdb_byte
*info_ptr
;
7694 struct objfile
*objfile
= per_objfile
->objfile
;
7696 dwarf_read_debug_printf ("Reading %s for %s",
7697 section
->get_name (),
7698 section
->get_file_name ());
7700 section
->read (objfile
);
7702 info_ptr
= section
->buffer
;
7704 while (info_ptr
< section
->buffer
+ section
->size
)
7706 std::unique_ptr
<dwarf2_per_cu_data
> this_cu
;
7708 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7710 comp_unit_head cu_header
;
7711 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
7712 abbrev_section
, info_ptr
,
7715 /* Save the compilation unit for later lookup. */
7716 if (cu_header
.unit_type
!= DW_UT_type
)
7717 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
7720 if (types_htab
== nullptr)
7721 types_htab
= allocate_signatured_type_table ();
7723 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
7724 signatured_type
*sig_ptr
= sig_type
.get ();
7725 sig_type
->signature
= cu_header
.signature
;
7726 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7727 this_cu
= std::move (sig_type
);
7729 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
7730 gdb_assert (slot
!= nullptr);
7731 if (*slot
!= nullptr)
7732 complaint (_("debug type entry at offset %s is duplicate to"
7733 " the entry at offset %s, signature %s"),
7734 sect_offset_str (sect_off
),
7735 sect_offset_str (sig_ptr
->sect_off
),
7736 hex_string (sig_ptr
->signature
));
7739 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7740 this_cu
->sect_off
= sect_off
;
7741 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7742 this_cu
->is_dwz
= is_dwz
;
7743 this_cu
->section
= section
;
7745 info_ptr
= info_ptr
+ this_cu
->length
;
7746 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (this_cu
));
7750 /* Create a list of all compilation units in OBJFILE.
7751 This is only done for -readnow and building partial symtabs. */
7754 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
7758 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
7759 &per_objfile
->per_bfd
->abbrev
, 0,
7760 types_htab
, rcuh_kind::COMPILE
);
7761 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
7762 read_comp_units_from_section (per_objfile
, §ion
,
7763 &per_objfile
->per_bfd
->abbrev
, 0,
7764 types_htab
, rcuh_kind::TYPE
);
7766 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
7768 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
7769 types_htab
, rcuh_kind::COMPILE
);
7771 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
7774 /* Process all loaded DIEs for compilation unit CU, starting at
7775 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7776 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7777 DW_AT_ranges). See the comments of add_partial_subprogram on how
7778 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7781 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7782 CORE_ADDR
*highpc
, int set_addrmap
,
7783 struct dwarf2_cu
*cu
)
7785 struct partial_die_info
*pdi
;
7787 /* Now, march along the PDI's, descending into ones which have
7788 interesting children but skipping the children of the other ones,
7789 until we reach the end of the compilation unit. */
7797 /* Anonymous namespaces or modules have no name but have interesting
7798 children, so we need to look at them. Ditto for anonymous
7801 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7802 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7803 || pdi
->tag
== DW_TAG_imported_unit
7804 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7808 case DW_TAG_subprogram
:
7809 case DW_TAG_inlined_subroutine
:
7810 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7811 if (cu
->language
== language_cplus
)
7812 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7815 case DW_TAG_constant
:
7816 case DW_TAG_variable
:
7817 case DW_TAG_typedef
:
7818 case DW_TAG_union_type
:
7819 if (!pdi
->is_declaration
7820 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
7822 add_partial_symbol (pdi
, cu
);
7825 case DW_TAG_class_type
:
7826 case DW_TAG_interface_type
:
7827 case DW_TAG_structure_type
:
7828 if (!pdi
->is_declaration
)
7830 add_partial_symbol (pdi
, cu
);
7832 if ((cu
->language
== language_rust
7833 || cu
->language
== language_cplus
) && pdi
->has_children
)
7834 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7837 case DW_TAG_enumeration_type
:
7838 if (!pdi
->is_declaration
)
7839 add_partial_enumeration (pdi
, cu
);
7841 case DW_TAG_base_type
:
7842 case DW_TAG_subrange_type
:
7843 /* File scope base type definitions are added to the partial
7845 add_partial_symbol (pdi
, cu
);
7847 case DW_TAG_namespace
:
7848 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7851 if (!pdi
->is_declaration
)
7852 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7854 case DW_TAG_imported_unit
:
7856 struct dwarf2_per_cu_data
*per_cu
;
7858 /* For now we don't handle imported units in type units. */
7859 if (cu
->per_cu
->is_debug_types
)
7861 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7862 " supported in type units [in module %s]"),
7863 objfile_name (cu
->per_objfile
->objfile
));
7866 per_cu
= dwarf2_find_containing_comp_unit
7867 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
7869 /* Go read the partial unit, if needed. */
7870 if (per_cu
->v
.psymtab
== NULL
)
7871 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
7874 cu
->per_cu
->imported_symtabs_push (per_cu
);
7877 case DW_TAG_imported_declaration
:
7878 add_partial_symbol (pdi
, cu
);
7885 /* If the die has a sibling, skip to the sibling. */
7887 pdi
= pdi
->die_sibling
;
7891 /* Functions used to compute the fully scoped name of a partial DIE.
7893 Normally, this is simple. For C++, the parent DIE's fully scoped
7894 name is concatenated with "::" and the partial DIE's name.
7895 Enumerators are an exception; they use the scope of their parent
7896 enumeration type, i.e. the name of the enumeration type is not
7897 prepended to the enumerator.
7899 There are two complexities. One is DW_AT_specification; in this
7900 case "parent" means the parent of the target of the specification,
7901 instead of the direct parent of the DIE. The other is compilers
7902 which do not emit DW_TAG_namespace; in this case we try to guess
7903 the fully qualified name of structure types from their members'
7904 linkage names. This must be done using the DIE's children rather
7905 than the children of any DW_AT_specification target. We only need
7906 to do this for structures at the top level, i.e. if the target of
7907 any DW_AT_specification (if any; otherwise the DIE itself) does not
7910 /* Compute the scope prefix associated with PDI's parent, in
7911 compilation unit CU. The result will be allocated on CU's
7912 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7913 field. NULL is returned if no prefix is necessary. */
7915 partial_die_parent_scope (struct partial_die_info
*pdi
,
7916 struct dwarf2_cu
*cu
)
7918 const char *grandparent_scope
;
7919 struct partial_die_info
*parent
, *real_pdi
;
7921 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7922 then this means the parent of the specification DIE. */
7925 while (real_pdi
->has_specification
)
7927 auto res
= find_partial_die (real_pdi
->spec_offset
,
7928 real_pdi
->spec_is_dwz
, cu
);
7933 parent
= real_pdi
->die_parent
;
7937 if (parent
->scope_set
)
7938 return parent
->scope
;
7942 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7944 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7945 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7946 Work around this problem here. */
7947 if (cu
->language
== language_cplus
7948 && parent
->tag
== DW_TAG_namespace
7949 && strcmp (parent
->name (cu
), "::") == 0
7950 && grandparent_scope
== NULL
)
7952 parent
->scope
= NULL
;
7953 parent
->scope_set
= 1;
7957 /* Nested subroutines in Fortran get a prefix. */
7958 if (pdi
->tag
== DW_TAG_enumerator
)
7959 /* Enumerators should not get the name of the enumeration as a prefix. */
7960 parent
->scope
= grandparent_scope
;
7961 else if (parent
->tag
== DW_TAG_namespace
7962 || parent
->tag
== DW_TAG_module
7963 || parent
->tag
== DW_TAG_structure_type
7964 || parent
->tag
== DW_TAG_class_type
7965 || parent
->tag
== DW_TAG_interface_type
7966 || parent
->tag
== DW_TAG_union_type
7967 || parent
->tag
== DW_TAG_enumeration_type
7968 || (cu
->language
== language_fortran
7969 && parent
->tag
== DW_TAG_subprogram
7970 && pdi
->tag
== DW_TAG_subprogram
))
7972 if (grandparent_scope
== NULL
)
7973 parent
->scope
= parent
->name (cu
);
7975 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7977 parent
->name (cu
), 0, cu
);
7981 /* FIXME drow/2004-04-01: What should we be doing with
7982 function-local names? For partial symbols, we should probably be
7984 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
7985 dwarf_tag_name (parent
->tag
),
7986 sect_offset_str (pdi
->sect_off
));
7987 parent
->scope
= grandparent_scope
;
7990 parent
->scope_set
= 1;
7991 return parent
->scope
;
7994 /* Return the fully scoped name associated with PDI, from compilation unit
7995 CU. The result will be allocated with malloc. */
7997 static gdb::unique_xmalloc_ptr
<char>
7998 partial_die_full_name (struct partial_die_info
*pdi
,
7999 struct dwarf2_cu
*cu
)
8001 const char *parent_scope
;
8003 /* If this is a template instantiation, we can not work out the
8004 template arguments from partial DIEs. So, unfortunately, we have
8005 to go through the full DIEs. At least any work we do building
8006 types here will be reused if full symbols are loaded later. */
8007 if (pdi
->has_template_arguments
)
8011 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8013 struct die_info
*die
;
8014 struct attribute attr
;
8015 struct dwarf2_cu
*ref_cu
= cu
;
8017 /* DW_FORM_ref_addr is using section offset. */
8018 attr
.name
= (enum dwarf_attribute
) 0;
8019 attr
.form
= DW_FORM_ref_addr
;
8020 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8021 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8023 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8027 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8028 if (parent_scope
== NULL
)
8031 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8037 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8039 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8040 struct objfile
*objfile
= per_objfile
->objfile
;
8041 struct gdbarch
*gdbarch
= objfile
->arch ();
8043 const char *actual_name
= NULL
;
8046 baseaddr
= objfile
->text_section_offset ();
8048 gdb::unique_xmalloc_ptr
<char> built_actual_name
8049 = partial_die_full_name (pdi
, cu
);
8050 if (built_actual_name
!= NULL
)
8051 actual_name
= built_actual_name
.get ();
8053 if (actual_name
== NULL
)
8054 actual_name
= pdi
->name (cu
);
8056 partial_symbol psymbol
;
8057 memset (&psymbol
, 0, sizeof (psymbol
));
8058 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8059 psymbol
.ginfo
.set_section_index (-1);
8061 /* The code below indicates that the psymbol should be installed by
8063 gdb::optional
<psymbol_placement
> where
;
8067 case DW_TAG_inlined_subroutine
:
8068 case DW_TAG_subprogram
:
8069 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8071 if (pdi
->is_external
8072 || cu
->language
== language_ada
8073 || (cu
->language
== language_fortran
8074 && pdi
->die_parent
!= NULL
8075 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8077 /* Normally, only "external" DIEs are part of the global scope.
8078 But in Ada and Fortran, we want to be able to access nested
8079 procedures globally. So all Ada and Fortran subprograms are
8080 stored in the global scope. */
8081 where
= psymbol_placement::GLOBAL
;
8084 where
= psymbol_placement::STATIC
;
8086 psymbol
.domain
= VAR_DOMAIN
;
8087 psymbol
.aclass
= LOC_BLOCK
;
8088 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8089 psymbol
.ginfo
.value
.address
= addr
;
8091 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8092 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8094 case DW_TAG_constant
:
8095 psymbol
.domain
= VAR_DOMAIN
;
8096 psymbol
.aclass
= LOC_STATIC
;
8097 where
= (pdi
->is_external
8098 ? psymbol_placement::GLOBAL
8099 : psymbol_placement::STATIC
);
8101 case DW_TAG_variable
:
8103 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8107 && !per_objfile
->per_bfd
->has_section_at_zero
)
8109 /* A global or static variable may also have been stripped
8110 out by the linker if unused, in which case its address
8111 will be nullified; do not add such variables into partial
8112 symbol table then. */
8114 else if (pdi
->is_external
)
8117 Don't enter into the minimal symbol tables as there is
8118 a minimal symbol table entry from the ELF symbols already.
8119 Enter into partial symbol table if it has a location
8120 descriptor or a type.
8121 If the location descriptor is missing, new_symbol will create
8122 a LOC_UNRESOLVED symbol, the address of the variable will then
8123 be determined from the minimal symbol table whenever the variable
8125 The address for the partial symbol table entry is not
8126 used by GDB, but it comes in handy for debugging partial symbol
8129 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8131 psymbol
.domain
= VAR_DOMAIN
;
8132 psymbol
.aclass
= LOC_STATIC
;
8133 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8134 psymbol
.ginfo
.value
.address
= addr
;
8135 where
= psymbol_placement::GLOBAL
;
8140 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8142 /* Static Variable. Skip symbols whose value we cannot know (those
8143 without location descriptors or constant values). */
8144 if (!has_loc
&& !pdi
->has_const_value
)
8147 psymbol
.domain
= VAR_DOMAIN
;
8148 psymbol
.aclass
= LOC_STATIC
;
8149 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8151 psymbol
.ginfo
.value
.address
= addr
;
8152 where
= psymbol_placement::STATIC
;
8155 case DW_TAG_array_type
:
8156 case DW_TAG_typedef
:
8157 case DW_TAG_base_type
:
8158 case DW_TAG_subrange_type
:
8159 psymbol
.domain
= VAR_DOMAIN
;
8160 psymbol
.aclass
= LOC_TYPEDEF
;
8161 where
= psymbol_placement::STATIC
;
8163 case DW_TAG_imported_declaration
:
8164 case DW_TAG_namespace
:
8165 psymbol
.domain
= VAR_DOMAIN
;
8166 psymbol
.aclass
= LOC_TYPEDEF
;
8167 where
= psymbol_placement::GLOBAL
;
8170 /* With Fortran 77 there might be a "BLOCK DATA" module
8171 available without any name. If so, we skip the module as it
8172 doesn't bring any value. */
8173 if (actual_name
!= nullptr)
8175 psymbol
.domain
= MODULE_DOMAIN
;
8176 psymbol
.aclass
= LOC_TYPEDEF
;
8177 where
= psymbol_placement::GLOBAL
;
8180 case DW_TAG_class_type
:
8181 case DW_TAG_interface_type
:
8182 case DW_TAG_structure_type
:
8183 case DW_TAG_union_type
:
8184 case DW_TAG_enumeration_type
:
8185 /* Skip external references. The DWARF standard says in the section
8186 about "Structure, Union, and Class Type Entries": "An incomplete
8187 structure, union or class type is represented by a structure,
8188 union or class entry that does not have a byte size attribute
8189 and that has a DW_AT_declaration attribute." */
8190 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8193 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8194 static vs. global. */
8195 psymbol
.domain
= STRUCT_DOMAIN
;
8196 psymbol
.aclass
= LOC_TYPEDEF
;
8197 where
= (cu
->language
== language_cplus
8198 ? psymbol_placement::GLOBAL
8199 : psymbol_placement::STATIC
);
8201 case DW_TAG_enumerator
:
8202 psymbol
.domain
= VAR_DOMAIN
;
8203 psymbol
.aclass
= LOC_CONST
;
8204 where
= (cu
->language
== language_cplus
8205 ? psymbol_placement::GLOBAL
8206 : psymbol_placement::STATIC
);
8212 if (where
.has_value ())
8214 if (built_actual_name
!= nullptr)
8215 actual_name
= objfile
->intern (actual_name
);
8216 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8217 psymbol
.ginfo
.set_linkage_name (actual_name
);
8220 psymbol
.ginfo
.set_demangled_name (actual_name
,
8221 &objfile
->objfile_obstack
);
8222 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8224 cu
->per_cu
->v
.psymtab
->add_psymbol
8225 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
8230 /* Read a partial die corresponding to a namespace; also, add a symbol
8231 corresponding to that namespace to the symbol table. NAMESPACE is
8232 the name of the enclosing namespace. */
8235 add_partial_namespace (struct partial_die_info
*pdi
,
8236 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8237 int set_addrmap
, struct dwarf2_cu
*cu
)
8239 /* Add a symbol for the namespace. */
8241 add_partial_symbol (pdi
, cu
);
8243 /* Now scan partial symbols in that namespace. */
8245 if (pdi
->has_children
)
8246 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8249 /* Read a partial die corresponding to a Fortran module. */
8252 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8253 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8255 /* Add a symbol for the namespace. */
8257 add_partial_symbol (pdi
, cu
);
8259 /* Now scan partial symbols in that module. */
8261 if (pdi
->has_children
)
8262 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8265 /* Read a partial die corresponding to a subprogram or an inlined
8266 subprogram and create a partial symbol for that subprogram.
8267 When the CU language allows it, this routine also defines a partial
8268 symbol for each nested subprogram that this subprogram contains.
8269 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8270 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8272 PDI may also be a lexical block, in which case we simply search
8273 recursively for subprograms defined inside that lexical block.
8274 Again, this is only performed when the CU language allows this
8275 type of definitions. */
8278 add_partial_subprogram (struct partial_die_info
*pdi
,
8279 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8280 int set_addrmap
, struct dwarf2_cu
*cu
)
8282 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8284 if (pdi
->has_pc_info
)
8286 if (pdi
->lowpc
< *lowpc
)
8287 *lowpc
= pdi
->lowpc
;
8288 if (pdi
->highpc
> *highpc
)
8289 *highpc
= pdi
->highpc
;
8292 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8293 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8294 struct gdbarch
*gdbarch
= objfile
->arch ();
8296 CORE_ADDR this_highpc
;
8297 CORE_ADDR this_lowpc
;
8299 baseaddr
= objfile
->text_section_offset ();
8301 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8302 pdi
->lowpc
+ baseaddr
)
8305 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8306 pdi
->highpc
+ baseaddr
)
8308 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8309 this_lowpc
, this_highpc
- 1,
8310 cu
->per_cu
->v
.psymtab
);
8314 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8316 if (!pdi
->is_declaration
)
8317 /* Ignore subprogram DIEs that do not have a name, they are
8318 illegal. Do not emit a complaint at this point, we will
8319 do so when we convert this psymtab into a symtab. */
8321 add_partial_symbol (pdi
, cu
);
8325 if (! pdi
->has_children
)
8328 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8330 pdi
= pdi
->die_child
;
8334 if (pdi
->tag
== DW_TAG_subprogram
8335 || pdi
->tag
== DW_TAG_inlined_subroutine
8336 || pdi
->tag
== DW_TAG_lexical_block
)
8337 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8338 pdi
= pdi
->die_sibling
;
8343 /* Read a partial die corresponding to an enumeration type. */
8346 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8347 struct dwarf2_cu
*cu
)
8349 struct partial_die_info
*pdi
;
8351 if (enum_pdi
->name (cu
) != NULL
)
8352 add_partial_symbol (enum_pdi
, cu
);
8354 pdi
= enum_pdi
->die_child
;
8357 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8358 complaint (_("malformed enumerator DIE ignored"));
8360 add_partial_symbol (pdi
, cu
);
8361 pdi
= pdi
->die_sibling
;
8365 /* Return the initial uleb128 in the die at INFO_PTR. */
8368 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8370 unsigned int bytes_read
;
8372 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8375 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8376 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8378 Return the corresponding abbrev, or NULL if the number is zero (indicating
8379 an empty DIE). In either case *BYTES_READ will be set to the length of
8380 the initial number. */
8382 static const struct abbrev_info
*
8383 peek_die_abbrev (const die_reader_specs
&reader
,
8384 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8386 dwarf2_cu
*cu
= reader
.cu
;
8387 bfd
*abfd
= reader
.abfd
;
8388 unsigned int abbrev_number
8389 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8391 if (abbrev_number
== 0)
8394 const abbrev_info
*abbrev
8395 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8398 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8399 " at offset %s [in module %s]"),
8400 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8401 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8407 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8408 Returns a pointer to the end of a series of DIEs, terminated by an empty
8409 DIE. Any children of the skipped DIEs will also be skipped. */
8411 static const gdb_byte
*
8412 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8416 unsigned int bytes_read
;
8417 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8421 return info_ptr
+ bytes_read
;
8423 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8427 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8428 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8429 abbrev corresponding to that skipped uleb128 should be passed in
8430 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8433 static const gdb_byte
*
8434 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8435 const struct abbrev_info
*abbrev
)
8437 unsigned int bytes_read
;
8438 struct attribute attr
;
8439 bfd
*abfd
= reader
->abfd
;
8440 struct dwarf2_cu
*cu
= reader
->cu
;
8441 const gdb_byte
*buffer
= reader
->buffer
;
8442 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8443 unsigned int form
, i
;
8445 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8447 /* The only abbrev we care about is DW_AT_sibling. */
8448 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8450 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8451 if (attr
.form
== DW_FORM_ref_addr
)
8452 complaint (_("ignoring absolute DW_AT_sibling"));
8455 sect_offset off
= attr
.get_ref_die_offset ();
8456 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8458 if (sibling_ptr
< info_ptr
)
8459 complaint (_("DW_AT_sibling points backwards"));
8460 else if (sibling_ptr
> reader
->buffer_end
)
8461 reader
->die_section
->overflow_complaint ();
8467 /* If it isn't DW_AT_sibling, skip this attribute. */
8468 form
= abbrev
->attrs
[i
].form
;
8472 case DW_FORM_ref_addr
:
8473 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8474 and later it is offset sized. */
8475 if (cu
->header
.version
== 2)
8476 info_ptr
+= cu
->header
.addr_size
;
8478 info_ptr
+= cu
->header
.offset_size
;
8480 case DW_FORM_GNU_ref_alt
:
8481 info_ptr
+= cu
->header
.offset_size
;
8484 info_ptr
+= cu
->header
.addr_size
;
8492 case DW_FORM_flag_present
:
8493 case DW_FORM_implicit_const
:
8510 case DW_FORM_ref_sig8
:
8513 case DW_FORM_data16
:
8516 case DW_FORM_string
:
8517 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8518 info_ptr
+= bytes_read
;
8520 case DW_FORM_sec_offset
:
8522 case DW_FORM_GNU_strp_alt
:
8523 info_ptr
+= cu
->header
.offset_size
;
8525 case DW_FORM_exprloc
:
8527 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8528 info_ptr
+= bytes_read
;
8530 case DW_FORM_block1
:
8531 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8533 case DW_FORM_block2
:
8534 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8536 case DW_FORM_block4
:
8537 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8543 case DW_FORM_ref_udata
:
8544 case DW_FORM_GNU_addr_index
:
8545 case DW_FORM_GNU_str_index
:
8546 case DW_FORM_rnglistx
:
8547 case DW_FORM_loclistx
:
8548 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8550 case DW_FORM_indirect
:
8551 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8552 info_ptr
+= bytes_read
;
8553 /* We need to continue parsing from here, so just go back to
8555 goto skip_attribute
;
8558 error (_("Dwarf Error: Cannot handle %s "
8559 "in DWARF reader [in module %s]"),
8560 dwarf_form_name (form
),
8561 bfd_get_filename (abfd
));
8565 if (abbrev
->has_children
)
8566 return skip_children (reader
, info_ptr
);
8571 /* Locate ORIG_PDI's sibling.
8572 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8574 static const gdb_byte
*
8575 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8576 struct partial_die_info
*orig_pdi
,
8577 const gdb_byte
*info_ptr
)
8579 /* Do we know the sibling already? */
8581 if (orig_pdi
->sibling
)
8582 return orig_pdi
->sibling
;
8584 /* Are there any children to deal with? */
8586 if (!orig_pdi
->has_children
)
8589 /* Skip the children the long way. */
8591 return skip_children (reader
, info_ptr
);
8594 /* Expand this partial symbol table into a full symbol table. SELF is
8598 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8600 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8602 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8604 /* If this psymtab is constructed from a debug-only objfile, the
8605 has_section_at_zero flag will not necessarily be correct. We
8606 can get the correct value for this flag by looking at the data
8607 associated with the (presumably stripped) associated objfile. */
8608 if (objfile
->separate_debug_objfile_backlink
)
8610 dwarf2_per_objfile
*per_objfile_backlink
8611 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8613 per_objfile
->per_bfd
->has_section_at_zero
8614 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8617 expand_psymtab (objfile
);
8619 process_cu_includes (per_objfile
);
8622 /* Reading in full CUs. */
8624 /* Add PER_CU to the queue. */
8627 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8628 dwarf2_per_objfile
*per_objfile
,
8629 enum language pretend_language
)
8633 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
8634 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
8637 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
8639 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8642 Return true if maybe_queue_comp_unit requires the caller to load the CU's
8643 DIEs, false otherwise.
8645 Explanation: there is an invariant that if a CU is queued for expansion
8646 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
8647 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
8648 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
8649 are not yet loaded, the the caller must load the CU's DIEs to ensure the
8650 invariant is respected.
8652 The caller is therefore not required to load the CU's DIEs (we return false)
8655 - the CU is already expanded, and therefore does not get enqueued
8656 - the CU gets enqueued for expansion, but its DIEs are already loaded
8658 Note that the caller should not use this function's return value as an
8659 indicator of whether the CU's DIEs are loaded right now, it should check
8660 that by calling `dwarf2_per_objfile::get_cu` instead. */
8663 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8664 dwarf2_per_cu_data
*per_cu
,
8665 dwarf2_per_objfile
*per_objfile
,
8666 enum language pretend_language
)
8668 /* We may arrive here during partial symbol reading, if we need full
8669 DIEs to process an unusual case (e.g. template arguments). Do
8670 not queue PER_CU, just tell our caller to load its DIEs. */
8671 if (per_cu
->per_bfd
->reading_partial_symbols
)
8673 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8675 if (cu
== NULL
|| cu
->dies
== NULL
)
8680 /* Mark the dependence relation so that we don't flush PER_CU
8682 if (dependent_cu
!= NULL
)
8683 dwarf2_add_dependence (dependent_cu
, per_cu
);
8685 /* If it's already on the queue, we have nothing to do. */
8688 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
8690 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
8692 /* If the CU is queued for expansion, it should not already be
8694 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
8696 /* The DIEs are already loaded, the caller doesn't need to do it. */
8700 bool queued
= false;
8701 if (!per_objfile
->symtab_set_p (per_cu
))
8703 /* Add it to the queue. */
8704 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8708 /* If the compilation unit is already loaded, just mark it as
8710 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8714 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
8715 and the DIEs are not already loaded. */
8716 return queued
&& cu
== nullptr;
8719 /* Process the queue. */
8722 process_queue (dwarf2_per_objfile
*per_objfile
)
8724 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
8725 objfile_name (per_objfile
->objfile
));
8727 /* The queue starts out with one item, but following a DIE reference
8728 may load a new CU, adding it to the end of the queue. */
8729 while (!per_objfile
->per_bfd
->queue
->empty ())
8731 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
8732 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8734 if (!per_objfile
->symtab_set_p (per_cu
))
8736 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8738 /* Skip dummy CUs. */
8741 unsigned int debug_print_threshold
;
8744 if (per_cu
->is_debug_types
)
8746 struct signatured_type
*sig_type
=
8747 (struct signatured_type
*) per_cu
;
8749 sprintf (buf
, "TU %s at offset %s",
8750 hex_string (sig_type
->signature
),
8751 sect_offset_str (per_cu
->sect_off
));
8752 /* There can be 100s of TUs.
8753 Only print them in verbose mode. */
8754 debug_print_threshold
= 2;
8758 sprintf (buf
, "CU at offset %s",
8759 sect_offset_str (per_cu
->sect_off
));
8760 debug_print_threshold
= 1;
8763 if (dwarf_read_debug
>= debug_print_threshold
)
8764 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
8766 if (per_cu
->is_debug_types
)
8767 process_full_type_unit (cu
, item
.pretend_language
);
8769 process_full_comp_unit (cu
, item
.pretend_language
);
8771 if (dwarf_read_debug
>= debug_print_threshold
)
8772 dwarf_read_debug_printf ("Done expanding %s", buf
);
8777 per_objfile
->per_bfd
->queue
->pop ();
8780 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
8781 objfile_name (per_objfile
->objfile
));
8784 /* Read in full symbols for PST, and anything it depends on. */
8787 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8789 gdb_assert (!readin_p (objfile
));
8791 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8792 free_cached_comp_units
freer (per_objfile
);
8793 expand_dependencies (objfile
);
8795 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
8796 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
8799 /* See psympriv.h. */
8802 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
8804 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8805 return per_objfile
->symtab_set_p (per_cu_data
);
8808 /* See psympriv.h. */
8811 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
8813 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8814 return per_objfile
->get_symtab (per_cu_data
);
8817 /* Trivial hash function for die_info: the hash value of a DIE
8818 is its offset in .debug_info for this objfile. */
8821 die_hash (const void *item
)
8823 const struct die_info
*die
= (const struct die_info
*) item
;
8825 return to_underlying (die
->sect_off
);
8828 /* Trivial comparison function for die_info structures: two DIEs
8829 are equal if they have the same offset. */
8832 die_eq (const void *item_lhs
, const void *item_rhs
)
8834 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8835 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8837 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8840 /* Load the DIEs associated with PER_CU into memory.
8842 In some cases, the caller, while reading partial symbols, will need to load
8843 the full symbols for the CU for some reason. It will already have a
8844 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
8845 rather than creating a new one. */
8848 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
8849 dwarf2_per_objfile
*per_objfile
,
8850 dwarf2_cu
*existing_cu
,
8852 enum language pretend_language
)
8854 gdb_assert (! this_cu
->is_debug_types
);
8856 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
8860 struct dwarf2_cu
*cu
= reader
.cu
;
8861 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8863 gdb_assert (cu
->die_hash
== NULL
);
8865 htab_create_alloc_ex (cu
->header
.length
/ 12,
8869 &cu
->comp_unit_obstack
,
8870 hashtab_obstack_allocate
,
8871 dummy_obstack_deallocate
);
8873 if (reader
.comp_unit_die
->has_children
)
8874 reader
.comp_unit_die
->child
8875 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8876 &info_ptr
, reader
.comp_unit_die
);
8877 cu
->dies
= reader
.comp_unit_die
;
8878 /* comp_unit_die is not stored in die_hash, no need. */
8880 /* We try not to read any attributes in this function, because not
8881 all CUs needed for references have been loaded yet, and symbol
8882 table processing isn't initialized. But we have to set the CU language,
8883 or we won't be able to build types correctly.
8884 Similarly, if we do not read the producer, we can not apply
8885 producer-specific interpretation. */
8886 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8891 /* Add a DIE to the delayed physname list. */
8894 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8895 const char *name
, struct die_info
*die
,
8896 struct dwarf2_cu
*cu
)
8898 struct delayed_method_info mi
;
8900 mi
.fnfield_index
= fnfield_index
;
8904 cu
->method_list
.push_back (mi
);
8907 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8908 "const" / "volatile". If so, decrements LEN by the length of the
8909 modifier and return true. Otherwise return false. */
8913 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8915 size_t mod_len
= sizeof (mod
) - 1;
8916 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8924 /* Compute the physnames of any methods on the CU's method list.
8926 The computation of method physnames is delayed in order to avoid the
8927 (bad) condition that one of the method's formal parameters is of an as yet
8931 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8933 /* Only C++ delays computing physnames. */
8934 if (cu
->method_list
.empty ())
8936 gdb_assert (cu
->language
== language_cplus
);
8938 for (const delayed_method_info
&mi
: cu
->method_list
)
8940 const char *physname
;
8941 struct fn_fieldlist
*fn_flp
8942 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8943 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8944 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8945 = physname
? physname
: "";
8947 /* Since there's no tag to indicate whether a method is a
8948 const/volatile overload, extract that information out of the
8950 if (physname
!= NULL
)
8952 size_t len
= strlen (physname
);
8956 if (physname
[len
] == ')') /* shortcut */
8958 else if (check_modifier (physname
, len
, " const"))
8959 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8960 else if (check_modifier (physname
, len
, " volatile"))
8961 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8968 /* The list is no longer needed. */
8969 cu
->method_list
.clear ();
8972 /* Go objects should be embedded in a DW_TAG_module DIE,
8973 and it's not clear if/how imported objects will appear.
8974 To keep Go support simple until that's worked out,
8975 go back through what we've read and create something usable.
8976 We could do this while processing each DIE, and feels kinda cleaner,
8977 but that way is more invasive.
8978 This is to, for example, allow the user to type "p var" or "b main"
8979 without having to specify the package name, and allow lookups
8980 of module.object to work in contexts that use the expression
8984 fixup_go_packaging (struct dwarf2_cu
*cu
)
8986 gdb::unique_xmalloc_ptr
<char> package_name
;
8987 struct pending
*list
;
8990 for (list
= *cu
->get_builder ()->get_global_symbols ();
8994 for (i
= 0; i
< list
->nsyms
; ++i
)
8996 struct symbol
*sym
= list
->symbol
[i
];
8998 if (sym
->language () == language_go
8999 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9001 gdb::unique_xmalloc_ptr
<char> this_package_name
9002 (go_symbol_package_name (sym
));
9004 if (this_package_name
== NULL
)
9006 if (package_name
== NULL
)
9007 package_name
= std::move (this_package_name
);
9010 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9011 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9012 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9013 (symbol_symtab (sym
) != NULL
9014 ? symtab_to_filename_for_display
9015 (symbol_symtab (sym
))
9016 : objfile_name (objfile
)),
9017 this_package_name
.get (), package_name
.get ());
9023 if (package_name
!= NULL
)
9025 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9026 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9027 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9028 saved_package_name
);
9031 sym
= new (&objfile
->objfile_obstack
) symbol
;
9032 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9033 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9034 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9035 e.g., "main" finds the "main" module and not C's main(). */
9036 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9037 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9038 SYMBOL_TYPE (sym
) = type
;
9040 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9044 /* Allocate a fully-qualified name consisting of the two parts on the
9048 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9050 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9053 /* A helper that allocates a variant part to attach to a Rust enum
9054 type. OBSTACK is where the results should be allocated. TYPE is
9055 the type we're processing. DISCRIMINANT_INDEX is the index of the
9056 discriminant. It must be the index of one of the fields of TYPE,
9057 or -1 to mean there is no discriminant (univariant enum).
9058 DEFAULT_INDEX is the index of the default field; or -1 if there is
9059 no default. RANGES is indexed by "effective" field number (the
9060 field index, but omitting the discriminant and default fields) and
9061 must hold the discriminant values used by the variants. Note that
9062 RANGES must have a lifetime at least as long as OBSTACK -- either
9063 already allocated on it, or static. */
9066 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9067 int discriminant_index
, int default_index
,
9068 gdb::array_view
<discriminant_range
> ranges
)
9070 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
9071 gdb_assert (discriminant_index
== -1
9072 || (discriminant_index
>= 0
9073 && discriminant_index
< type
->num_fields ()));
9074 gdb_assert (default_index
== -1
9075 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9077 /* We have one variant for each non-discriminant field. */
9078 int n_variants
= type
->num_fields ();
9079 if (discriminant_index
!= -1)
9082 variant
*variants
= new (obstack
) variant
[n_variants
];
9085 for (int i
= 0; i
< type
->num_fields (); ++i
)
9087 if (i
== discriminant_index
)
9090 variants
[var_idx
].first_field
= i
;
9091 variants
[var_idx
].last_field
= i
+ 1;
9093 /* The default field does not need a range, but other fields do.
9094 We skipped the discriminant above. */
9095 if (i
!= default_index
)
9097 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9104 gdb_assert (range_idx
== ranges
.size ());
9105 gdb_assert (var_idx
== n_variants
);
9107 variant_part
*part
= new (obstack
) variant_part
;
9108 part
->discriminant_index
= discriminant_index
;
9109 /* If there is no discriminant, then whether it is signed is of no
9112 = (discriminant_index
== -1
9114 : type
->field (discriminant_index
).type ()->is_unsigned ());
9115 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9117 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9118 gdb::array_view
<variant_part
> *prop_value
9119 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9121 struct dynamic_prop prop
;
9122 prop
.set_variant_parts (prop_value
);
9124 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9127 /* Some versions of rustc emitted enums in an unusual way.
9129 Ordinary enums were emitted as unions. The first element of each
9130 structure in the union was named "RUST$ENUM$DISR". This element
9131 held the discriminant.
9133 These versions of Rust also implemented the "non-zero"
9134 optimization. When the enum had two values, and one is empty and
9135 the other holds a pointer that cannot be zero, the pointer is used
9136 as the discriminant, with a zero value meaning the empty variant.
9137 Here, the union's first member is of the form
9138 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9139 where the fieldnos are the indices of the fields that should be
9140 traversed in order to find the field (which may be several fields deep)
9141 and the variantname is the name of the variant of the case when the
9144 This function recognizes whether TYPE is of one of these forms,
9145 and, if so, smashes it to be a variant type. */
9148 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9150 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9152 /* We don't need to deal with empty enums. */
9153 if (type
->num_fields () == 0)
9156 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9157 if (type
->num_fields () == 1
9158 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9160 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9162 /* Decode the field name to find the offset of the
9164 ULONGEST bit_offset
= 0;
9165 struct type
*field_type
= type
->field (0).type ();
9166 while (name
[0] >= '0' && name
[0] <= '9')
9169 unsigned long index
= strtoul (name
, &tail
, 10);
9172 || index
>= field_type
->num_fields ()
9173 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9174 != FIELD_LOC_KIND_BITPOS
))
9176 complaint (_("Could not parse Rust enum encoding string \"%s\""
9178 TYPE_FIELD_NAME (type
, 0),
9179 objfile_name (objfile
));
9184 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9185 field_type
= field_type
->field (index
).type ();
9188 /* Smash this type to be a structure type. We have to do this
9189 because the type has already been recorded. */
9190 type
->set_code (TYPE_CODE_STRUCT
);
9191 type
->set_num_fields (3);
9192 /* Save the field we care about. */
9193 struct field saved_field
= type
->field (0);
9195 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9197 /* Put the discriminant at index 0. */
9198 type
->field (0).set_type (field_type
);
9199 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9200 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9201 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9203 /* The order of fields doesn't really matter, so put the real
9204 field at index 1 and the data-less field at index 2. */
9205 type
->field (1) = saved_field
;
9206 TYPE_FIELD_NAME (type
, 1)
9207 = rust_last_path_segment (type
->field (1).type ()->name ());
9208 type
->field (1).type ()->set_name
9209 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9210 TYPE_FIELD_NAME (type
, 1)));
9212 const char *dataless_name
9213 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9215 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9217 type
->field (2).set_type (dataless_type
);
9218 /* NAME points into the original discriminant name, which
9219 already has the correct lifetime. */
9220 TYPE_FIELD_NAME (type
, 2) = name
;
9221 SET_FIELD_BITPOS (type
->field (2), 0);
9223 /* Indicate that this is a variant type. */
9224 static discriminant_range ranges
[1] = { { 0, 0 } };
9225 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9227 /* A union with a single anonymous field is probably an old-style
9229 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9231 /* Smash this type to be a structure type. We have to do this
9232 because the type has already been recorded. */
9233 type
->set_code (TYPE_CODE_STRUCT
);
9235 struct type
*field_type
= type
->field (0).type ();
9236 const char *variant_name
9237 = rust_last_path_segment (field_type
->name ());
9238 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9239 field_type
->set_name
9240 (rust_fully_qualify (&objfile
->objfile_obstack
,
9241 type
->name (), variant_name
));
9243 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9247 struct type
*disr_type
= nullptr;
9248 for (int i
= 0; i
< type
->num_fields (); ++i
)
9250 disr_type
= type
->field (i
).type ();
9252 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9254 /* All fields of a true enum will be structs. */
9257 else if (disr_type
->num_fields () == 0)
9259 /* Could be data-less variant, so keep going. */
9260 disr_type
= nullptr;
9262 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9263 "RUST$ENUM$DISR") != 0)
9265 /* Not a Rust enum. */
9275 /* If we got here without a discriminant, then it's probably
9277 if (disr_type
== nullptr)
9280 /* Smash this type to be a structure type. We have to do this
9281 because the type has already been recorded. */
9282 type
->set_code (TYPE_CODE_STRUCT
);
9284 /* Make space for the discriminant field. */
9285 struct field
*disr_field
= &disr_type
->field (0);
9287 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9288 * sizeof (struct field
)));
9289 memcpy (new_fields
+ 1, type
->fields (),
9290 type
->num_fields () * sizeof (struct field
));
9291 type
->set_fields (new_fields
);
9292 type
->set_num_fields (type
->num_fields () + 1);
9294 /* Install the discriminant at index 0 in the union. */
9295 type
->field (0) = *disr_field
;
9296 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9297 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9299 /* We need a way to find the correct discriminant given a
9300 variant name. For convenience we build a map here. */
9301 struct type
*enum_type
= disr_field
->type ();
9302 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9303 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9305 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9308 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9309 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9313 int n_fields
= type
->num_fields ();
9314 /* We don't need a range entry for the discriminant, but we do
9315 need one for every other field, as there is no default
9317 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9320 /* Skip the discriminant here. */
9321 for (int i
= 1; i
< n_fields
; ++i
)
9323 /* Find the final word in the name of this variant's type.
9324 That name can be used to look up the correct
9326 const char *variant_name
9327 = rust_last_path_segment (type
->field (i
).type ()->name ());
9329 auto iter
= discriminant_map
.find (variant_name
);
9330 if (iter
!= discriminant_map
.end ())
9332 ranges
[i
- 1].low
= iter
->second
;
9333 ranges
[i
- 1].high
= iter
->second
;
9336 /* In Rust, each element should have the size of the
9338 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9340 /* Remove the discriminant field, if it exists. */
9341 struct type
*sub_type
= type
->field (i
).type ();
9342 if (sub_type
->num_fields () > 0)
9344 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9345 sub_type
->set_fields (sub_type
->fields () + 1);
9347 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9349 (rust_fully_qualify (&objfile
->objfile_obstack
,
9350 type
->name (), variant_name
));
9353 /* Indicate that this is a variant type. */
9354 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9355 gdb::array_view
<discriminant_range
> (ranges
,
9360 /* Rewrite some Rust unions to be structures with variants parts. */
9363 rust_union_quirks (struct dwarf2_cu
*cu
)
9365 gdb_assert (cu
->language
== language_rust
);
9366 for (type
*type_
: cu
->rust_unions
)
9367 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9368 /* We don't need this any more. */
9369 cu
->rust_unions
.clear ();
9374 type_unit_group_unshareable
*
9375 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9377 auto iter
= this->m_type_units
.find (tu_group
);
9378 if (iter
!= this->m_type_units
.end ())
9379 return iter
->second
.get ();
9381 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9382 type_unit_group_unshareable
*result
= uniq
.get ();
9383 this->m_type_units
[tu_group
] = std::move (uniq
);
9388 dwarf2_per_objfile::get_type_for_signatured_type
9389 (signatured_type
*sig_type
) const
9391 auto iter
= this->m_type_map
.find (sig_type
);
9392 if (iter
== this->m_type_map
.end ())
9395 return iter
->second
;
9398 void dwarf2_per_objfile::set_type_for_signatured_type
9399 (signatured_type
*sig_type
, struct type
*type
)
9401 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9403 this->m_type_map
[sig_type
] = type
;
9406 /* A helper function for computing the list of all symbol tables
9407 included by PER_CU. */
9410 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9411 htab_t all_children
, htab_t all_type_symtabs
,
9412 dwarf2_per_cu_data
*per_cu
,
9413 dwarf2_per_objfile
*per_objfile
,
9414 struct compunit_symtab
*immediate_parent
)
9416 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9419 /* This inclusion and its children have been processed. */
9425 /* Only add a CU if it has a symbol table. */
9426 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9429 /* If this is a type unit only add its symbol table if we haven't
9430 seen it yet (type unit per_cu's can share symtabs). */
9431 if (per_cu
->is_debug_types
)
9433 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9437 result
->push_back (cust
);
9438 if (cust
->user
== NULL
)
9439 cust
->user
= immediate_parent
;
9444 result
->push_back (cust
);
9445 if (cust
->user
== NULL
)
9446 cust
->user
= immediate_parent
;
9450 if (!per_cu
->imported_symtabs_empty ())
9451 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9453 recursively_compute_inclusions (result
, all_children
,
9454 all_type_symtabs
, ptr
, per_objfile
,
9459 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9463 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9464 dwarf2_per_objfile
*per_objfile
)
9466 gdb_assert (! per_cu
->is_debug_types
);
9468 if (!per_cu
->imported_symtabs_empty ())
9471 std::vector
<compunit_symtab
*> result_symtabs
;
9472 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9474 /* If we don't have a symtab, we can just skip this case. */
9478 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9480 NULL
, xcalloc
, xfree
));
9481 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9483 NULL
, xcalloc
, xfree
));
9485 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9487 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9488 all_type_symtabs
.get (), ptr
,
9492 /* Now we have a transitive closure of all the included symtabs. */
9493 len
= result_symtabs
.size ();
9495 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9496 struct compunit_symtab
*, len
+ 1);
9497 memcpy (cust
->includes
, result_symtabs
.data (),
9498 len
* sizeof (compunit_symtab
*));
9499 cust
->includes
[len
] = NULL
;
9503 /* Compute the 'includes' field for the symtabs of all the CUs we just
9507 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9509 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9511 if (! iter
->is_debug_types
)
9512 compute_compunit_symtab_includes (iter
, per_objfile
);
9515 per_objfile
->per_bfd
->just_read_cus
.clear ();
9518 /* Generate full symbol information for CU, whose DIEs have
9519 already been loaded into memory. */
9522 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9524 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9525 struct objfile
*objfile
= per_objfile
->objfile
;
9526 struct gdbarch
*gdbarch
= objfile
->arch ();
9527 CORE_ADDR lowpc
, highpc
;
9528 struct compunit_symtab
*cust
;
9530 struct block
*static_block
;
9533 baseaddr
= objfile
->text_section_offset ();
9535 /* Clear the list here in case something was left over. */
9536 cu
->method_list
.clear ();
9538 cu
->language
= pretend_language
;
9539 cu
->language_defn
= language_def (cu
->language
);
9541 dwarf2_find_base_address (cu
->dies
, cu
);
9543 /* Before we start reading the top-level DIE, ensure it has a valid tag
9545 switch (cu
->dies
->tag
)
9547 case DW_TAG_compile_unit
:
9548 case DW_TAG_partial_unit
:
9549 case DW_TAG_type_unit
:
9552 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
9553 dwarf_tag_name (cu
->dies
->tag
),
9554 sect_offset_str (cu
->per_cu
->sect_off
),
9555 objfile_name (per_objfile
->objfile
));
9558 /* Do line number decoding in read_file_scope () */
9559 process_die (cu
->dies
, cu
);
9561 /* For now fudge the Go package. */
9562 if (cu
->language
== language_go
)
9563 fixup_go_packaging (cu
);
9565 /* Now that we have processed all the DIEs in the CU, all the types
9566 should be complete, and it should now be safe to compute all of the
9568 compute_delayed_physnames (cu
);
9570 if (cu
->language
== language_rust
)
9571 rust_union_quirks (cu
);
9573 /* Some compilers don't define a DW_AT_high_pc attribute for the
9574 compilation unit. If the DW_AT_high_pc is missing, synthesize
9575 it, by scanning the DIE's below the compilation unit. */
9576 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9578 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9579 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9581 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9582 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9583 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9584 addrmap to help ensure it has an accurate map of pc values belonging to
9586 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9588 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9589 SECT_OFF_TEXT (objfile
),
9594 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9596 /* Set symtab language to language from DW_AT_language. If the
9597 compilation is from a C file generated by language preprocessors, do
9598 not set the language if it was already deduced by start_subfile. */
9599 if (!(cu
->language
== language_c
9600 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9601 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9603 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9604 produce DW_AT_location with location lists but it can be possibly
9605 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9606 there were bugs in prologue debug info, fixed later in GCC-4.5
9607 by "unwind info for epilogues" patch (which is not directly related).
9609 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9610 needed, it would be wrong due to missing DW_AT_producer there.
9612 Still one can confuse GDB by using non-standard GCC compilation
9613 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9615 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9616 cust
->locations_valid
= 1;
9618 if (gcc_4_minor
>= 5)
9619 cust
->epilogue_unwind_valid
= 1;
9621 cust
->call_site_htab
= cu
->call_site_htab
;
9624 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9626 /* Push it for inclusion processing later. */
9627 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9629 /* Not needed any more. */
9630 cu
->reset_builder ();
9633 /* Generate full symbol information for type unit CU, whose DIEs have
9634 already been loaded into memory. */
9637 process_full_type_unit (dwarf2_cu
*cu
,
9638 enum language pretend_language
)
9640 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9641 struct objfile
*objfile
= per_objfile
->objfile
;
9642 struct compunit_symtab
*cust
;
9643 struct signatured_type
*sig_type
;
9645 gdb_assert (cu
->per_cu
->is_debug_types
);
9646 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9648 /* Clear the list here in case something was left over. */
9649 cu
->method_list
.clear ();
9651 cu
->language
= pretend_language
;
9652 cu
->language_defn
= language_def (cu
->language
);
9654 /* The symbol tables are set up in read_type_unit_scope. */
9655 process_die (cu
->dies
, cu
);
9657 /* For now fudge the Go package. */
9658 if (cu
->language
== language_go
)
9659 fixup_go_packaging (cu
);
9661 /* Now that we have processed all the DIEs in the CU, all the types
9662 should be complete, and it should now be safe to compute all of the
9664 compute_delayed_physnames (cu
);
9666 if (cu
->language
== language_rust
)
9667 rust_union_quirks (cu
);
9669 /* TUs share symbol tables.
9670 If this is the first TU to use this symtab, complete the construction
9671 of it with end_expandable_symtab. Otherwise, complete the addition of
9672 this TU's symbols to the existing symtab. */
9673 type_unit_group_unshareable
*tug_unshare
=
9674 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9675 if (tug_unshare
->compunit_symtab
== NULL
)
9677 buildsym_compunit
*builder
= cu
->get_builder ();
9678 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9679 tug_unshare
->compunit_symtab
= cust
;
9683 /* Set symtab language to language from DW_AT_language. If the
9684 compilation is from a C file generated by language preprocessors,
9685 do not set the language if it was already deduced by
9687 if (!(cu
->language
== language_c
9688 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9689 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9694 cu
->get_builder ()->augment_type_symtab ();
9695 cust
= tug_unshare
->compunit_symtab
;
9698 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9700 /* Not needed any more. */
9701 cu
->reset_builder ();
9704 /* Process an imported unit DIE. */
9707 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9709 struct attribute
*attr
;
9711 /* For now we don't handle imported units in type units. */
9712 if (cu
->per_cu
->is_debug_types
)
9714 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9715 " supported in type units [in module %s]"),
9716 objfile_name (cu
->per_objfile
->objfile
));
9719 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9722 sect_offset sect_off
= attr
->get_ref_die_offset ();
9723 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9724 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9725 dwarf2_per_cu_data
*per_cu
9726 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
9728 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9729 into another compilation unit, at root level. Regard this as a hint,
9731 if (die
->parent
&& die
->parent
->parent
== NULL
9732 && per_cu
->unit_type
== DW_UT_compile
9733 && per_cu
->lang
== language_cplus
)
9736 /* If necessary, add it to the queue and load its DIEs. */
9737 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
9738 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
9739 false, cu
->language
);
9741 cu
->per_cu
->imported_symtabs_push (per_cu
);
9745 /* RAII object that represents a process_die scope: i.e.,
9746 starts/finishes processing a DIE. */
9747 class process_die_scope
9750 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9751 : m_die (die
), m_cu (cu
)
9753 /* We should only be processing DIEs not already in process. */
9754 gdb_assert (!m_die
->in_process
);
9755 m_die
->in_process
= true;
9758 ~process_die_scope ()
9760 m_die
->in_process
= false;
9762 /* If we're done processing the DIE for the CU that owns the line
9763 header, we don't need the line header anymore. */
9764 if (m_cu
->line_header_die_owner
== m_die
)
9766 delete m_cu
->line_header
;
9767 m_cu
->line_header
= NULL
;
9768 m_cu
->line_header_die_owner
= NULL
;
9777 /* Process a die and its children. */
9780 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9782 process_die_scope
scope (die
, cu
);
9786 case DW_TAG_padding
:
9788 case DW_TAG_compile_unit
:
9789 case DW_TAG_partial_unit
:
9790 read_file_scope (die
, cu
);
9792 case DW_TAG_type_unit
:
9793 read_type_unit_scope (die
, cu
);
9795 case DW_TAG_subprogram
:
9796 /* Nested subprograms in Fortran get a prefix. */
9797 if (cu
->language
== language_fortran
9798 && die
->parent
!= NULL
9799 && die
->parent
->tag
== DW_TAG_subprogram
)
9800 cu
->processing_has_namespace_info
= true;
9802 case DW_TAG_inlined_subroutine
:
9803 read_func_scope (die
, cu
);
9805 case DW_TAG_lexical_block
:
9806 case DW_TAG_try_block
:
9807 case DW_TAG_catch_block
:
9808 read_lexical_block_scope (die
, cu
);
9810 case DW_TAG_call_site
:
9811 case DW_TAG_GNU_call_site
:
9812 read_call_site_scope (die
, cu
);
9814 case DW_TAG_class_type
:
9815 case DW_TAG_interface_type
:
9816 case DW_TAG_structure_type
:
9817 case DW_TAG_union_type
:
9818 process_structure_scope (die
, cu
);
9820 case DW_TAG_enumeration_type
:
9821 process_enumeration_scope (die
, cu
);
9824 /* These dies have a type, but processing them does not create
9825 a symbol or recurse to process the children. Therefore we can
9826 read them on-demand through read_type_die. */
9827 case DW_TAG_subroutine_type
:
9828 case DW_TAG_set_type
:
9829 case DW_TAG_pointer_type
:
9830 case DW_TAG_ptr_to_member_type
:
9831 case DW_TAG_reference_type
:
9832 case DW_TAG_rvalue_reference_type
:
9833 case DW_TAG_string_type
:
9836 case DW_TAG_array_type
:
9837 /* We only need to handle this case for Ada -- in other
9838 languages, it's normal for the compiler to emit a typedef
9840 if (cu
->language
!= language_ada
)
9843 case DW_TAG_base_type
:
9844 case DW_TAG_subrange_type
:
9845 case DW_TAG_typedef
:
9846 /* Add a typedef symbol for the type definition, if it has a
9848 new_symbol (die
, read_type_die (die
, cu
), cu
);
9850 case DW_TAG_common_block
:
9851 read_common_block (die
, cu
);
9853 case DW_TAG_common_inclusion
:
9855 case DW_TAG_namespace
:
9856 cu
->processing_has_namespace_info
= true;
9857 read_namespace (die
, cu
);
9860 cu
->processing_has_namespace_info
= true;
9861 read_module (die
, cu
);
9863 case DW_TAG_imported_declaration
:
9864 cu
->processing_has_namespace_info
= true;
9865 if (read_namespace_alias (die
, cu
))
9867 /* The declaration is not a global namespace alias. */
9869 case DW_TAG_imported_module
:
9870 cu
->processing_has_namespace_info
= true;
9871 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9872 || cu
->language
!= language_fortran
))
9873 complaint (_("Tag '%s' has unexpected children"),
9874 dwarf_tag_name (die
->tag
));
9875 read_import_statement (die
, cu
);
9878 case DW_TAG_imported_unit
:
9879 process_imported_unit_die (die
, cu
);
9882 case DW_TAG_variable
:
9883 read_variable (die
, cu
);
9887 new_symbol (die
, NULL
, cu
);
9892 /* DWARF name computation. */
9894 /* A helper function for dwarf2_compute_name which determines whether DIE
9895 needs to have the name of the scope prepended to the name listed in the
9899 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9901 struct attribute
*attr
;
9905 case DW_TAG_namespace
:
9906 case DW_TAG_typedef
:
9907 case DW_TAG_class_type
:
9908 case DW_TAG_interface_type
:
9909 case DW_TAG_structure_type
:
9910 case DW_TAG_union_type
:
9911 case DW_TAG_enumeration_type
:
9912 case DW_TAG_enumerator
:
9913 case DW_TAG_subprogram
:
9914 case DW_TAG_inlined_subroutine
:
9916 case DW_TAG_imported_declaration
:
9919 case DW_TAG_variable
:
9920 case DW_TAG_constant
:
9921 /* We only need to prefix "globally" visible variables. These include
9922 any variable marked with DW_AT_external or any variable that
9923 lives in a namespace. [Variables in anonymous namespaces
9924 require prefixing, but they are not DW_AT_external.] */
9926 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9928 struct dwarf2_cu
*spec_cu
= cu
;
9930 return die_needs_namespace (die_specification (die
, &spec_cu
),
9934 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9935 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9936 && die
->parent
->tag
!= DW_TAG_module
)
9938 /* A variable in a lexical block of some kind does not need a
9939 namespace, even though in C++ such variables may be external
9940 and have a mangled name. */
9941 if (die
->parent
->tag
== DW_TAG_lexical_block
9942 || die
->parent
->tag
== DW_TAG_try_block
9943 || die
->parent
->tag
== DW_TAG_catch_block
9944 || die
->parent
->tag
== DW_TAG_subprogram
)
9953 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9954 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9955 defined for the given DIE. */
9957 static struct attribute
*
9958 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9960 struct attribute
*attr
;
9962 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9964 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9969 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9970 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9971 defined for the given DIE. */
9974 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9976 const char *linkage_name
;
9978 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9979 if (linkage_name
== NULL
)
9980 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9982 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9983 See https://github.com/rust-lang/rust/issues/32925. */
9984 if (cu
->language
== language_rust
&& linkage_name
!= NULL
9985 && strchr (linkage_name
, '{') != NULL
)
9986 linkage_name
= NULL
;
9988 return linkage_name
;
9991 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9992 compute the physname for the object, which include a method's:
9993 - formal parameters (C++),
9994 - receiver type (Go),
9996 The term "physname" is a bit confusing.
9997 For C++, for example, it is the demangled name.
9998 For Go, for example, it's the mangled name.
10000 For Ada, return the DIE's linkage name rather than the fully qualified
10001 name. PHYSNAME is ignored..
10003 The result is allocated on the objfile->per_bfd's obstack and
10006 static const char *
10007 dwarf2_compute_name (const char *name
,
10008 struct die_info
*die
, struct dwarf2_cu
*cu
,
10011 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10014 name
= dwarf2_name (die
, cu
);
10016 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10017 but otherwise compute it by typename_concat inside GDB.
10018 FIXME: Actually this is not really true, or at least not always true.
10019 It's all very confusing. compute_and_set_names doesn't try to demangle
10020 Fortran names because there is no mangling standard. So new_symbol
10021 will set the demangled name to the result of dwarf2_full_name, and it is
10022 the demangled name that GDB uses if it exists. */
10023 if (cu
->language
== language_ada
10024 || (cu
->language
== language_fortran
&& physname
))
10026 /* For Ada unit, we prefer the linkage name over the name, as
10027 the former contains the exported name, which the user expects
10028 to be able to reference. Ideally, we want the user to be able
10029 to reference this entity using either natural or linkage name,
10030 but we haven't started looking at this enhancement yet. */
10031 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10033 if (linkage_name
!= NULL
)
10034 return linkage_name
;
10037 /* These are the only languages we know how to qualify names in. */
10039 && (cu
->language
== language_cplus
10040 || cu
->language
== language_fortran
|| cu
->language
== language_d
10041 || cu
->language
== language_rust
))
10043 if (die_needs_namespace (die
, cu
))
10045 const char *prefix
;
10046 const char *canonical_name
= NULL
;
10050 prefix
= determine_prefix (die
, cu
);
10051 if (*prefix
!= '\0')
10053 gdb::unique_xmalloc_ptr
<char> prefixed_name
10054 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10056 buf
.puts (prefixed_name
.get ());
10061 /* Template parameters may be specified in the DIE's DW_AT_name, or
10062 as children with DW_TAG_template_type_param or
10063 DW_TAG_value_type_param. If the latter, add them to the name
10064 here. If the name already has template parameters, then
10065 skip this step; some versions of GCC emit both, and
10066 it is more efficient to use the pre-computed name.
10068 Something to keep in mind about this process: it is very
10069 unlikely, or in some cases downright impossible, to produce
10070 something that will match the mangled name of a function.
10071 If the definition of the function has the same debug info,
10072 we should be able to match up with it anyway. But fallbacks
10073 using the minimal symbol, for instance to find a method
10074 implemented in a stripped copy of libstdc++, will not work.
10075 If we do not have debug info for the definition, we will have to
10076 match them up some other way.
10078 When we do name matching there is a related problem with function
10079 templates; two instantiated function templates are allowed to
10080 differ only by their return types, which we do not add here. */
10082 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10084 struct attribute
*attr
;
10085 struct die_info
*child
;
10087 const language_defn
*cplus_lang
= language_def (cu
->language
);
10089 die
->building_fullname
= 1;
10091 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10095 const gdb_byte
*bytes
;
10096 struct dwarf2_locexpr_baton
*baton
;
10099 if (child
->tag
!= DW_TAG_template_type_param
10100 && child
->tag
!= DW_TAG_template_value_param
)
10111 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10114 complaint (_("template parameter missing DW_AT_type"));
10115 buf
.puts ("UNKNOWN_TYPE");
10118 type
= die_type (child
, cu
);
10120 if (child
->tag
== DW_TAG_template_type_param
)
10122 cplus_lang
->print_type (type
, "", &buf
, -1, 0,
10123 &type_print_raw_options
);
10127 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10130 complaint (_("template parameter missing "
10131 "DW_AT_const_value"));
10132 buf
.puts ("UNKNOWN_VALUE");
10136 dwarf2_const_value_attr (attr
, type
, name
,
10137 &cu
->comp_unit_obstack
, cu
,
10138 &value
, &bytes
, &baton
);
10140 if (type
->has_no_signedness ())
10141 /* GDB prints characters as NUMBER 'CHAR'. If that's
10142 changed, this can use value_print instead. */
10143 cplus_lang
->printchar (value
, type
, &buf
);
10146 struct value_print_options opts
;
10149 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10153 baton
->per_objfile
);
10154 else if (bytes
!= NULL
)
10156 v
= allocate_value (type
);
10157 memcpy (value_contents_writeable (v
), bytes
,
10158 TYPE_LENGTH (type
));
10161 v
= value_from_longest (type
, value
);
10163 /* Specify decimal so that we do not depend on
10165 get_formatted_print_options (&opts
, 'd');
10167 value_print (v
, &buf
, &opts
);
10172 die
->building_fullname
= 0;
10176 /* Close the argument list, with a space if necessary
10177 (nested templates). */
10178 if (!buf
.empty () && buf
.string ().back () == '>')
10185 /* For C++ methods, append formal parameter type
10186 information, if PHYSNAME. */
10188 if (physname
&& die
->tag
== DW_TAG_subprogram
10189 && cu
->language
== language_cplus
)
10191 struct type
*type
= read_type_die (die
, cu
);
10193 c_type_print_args (type
, &buf
, 1, cu
->language
,
10194 &type_print_raw_options
);
10196 if (cu
->language
== language_cplus
)
10198 /* Assume that an artificial first parameter is
10199 "this", but do not crash if it is not. RealView
10200 marks unnamed (and thus unused) parameters as
10201 artificial; there is no way to differentiate
10203 if (type
->num_fields () > 0
10204 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10205 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10206 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10207 buf
.puts (" const");
10211 const std::string
&intermediate_name
= buf
.string ();
10213 if (cu
->language
== language_cplus
)
10215 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10218 /* If we only computed INTERMEDIATE_NAME, or if
10219 INTERMEDIATE_NAME is already canonical, then we need to
10221 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10222 name
= objfile
->intern (intermediate_name
);
10224 name
= canonical_name
;
10231 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10232 If scope qualifiers are appropriate they will be added. The result
10233 will be allocated on the storage_obstack, or NULL if the DIE does
10234 not have a name. NAME may either be from a previous call to
10235 dwarf2_name or NULL.
10237 The output string will be canonicalized (if C++). */
10239 static const char *
10240 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10242 return dwarf2_compute_name (name
, die
, cu
, 0);
10245 /* Construct a physname for the given DIE in CU. NAME may either be
10246 from a previous call to dwarf2_name or NULL. The result will be
10247 allocated on the objfile_objstack or NULL if the DIE does not have a
10250 The output string will be canonicalized (if C++). */
10252 static const char *
10253 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10255 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10256 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10259 /* In this case dwarf2_compute_name is just a shortcut not building anything
10261 if (!die_needs_namespace (die
, cu
))
10262 return dwarf2_compute_name (name
, die
, cu
, 1);
10264 if (cu
->language
!= language_rust
)
10265 mangled
= dw2_linkage_name (die
, cu
);
10267 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10269 gdb::unique_xmalloc_ptr
<char> demangled
;
10270 if (mangled
!= NULL
)
10273 if (language_def (cu
->language
)->store_sym_names_in_linkage_form_p ())
10275 /* Do nothing (do not demangle the symbol name). */
10279 /* Use DMGL_RET_DROP for C++ template functions to suppress
10280 their return type. It is easier for GDB users to search
10281 for such functions as `name(params)' than `long name(params)'.
10282 In such case the minimal symbol names do not match the full
10283 symbol names but for template functions there is never a need
10284 to look up their definition from their declaration so
10285 the only disadvantage remains the minimal symbol variant
10286 `long name(params)' does not have the proper inferior type. */
10287 demangled
.reset (gdb_demangle (mangled
,
10288 (DMGL_PARAMS
| DMGL_ANSI
10289 | DMGL_RET_DROP
)));
10292 canon
= demangled
.get ();
10300 if (canon
== NULL
|| check_physname
)
10302 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10304 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10306 /* It may not mean a bug in GDB. The compiler could also
10307 compute DW_AT_linkage_name incorrectly. But in such case
10308 GDB would need to be bug-to-bug compatible. */
10310 complaint (_("Computed physname <%s> does not match demangled <%s> "
10311 "(from linkage <%s>) - DIE at %s [in module %s]"),
10312 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10313 objfile_name (objfile
));
10315 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10316 is available here - over computed PHYSNAME. It is safer
10317 against both buggy GDB and buggy compilers. */
10331 retval
= objfile
->intern (retval
);
10336 /* Inspect DIE in CU for a namespace alias. If one exists, record
10337 a new symbol for it.
10339 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10342 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10344 struct attribute
*attr
;
10346 /* If the die does not have a name, this is not a namespace
10348 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10352 struct die_info
*d
= die
;
10353 struct dwarf2_cu
*imported_cu
= cu
;
10355 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10356 keep inspecting DIEs until we hit the underlying import. */
10357 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10358 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10360 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10364 d
= follow_die_ref (d
, attr
, &imported_cu
);
10365 if (d
->tag
!= DW_TAG_imported_declaration
)
10369 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10371 complaint (_("DIE at %s has too many recursively imported "
10372 "declarations"), sect_offset_str (d
->sect_off
));
10379 sect_offset sect_off
= attr
->get_ref_die_offset ();
10381 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10382 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10384 /* This declaration is a global namespace alias. Add
10385 a symbol for it whose type is the aliased namespace. */
10386 new_symbol (die
, type
, cu
);
10395 /* Return the using directives repository (global or local?) to use in the
10396 current context for CU.
10398 For Ada, imported declarations can materialize renamings, which *may* be
10399 global. However it is impossible (for now?) in DWARF to distinguish
10400 "external" imported declarations and "static" ones. As all imported
10401 declarations seem to be static in all other languages, make them all CU-wide
10402 global only in Ada. */
10404 static struct using_direct
**
10405 using_directives (struct dwarf2_cu
*cu
)
10407 if (cu
->language
== language_ada
10408 && cu
->get_builder ()->outermost_context_p ())
10409 return cu
->get_builder ()->get_global_using_directives ();
10411 return cu
->get_builder ()->get_local_using_directives ();
10414 /* Read the import statement specified by the given die and record it. */
10417 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10419 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10420 struct attribute
*import_attr
;
10421 struct die_info
*imported_die
, *child_die
;
10422 struct dwarf2_cu
*imported_cu
;
10423 const char *imported_name
;
10424 const char *imported_name_prefix
;
10425 const char *canonical_name
;
10426 const char *import_alias
;
10427 const char *imported_declaration
= NULL
;
10428 const char *import_prefix
;
10429 std::vector
<const char *> excludes
;
10431 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10432 if (import_attr
== NULL
)
10434 complaint (_("Tag '%s' has no DW_AT_import"),
10435 dwarf_tag_name (die
->tag
));
10440 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10441 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10442 if (imported_name
== NULL
)
10444 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10446 The import in the following code:
10460 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10461 <52> DW_AT_decl_file : 1
10462 <53> DW_AT_decl_line : 6
10463 <54> DW_AT_import : <0x75>
10464 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10465 <59> DW_AT_name : B
10466 <5b> DW_AT_decl_file : 1
10467 <5c> DW_AT_decl_line : 2
10468 <5d> DW_AT_type : <0x6e>
10470 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10471 <76> DW_AT_byte_size : 4
10472 <77> DW_AT_encoding : 5 (signed)
10474 imports the wrong die ( 0x75 instead of 0x58 ).
10475 This case will be ignored until the gcc bug is fixed. */
10479 /* Figure out the local name after import. */
10480 import_alias
= dwarf2_name (die
, cu
);
10482 /* Figure out where the statement is being imported to. */
10483 import_prefix
= determine_prefix (die
, cu
);
10485 /* Figure out what the scope of the imported die is and prepend it
10486 to the name of the imported die. */
10487 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10489 if (imported_die
->tag
!= DW_TAG_namespace
10490 && imported_die
->tag
!= DW_TAG_module
)
10492 imported_declaration
= imported_name
;
10493 canonical_name
= imported_name_prefix
;
10495 else if (strlen (imported_name_prefix
) > 0)
10496 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10497 imported_name_prefix
,
10498 (cu
->language
== language_d
? "." : "::"),
10499 imported_name
, (char *) NULL
);
10501 canonical_name
= imported_name
;
10503 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10504 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10505 child_die
= child_die
->sibling
)
10507 /* DWARF-4: A Fortran use statement with a “rename list” may be
10508 represented by an imported module entry with an import attribute
10509 referring to the module and owned entries corresponding to those
10510 entities that are renamed as part of being imported. */
10512 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10514 complaint (_("child DW_TAG_imported_declaration expected "
10515 "- DIE at %s [in module %s]"),
10516 sect_offset_str (child_die
->sect_off
),
10517 objfile_name (objfile
));
10521 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10522 if (import_attr
== NULL
)
10524 complaint (_("Tag '%s' has no DW_AT_import"),
10525 dwarf_tag_name (child_die
->tag
));
10530 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10532 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10533 if (imported_name
== NULL
)
10535 complaint (_("child DW_TAG_imported_declaration has unknown "
10536 "imported name - DIE at %s [in module %s]"),
10537 sect_offset_str (child_die
->sect_off
),
10538 objfile_name (objfile
));
10542 excludes
.push_back (imported_name
);
10544 process_die (child_die
, cu
);
10547 add_using_directive (using_directives (cu
),
10551 imported_declaration
,
10554 &objfile
->objfile_obstack
);
10557 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10558 types, but gives them a size of zero. Starting with version 14,
10559 ICC is compatible with GCC. */
10562 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10564 if (!cu
->checked_producer
)
10565 check_producer (cu
);
10567 return cu
->producer_is_icc_lt_14
;
10570 /* ICC generates a DW_AT_type for C void functions. This was observed on
10571 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10572 which says that void functions should not have a DW_AT_type. */
10575 producer_is_icc (struct dwarf2_cu
*cu
)
10577 if (!cu
->checked_producer
)
10578 check_producer (cu
);
10580 return cu
->producer_is_icc
;
10583 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10584 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10585 this, it was first present in GCC release 4.3.0. */
10588 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10590 if (!cu
->checked_producer
)
10591 check_producer (cu
);
10593 return cu
->producer_is_gcc_lt_4_3
;
10596 static file_and_directory
10597 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10599 file_and_directory res
;
10601 /* Find the filename. Do not use dwarf2_name here, since the filename
10602 is not a source language identifier. */
10603 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10604 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10606 if (res
.comp_dir
== NULL
10607 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10608 && IS_ABSOLUTE_PATH (res
.name
))
10610 res
.comp_dir_storage
= ldirname (res
.name
);
10611 if (!res
.comp_dir_storage
.empty ())
10612 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10614 if (res
.comp_dir
!= NULL
)
10616 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10617 directory, get rid of it. */
10618 const char *cp
= strchr (res
.comp_dir
, ':');
10620 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10621 res
.comp_dir
= cp
+ 1;
10624 if (res
.name
== NULL
)
10625 res
.name
= "<unknown>";
10630 /* Handle DW_AT_stmt_list for a compilation unit.
10631 DIE is the DW_TAG_compile_unit die for CU.
10632 COMP_DIR is the compilation directory. LOWPC is passed to
10633 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10636 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10637 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10639 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10640 struct attribute
*attr
;
10641 struct line_header line_header_local
;
10642 hashval_t line_header_local_hash
;
10644 int decode_mapping
;
10646 gdb_assert (! cu
->per_cu
->is_debug_types
);
10648 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10649 if (attr
== NULL
|| !attr
->form_is_unsigned ())
10652 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10654 /* The line header hash table is only created if needed (it exists to
10655 prevent redundant reading of the line table for partial_units).
10656 If we're given a partial_unit, we'll need it. If we're given a
10657 compile_unit, then use the line header hash table if it's already
10658 created, but don't create one just yet. */
10660 if (per_objfile
->line_header_hash
== NULL
10661 && die
->tag
== DW_TAG_partial_unit
)
10663 per_objfile
->line_header_hash
10664 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10665 line_header_eq_voidp
,
10666 free_line_header_voidp
,
10670 line_header_local
.sect_off
= line_offset
;
10671 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10672 line_header_local_hash
= line_header_hash (&line_header_local
);
10673 if (per_objfile
->line_header_hash
!= NULL
)
10675 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10676 &line_header_local
,
10677 line_header_local_hash
, NO_INSERT
);
10679 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10680 is not present in *SLOT (since if there is something in *SLOT then
10681 it will be for a partial_unit). */
10682 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10684 gdb_assert (*slot
!= NULL
);
10685 cu
->line_header
= (struct line_header
*) *slot
;
10690 /* dwarf_decode_line_header does not yet provide sufficient information.
10691 We always have to call also dwarf_decode_lines for it. */
10692 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10696 cu
->line_header
= lh
.release ();
10697 cu
->line_header_die_owner
= die
;
10699 if (per_objfile
->line_header_hash
== NULL
)
10703 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10704 &line_header_local
,
10705 line_header_local_hash
, INSERT
);
10706 gdb_assert (slot
!= NULL
);
10708 if (slot
!= NULL
&& *slot
== NULL
)
10710 /* This newly decoded line number information unit will be owned
10711 by line_header_hash hash table. */
10712 *slot
= cu
->line_header
;
10713 cu
->line_header_die_owner
= NULL
;
10717 /* We cannot free any current entry in (*slot) as that struct line_header
10718 may be already used by multiple CUs. Create only temporary decoded
10719 line_header for this CU - it may happen at most once for each line
10720 number information unit. And if we're not using line_header_hash
10721 then this is what we want as well. */
10722 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10724 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10725 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10730 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10733 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10735 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10736 struct objfile
*objfile
= per_objfile
->objfile
;
10737 struct gdbarch
*gdbarch
= objfile
->arch ();
10738 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10739 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10740 struct attribute
*attr
;
10741 struct die_info
*child_die
;
10742 CORE_ADDR baseaddr
;
10744 prepare_one_comp_unit (cu
, die
, cu
->language
);
10745 baseaddr
= objfile
->text_section_offset ();
10747 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10749 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10750 from finish_block. */
10751 if (lowpc
== ((CORE_ADDR
) -1))
10753 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10755 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10757 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10758 standardised yet. As a workaround for the language detection we fall
10759 back to the DW_AT_producer string. */
10760 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10761 cu
->language
= language_opencl
;
10763 /* Similar hack for Go. */
10764 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10765 set_cu_language (DW_LANG_Go
, cu
);
10767 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10769 /* Decode line number information if present. We do this before
10770 processing child DIEs, so that the line header table is available
10771 for DW_AT_decl_file. */
10772 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10774 /* Process all dies in compilation unit. */
10775 if (die
->child
!= NULL
)
10777 child_die
= die
->child
;
10778 while (child_die
&& child_die
->tag
)
10780 process_die (child_die
, cu
);
10781 child_die
= child_die
->sibling
;
10785 /* Decode macro information, if present. Dwarf 2 macro information
10786 refers to information in the line number info statement program
10787 header, so we can only read it if we've read the header
10789 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10791 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10792 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10794 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10795 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10797 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
10801 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10802 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10804 unsigned int macro_offset
= attr
->as_unsigned ();
10806 dwarf_decode_macros (cu
, macro_offset
, 0);
10812 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10814 struct type_unit_group
*tu_group
;
10816 struct attribute
*attr
;
10818 struct signatured_type
*sig_type
;
10820 gdb_assert (per_cu
->is_debug_types
);
10821 sig_type
= (struct signatured_type
*) per_cu
;
10823 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10825 /* If we're using .gdb_index (includes -readnow) then
10826 per_cu->type_unit_group may not have been set up yet. */
10827 if (sig_type
->type_unit_group
== NULL
)
10828 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10829 tu_group
= sig_type
->type_unit_group
;
10831 /* If we've already processed this stmt_list there's no real need to
10832 do it again, we could fake it and just recreate the part we need
10833 (file name,index -> symtab mapping). If data shows this optimization
10834 is useful we can do it then. */
10835 type_unit_group_unshareable
*tug_unshare
10836 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
10837 first_time
= tug_unshare
->compunit_symtab
== NULL
;
10839 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10842 if (attr
!= NULL
&& attr
->form_is_unsigned ())
10844 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10845 lh
= dwarf_decode_line_header (line_offset
, this);
10850 start_symtab ("", NULL
, 0);
10853 gdb_assert (tug_unshare
->symtabs
== NULL
);
10854 gdb_assert (m_builder
== nullptr);
10855 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10856 m_builder
.reset (new struct buildsym_compunit
10857 (COMPUNIT_OBJFILE (cust
), "",
10858 COMPUNIT_DIRNAME (cust
),
10859 compunit_language (cust
),
10861 list_in_scope
= get_builder ()->get_file_symbols ();
10866 line_header
= lh
.release ();
10867 line_header_die_owner
= die
;
10871 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10873 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10874 still initializing it, and our caller (a few levels up)
10875 process_full_type_unit still needs to know if this is the first
10878 tug_unshare
->symtabs
10879 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10880 struct symtab
*, line_header
->file_names_size ());
10882 auto &file_names
= line_header
->file_names ();
10883 for (i
= 0; i
< file_names
.size (); ++i
)
10885 file_entry
&fe
= file_names
[i
];
10886 dwarf2_start_subfile (this, fe
.name
,
10887 fe
.include_dir (line_header
));
10888 buildsym_compunit
*b
= get_builder ();
10889 if (b
->get_current_subfile ()->symtab
== NULL
)
10891 /* NOTE: start_subfile will recognize when it's been
10892 passed a file it has already seen. So we can't
10893 assume there's a simple mapping from
10894 cu->line_header->file_names to subfiles, plus
10895 cu->line_header->file_names may contain dups. */
10896 b
->get_current_subfile ()->symtab
10897 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10900 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10901 tug_unshare
->symtabs
[i
] = fe
.symtab
;
10906 gdb_assert (m_builder
== nullptr);
10907 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10908 m_builder
.reset (new struct buildsym_compunit
10909 (COMPUNIT_OBJFILE (cust
), "",
10910 COMPUNIT_DIRNAME (cust
),
10911 compunit_language (cust
),
10913 list_in_scope
= get_builder ()->get_file_symbols ();
10915 auto &file_names
= line_header
->file_names ();
10916 for (i
= 0; i
< file_names
.size (); ++i
)
10918 file_entry
&fe
= file_names
[i
];
10919 fe
.symtab
= tug_unshare
->symtabs
[i
];
10923 /* The main symtab is allocated last. Type units don't have DW_AT_name
10924 so they don't have a "real" (so to speak) symtab anyway.
10925 There is later code that will assign the main symtab to all symbols
10926 that don't have one. We need to handle the case of a symbol with a
10927 missing symtab (DW_AT_decl_file) anyway. */
10930 /* Process DW_TAG_type_unit.
10931 For TUs we want to skip the first top level sibling if it's not the
10932 actual type being defined by this TU. In this case the first top
10933 level sibling is there to provide context only. */
10936 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10938 struct die_info
*child_die
;
10940 prepare_one_comp_unit (cu
, die
, language_minimal
);
10942 /* Initialize (or reinitialize) the machinery for building symtabs.
10943 We do this before processing child DIEs, so that the line header table
10944 is available for DW_AT_decl_file. */
10945 cu
->setup_type_unit_groups (die
);
10947 if (die
->child
!= NULL
)
10949 child_die
= die
->child
;
10950 while (child_die
&& child_die
->tag
)
10952 process_die (child_die
, cu
);
10953 child_die
= child_die
->sibling
;
10960 http://gcc.gnu.org/wiki/DebugFission
10961 http://gcc.gnu.org/wiki/DebugFissionDWP
10963 To simplify handling of both DWO files ("object" files with the DWARF info)
10964 and DWP files (a file with the DWOs packaged up into one file), we treat
10965 DWP files as having a collection of virtual DWO files. */
10968 hash_dwo_file (const void *item
)
10970 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10973 hash
= htab_hash_string (dwo_file
->dwo_name
);
10974 if (dwo_file
->comp_dir
!= NULL
)
10975 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10980 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10982 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10983 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10985 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10987 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10988 return lhs
->comp_dir
== rhs
->comp_dir
;
10989 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10992 /* Allocate a hash table for DWO files. */
10995 allocate_dwo_file_hash_table ()
10997 auto delete_dwo_file
= [] (void *item
)
10999 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11004 return htab_up (htab_create_alloc (41,
11011 /* Lookup DWO file DWO_NAME. */
11014 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11015 const char *dwo_name
,
11016 const char *comp_dir
)
11018 struct dwo_file find_entry
;
11021 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11022 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11024 find_entry
.dwo_name
= dwo_name
;
11025 find_entry
.comp_dir
= comp_dir
;
11026 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11033 hash_dwo_unit (const void *item
)
11035 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11037 /* This drops the top 32 bits of the id, but is ok for a hash. */
11038 return dwo_unit
->signature
;
11042 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11044 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11045 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11047 /* The signature is assumed to be unique within the DWO file.
11048 So while object file CU dwo_id's always have the value zero,
11049 that's OK, assuming each object file DWO file has only one CU,
11050 and that's the rule for now. */
11051 return lhs
->signature
== rhs
->signature
;
11054 /* Allocate a hash table for DWO CUs,TUs.
11055 There is one of these tables for each of CUs,TUs for each DWO file. */
11058 allocate_dwo_unit_table ()
11060 /* Start out with a pretty small number.
11061 Generally DWO files contain only one CU and maybe some TUs. */
11062 return htab_up (htab_create_alloc (3,
11065 NULL
, xcalloc
, xfree
));
11068 /* die_reader_func for create_dwo_cu. */
11071 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11072 const gdb_byte
*info_ptr
,
11073 struct die_info
*comp_unit_die
,
11074 struct dwo_file
*dwo_file
,
11075 struct dwo_unit
*dwo_unit
)
11077 struct dwarf2_cu
*cu
= reader
->cu
;
11078 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11079 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11081 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11082 if (!signature
.has_value ())
11084 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11085 " its dwo_id [in module %s]"),
11086 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11090 dwo_unit
->dwo_file
= dwo_file
;
11091 dwo_unit
->signature
= *signature
;
11092 dwo_unit
->section
= section
;
11093 dwo_unit
->sect_off
= sect_off
;
11094 dwo_unit
->length
= cu
->per_cu
->length
;
11096 dwarf_read_debug_printf (" offset %s, dwo_id %s",
11097 sect_offset_str (sect_off
),
11098 hex_string (dwo_unit
->signature
));
11101 /* Create the dwo_units for the CUs in a DWO_FILE.
11102 Note: This function processes DWO files only, not DWP files. */
11105 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11106 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11107 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11109 struct objfile
*objfile
= per_objfile
->objfile
;
11110 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11111 const gdb_byte
*info_ptr
, *end_ptr
;
11113 section
.read (objfile
);
11114 info_ptr
= section
.buffer
;
11116 if (info_ptr
== NULL
)
11119 dwarf_read_debug_printf ("Reading %s for %s:",
11120 section
.get_name (),
11121 section
.get_file_name ());
11123 end_ptr
= info_ptr
+ section
.size
;
11124 while (info_ptr
< end_ptr
)
11126 struct dwarf2_per_cu_data per_cu
;
11127 struct dwo_unit read_unit
{};
11128 struct dwo_unit
*dwo_unit
;
11130 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11132 per_cu
.per_bfd
= per_bfd
;
11133 per_cu
.is_debug_types
= 0;
11134 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11135 per_cu
.section
= §ion
;
11137 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11138 if (!reader
.dummy_p
)
11139 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11140 &dwo_file
, &read_unit
);
11141 info_ptr
+= per_cu
.length
;
11143 // If the unit could not be parsed, skip it.
11144 if (read_unit
.dwo_file
== NULL
)
11147 if (cus_htab
== NULL
)
11148 cus_htab
= allocate_dwo_unit_table ();
11150 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11152 *dwo_unit
= read_unit
;
11153 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11154 gdb_assert (slot
!= NULL
);
11157 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11158 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11160 complaint (_("debug cu entry at offset %s is duplicate to"
11161 " the entry at offset %s, signature %s"),
11162 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11163 hex_string (dwo_unit
->signature
));
11165 *slot
= (void *)dwo_unit
;
11169 /* DWP file .debug_{cu,tu}_index section format:
11170 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11171 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11173 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11174 officially standard DWP format was published with DWARF v5 and is called
11175 Version 5. There are no versions 3 or 4.
11179 Both index sections have the same format, and serve to map a 64-bit
11180 signature to a set of section numbers. Each section begins with a header,
11181 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11182 indexes, and a pool of 32-bit section numbers. The index sections will be
11183 aligned at 8-byte boundaries in the file.
11185 The index section header consists of:
11187 V, 32 bit version number
11189 N, 32 bit number of compilation units or type units in the index
11190 M, 32 bit number of slots in the hash table
11192 Numbers are recorded using the byte order of the application binary.
11194 The hash table begins at offset 16 in the section, and consists of an array
11195 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11196 order of the application binary). Unused slots in the hash table are 0.
11197 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11199 The parallel table begins immediately after the hash table
11200 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11201 array of 32-bit indexes (using the byte order of the application binary),
11202 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11203 table contains a 32-bit index into the pool of section numbers. For unused
11204 hash table slots, the corresponding entry in the parallel table will be 0.
11206 The pool of section numbers begins immediately following the hash table
11207 (at offset 16 + 12 * M from the beginning of the section). The pool of
11208 section numbers consists of an array of 32-bit words (using the byte order
11209 of the application binary). Each item in the array is indexed starting
11210 from 0. The hash table entry provides the index of the first section
11211 number in the set. Additional section numbers in the set follow, and the
11212 set is terminated by a 0 entry (section number 0 is not used in ELF).
11214 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11215 section must be the first entry in the set, and the .debug_abbrev.dwo must
11216 be the second entry. Other members of the set may follow in any order.
11220 DWP Versions 2 and 5:
11222 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11223 and the entries in the index tables are now offsets into these sections.
11224 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11227 Index Section Contents:
11229 Hash Table of Signatures dwp_hash_table.hash_table
11230 Parallel Table of Indices dwp_hash_table.unit_table
11231 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11232 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11234 The index section header consists of:
11236 V, 32 bit version number
11237 L, 32 bit number of columns in the table of section offsets
11238 N, 32 bit number of compilation units or type units in the index
11239 M, 32 bit number of slots in the hash table
11241 Numbers are recorded using the byte order of the application binary.
11243 The hash table has the same format as version 1.
11244 The parallel table of indices has the same format as version 1,
11245 except that the entries are origin-1 indices into the table of sections
11246 offsets and the table of section sizes.
11248 The table of offsets begins immediately following the parallel table
11249 (at offset 16 + 12 * M from the beginning of the section). The table is
11250 a two-dimensional array of 32-bit words (using the byte order of the
11251 application binary), with L columns and N+1 rows, in row-major order.
11252 Each row in the array is indexed starting from 0. The first row provides
11253 a key to the remaining rows: each column in this row provides an identifier
11254 for a debug section, and the offsets in the same column of subsequent rows
11255 refer to that section. The section identifiers for Version 2 are:
11257 DW_SECT_INFO 1 .debug_info.dwo
11258 DW_SECT_TYPES 2 .debug_types.dwo
11259 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11260 DW_SECT_LINE 4 .debug_line.dwo
11261 DW_SECT_LOC 5 .debug_loc.dwo
11262 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11263 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11264 DW_SECT_MACRO 8 .debug_macro.dwo
11266 The section identifiers for Version 5 are:
11268 DW_SECT_INFO_V5 1 .debug_info.dwo
11269 DW_SECT_RESERVED_V5 2 --
11270 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11271 DW_SECT_LINE_V5 4 .debug_line.dwo
11272 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11273 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11274 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11275 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11277 The offsets provided by the CU and TU index sections are the base offsets
11278 for the contributions made by each CU or TU to the corresponding section
11279 in the package file. Each CU and TU header contains an abbrev_offset
11280 field, used to find the abbreviations table for that CU or TU within the
11281 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11282 be interpreted as relative to the base offset given in the index section.
11283 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11284 should be interpreted as relative to the base offset for .debug_line.dwo,
11285 and offsets into other debug sections obtained from DWARF attributes should
11286 also be interpreted as relative to the corresponding base offset.
11288 The table of sizes begins immediately following the table of offsets.
11289 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11290 with L columns and N rows, in row-major order. Each row in the array is
11291 indexed starting from 1 (row 0 is shared by the two tables).
11295 Hash table lookup is handled the same in version 1 and 2:
11297 We assume that N and M will not exceed 2^32 - 1.
11298 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11300 Given a 64-bit compilation unit signature or a type signature S, an entry
11301 in the hash table is located as follows:
11303 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11304 the low-order k bits all set to 1.
11306 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11308 3) If the hash table entry at index H matches the signature, use that
11309 entry. If the hash table entry at index H is unused (all zeroes),
11310 terminate the search: the signature is not present in the table.
11312 4) Let H = (H + H') modulo M. Repeat at Step 3.
11314 Because M > N and H' and M are relatively prime, the search is guaranteed
11315 to stop at an unused slot or find the match. */
11317 /* Create a hash table to map DWO IDs to their CU/TU entry in
11318 .debug_{info,types}.dwo in DWP_FILE.
11319 Returns NULL if there isn't one.
11320 Note: This function processes DWP files only, not DWO files. */
11322 static struct dwp_hash_table
*
11323 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11324 struct dwp_file
*dwp_file
, int is_debug_types
)
11326 struct objfile
*objfile
= per_objfile
->objfile
;
11327 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11328 const gdb_byte
*index_ptr
, *index_end
;
11329 struct dwarf2_section_info
*index
;
11330 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11331 struct dwp_hash_table
*htab
;
11333 if (is_debug_types
)
11334 index
= &dwp_file
->sections
.tu_index
;
11336 index
= &dwp_file
->sections
.cu_index
;
11338 if (index
->empty ())
11340 index
->read (objfile
);
11342 index_ptr
= index
->buffer
;
11343 index_end
= index_ptr
+ index
->size
;
11345 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11346 For now it's safe to just read 4 bytes (particularly as it's difficult to
11347 tell if you're dealing with Version 5 before you've read the version). */
11348 version
= read_4_bytes (dbfd
, index_ptr
);
11350 if (version
== 2 || version
== 5)
11351 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11355 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11357 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11360 if (version
!= 1 && version
!= 2 && version
!= 5)
11362 error (_("Dwarf Error: unsupported DWP file version (%s)"
11363 " [in module %s]"),
11364 pulongest (version
), dwp_file
->name
);
11366 if (nr_slots
!= (nr_slots
& -nr_slots
))
11368 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11369 " is not power of 2 [in module %s]"),
11370 pulongest (nr_slots
), dwp_file
->name
);
11373 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11374 htab
->version
= version
;
11375 htab
->nr_columns
= nr_columns
;
11376 htab
->nr_units
= nr_units
;
11377 htab
->nr_slots
= nr_slots
;
11378 htab
->hash_table
= index_ptr
;
11379 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11381 /* Exit early if the table is empty. */
11382 if (nr_slots
== 0 || nr_units
== 0
11383 || (version
== 2 && nr_columns
== 0)
11384 || (version
== 5 && nr_columns
== 0))
11386 /* All must be zero. */
11387 if (nr_slots
!= 0 || nr_units
!= 0
11388 || (version
== 2 && nr_columns
!= 0)
11389 || (version
== 5 && nr_columns
!= 0))
11391 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11392 " all zero [in modules %s]"),
11400 htab
->section_pool
.v1
.indices
=
11401 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11402 /* It's harder to decide whether the section is too small in v1.
11403 V1 is deprecated anyway so we punt. */
11405 else if (version
== 2)
11407 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11408 int *ids
= htab
->section_pool
.v2
.section_ids
;
11409 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11410 /* Reverse map for error checking. */
11411 int ids_seen
[DW_SECT_MAX
+ 1];
11414 if (nr_columns
< 2)
11416 error (_("Dwarf Error: bad DWP hash table, too few columns"
11417 " in section table [in module %s]"),
11420 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11422 error (_("Dwarf Error: bad DWP hash table, too many columns"
11423 " in section table [in module %s]"),
11426 memset (ids
, 255, sizeof_ids
);
11427 memset (ids_seen
, 255, sizeof (ids_seen
));
11428 for (i
= 0; i
< nr_columns
; ++i
)
11430 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11432 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11434 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11435 " in section table [in module %s]"),
11436 id
, dwp_file
->name
);
11438 if (ids_seen
[id
] != -1)
11440 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11441 " id %d in section table [in module %s]"),
11442 id
, dwp_file
->name
);
11447 /* Must have exactly one info or types section. */
11448 if (((ids_seen
[DW_SECT_INFO
] != -1)
11449 + (ids_seen
[DW_SECT_TYPES
] != -1))
11452 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11453 " DWO info/types section [in module %s]"),
11456 /* Must have an abbrev section. */
11457 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11459 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11460 " section [in module %s]"),
11463 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11464 htab
->section_pool
.v2
.sizes
=
11465 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11466 * nr_units
* nr_columns
);
11467 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11468 * nr_units
* nr_columns
))
11471 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11472 " [in module %s]"),
11476 else /* version == 5 */
11478 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11479 int *ids
= htab
->section_pool
.v5
.section_ids
;
11480 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11481 /* Reverse map for error checking. */
11482 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11484 if (nr_columns
< 2)
11486 error (_("Dwarf Error: bad DWP hash table, too few columns"
11487 " in section table [in module %s]"),
11490 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11492 error (_("Dwarf Error: bad DWP hash table, too many columns"
11493 " in section table [in module %s]"),
11496 memset (ids
, 255, sizeof_ids
);
11497 memset (ids_seen
, 255, sizeof (ids_seen
));
11498 for (int i
= 0; i
< nr_columns
; ++i
)
11500 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11502 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11504 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11505 " in section table [in module %s]"),
11506 id
, dwp_file
->name
);
11508 if (ids_seen
[id
] != -1)
11510 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11511 " id %d in section table [in module %s]"),
11512 id
, dwp_file
->name
);
11517 /* Must have seen an info section. */
11518 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11520 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11521 " DWO info/types section [in module %s]"),
11524 /* Must have an abbrev section. */
11525 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11527 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11528 " section [in module %s]"),
11531 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11532 htab
->section_pool
.v5
.sizes
11533 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11534 * nr_units
* nr_columns
);
11535 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11536 * nr_units
* nr_columns
))
11539 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11540 " [in module %s]"),
11548 /* Update SECTIONS with the data from SECTP.
11550 This function is like the other "locate" section routines, but in
11551 this context the sections to read comes from the DWP V1 hash table,
11552 not the full ELF section table.
11554 The result is non-zero for success, or zero if an error was found. */
11557 locate_v1_virtual_dwo_sections (asection
*sectp
,
11558 struct virtual_v1_dwo_sections
*sections
)
11560 const struct dwop_section_names
*names
= &dwop_section_names
;
11562 if (names
->abbrev_dwo
.matches (sectp
->name
))
11564 /* There can be only one. */
11565 if (sections
->abbrev
.s
.section
!= NULL
)
11567 sections
->abbrev
.s
.section
= sectp
;
11568 sections
->abbrev
.size
= bfd_section_size (sectp
);
11570 else if (names
->info_dwo
.matches (sectp
->name
)
11571 || names
->types_dwo
.matches (sectp
->name
))
11573 /* There can be only one. */
11574 if (sections
->info_or_types
.s
.section
!= NULL
)
11576 sections
->info_or_types
.s
.section
= sectp
;
11577 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11579 else if (names
->line_dwo
.matches (sectp
->name
))
11581 /* There can be only one. */
11582 if (sections
->line
.s
.section
!= NULL
)
11584 sections
->line
.s
.section
= sectp
;
11585 sections
->line
.size
= bfd_section_size (sectp
);
11587 else if (names
->loc_dwo
.matches (sectp
->name
))
11589 /* There can be only one. */
11590 if (sections
->loc
.s
.section
!= NULL
)
11592 sections
->loc
.s
.section
= sectp
;
11593 sections
->loc
.size
= bfd_section_size (sectp
);
11595 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11597 /* There can be only one. */
11598 if (sections
->macinfo
.s
.section
!= NULL
)
11600 sections
->macinfo
.s
.section
= sectp
;
11601 sections
->macinfo
.size
= bfd_section_size (sectp
);
11603 else if (names
->macro_dwo
.matches (sectp
->name
))
11605 /* There can be only one. */
11606 if (sections
->macro
.s
.section
!= NULL
)
11608 sections
->macro
.s
.section
= sectp
;
11609 sections
->macro
.size
= bfd_section_size (sectp
);
11611 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11613 /* There can be only one. */
11614 if (sections
->str_offsets
.s
.section
!= NULL
)
11616 sections
->str_offsets
.s
.section
= sectp
;
11617 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11621 /* No other kind of section is valid. */
11628 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11629 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11630 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11631 This is for DWP version 1 files. */
11633 static struct dwo_unit
*
11634 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11635 struct dwp_file
*dwp_file
,
11636 uint32_t unit_index
,
11637 const char *comp_dir
,
11638 ULONGEST signature
, int is_debug_types
)
11640 const struct dwp_hash_table
*dwp_htab
=
11641 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11642 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11643 const char *kind
= is_debug_types
? "TU" : "CU";
11644 struct dwo_file
*dwo_file
;
11645 struct dwo_unit
*dwo_unit
;
11646 struct virtual_v1_dwo_sections sections
;
11647 void **dwo_file_slot
;
11650 gdb_assert (dwp_file
->version
== 1);
11652 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
11653 kind
, pulongest (unit_index
), hex_string (signature
),
11656 /* Fetch the sections of this DWO unit.
11657 Put a limit on the number of sections we look for so that bad data
11658 doesn't cause us to loop forever. */
11660 #define MAX_NR_V1_DWO_SECTIONS \
11661 (1 /* .debug_info or .debug_types */ \
11662 + 1 /* .debug_abbrev */ \
11663 + 1 /* .debug_line */ \
11664 + 1 /* .debug_loc */ \
11665 + 1 /* .debug_str_offsets */ \
11666 + 1 /* .debug_macro or .debug_macinfo */ \
11667 + 1 /* trailing zero */)
11669 memset (§ions
, 0, sizeof (sections
));
11671 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11674 uint32_t section_nr
=
11675 read_4_bytes (dbfd
,
11676 dwp_htab
->section_pool
.v1
.indices
11677 + (unit_index
+ i
) * sizeof (uint32_t));
11679 if (section_nr
== 0)
11681 if (section_nr
>= dwp_file
->num_sections
)
11683 error (_("Dwarf Error: bad DWP hash table, section number too large"
11684 " [in module %s]"),
11688 sectp
= dwp_file
->elf_sections
[section_nr
];
11689 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11691 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11692 " [in module %s]"),
11698 || sections
.info_or_types
.empty ()
11699 || sections
.abbrev
.empty ())
11701 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11702 " [in module %s]"),
11705 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11707 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11708 " [in module %s]"),
11712 /* It's easier for the rest of the code if we fake a struct dwo_file and
11713 have dwo_unit "live" in that. At least for now.
11715 The DWP file can be made up of a random collection of CUs and TUs.
11716 However, for each CU + set of TUs that came from the same original DWO
11717 file, we can combine them back into a virtual DWO file to save space
11718 (fewer struct dwo_file objects to allocate). Remember that for really
11719 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11721 std::string virtual_dwo_name
=
11722 string_printf ("virtual-dwo/%d-%d-%d-%d",
11723 sections
.abbrev
.get_id (),
11724 sections
.line
.get_id (),
11725 sections
.loc
.get_id (),
11726 sections
.str_offsets
.get_id ());
11727 /* Can we use an existing virtual DWO file? */
11728 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11730 /* Create one if necessary. */
11731 if (*dwo_file_slot
== NULL
)
11733 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11734 virtual_dwo_name
.c_str ());
11736 dwo_file
= new struct dwo_file
;
11737 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11738 dwo_file
->comp_dir
= comp_dir
;
11739 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11740 dwo_file
->sections
.line
= sections
.line
;
11741 dwo_file
->sections
.loc
= sections
.loc
;
11742 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11743 dwo_file
->sections
.macro
= sections
.macro
;
11744 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11745 /* The "str" section is global to the entire DWP file. */
11746 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11747 /* The info or types section is assigned below to dwo_unit,
11748 there's no need to record it in dwo_file.
11749 Also, we can't simply record type sections in dwo_file because
11750 we record a pointer into the vector in dwo_unit. As we collect more
11751 types we'll grow the vector and eventually have to reallocate space
11752 for it, invalidating all copies of pointers into the previous
11754 *dwo_file_slot
= dwo_file
;
11758 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11759 virtual_dwo_name
.c_str ());
11761 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11764 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11765 dwo_unit
->dwo_file
= dwo_file
;
11766 dwo_unit
->signature
= signature
;
11767 dwo_unit
->section
=
11768 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11769 *dwo_unit
->section
= sections
.info_or_types
;
11770 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11775 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
11776 simplify them. Given a pointer to the containing section SECTION, and
11777 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
11778 virtual section of just that piece. */
11780 static struct dwarf2_section_info
11781 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
11782 struct dwarf2_section_info
*section
,
11783 bfd_size_type offset
, bfd_size_type size
)
11785 struct dwarf2_section_info result
;
11788 gdb_assert (section
!= NULL
);
11789 gdb_assert (!section
->is_virtual
);
11791 memset (&result
, 0, sizeof (result
));
11792 result
.s
.containing_section
= section
;
11793 result
.is_virtual
= true;
11798 sectp
= section
->get_bfd_section ();
11800 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11801 bounds of the real section. This is a pretty-rare event, so just
11802 flag an error (easier) instead of a warning and trying to cope. */
11804 || offset
+ size
> bfd_section_size (sectp
))
11806 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
11807 " in section %s [in module %s]"),
11808 sectp
? bfd_section_name (sectp
) : "<unknown>",
11809 objfile_name (per_objfile
->objfile
));
11812 result
.virtual_offset
= offset
;
11813 result
.size
= size
;
11817 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11818 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11819 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11820 This is for DWP version 2 files. */
11822 static struct dwo_unit
*
11823 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
11824 struct dwp_file
*dwp_file
,
11825 uint32_t unit_index
,
11826 const char *comp_dir
,
11827 ULONGEST signature
, int is_debug_types
)
11829 const struct dwp_hash_table
*dwp_htab
=
11830 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11831 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11832 const char *kind
= is_debug_types
? "TU" : "CU";
11833 struct dwo_file
*dwo_file
;
11834 struct dwo_unit
*dwo_unit
;
11835 struct virtual_v2_or_v5_dwo_sections sections
;
11836 void **dwo_file_slot
;
11839 gdb_assert (dwp_file
->version
== 2);
11841 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
11842 kind
, pulongest (unit_index
), hex_string (signature
),
11845 /* Fetch the section offsets of this DWO unit. */
11847 memset (§ions
, 0, sizeof (sections
));
11849 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11851 uint32_t offset
= read_4_bytes (dbfd
,
11852 dwp_htab
->section_pool
.v2
.offsets
11853 + (((unit_index
- 1) * dwp_htab
->nr_columns
11855 * sizeof (uint32_t)));
11856 uint32_t size
= read_4_bytes (dbfd
,
11857 dwp_htab
->section_pool
.v2
.sizes
11858 + (((unit_index
- 1) * dwp_htab
->nr_columns
11860 * sizeof (uint32_t)));
11862 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11865 case DW_SECT_TYPES
:
11866 sections
.info_or_types_offset
= offset
;
11867 sections
.info_or_types_size
= size
;
11869 case DW_SECT_ABBREV
:
11870 sections
.abbrev_offset
= offset
;
11871 sections
.abbrev_size
= size
;
11874 sections
.line_offset
= offset
;
11875 sections
.line_size
= size
;
11878 sections
.loc_offset
= offset
;
11879 sections
.loc_size
= size
;
11881 case DW_SECT_STR_OFFSETS
:
11882 sections
.str_offsets_offset
= offset
;
11883 sections
.str_offsets_size
= size
;
11885 case DW_SECT_MACINFO
:
11886 sections
.macinfo_offset
= offset
;
11887 sections
.macinfo_size
= size
;
11889 case DW_SECT_MACRO
:
11890 sections
.macro_offset
= offset
;
11891 sections
.macro_size
= size
;
11896 /* It's easier for the rest of the code if we fake a struct dwo_file and
11897 have dwo_unit "live" in that. At least for now.
11899 The DWP file can be made up of a random collection of CUs and TUs.
11900 However, for each CU + set of TUs that came from the same original DWO
11901 file, we can combine them back into a virtual DWO file to save space
11902 (fewer struct dwo_file objects to allocate). Remember that for really
11903 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11905 std::string virtual_dwo_name
=
11906 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11907 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11908 (long) (sections
.line_size
? sections
.line_offset
: 0),
11909 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11910 (long) (sections
.str_offsets_size
11911 ? sections
.str_offsets_offset
: 0));
11912 /* Can we use an existing virtual DWO file? */
11913 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11915 /* Create one if necessary. */
11916 if (*dwo_file_slot
== NULL
)
11918 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11919 virtual_dwo_name
.c_str ());
11921 dwo_file
= new struct dwo_file
;
11922 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11923 dwo_file
->comp_dir
= comp_dir
;
11924 dwo_file
->sections
.abbrev
=
11925 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
11926 sections
.abbrev_offset
,
11927 sections
.abbrev_size
);
11928 dwo_file
->sections
.line
=
11929 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
11930 sections
.line_offset
,
11931 sections
.line_size
);
11932 dwo_file
->sections
.loc
=
11933 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
11934 sections
.loc_offset
, sections
.loc_size
);
11935 dwo_file
->sections
.macinfo
=
11936 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
11937 sections
.macinfo_offset
,
11938 sections
.macinfo_size
);
11939 dwo_file
->sections
.macro
=
11940 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
11941 sections
.macro_offset
,
11942 sections
.macro_size
);
11943 dwo_file
->sections
.str_offsets
=
11944 create_dwp_v2_or_v5_section (per_objfile
,
11945 &dwp_file
->sections
.str_offsets
,
11946 sections
.str_offsets_offset
,
11947 sections
.str_offsets_size
);
11948 /* The "str" section is global to the entire DWP file. */
11949 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11950 /* The info or types section is assigned below to dwo_unit,
11951 there's no need to record it in dwo_file.
11952 Also, we can't simply record type sections in dwo_file because
11953 we record a pointer into the vector in dwo_unit. As we collect more
11954 types we'll grow the vector and eventually have to reallocate space
11955 for it, invalidating all copies of pointers into the previous
11957 *dwo_file_slot
= dwo_file
;
11961 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11962 virtual_dwo_name
.c_str ());
11964 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11967 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11968 dwo_unit
->dwo_file
= dwo_file
;
11969 dwo_unit
->signature
= signature
;
11970 dwo_unit
->section
=
11971 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11972 *dwo_unit
->section
= create_dwp_v2_or_v5_section
11975 ? &dwp_file
->sections
.types
11976 : &dwp_file
->sections
.info
,
11977 sections
.info_or_types_offset
,
11978 sections
.info_or_types_size
);
11979 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11984 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11985 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11986 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11987 This is for DWP version 5 files. */
11989 static struct dwo_unit
*
11990 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
11991 struct dwp_file
*dwp_file
,
11992 uint32_t unit_index
,
11993 const char *comp_dir
,
11994 ULONGEST signature
, int is_debug_types
)
11996 const struct dwp_hash_table
*dwp_htab
11997 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11998 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11999 const char *kind
= is_debug_types
? "TU" : "CU";
12000 struct dwo_file
*dwo_file
;
12001 struct dwo_unit
*dwo_unit
;
12002 struct virtual_v2_or_v5_dwo_sections sections
{};
12003 void **dwo_file_slot
;
12005 gdb_assert (dwp_file
->version
== 5);
12007 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
12008 kind
, pulongest (unit_index
), hex_string (signature
),
12011 /* Fetch the section offsets of this DWO unit. */
12013 /* memset (§ions, 0, sizeof (sections)); */
12015 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12017 uint32_t offset
= read_4_bytes (dbfd
,
12018 dwp_htab
->section_pool
.v5
.offsets
12019 + (((unit_index
- 1)
12020 * dwp_htab
->nr_columns
12022 * sizeof (uint32_t)));
12023 uint32_t size
= read_4_bytes (dbfd
,
12024 dwp_htab
->section_pool
.v5
.sizes
12025 + (((unit_index
- 1) * dwp_htab
->nr_columns
12027 * sizeof (uint32_t)));
12029 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
12031 case DW_SECT_ABBREV_V5
:
12032 sections
.abbrev_offset
= offset
;
12033 sections
.abbrev_size
= size
;
12035 case DW_SECT_INFO_V5
:
12036 sections
.info_or_types_offset
= offset
;
12037 sections
.info_or_types_size
= size
;
12039 case DW_SECT_LINE_V5
:
12040 sections
.line_offset
= offset
;
12041 sections
.line_size
= size
;
12043 case DW_SECT_LOCLISTS_V5
:
12044 sections
.loclists_offset
= offset
;
12045 sections
.loclists_size
= size
;
12047 case DW_SECT_MACRO_V5
:
12048 sections
.macro_offset
= offset
;
12049 sections
.macro_size
= size
;
12051 case DW_SECT_RNGLISTS_V5
:
12052 sections
.rnglists_offset
= offset
;
12053 sections
.rnglists_size
= size
;
12055 case DW_SECT_STR_OFFSETS_V5
:
12056 sections
.str_offsets_offset
= offset
;
12057 sections
.str_offsets_size
= size
;
12059 case DW_SECT_RESERVED_V5
:
12065 /* It's easier for the rest of the code if we fake a struct dwo_file and
12066 have dwo_unit "live" in that. At least for now.
12068 The DWP file can be made up of a random collection of CUs and TUs.
12069 However, for each CU + set of TUs that came from the same original DWO
12070 file, we can combine them back into a virtual DWO file to save space
12071 (fewer struct dwo_file objects to allocate). Remember that for really
12072 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12074 std::string virtual_dwo_name
=
12075 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
12076 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12077 (long) (sections
.line_size
? sections
.line_offset
: 0),
12078 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
12079 (long) (sections
.str_offsets_size
12080 ? sections
.str_offsets_offset
: 0),
12081 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
12082 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
12083 /* Can we use an existing virtual DWO file? */
12084 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
12085 virtual_dwo_name
.c_str (),
12087 /* Create one if necessary. */
12088 if (*dwo_file_slot
== NULL
)
12090 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12091 virtual_dwo_name
.c_str ());
12093 dwo_file
= new struct dwo_file
;
12094 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12095 dwo_file
->comp_dir
= comp_dir
;
12096 dwo_file
->sections
.abbrev
=
12097 create_dwp_v2_or_v5_section (per_objfile
,
12098 &dwp_file
->sections
.abbrev
,
12099 sections
.abbrev_offset
,
12100 sections
.abbrev_size
);
12101 dwo_file
->sections
.line
=
12102 create_dwp_v2_or_v5_section (per_objfile
,
12103 &dwp_file
->sections
.line
,
12104 sections
.line_offset
, sections
.line_size
);
12105 dwo_file
->sections
.macro
=
12106 create_dwp_v2_or_v5_section (per_objfile
,
12107 &dwp_file
->sections
.macro
,
12108 sections
.macro_offset
,
12109 sections
.macro_size
);
12110 dwo_file
->sections
.loclists
=
12111 create_dwp_v2_or_v5_section (per_objfile
,
12112 &dwp_file
->sections
.loclists
,
12113 sections
.loclists_offset
,
12114 sections
.loclists_size
);
12115 dwo_file
->sections
.rnglists
=
12116 create_dwp_v2_or_v5_section (per_objfile
,
12117 &dwp_file
->sections
.rnglists
,
12118 sections
.rnglists_offset
,
12119 sections
.rnglists_size
);
12120 dwo_file
->sections
.str_offsets
=
12121 create_dwp_v2_or_v5_section (per_objfile
,
12122 &dwp_file
->sections
.str_offsets
,
12123 sections
.str_offsets_offset
,
12124 sections
.str_offsets_size
);
12125 /* The "str" section is global to the entire DWP file. */
12126 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12127 /* The info or types section is assigned below to dwo_unit,
12128 there's no need to record it in dwo_file.
12129 Also, we can't simply record type sections in dwo_file because
12130 we record a pointer into the vector in dwo_unit. As we collect more
12131 types we'll grow the vector and eventually have to reallocate space
12132 for it, invalidating all copies of pointers into the previous
12134 *dwo_file_slot
= dwo_file
;
12138 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12139 virtual_dwo_name
.c_str ());
12141 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12144 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12145 dwo_unit
->dwo_file
= dwo_file
;
12146 dwo_unit
->signature
= signature
;
12148 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12149 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12150 &dwp_file
->sections
.info
,
12151 sections
.info_or_types_offset
,
12152 sections
.info_or_types_size
);
12153 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12158 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12159 Returns NULL if the signature isn't found. */
12161 static struct dwo_unit
*
12162 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12163 struct dwp_file
*dwp_file
, const char *comp_dir
,
12164 ULONGEST signature
, int is_debug_types
)
12166 const struct dwp_hash_table
*dwp_htab
=
12167 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12168 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12169 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12170 uint32_t hash
= signature
& mask
;
12171 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12174 struct dwo_unit find_dwo_cu
;
12176 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12177 find_dwo_cu
.signature
= signature
;
12178 slot
= htab_find_slot (is_debug_types
12179 ? dwp_file
->loaded_tus
.get ()
12180 : dwp_file
->loaded_cus
.get (),
12181 &find_dwo_cu
, INSERT
);
12184 return (struct dwo_unit
*) *slot
;
12186 /* Use a for loop so that we don't loop forever on bad debug info. */
12187 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12189 ULONGEST signature_in_table
;
12191 signature_in_table
=
12192 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12193 if (signature_in_table
== signature
)
12195 uint32_t unit_index
=
12196 read_4_bytes (dbfd
,
12197 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12199 if (dwp_file
->version
== 1)
12201 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12202 unit_index
, comp_dir
,
12203 signature
, is_debug_types
);
12205 else if (dwp_file
->version
== 2)
12207 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12208 unit_index
, comp_dir
,
12209 signature
, is_debug_types
);
12211 else /* version == 5 */
12213 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12214 unit_index
, comp_dir
,
12215 signature
, is_debug_types
);
12217 return (struct dwo_unit
*) *slot
;
12219 if (signature_in_table
== 0)
12221 hash
= (hash
+ hash2
) & mask
;
12224 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12225 " [in module %s]"),
12229 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12230 Open the file specified by FILE_NAME and hand it off to BFD for
12231 preliminary analysis. Return a newly initialized bfd *, which
12232 includes a canonicalized copy of FILE_NAME.
12233 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12234 SEARCH_CWD is true if the current directory is to be searched.
12235 It will be searched before debug-file-directory.
12236 If successful, the file is added to the bfd include table of the
12237 objfile's bfd (see gdb_bfd_record_inclusion).
12238 If unable to find/open the file, return NULL.
12239 NOTE: This function is derived from symfile_bfd_open. */
12241 static gdb_bfd_ref_ptr
12242 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12243 const char *file_name
, int is_dwp
, int search_cwd
)
12246 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12247 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12248 to debug_file_directory. */
12249 const char *search_path
;
12250 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12252 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12255 if (*debug_file_directory
!= '\0')
12257 search_path_holder
.reset (concat (".", dirname_separator_string
,
12258 debug_file_directory
,
12260 search_path
= search_path_holder
.get ();
12266 search_path
= debug_file_directory
;
12268 /* Add the path for the executable binary to the list of search paths. */
12269 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
12270 search_path_holder
.reset (concat (objfile_dir
.c_str (),
12271 dirname_separator_string
,
12272 search_path
, nullptr));
12273 search_path
= search_path_holder
.get ();
12275 openp_flags flags
= OPF_RETURN_REALPATH
;
12277 flags
|= OPF_SEARCH_IN_PATH
;
12279 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12280 desc
= openp (search_path
, flags
, file_name
,
12281 O_RDONLY
| O_BINARY
, &absolute_name
);
12285 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12287 if (sym_bfd
== NULL
)
12289 bfd_set_cacheable (sym_bfd
.get (), 1);
12291 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12294 /* Success. Record the bfd as having been included by the objfile's bfd.
12295 This is important because things like demangled_names_hash lives in the
12296 objfile's per_bfd space and may have references to things like symbol
12297 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12298 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12303 /* Try to open DWO file FILE_NAME.
12304 COMP_DIR is the DW_AT_comp_dir attribute.
12305 The result is the bfd handle of the file.
12306 If there is a problem finding or opening the file, return NULL.
12307 Upon success, the canonicalized path of the file is stored in the bfd,
12308 same as symfile_bfd_open. */
12310 static gdb_bfd_ref_ptr
12311 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12312 const char *file_name
, const char *comp_dir
)
12314 if (IS_ABSOLUTE_PATH (file_name
))
12315 return try_open_dwop_file (per_objfile
, file_name
,
12316 0 /*is_dwp*/, 0 /*search_cwd*/);
12318 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12320 if (comp_dir
!= NULL
)
12322 gdb::unique_xmalloc_ptr
<char> path_to_try
12323 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12325 /* NOTE: If comp_dir is a relative path, this will also try the
12326 search path, which seems useful. */
12327 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12329 1 /*search_cwd*/));
12334 /* That didn't work, try debug-file-directory, which, despite its name,
12335 is a list of paths. */
12337 if (*debug_file_directory
== '\0')
12340 return try_open_dwop_file (per_objfile
, file_name
,
12341 0 /*is_dwp*/, 1 /*search_cwd*/);
12344 /* This function is mapped across the sections and remembers the offset and
12345 size of each of the DWO debugging sections we are interested in. */
12348 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12349 dwo_sections
*dwo_sections
)
12351 const struct dwop_section_names
*names
= &dwop_section_names
;
12353 if (names
->abbrev_dwo
.matches (sectp
->name
))
12355 dwo_sections
->abbrev
.s
.section
= sectp
;
12356 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12358 else if (names
->info_dwo
.matches (sectp
->name
))
12360 dwo_sections
->info
.s
.section
= sectp
;
12361 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12363 else if (names
->line_dwo
.matches (sectp
->name
))
12365 dwo_sections
->line
.s
.section
= sectp
;
12366 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12368 else if (names
->loc_dwo
.matches (sectp
->name
))
12370 dwo_sections
->loc
.s
.section
= sectp
;
12371 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12373 else if (names
->loclists_dwo
.matches (sectp
->name
))
12375 dwo_sections
->loclists
.s
.section
= sectp
;
12376 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12378 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12380 dwo_sections
->macinfo
.s
.section
= sectp
;
12381 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12383 else if (names
->macro_dwo
.matches (sectp
->name
))
12385 dwo_sections
->macro
.s
.section
= sectp
;
12386 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12388 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12390 dwo_sections
->rnglists
.s
.section
= sectp
;
12391 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12393 else if (names
->str_dwo
.matches (sectp
->name
))
12395 dwo_sections
->str
.s
.section
= sectp
;
12396 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12398 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12400 dwo_sections
->str_offsets
.s
.section
= sectp
;
12401 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12403 else if (names
->types_dwo
.matches (sectp
->name
))
12405 struct dwarf2_section_info type_section
;
12407 memset (&type_section
, 0, sizeof (type_section
));
12408 type_section
.s
.section
= sectp
;
12409 type_section
.size
= bfd_section_size (sectp
);
12410 dwo_sections
->types
.push_back (type_section
);
12414 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12415 by PER_CU. This is for the non-DWP case.
12416 The result is NULL if DWO_NAME can't be found. */
12418 static struct dwo_file
*
12419 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12420 const char *comp_dir
)
12422 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12424 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12427 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12432 dwo_file_up
dwo_file (new struct dwo_file
);
12433 dwo_file
->dwo_name
= dwo_name
;
12434 dwo_file
->comp_dir
= comp_dir
;
12435 dwo_file
->dbfd
= std::move (dbfd
);
12437 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12438 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12439 &dwo_file
->sections
);
12441 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12444 if (cu
->per_cu
->dwarf_version
< 5)
12446 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12447 dwo_file
->sections
.types
, dwo_file
->tus
);
12451 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12452 &dwo_file
->sections
.info
, dwo_file
->tus
,
12453 rcuh_kind::COMPILE
);
12456 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12458 return dwo_file
.release ();
12461 /* This function is mapped across the sections and remembers the offset and
12462 size of each of the DWP debugging sections common to version 1 and 2 that
12463 we are interested in. */
12466 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12467 dwp_file
*dwp_file
)
12469 const struct dwop_section_names
*names
= &dwop_section_names
;
12470 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12472 /* Record the ELF section number for later lookup: this is what the
12473 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12474 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12475 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12477 /* Look for specific sections that we need. */
12478 if (names
->str_dwo
.matches (sectp
->name
))
12480 dwp_file
->sections
.str
.s
.section
= sectp
;
12481 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12483 else if (names
->cu_index
.matches (sectp
->name
))
12485 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12486 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12488 else if (names
->tu_index
.matches (sectp
->name
))
12490 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12491 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12495 /* This function is mapped across the sections and remembers the offset and
12496 size of each of the DWP version 2 debugging sections that we are interested
12497 in. This is split into a separate function because we don't know if we
12498 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12501 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12503 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12504 const struct dwop_section_names
*names
= &dwop_section_names
;
12505 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12507 /* Record the ELF section number for later lookup: this is what the
12508 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12509 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12510 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12512 /* Look for specific sections that we need. */
12513 if (names
->abbrev_dwo
.matches (sectp
->name
))
12515 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12516 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12518 else if (names
->info_dwo
.matches (sectp
->name
))
12520 dwp_file
->sections
.info
.s
.section
= sectp
;
12521 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12523 else if (names
->line_dwo
.matches (sectp
->name
))
12525 dwp_file
->sections
.line
.s
.section
= sectp
;
12526 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12528 else if (names
->loc_dwo
.matches (sectp
->name
))
12530 dwp_file
->sections
.loc
.s
.section
= sectp
;
12531 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12533 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12535 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12536 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12538 else if (names
->macro_dwo
.matches (sectp
->name
))
12540 dwp_file
->sections
.macro
.s
.section
= sectp
;
12541 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12543 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12545 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12546 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12548 else if (names
->types_dwo
.matches (sectp
->name
))
12550 dwp_file
->sections
.types
.s
.section
= sectp
;
12551 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12555 /* This function is mapped across the sections and remembers the offset and
12556 size of each of the DWP version 5 debugging sections that we are interested
12557 in. This is split into a separate function because we don't know if we
12558 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12561 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12563 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12564 const struct dwop_section_names
*names
= &dwop_section_names
;
12565 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12567 /* Record the ELF section number for later lookup: this is what the
12568 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12569 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12570 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12572 /* Look for specific sections that we need. */
12573 if (names
->abbrev_dwo
.matches (sectp
->name
))
12575 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12576 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12578 else if (names
->info_dwo
.matches (sectp
->name
))
12580 dwp_file
->sections
.info
.s
.section
= sectp
;
12581 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12583 else if (names
->line_dwo
.matches (sectp
->name
))
12585 dwp_file
->sections
.line
.s
.section
= sectp
;
12586 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12588 else if (names
->loclists_dwo
.matches (sectp
->name
))
12590 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12591 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12593 else if (names
->macro_dwo
.matches (sectp
->name
))
12595 dwp_file
->sections
.macro
.s
.section
= sectp
;
12596 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12598 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12600 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12601 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12603 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12605 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12606 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12610 /* Hash function for dwp_file loaded CUs/TUs. */
12613 hash_dwp_loaded_cutus (const void *item
)
12615 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12617 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12618 return dwo_unit
->signature
;
12621 /* Equality function for dwp_file loaded CUs/TUs. */
12624 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12626 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12627 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12629 return dua
->signature
== dub
->signature
;
12632 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12635 allocate_dwp_loaded_cutus_table ()
12637 return htab_up (htab_create_alloc (3,
12638 hash_dwp_loaded_cutus
,
12639 eq_dwp_loaded_cutus
,
12640 NULL
, xcalloc
, xfree
));
12643 /* Try to open DWP file FILE_NAME.
12644 The result is the bfd handle of the file.
12645 If there is a problem finding or opening the file, return NULL.
12646 Upon success, the canonicalized path of the file is stored in the bfd,
12647 same as symfile_bfd_open. */
12649 static gdb_bfd_ref_ptr
12650 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12652 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12654 1 /*search_cwd*/));
12658 /* Work around upstream bug 15652.
12659 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12660 [Whether that's a "bug" is debatable, but it is getting in our way.]
12661 We have no real idea where the dwp file is, because gdb's realpath-ing
12662 of the executable's path may have discarded the needed info.
12663 [IWBN if the dwp file name was recorded in the executable, akin to
12664 .gnu_debuglink, but that doesn't exist yet.]
12665 Strip the directory from FILE_NAME and search again. */
12666 if (*debug_file_directory
!= '\0')
12668 /* Don't implicitly search the current directory here.
12669 If the user wants to search "." to handle this case,
12670 it must be added to debug-file-directory. */
12671 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12679 /* Initialize the use of the DWP file for the current objfile.
12680 By convention the name of the DWP file is ${objfile}.dwp.
12681 The result is NULL if it can't be found. */
12683 static std::unique_ptr
<struct dwp_file
>
12684 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12686 struct objfile
*objfile
= per_objfile
->objfile
;
12688 /* Try to find first .dwp for the binary file before any symbolic links
12691 /* If the objfile is a debug file, find the name of the real binary
12692 file and get the name of dwp file from there. */
12693 std::string dwp_name
;
12694 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12696 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12697 const char *backlink_basename
= lbasename (backlink
->original_name
);
12699 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12702 dwp_name
= objfile
->original_name
;
12704 dwp_name
+= ".dwp";
12706 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12708 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12710 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12711 dwp_name
= objfile_name (objfile
);
12712 dwp_name
+= ".dwp";
12713 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12718 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
12720 return std::unique_ptr
<dwp_file
> ();
12723 const char *name
= bfd_get_filename (dbfd
.get ());
12724 std::unique_ptr
<struct dwp_file
> dwp_file
12725 (new struct dwp_file (name
, std::move (dbfd
)));
12727 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12728 dwp_file
->elf_sections
=
12729 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12730 dwp_file
->num_sections
, asection
*);
12732 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12733 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12736 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12738 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12740 /* The DWP file version is stored in the hash table. Oh well. */
12741 if (dwp_file
->cus
&& dwp_file
->tus
12742 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12744 /* Technically speaking, we should try to limp along, but this is
12745 pretty bizarre. We use pulongest here because that's the established
12746 portability solution (e.g, we cannot use %u for uint32_t). */
12747 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12748 " TU version %s [in DWP file %s]"),
12749 pulongest (dwp_file
->cus
->version
),
12750 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12754 dwp_file
->version
= dwp_file
->cus
->version
;
12755 else if (dwp_file
->tus
)
12756 dwp_file
->version
= dwp_file
->tus
->version
;
12758 dwp_file
->version
= 2;
12760 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12762 if (dwp_file
->version
== 2)
12763 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12766 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12770 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12771 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12773 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
12774 dwarf_read_debug_printf (" %s CUs, %s TUs",
12775 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12776 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12781 /* Wrapper around open_and_init_dwp_file, only open it once. */
12783 static struct dwp_file
*
12784 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12786 if (!per_objfile
->per_bfd
->dwp_checked
)
12788 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12789 per_objfile
->per_bfd
->dwp_checked
= 1;
12791 return per_objfile
->per_bfd
->dwp_file
.get ();
12794 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12795 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12796 or in the DWP file for the objfile, referenced by THIS_UNIT.
12797 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12798 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12800 This is called, for example, when wanting to read a variable with a
12801 complex location. Therefore we don't want to do file i/o for every call.
12802 Therefore we don't want to look for a DWO file on every call.
12803 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12804 then we check if we've already seen DWO_NAME, and only THEN do we check
12807 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12808 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12810 static struct dwo_unit
*
12811 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12812 ULONGEST signature
, int is_debug_types
)
12814 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12815 struct objfile
*objfile
= per_objfile
->objfile
;
12816 const char *kind
= is_debug_types
? "TU" : "CU";
12817 void **dwo_file_slot
;
12818 struct dwo_file
*dwo_file
;
12819 struct dwp_file
*dwp_file
;
12821 /* First see if there's a DWP file.
12822 If we have a DWP file but didn't find the DWO inside it, don't
12823 look for the original DWO file. It makes gdb behave differently
12824 depending on whether one is debugging in the build tree. */
12826 dwp_file
= get_dwp_file (per_objfile
);
12827 if (dwp_file
!= NULL
)
12829 const struct dwp_hash_table
*dwp_htab
=
12830 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12832 if (dwp_htab
!= NULL
)
12834 struct dwo_unit
*dwo_cutu
=
12835 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12838 if (dwo_cutu
!= NULL
)
12840 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
12841 kind
, hex_string (signature
),
12842 host_address_to_string (dwo_cutu
));
12850 /* No DWP file, look for the DWO file. */
12852 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12853 if (*dwo_file_slot
== NULL
)
12855 /* Read in the file and build a table of the CUs/TUs it contains. */
12856 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12858 /* NOTE: This will be NULL if unable to open the file. */
12859 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12861 if (dwo_file
!= NULL
)
12863 struct dwo_unit
*dwo_cutu
= NULL
;
12865 if (is_debug_types
&& dwo_file
->tus
)
12867 struct dwo_unit find_dwo_cutu
;
12869 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12870 find_dwo_cutu
.signature
= signature
;
12872 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12875 else if (!is_debug_types
&& dwo_file
->cus
)
12877 struct dwo_unit find_dwo_cutu
;
12879 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12880 find_dwo_cutu
.signature
= signature
;
12881 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12885 if (dwo_cutu
!= NULL
)
12887 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
12888 kind
, dwo_name
, hex_string (signature
),
12889 host_address_to_string (dwo_cutu
));
12896 /* We didn't find it. This could mean a dwo_id mismatch, or
12897 someone deleted the DWO/DWP file, or the search path isn't set up
12898 correctly to find the file. */
12900 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
12901 kind
, dwo_name
, hex_string (signature
));
12903 /* This is a warning and not a complaint because it can be caused by
12904 pilot error (e.g., user accidentally deleting the DWO). */
12906 /* Print the name of the DWP file if we looked there, helps the user
12907 better diagnose the problem. */
12908 std::string dwp_text
;
12910 if (dwp_file
!= NULL
)
12911 dwp_text
= string_printf (" [in DWP file %s]",
12912 lbasename (dwp_file
->name
));
12914 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12915 " [in module %s]"),
12916 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12917 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12922 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12923 See lookup_dwo_cutu_unit for details. */
12925 static struct dwo_unit
*
12926 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12927 ULONGEST signature
)
12929 gdb_assert (!cu
->per_cu
->is_debug_types
);
12931 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12934 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12935 See lookup_dwo_cutu_unit for details. */
12937 static struct dwo_unit
*
12938 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12940 gdb_assert (cu
->per_cu
->is_debug_types
);
12942 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12944 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12947 /* Traversal function for queue_and_load_all_dwo_tus. */
12950 queue_and_load_dwo_tu (void **slot
, void *info
)
12952 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12953 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12954 ULONGEST signature
= dwo_unit
->signature
;
12955 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12957 if (sig_type
!= NULL
)
12959 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12960 a real dependency of PER_CU on SIG_TYPE. That is detected later
12961 while processing PER_CU. */
12962 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
12964 load_full_type_unit (sig_type
, cu
->per_objfile
);
12965 cu
->per_cu
->imported_symtabs_push (sig_type
);
12971 /* Queue all TUs contained in the DWO of CU to be read in.
12972 The DWO may have the only definition of the type, though it may not be
12973 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12974 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12977 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12979 struct dwo_unit
*dwo_unit
;
12980 struct dwo_file
*dwo_file
;
12982 gdb_assert (cu
!= nullptr);
12983 gdb_assert (!cu
->per_cu
->is_debug_types
);
12984 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12986 dwo_unit
= cu
->dwo_unit
;
12987 gdb_assert (dwo_unit
!= NULL
);
12989 dwo_file
= dwo_unit
->dwo_file
;
12990 if (dwo_file
->tus
!= NULL
)
12991 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
12994 /* Read in various DIEs. */
12996 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12997 Inherit only the children of the DW_AT_abstract_origin DIE not being
12998 already referenced by DW_AT_abstract_origin from the children of the
13002 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13004 struct die_info
*child_die
;
13005 sect_offset
*offsetp
;
13006 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13007 struct die_info
*origin_die
;
13008 /* Iterator of the ORIGIN_DIE children. */
13009 struct die_info
*origin_child_die
;
13010 struct attribute
*attr
;
13011 struct dwarf2_cu
*origin_cu
;
13012 struct pending
**origin_previous_list_in_scope
;
13014 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13018 /* Note that following die references may follow to a die in a
13022 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13024 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13026 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13027 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13029 if (die
->tag
!= origin_die
->tag
13030 && !(die
->tag
== DW_TAG_inlined_subroutine
13031 && origin_die
->tag
== DW_TAG_subprogram
))
13032 complaint (_("DIE %s and its abstract origin %s have different tags"),
13033 sect_offset_str (die
->sect_off
),
13034 sect_offset_str (origin_die
->sect_off
));
13036 /* Find if the concrete and abstract trees are structurally the
13037 same. This is a shallow traversal and it is not bullet-proof;
13038 the compiler can trick the debugger into believing that the trees
13039 are isomorphic, whereas they actually are not. However, the
13040 likelyhood of this happening is pretty low, and a full-fledged
13041 check would be an overkill. */
13042 bool are_isomorphic
= true;
13043 die_info
*concrete_child
= die
->child
;
13044 die_info
*abstract_child
= origin_die
->child
;
13045 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
13047 if (concrete_child
== nullptr
13048 || abstract_child
== nullptr
13049 || concrete_child
->tag
!= abstract_child
->tag
)
13051 are_isomorphic
= false;
13055 concrete_child
= concrete_child
->sibling
;
13056 abstract_child
= abstract_child
->sibling
;
13059 /* Walk the origin's children in parallel to the concrete children.
13060 This helps match an origin child in case the debug info misses
13061 DW_AT_abstract_origin attributes. Keep in mind that the abstract
13062 origin tree may not have the same tree structure as the concrete
13064 die_info
*corresponding_abstract_child
13065 = are_isomorphic
? origin_die
->child
: nullptr;
13067 std::vector
<sect_offset
> offsets
;
13069 for (child_die
= die
->child
;
13070 child_die
&& child_die
->tag
;
13071 child_die
= child_die
->sibling
)
13073 struct die_info
*child_origin_die
;
13074 struct dwarf2_cu
*child_origin_cu
;
13076 /* We are trying to process concrete instance entries:
13077 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13078 it's not relevant to our analysis here. i.e. detecting DIEs that are
13079 present in the abstract instance but not referenced in the concrete
13081 if (child_die
->tag
== DW_TAG_call_site
13082 || child_die
->tag
== DW_TAG_GNU_call_site
)
13084 if (are_isomorphic
)
13085 corresponding_abstract_child
13086 = corresponding_abstract_child
->sibling
;
13090 /* For each CHILD_DIE, find the corresponding child of
13091 ORIGIN_DIE. If there is more than one layer of
13092 DW_AT_abstract_origin, follow them all; there shouldn't be,
13093 but GCC versions at least through 4.4 generate this (GCC PR
13095 child_origin_die
= child_die
;
13096 child_origin_cu
= cu
;
13099 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13103 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13107 /* If missing DW_AT_abstract_origin, try the corresponding child
13108 of the origin. Clang emits such lexical scopes. */
13109 if (child_origin_die
== child_die
13110 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
13112 && child_die
->tag
== DW_TAG_lexical_block
)
13113 child_origin_die
= corresponding_abstract_child
;
13115 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13116 counterpart may exist. */
13117 if (child_origin_die
!= child_die
)
13119 if (child_die
->tag
!= child_origin_die
->tag
13120 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13121 && child_origin_die
->tag
== DW_TAG_subprogram
))
13122 complaint (_("Child DIE %s and its abstract origin %s have "
13124 sect_offset_str (child_die
->sect_off
),
13125 sect_offset_str (child_origin_die
->sect_off
));
13126 if (child_origin_die
->parent
!= origin_die
)
13127 complaint (_("Child DIE %s and its abstract origin %s have "
13128 "different parents"),
13129 sect_offset_str (child_die
->sect_off
),
13130 sect_offset_str (child_origin_die
->sect_off
));
13132 offsets
.push_back (child_origin_die
->sect_off
);
13135 if (are_isomorphic
)
13136 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
13138 std::sort (offsets
.begin (), offsets
.end ());
13139 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13140 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13141 if (offsetp
[-1] == *offsetp
)
13142 complaint (_("Multiple children of DIE %s refer "
13143 "to DIE %s as their abstract origin"),
13144 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13146 offsetp
= offsets
.data ();
13147 origin_child_die
= origin_die
->child
;
13148 while (origin_child_die
&& origin_child_die
->tag
)
13150 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13151 while (offsetp
< offsets_end
13152 && *offsetp
< origin_child_die
->sect_off
)
13154 if (offsetp
>= offsets_end
13155 || *offsetp
> origin_child_die
->sect_off
)
13157 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13158 Check whether we're already processing ORIGIN_CHILD_DIE.
13159 This can happen with mutually referenced abstract_origins.
13161 if (!origin_child_die
->in_process
)
13162 process_die (origin_child_die
, origin_cu
);
13164 origin_child_die
= origin_child_die
->sibling
;
13166 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13168 if (cu
!= origin_cu
)
13169 compute_delayed_physnames (origin_cu
);
13173 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13175 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13176 struct gdbarch
*gdbarch
= objfile
->arch ();
13177 struct context_stack
*newobj
;
13180 struct die_info
*child_die
;
13181 struct attribute
*attr
, *call_line
, *call_file
;
13183 CORE_ADDR baseaddr
;
13184 struct block
*block
;
13185 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13186 std::vector
<struct symbol
*> template_args
;
13187 struct template_symbol
*templ_func
= NULL
;
13191 /* If we do not have call site information, we can't show the
13192 caller of this inlined function. That's too confusing, so
13193 only use the scope for local variables. */
13194 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13195 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13196 if (call_line
== NULL
|| call_file
== NULL
)
13198 read_lexical_block_scope (die
, cu
);
13203 baseaddr
= objfile
->text_section_offset ();
13205 name
= dwarf2_name (die
, cu
);
13207 /* Ignore functions with missing or empty names. These are actually
13208 illegal according to the DWARF standard. */
13211 complaint (_("missing name for subprogram DIE at %s"),
13212 sect_offset_str (die
->sect_off
));
13216 /* Ignore functions with missing or invalid low and high pc attributes. */
13217 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13218 <= PC_BOUNDS_INVALID
)
13220 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13221 if (attr
== nullptr || !attr
->as_boolean ())
13222 complaint (_("cannot get low and high bounds "
13223 "for subprogram DIE at %s"),
13224 sect_offset_str (die
->sect_off
));
13228 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13229 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13231 /* If we have any template arguments, then we must allocate a
13232 different sort of symbol. */
13233 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13235 if (child_die
->tag
== DW_TAG_template_type_param
13236 || child_die
->tag
== DW_TAG_template_value_param
)
13238 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13239 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13244 gdb_assert (cu
->get_builder () != nullptr);
13245 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13246 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13247 (struct symbol
*) templ_func
);
13249 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13250 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13253 /* If there is a location expression for DW_AT_frame_base, record
13255 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13256 if (attr
!= nullptr)
13257 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13259 /* If there is a location for the static link, record it. */
13260 newobj
->static_link
= NULL
;
13261 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13262 if (attr
!= nullptr)
13264 newobj
->static_link
13265 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13266 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13270 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13272 if (die
->child
!= NULL
)
13274 child_die
= die
->child
;
13275 while (child_die
&& child_die
->tag
)
13277 if (child_die
->tag
== DW_TAG_template_type_param
13278 || child_die
->tag
== DW_TAG_template_value_param
)
13280 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13283 template_args
.push_back (arg
);
13286 process_die (child_die
, cu
);
13287 child_die
= child_die
->sibling
;
13291 inherit_abstract_dies (die
, cu
);
13293 /* If we have a DW_AT_specification, we might need to import using
13294 directives from the context of the specification DIE. See the
13295 comment in determine_prefix. */
13296 if (cu
->language
== language_cplus
13297 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13299 struct dwarf2_cu
*spec_cu
= cu
;
13300 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13304 child_die
= spec_die
->child
;
13305 while (child_die
&& child_die
->tag
)
13307 if (child_die
->tag
== DW_TAG_imported_module
)
13308 process_die (child_die
, spec_cu
);
13309 child_die
= child_die
->sibling
;
13312 /* In some cases, GCC generates specification DIEs that
13313 themselves contain DW_AT_specification attributes. */
13314 spec_die
= die_specification (spec_die
, &spec_cu
);
13318 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13319 /* Make a block for the local symbols within. */
13320 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13321 cstk
.static_link
, lowpc
, highpc
);
13323 /* For C++, set the block's scope. */
13324 if ((cu
->language
== language_cplus
13325 || cu
->language
== language_fortran
13326 || cu
->language
== language_d
13327 || cu
->language
== language_rust
)
13328 && cu
->processing_has_namespace_info
)
13329 block_set_scope (block
, determine_prefix (die
, cu
),
13330 &objfile
->objfile_obstack
);
13332 /* If we have address ranges, record them. */
13333 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13335 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13337 /* Attach template arguments to function. */
13338 if (!template_args
.empty ())
13340 gdb_assert (templ_func
!= NULL
);
13342 templ_func
->n_template_arguments
= template_args
.size ();
13343 templ_func
->template_arguments
13344 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13345 templ_func
->n_template_arguments
);
13346 memcpy (templ_func
->template_arguments
,
13347 template_args
.data (),
13348 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13350 /* Make sure that the symtab is set on the new symbols. Even
13351 though they don't appear in this symtab directly, other parts
13352 of gdb assume that symbols do, and this is reasonably
13354 for (symbol
*sym
: template_args
)
13355 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13358 /* In C++, we can have functions nested inside functions (e.g., when
13359 a function declares a class that has methods). This means that
13360 when we finish processing a function scope, we may need to go
13361 back to building a containing block's symbol lists. */
13362 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13363 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13365 /* If we've finished processing a top-level function, subsequent
13366 symbols go in the file symbol list. */
13367 if (cu
->get_builder ()->outermost_context_p ())
13368 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13371 /* Process all the DIES contained within a lexical block scope. Start
13372 a new scope, process the dies, and then close the scope. */
13375 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13377 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13378 struct gdbarch
*gdbarch
= objfile
->arch ();
13379 CORE_ADDR lowpc
, highpc
;
13380 struct die_info
*child_die
;
13381 CORE_ADDR baseaddr
;
13383 baseaddr
= objfile
->text_section_offset ();
13385 /* Ignore blocks with missing or invalid low and high pc attributes. */
13386 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13387 as multiple lexical blocks? Handling children in a sane way would
13388 be nasty. Might be easier to properly extend generic blocks to
13389 describe ranges. */
13390 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13392 case PC_BOUNDS_NOT_PRESENT
:
13393 /* DW_TAG_lexical_block has no attributes, process its children as if
13394 there was no wrapping by that DW_TAG_lexical_block.
13395 GCC does no longer produces such DWARF since GCC r224161. */
13396 for (child_die
= die
->child
;
13397 child_die
!= NULL
&& child_die
->tag
;
13398 child_die
= child_die
->sibling
)
13400 /* We might already be processing this DIE. This can happen
13401 in an unusual circumstance -- where a subroutine A
13402 appears lexically in another subroutine B, but A actually
13403 inlines B. The recursion is broken here, rather than in
13404 inherit_abstract_dies, because it seems better to simply
13405 drop concrete children here. */
13406 if (!child_die
->in_process
)
13407 process_die (child_die
, cu
);
13410 case PC_BOUNDS_INVALID
:
13413 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13414 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13416 cu
->get_builder ()->push_context (0, lowpc
);
13417 if (die
->child
!= NULL
)
13419 child_die
= die
->child
;
13420 while (child_die
&& child_die
->tag
)
13422 process_die (child_die
, cu
);
13423 child_die
= child_die
->sibling
;
13426 inherit_abstract_dies (die
, cu
);
13427 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13429 if (*cu
->get_builder ()->get_local_symbols () != NULL
13430 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13432 struct block
*block
13433 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13434 cstk
.start_addr
, highpc
);
13436 /* Note that recording ranges after traversing children, as we
13437 do here, means that recording a parent's ranges entails
13438 walking across all its children's ranges as they appear in
13439 the address map, which is quadratic behavior.
13441 It would be nicer to record the parent's ranges before
13442 traversing its children, simply overriding whatever you find
13443 there. But since we don't even decide whether to create a
13444 block until after we've traversed its children, that's hard
13446 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13448 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13449 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13452 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13455 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13457 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13458 struct objfile
*objfile
= per_objfile
->objfile
;
13459 struct gdbarch
*gdbarch
= objfile
->arch ();
13460 CORE_ADDR pc
, baseaddr
;
13461 struct attribute
*attr
;
13462 struct call_site
*call_site
, call_site_local
;
13465 struct die_info
*child_die
;
13467 baseaddr
= objfile
->text_section_offset ();
13469 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13472 /* This was a pre-DWARF-5 GNU extension alias
13473 for DW_AT_call_return_pc. */
13474 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13478 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13479 "DIE %s [in module %s]"),
13480 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13483 pc
= attr
->as_address () + baseaddr
;
13484 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13486 if (cu
->call_site_htab
== NULL
)
13487 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13488 NULL
, &objfile
->objfile_obstack
,
13489 hashtab_obstack_allocate
, NULL
);
13490 call_site_local
.pc
= pc
;
13491 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13494 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13495 "DIE %s [in module %s]"),
13496 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13497 objfile_name (objfile
));
13501 /* Count parameters at the caller. */
13504 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13505 child_die
= child_die
->sibling
)
13507 if (child_die
->tag
!= DW_TAG_call_site_parameter
13508 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13510 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13511 "DW_TAG_call_site child DIE %s [in module %s]"),
13512 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13513 objfile_name (objfile
));
13521 = ((struct call_site
*)
13522 obstack_alloc (&objfile
->objfile_obstack
,
13523 sizeof (*call_site
)
13524 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13526 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13527 call_site
->pc
= pc
;
13529 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13530 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13532 struct die_info
*func_die
;
13534 /* Skip also over DW_TAG_inlined_subroutine. */
13535 for (func_die
= die
->parent
;
13536 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13537 && func_die
->tag
!= DW_TAG_subroutine_type
;
13538 func_die
= func_die
->parent
);
13540 /* DW_AT_call_all_calls is a superset
13541 of DW_AT_call_all_tail_calls. */
13543 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13544 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13545 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13546 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13548 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13549 not complete. But keep CALL_SITE for look ups via call_site_htab,
13550 both the initial caller containing the real return address PC and
13551 the final callee containing the current PC of a chain of tail
13552 calls do not need to have the tail call list complete. But any
13553 function candidate for a virtual tail call frame searched via
13554 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13555 determined unambiguously. */
13559 struct type
*func_type
= NULL
;
13562 func_type
= get_die_type (func_die
, cu
);
13563 if (func_type
!= NULL
)
13565 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13567 /* Enlist this call site to the function. */
13568 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13569 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13572 complaint (_("Cannot find function owning DW_TAG_call_site "
13573 "DIE %s [in module %s]"),
13574 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13578 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13580 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13582 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13585 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13586 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13588 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13589 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13590 /* Keep NULL DWARF_BLOCK. */;
13591 else if (attr
->form_is_block ())
13593 struct dwarf2_locexpr_baton
*dlbaton
;
13594 struct dwarf_block
*block
= attr
->as_block ();
13596 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13597 dlbaton
->data
= block
->data
;
13598 dlbaton
->size
= block
->size
;
13599 dlbaton
->per_objfile
= per_objfile
;
13600 dlbaton
->per_cu
= cu
->per_cu
;
13602 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13604 else if (attr
->form_is_ref ())
13606 struct dwarf2_cu
*target_cu
= cu
;
13607 struct die_info
*target_die
;
13609 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13610 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13611 if (die_is_declaration (target_die
, target_cu
))
13613 const char *target_physname
;
13615 /* Prefer the mangled name; otherwise compute the demangled one. */
13616 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13617 if (target_physname
== NULL
)
13618 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13619 if (target_physname
== NULL
)
13620 complaint (_("DW_AT_call_target target DIE has invalid "
13621 "physname, for referencing DIE %s [in module %s]"),
13622 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13624 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13630 /* DW_AT_entry_pc should be preferred. */
13631 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13632 <= PC_BOUNDS_INVALID
)
13633 complaint (_("DW_AT_call_target target DIE has invalid "
13634 "low pc, for referencing DIE %s [in module %s]"),
13635 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13638 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13639 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13644 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13645 "block nor reference, for DIE %s [in module %s]"),
13646 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13648 call_site
->per_cu
= cu
->per_cu
;
13649 call_site
->per_objfile
= per_objfile
;
13651 for (child_die
= die
->child
;
13652 child_die
&& child_die
->tag
;
13653 child_die
= child_die
->sibling
)
13655 struct call_site_parameter
*parameter
;
13656 struct attribute
*loc
, *origin
;
13658 if (child_die
->tag
!= DW_TAG_call_site_parameter
13659 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13661 /* Already printed the complaint above. */
13665 gdb_assert (call_site
->parameter_count
< nparams
);
13666 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13668 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13669 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13670 register is contained in DW_AT_call_value. */
13672 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13673 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13674 if (origin
== NULL
)
13676 /* This was a pre-DWARF-5 GNU extension alias
13677 for DW_AT_call_parameter. */
13678 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13680 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13682 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13684 sect_offset sect_off
= origin
->get_ref_die_offset ();
13685 if (!cu
->header
.offset_in_cu_p (sect_off
))
13687 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13688 binding can be done only inside one CU. Such referenced DIE
13689 therefore cannot be even moved to DW_TAG_partial_unit. */
13690 complaint (_("DW_AT_call_parameter offset is not in CU for "
13691 "DW_TAG_call_site child DIE %s [in module %s]"),
13692 sect_offset_str (child_die
->sect_off
),
13693 objfile_name (objfile
));
13696 parameter
->u
.param_cu_off
13697 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13699 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13701 complaint (_("No DW_FORM_block* DW_AT_location for "
13702 "DW_TAG_call_site child DIE %s [in module %s]"),
13703 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13708 struct dwarf_block
*block
= loc
->as_block ();
13710 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13711 (block
->data
, &block
->data
[block
->size
]);
13712 if (parameter
->u
.dwarf_reg
!= -1)
13713 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13714 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
13715 &block
->data
[block
->size
],
13716 ¶meter
->u
.fb_offset
))
13717 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13720 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13721 "for DW_FORM_block* DW_AT_location is supported for "
13722 "DW_TAG_call_site child DIE %s "
13724 sect_offset_str (child_die
->sect_off
),
13725 objfile_name (objfile
));
13730 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13732 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13733 if (attr
== NULL
|| !attr
->form_is_block ())
13735 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13736 "DW_TAG_call_site child DIE %s [in module %s]"),
13737 sect_offset_str (child_die
->sect_off
),
13738 objfile_name (objfile
));
13742 struct dwarf_block
*block
= attr
->as_block ();
13743 parameter
->value
= block
->data
;
13744 parameter
->value_size
= block
->size
;
13746 /* Parameters are not pre-cleared by memset above. */
13747 parameter
->data_value
= NULL
;
13748 parameter
->data_value_size
= 0;
13749 call_site
->parameter_count
++;
13751 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13753 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13754 if (attr
!= nullptr)
13756 if (!attr
->form_is_block ())
13757 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13758 "DW_TAG_call_site child DIE %s [in module %s]"),
13759 sect_offset_str (child_die
->sect_off
),
13760 objfile_name (objfile
));
13763 block
= attr
->as_block ();
13764 parameter
->data_value
= block
->data
;
13765 parameter
->data_value_size
= block
->size
;
13771 /* Helper function for read_variable. If DIE represents a virtual
13772 table, then return the type of the concrete object that is
13773 associated with the virtual table. Otherwise, return NULL. */
13775 static struct type
*
13776 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13778 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13782 /* Find the type DIE. */
13783 struct die_info
*type_die
= NULL
;
13784 struct dwarf2_cu
*type_cu
= cu
;
13786 if (attr
->form_is_ref ())
13787 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13788 if (type_die
== NULL
)
13791 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13793 return die_containing_type (type_die
, type_cu
);
13796 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13799 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13801 struct rust_vtable_symbol
*storage
= NULL
;
13803 if (cu
->language
== language_rust
)
13805 struct type
*containing_type
= rust_containing_type (die
, cu
);
13807 if (containing_type
!= NULL
)
13809 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13811 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13812 storage
->concrete_type
= containing_type
;
13813 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13817 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13818 struct attribute
*abstract_origin
13819 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13820 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13821 if (res
== NULL
&& loc
&& abstract_origin
)
13823 /* We have a variable without a name, but with a location and an abstract
13824 origin. This may be a concrete instance of an abstract variable
13825 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13827 struct dwarf2_cu
*origin_cu
= cu
;
13828 struct die_info
*origin_die
13829 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13830 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13831 per_objfile
->per_bfd
->abstract_to_concrete
13832 [origin_die
->sect_off
].push_back (die
->sect_off
);
13836 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13837 reading .debug_rnglists.
13838 Callback's type should be:
13839 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13840 Return true if the attributes are present and valid, otherwise,
13843 template <typename Callback
>
13845 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13846 dwarf_tag tag
, Callback
&&callback
)
13848 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13849 struct objfile
*objfile
= per_objfile
->objfile
;
13850 bfd
*obfd
= objfile
->obfd
;
13851 /* Base address selection entry. */
13852 gdb::optional
<CORE_ADDR
> base
;
13853 const gdb_byte
*buffer
;
13854 CORE_ADDR baseaddr
;
13855 bool overflow
= false;
13856 ULONGEST addr_index
;
13857 struct dwarf2_section_info
*rnglists_section
;
13859 base
= cu
->base_address
;
13860 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
13861 rnglists_section
->read (objfile
);
13863 if (offset
>= rnglists_section
->size
)
13865 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13869 buffer
= rnglists_section
->buffer
+ offset
;
13871 baseaddr
= objfile
->text_section_offset ();
13875 /* Initialize it due to a false compiler warning. */
13876 CORE_ADDR range_beginning
= 0, range_end
= 0;
13877 const gdb_byte
*buf_end
= (rnglists_section
->buffer
13878 + rnglists_section
->size
);
13879 unsigned int bytes_read
;
13881 if (buffer
== buf_end
)
13886 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13889 case DW_RLE_end_of_list
:
13891 case DW_RLE_base_address
:
13892 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13897 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13898 buffer
+= bytes_read
;
13900 case DW_RLE_base_addressx
:
13901 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13902 buffer
+= bytes_read
;
13903 base
= read_addr_index (cu
, addr_index
);
13905 case DW_RLE_start_length
:
13906 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13911 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13913 buffer
+= bytes_read
;
13914 range_end
= (range_beginning
13915 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13916 buffer
+= bytes_read
;
13917 if (buffer
> buf_end
)
13923 case DW_RLE_startx_length
:
13924 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13925 buffer
+= bytes_read
;
13926 range_beginning
= read_addr_index (cu
, addr_index
);
13927 if (buffer
> buf_end
)
13932 range_end
= (range_beginning
13933 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13934 buffer
+= bytes_read
;
13936 case DW_RLE_offset_pair
:
13937 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13938 buffer
+= bytes_read
;
13939 if (buffer
> buf_end
)
13944 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13945 buffer
+= bytes_read
;
13946 if (buffer
> buf_end
)
13952 case DW_RLE_start_end
:
13953 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13958 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13960 buffer
+= bytes_read
;
13961 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13962 buffer
+= bytes_read
;
13964 case DW_RLE_startx_endx
:
13965 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13966 buffer
+= bytes_read
;
13967 range_beginning
= read_addr_index (cu
, addr_index
);
13968 if (buffer
> buf_end
)
13973 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13974 buffer
+= bytes_read
;
13975 range_end
= read_addr_index (cu
, addr_index
);
13978 complaint (_("Invalid .debug_rnglists data (no base address)"));
13981 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13983 if (rlet
== DW_RLE_base_address
)
13986 if (range_beginning
> range_end
)
13988 /* Inverted range entries are invalid. */
13989 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13993 /* Empty range entries have no effect. */
13994 if (range_beginning
== range_end
)
13997 /* Only DW_RLE_offset_pair needs the base address added. */
13998 if (rlet
== DW_RLE_offset_pair
)
14000 if (!base
.has_value ())
14002 /* We have no valid base address for the DW_RLE_offset_pair. */
14003 complaint (_("Invalid .debug_rnglists data (no base address for "
14004 "DW_RLE_offset_pair)"));
14008 range_beginning
+= *base
;
14009 range_end
+= *base
;
14012 /* A not-uncommon case of bad debug info.
14013 Don't pollute the addrmap with bad data. */
14014 if (range_beginning
+ baseaddr
== 0
14015 && !per_objfile
->per_bfd
->has_section_at_zero
)
14017 complaint (_(".debug_rnglists entry has start address of zero"
14018 " [in module %s]"), objfile_name (objfile
));
14022 callback (range_beginning
, range_end
);
14027 complaint (_("Offset %d is not terminated "
14028 "for DW_AT_ranges attribute"),
14036 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14037 Callback's type should be:
14038 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14039 Return 1 if the attributes are present and valid, otherwise, return 0. */
14041 template <typename Callback
>
14043 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
14044 Callback
&&callback
)
14046 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14047 struct objfile
*objfile
= per_objfile
->objfile
;
14048 struct comp_unit_head
*cu_header
= &cu
->header
;
14049 bfd
*obfd
= objfile
->obfd
;
14050 unsigned int addr_size
= cu_header
->addr_size
;
14051 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14052 /* Base address selection entry. */
14053 gdb::optional
<CORE_ADDR
> base
;
14054 unsigned int dummy
;
14055 const gdb_byte
*buffer
;
14056 CORE_ADDR baseaddr
;
14058 if (cu_header
->version
>= 5)
14059 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
14061 base
= cu
->base_address
;
14063 per_objfile
->per_bfd
->ranges
.read (objfile
);
14064 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
14066 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14070 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
14072 baseaddr
= objfile
->text_section_offset ();
14076 CORE_ADDR range_beginning
, range_end
;
14078 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14079 buffer
+= addr_size
;
14080 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14081 buffer
+= addr_size
;
14082 offset
+= 2 * addr_size
;
14084 /* An end of list marker is a pair of zero addresses. */
14085 if (range_beginning
== 0 && range_end
== 0)
14086 /* Found the end of list entry. */
14089 /* Each base address selection entry is a pair of 2 values.
14090 The first is the largest possible address, the second is
14091 the base address. Check for a base address here. */
14092 if ((range_beginning
& mask
) == mask
)
14094 /* If we found the largest possible address, then we already
14095 have the base address in range_end. */
14100 if (!base
.has_value ())
14102 /* We have no valid base address for the ranges
14104 complaint (_("Invalid .debug_ranges data (no base address)"));
14108 if (range_beginning
> range_end
)
14110 /* Inverted range entries are invalid. */
14111 complaint (_("Invalid .debug_ranges data (inverted range)"));
14115 /* Empty range entries have no effect. */
14116 if (range_beginning
== range_end
)
14119 range_beginning
+= *base
;
14120 range_end
+= *base
;
14122 /* A not-uncommon case of bad debug info.
14123 Don't pollute the addrmap with bad data. */
14124 if (range_beginning
+ baseaddr
== 0
14125 && !per_objfile
->per_bfd
->has_section_at_zero
)
14127 complaint (_(".debug_ranges entry has start address of zero"
14128 " [in module %s]"), objfile_name (objfile
));
14132 callback (range_beginning
, range_end
);
14138 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14139 Return 1 if the attributes are present and valid, otherwise, return 0.
14140 If RANGES_PST is not NULL we should set up the `psymtabs_addrmap'. */
14143 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14144 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14145 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
14147 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14148 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
14149 struct gdbarch
*gdbarch
= objfile
->arch ();
14150 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14153 CORE_ADDR high
= 0;
14156 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14157 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14159 if (ranges_pst
!= NULL
)
14164 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14165 range_beginning
+ baseaddr
)
14167 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14168 range_end
+ baseaddr
)
14170 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
14171 lowpc
, highpc
- 1, ranges_pst
);
14174 /* FIXME: This is recording everything as a low-high
14175 segment of consecutive addresses. We should have a
14176 data structure for discontiguous block ranges
14180 low
= range_beginning
;
14186 if (range_beginning
< low
)
14187 low
= range_beginning
;
14188 if (range_end
> high
)
14196 /* If the first entry is an end-of-list marker, the range
14197 describes an empty scope, i.e. no instructions. */
14203 *high_return
= high
;
14207 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14208 definition for the return value. *LOWPC and *HIGHPC are set iff
14209 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14211 static enum pc_bounds_kind
14212 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14213 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14214 dwarf2_psymtab
*pst
)
14216 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14217 struct attribute
*attr
;
14218 struct attribute
*attr_high
;
14220 CORE_ADDR high
= 0;
14221 enum pc_bounds_kind ret
;
14223 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14226 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14227 if (attr
!= nullptr)
14229 low
= attr
->as_address ();
14230 high
= attr_high
->as_address ();
14231 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14235 /* Found high w/o low attribute. */
14236 return PC_BOUNDS_INVALID
;
14238 /* Found consecutive range of addresses. */
14239 ret
= PC_BOUNDS_HIGH_LOW
;
14243 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14244 if (attr
!= nullptr && attr
->form_is_unsigned ())
14246 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14247 on DWARF version). */
14248 ULONGEST ranges_offset
= attr
->as_unsigned ();
14250 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14252 if (die
->tag
!= DW_TAG_compile_unit
)
14253 ranges_offset
+= cu
->gnu_ranges_base
;
14255 /* Value of the DW_AT_ranges attribute is the offset in the
14256 .debug_ranges section. */
14257 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14259 return PC_BOUNDS_INVALID
;
14260 /* Found discontinuous range of addresses. */
14261 ret
= PC_BOUNDS_RANGES
;
14264 return PC_BOUNDS_NOT_PRESENT
;
14267 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14269 return PC_BOUNDS_INVALID
;
14271 /* When using the GNU linker, .gnu.linkonce. sections are used to
14272 eliminate duplicate copies of functions and vtables and such.
14273 The linker will arbitrarily choose one and discard the others.
14274 The AT_*_pc values for such functions refer to local labels in
14275 these sections. If the section from that file was discarded, the
14276 labels are not in the output, so the relocs get a value of 0.
14277 If this is a discarded function, mark the pc bounds as invalid,
14278 so that GDB will ignore it. */
14279 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14280 return PC_BOUNDS_INVALID
;
14288 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14289 its low and high PC addresses. Do nothing if these addresses could not
14290 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14291 and HIGHPC to the high address if greater than HIGHPC. */
14294 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14295 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14296 struct dwarf2_cu
*cu
)
14298 CORE_ADDR low
, high
;
14299 struct die_info
*child
= die
->child
;
14301 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14303 *lowpc
= std::min (*lowpc
, low
);
14304 *highpc
= std::max (*highpc
, high
);
14307 /* If the language does not allow nested subprograms (either inside
14308 subprograms or lexical blocks), we're done. */
14309 if (cu
->language
!= language_ada
)
14312 /* Check all the children of the given DIE. If it contains nested
14313 subprograms, then check their pc bounds. Likewise, we need to
14314 check lexical blocks as well, as they may also contain subprogram
14316 while (child
&& child
->tag
)
14318 if (child
->tag
== DW_TAG_subprogram
14319 || child
->tag
== DW_TAG_lexical_block
)
14320 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14321 child
= child
->sibling
;
14325 /* Get the low and high pc's represented by the scope DIE, and store
14326 them in *LOWPC and *HIGHPC. If the correct values can't be
14327 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14330 get_scope_pc_bounds (struct die_info
*die
,
14331 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14332 struct dwarf2_cu
*cu
)
14334 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14335 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14336 CORE_ADDR current_low
, current_high
;
14338 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14339 >= PC_BOUNDS_RANGES
)
14341 best_low
= current_low
;
14342 best_high
= current_high
;
14346 struct die_info
*child
= die
->child
;
14348 while (child
&& child
->tag
)
14350 switch (child
->tag
) {
14351 case DW_TAG_subprogram
:
14352 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14354 case DW_TAG_namespace
:
14355 case DW_TAG_module
:
14356 /* FIXME: carlton/2004-01-16: Should we do this for
14357 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14358 that current GCC's always emit the DIEs corresponding
14359 to definitions of methods of classes as children of a
14360 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14361 the DIEs giving the declarations, which could be
14362 anywhere). But I don't see any reason why the
14363 standards says that they have to be there. */
14364 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14366 if (current_low
!= ((CORE_ADDR
) -1))
14368 best_low
= std::min (best_low
, current_low
);
14369 best_high
= std::max (best_high
, current_high
);
14377 child
= child
->sibling
;
14382 *highpc
= best_high
;
14385 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14389 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14390 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14392 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14393 struct gdbarch
*gdbarch
= objfile
->arch ();
14394 struct attribute
*attr
;
14395 struct attribute
*attr_high
;
14397 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14400 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14401 if (attr
!= nullptr)
14403 CORE_ADDR low
= attr
->as_address ();
14404 CORE_ADDR high
= attr_high
->as_address ();
14406 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14409 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14410 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14411 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14415 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14416 if (attr
!= nullptr && attr
->form_is_unsigned ())
14418 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14419 on DWARF version). */
14420 ULONGEST ranges_offset
= attr
->as_unsigned ();
14422 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14424 if (die
->tag
!= DW_TAG_compile_unit
)
14425 ranges_offset
+= cu
->gnu_ranges_base
;
14427 std::vector
<blockrange
> blockvec
;
14428 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14429 [&] (CORE_ADDR start
, CORE_ADDR end
)
14433 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14434 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14435 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14436 blockvec
.emplace_back (start
, end
);
14439 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14443 /* Check whether the producer field indicates either of GCC < 4.6, or the
14444 Intel C/C++ compiler, and cache the result in CU. */
14447 check_producer (struct dwarf2_cu
*cu
)
14451 if (cu
->producer
== NULL
)
14453 /* For unknown compilers expect their behavior is DWARF version
14456 GCC started to support .debug_types sections by -gdwarf-4 since
14457 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14458 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14459 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14460 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14462 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14464 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14465 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14467 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14469 cu
->producer_is_icc
= true;
14470 cu
->producer_is_icc_lt_14
= major
< 14;
14472 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14473 cu
->producer_is_codewarrior
= true;
14476 /* For other non-GCC compilers, expect their behavior is DWARF version
14480 cu
->checked_producer
= true;
14483 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14484 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14485 during 4.6.0 experimental. */
14488 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14490 if (!cu
->checked_producer
)
14491 check_producer (cu
);
14493 return cu
->producer_is_gxx_lt_4_6
;
14497 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14498 with incorrect is_stmt attributes. */
14501 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14503 if (!cu
->checked_producer
)
14504 check_producer (cu
);
14506 return cu
->producer_is_codewarrior
;
14509 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14510 If that attribute is not available, return the appropriate
14513 static enum dwarf_access_attribute
14514 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14516 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14517 if (attr
!= nullptr)
14519 LONGEST value
= attr
->constant_value (-1);
14520 if (value
== DW_ACCESS_public
14521 || value
== DW_ACCESS_protected
14522 || value
== DW_ACCESS_private
)
14523 return (dwarf_access_attribute
) value
;
14524 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14528 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14530 /* The default DWARF 2 accessibility for members is public, the default
14531 accessibility for inheritance is private. */
14533 if (die
->tag
!= DW_TAG_inheritance
)
14534 return DW_ACCESS_public
;
14536 return DW_ACCESS_private
;
14540 /* DWARF 3+ defines the default accessibility a different way. The same
14541 rules apply now for DW_TAG_inheritance as for the members and it only
14542 depends on the container kind. */
14544 if (die
->parent
->tag
== DW_TAG_class_type
)
14545 return DW_ACCESS_private
;
14547 return DW_ACCESS_public
;
14551 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14552 offset. If the attribute was not found return 0, otherwise return
14553 1. If it was found but could not properly be handled, set *OFFSET
14557 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14560 struct attribute
*attr
;
14562 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14567 /* Note that we do not check for a section offset first here.
14568 This is because DW_AT_data_member_location is new in DWARF 4,
14569 so if we see it, we can assume that a constant form is really
14570 a constant and not a section offset. */
14571 if (attr
->form_is_constant ())
14572 *offset
= attr
->constant_value (0);
14573 else if (attr
->form_is_section_offset ())
14574 dwarf2_complex_location_expr_complaint ();
14575 else if (attr
->form_is_block ())
14576 *offset
= decode_locdesc (attr
->as_block (), cu
);
14578 dwarf2_complex_location_expr_complaint ();
14586 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14589 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14590 struct field
*field
)
14592 struct attribute
*attr
;
14594 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14597 if (attr
->form_is_constant ())
14599 LONGEST offset
= attr
->constant_value (0);
14600 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14602 else if (attr
->form_is_section_offset ())
14603 dwarf2_complex_location_expr_complaint ();
14604 else if (attr
->form_is_block ())
14607 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14609 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14612 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14613 struct objfile
*objfile
= per_objfile
->objfile
;
14614 struct dwarf2_locexpr_baton
*dlbaton
14615 = XOBNEW (&objfile
->objfile_obstack
,
14616 struct dwarf2_locexpr_baton
);
14617 dlbaton
->data
= attr
->as_block ()->data
;
14618 dlbaton
->size
= attr
->as_block ()->size
;
14619 /* When using this baton, we want to compute the address
14620 of the field, not the value. This is why
14621 is_reference is set to false here. */
14622 dlbaton
->is_reference
= false;
14623 dlbaton
->per_objfile
= per_objfile
;
14624 dlbaton
->per_cu
= cu
->per_cu
;
14626 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14630 dwarf2_complex_location_expr_complaint ();
14634 /* Add an aggregate field to the field list. */
14637 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14638 struct dwarf2_cu
*cu
)
14640 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14641 struct gdbarch
*gdbarch
= objfile
->arch ();
14642 struct nextfield
*new_field
;
14643 struct attribute
*attr
;
14645 const char *fieldname
= "";
14647 if (die
->tag
== DW_TAG_inheritance
)
14649 fip
->baseclasses
.emplace_back ();
14650 new_field
= &fip
->baseclasses
.back ();
14654 fip
->fields
.emplace_back ();
14655 new_field
= &fip
->fields
.back ();
14658 new_field
->offset
= die
->sect_off
;
14660 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14661 if (new_field
->accessibility
!= DW_ACCESS_public
)
14662 fip
->non_public_fields
= true;
14664 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14665 if (attr
!= nullptr)
14666 new_field
->virtuality
= attr
->as_virtuality ();
14668 new_field
->virtuality
= DW_VIRTUALITY_none
;
14670 fp
= &new_field
->field
;
14672 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14674 /* Data member other than a C++ static data member. */
14676 /* Get type of field. */
14677 fp
->set_type (die_type (die
, cu
));
14679 SET_FIELD_BITPOS (*fp
, 0);
14681 /* Get bit size of field (zero if none). */
14682 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14683 if (attr
!= nullptr)
14685 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
14689 FIELD_BITSIZE (*fp
) = 0;
14692 /* Get bit offset of field. */
14693 handle_data_member_location (die
, cu
, fp
);
14694 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14695 if (attr
!= nullptr && attr
->form_is_constant ())
14697 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14699 /* For big endian bits, the DW_AT_bit_offset gives the
14700 additional bit offset from the MSB of the containing
14701 anonymous object to the MSB of the field. We don't
14702 have to do anything special since we don't need to
14703 know the size of the anonymous object. */
14704 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14705 + attr
->constant_value (0)));
14709 /* For little endian bits, compute the bit offset to the
14710 MSB of the anonymous object, subtract off the number of
14711 bits from the MSB of the field to the MSB of the
14712 object, and then subtract off the number of bits of
14713 the field itself. The result is the bit offset of
14714 the LSB of the field. */
14715 int anonymous_size
;
14716 int bit_offset
= attr
->constant_value (0);
14718 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14719 if (attr
!= nullptr && attr
->form_is_constant ())
14721 /* The size of the anonymous object containing
14722 the bit field is explicit, so use the
14723 indicated size (in bytes). */
14724 anonymous_size
= attr
->constant_value (0);
14728 /* The size of the anonymous object containing
14729 the bit field must be inferred from the type
14730 attribute of the data member containing the
14732 anonymous_size
= TYPE_LENGTH (fp
->type ());
14734 SET_FIELD_BITPOS (*fp
,
14735 (FIELD_BITPOS (*fp
)
14736 + anonymous_size
* bits_per_byte
14737 - bit_offset
- FIELD_BITSIZE (*fp
)));
14740 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14742 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14743 + attr
->constant_value (0)));
14745 /* Get name of field. */
14746 fieldname
= dwarf2_name (die
, cu
);
14747 if (fieldname
== NULL
)
14750 /* The name is already allocated along with this objfile, so we don't
14751 need to duplicate it for the type. */
14752 fp
->name
= fieldname
;
14754 /* Change accessibility for artificial fields (e.g. virtual table
14755 pointer or virtual base class pointer) to private. */
14756 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14758 FIELD_ARTIFICIAL (*fp
) = 1;
14759 new_field
->accessibility
= DW_ACCESS_private
;
14760 fip
->non_public_fields
= true;
14763 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14765 /* C++ static member. */
14767 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14768 is a declaration, but all versions of G++ as of this writing
14769 (so through at least 3.2.1) incorrectly generate
14770 DW_TAG_variable tags. */
14772 const char *physname
;
14774 /* Get name of field. */
14775 fieldname
= dwarf2_name (die
, cu
);
14776 if (fieldname
== NULL
)
14779 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14781 /* Only create a symbol if this is an external value.
14782 new_symbol checks this and puts the value in the global symbol
14783 table, which we want. If it is not external, new_symbol
14784 will try to put the value in cu->list_in_scope which is wrong. */
14785 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14787 /* A static const member, not much different than an enum as far as
14788 we're concerned, except that we can support more types. */
14789 new_symbol (die
, NULL
, cu
);
14792 /* Get physical name. */
14793 physname
= dwarf2_physname (fieldname
, die
, cu
);
14795 /* The name is already allocated along with this objfile, so we don't
14796 need to duplicate it for the type. */
14797 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14798 fp
->set_type (die_type (die
, cu
));
14799 FIELD_NAME (*fp
) = fieldname
;
14801 else if (die
->tag
== DW_TAG_inheritance
)
14803 /* C++ base class field. */
14804 handle_data_member_location (die
, cu
, fp
);
14805 FIELD_BITSIZE (*fp
) = 0;
14806 fp
->set_type (die_type (die
, cu
));
14807 FIELD_NAME (*fp
) = fp
->type ()->name ();
14810 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14813 /* Can the type given by DIE define another type? */
14816 type_can_define_types (const struct die_info
*die
)
14820 case DW_TAG_typedef
:
14821 case DW_TAG_class_type
:
14822 case DW_TAG_structure_type
:
14823 case DW_TAG_union_type
:
14824 case DW_TAG_enumeration_type
:
14832 /* Add a type definition defined in the scope of the FIP's class. */
14835 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14836 struct dwarf2_cu
*cu
)
14838 struct decl_field fp
;
14839 memset (&fp
, 0, sizeof (fp
));
14841 gdb_assert (type_can_define_types (die
));
14843 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14844 fp
.name
= dwarf2_name (die
, cu
);
14845 fp
.type
= read_type_die (die
, cu
);
14847 /* Save accessibility. */
14848 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
14849 switch (accessibility
)
14851 case DW_ACCESS_public
:
14852 /* The assumed value if neither private nor protected. */
14854 case DW_ACCESS_private
:
14857 case DW_ACCESS_protected
:
14858 fp
.is_protected
= 1;
14862 if (die
->tag
== DW_TAG_typedef
)
14863 fip
->typedef_field_list
.push_back (fp
);
14865 fip
->nested_types_list
.push_back (fp
);
14868 /* A convenience typedef that's used when finding the discriminant
14869 field for a variant part. */
14870 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14873 /* Compute the discriminant range for a given variant. OBSTACK is
14874 where the results will be stored. VARIANT is the variant to
14875 process. IS_UNSIGNED indicates whether the discriminant is signed
14878 static const gdb::array_view
<discriminant_range
>
14879 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14882 std::vector
<discriminant_range
> ranges
;
14884 if (variant
.default_branch
)
14887 if (variant
.discr_list_data
== nullptr)
14889 discriminant_range r
14890 = {variant
.discriminant_value
, variant
.discriminant_value
};
14891 ranges
.push_back (r
);
14895 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14896 variant
.discr_list_data
->size
);
14897 while (!data
.empty ())
14899 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14901 complaint (_("invalid discriminant marker: %d"), data
[0]);
14904 bool is_range
= data
[0] == DW_DSC_range
;
14905 data
= data
.slice (1);
14907 ULONGEST low
, high
;
14908 unsigned int bytes_read
;
14912 complaint (_("DW_AT_discr_list missing low value"));
14916 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14918 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14920 data
= data
.slice (bytes_read
);
14926 complaint (_("DW_AT_discr_list missing high value"));
14930 high
= read_unsigned_leb128 (nullptr, data
.data (),
14933 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14935 data
= data
.slice (bytes_read
);
14940 ranges
.push_back ({ low
, high
});
14944 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14946 std::copy (ranges
.begin (), ranges
.end (), result
);
14947 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14950 static const gdb::array_view
<variant_part
> create_variant_parts
14951 (struct obstack
*obstack
,
14952 const offset_map_type
&offset_map
,
14953 struct field_info
*fi
,
14954 const std::vector
<variant_part_builder
> &variant_parts
);
14956 /* Fill in a "struct variant" for a given variant field. RESULT is
14957 the variant to fill in. OBSTACK is where any needed allocations
14958 will be done. OFFSET_MAP holds the mapping from section offsets to
14959 fields for the type. FI describes the fields of the type we're
14960 processing. FIELD is the variant field we're converting. */
14963 create_one_variant (variant
&result
, struct obstack
*obstack
,
14964 const offset_map_type
&offset_map
,
14965 struct field_info
*fi
, const variant_field
&field
)
14967 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14968 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14969 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14970 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14971 field
.variant_parts
);
14974 /* Fill in a "struct variant_part" for a given variant part. RESULT
14975 is the variant part to fill in. OBSTACK is where any needed
14976 allocations will be done. OFFSET_MAP holds the mapping from
14977 section offsets to fields for the type. FI describes the fields of
14978 the type we're processing. BUILDER is the variant part to be
14982 create_one_variant_part (variant_part
&result
,
14983 struct obstack
*obstack
,
14984 const offset_map_type
&offset_map
,
14985 struct field_info
*fi
,
14986 const variant_part_builder
&builder
)
14988 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14989 if (iter
== offset_map
.end ())
14991 result
.discriminant_index
= -1;
14992 /* Doesn't matter. */
14993 result
.is_unsigned
= false;
14997 result
.discriminant_index
= iter
->second
;
14999 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
15002 size_t n
= builder
.variants
.size ();
15003 variant
*output
= new (obstack
) variant
[n
];
15004 for (size_t i
= 0; i
< n
; ++i
)
15005 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
15006 builder
.variants
[i
]);
15008 result
.variants
= gdb::array_view
<variant
> (output
, n
);
15011 /* Create a vector of variant parts that can be attached to a type.
15012 OBSTACK is where any needed allocations will be done. OFFSET_MAP
15013 holds the mapping from section offsets to fields for the type. FI
15014 describes the fields of the type we're processing. VARIANT_PARTS
15015 is the vector to convert. */
15017 static const gdb::array_view
<variant_part
>
15018 create_variant_parts (struct obstack
*obstack
,
15019 const offset_map_type
&offset_map
,
15020 struct field_info
*fi
,
15021 const std::vector
<variant_part_builder
> &variant_parts
)
15023 if (variant_parts
.empty ())
15026 size_t n
= variant_parts
.size ();
15027 variant_part
*result
= new (obstack
) variant_part
[n
];
15028 for (size_t i
= 0; i
< n
; ++i
)
15029 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
15032 return gdb::array_view
<variant_part
> (result
, n
);
15035 /* Compute the variant part vector for FIP, attaching it to TYPE when
15039 add_variant_property (struct field_info
*fip
, struct type
*type
,
15040 struct dwarf2_cu
*cu
)
15042 /* Map section offsets of fields to their field index. Note the
15043 field index here does not take the number of baseclasses into
15045 offset_map_type offset_map
;
15046 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
15047 offset_map
[fip
->fields
[i
].offset
] = i
;
15049 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15050 gdb::array_view
<variant_part
> parts
15051 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
15052 fip
->variant_parts
);
15054 struct dynamic_prop prop
;
15055 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
15056 obstack_copy (&objfile
->objfile_obstack
, &parts
,
15059 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
15062 /* Create the vector of fields, and attach it to the type. */
15065 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15066 struct dwarf2_cu
*cu
)
15068 int nfields
= fip
->nfields ();
15070 /* Record the field count, allocate space for the array of fields,
15071 and create blank accessibility bitfields if necessary. */
15072 type
->set_num_fields (nfields
);
15074 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
15076 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15078 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15080 TYPE_FIELD_PRIVATE_BITS (type
) =
15081 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15082 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15084 TYPE_FIELD_PROTECTED_BITS (type
) =
15085 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15086 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15088 TYPE_FIELD_IGNORE_BITS (type
) =
15089 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15090 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15093 /* If the type has baseclasses, allocate and clear a bit vector for
15094 TYPE_FIELD_VIRTUAL_BITS. */
15095 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15097 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15098 unsigned char *pointer
;
15100 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15101 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15102 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15103 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15104 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15107 if (!fip
->variant_parts
.empty ())
15108 add_variant_property (fip
, type
, cu
);
15110 /* Copy the saved-up fields into the field vector. */
15111 for (int i
= 0; i
< nfields
; ++i
)
15113 struct nextfield
&field
15114 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15115 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15117 type
->field (i
) = field
.field
;
15118 switch (field
.accessibility
)
15120 case DW_ACCESS_private
:
15121 if (cu
->language
!= language_ada
)
15122 SET_TYPE_FIELD_PRIVATE (type
, i
);
15125 case DW_ACCESS_protected
:
15126 if (cu
->language
!= language_ada
)
15127 SET_TYPE_FIELD_PROTECTED (type
, i
);
15130 case DW_ACCESS_public
:
15134 /* Unknown accessibility. Complain and treat it as public. */
15136 complaint (_("unsupported accessibility %d"),
15137 field
.accessibility
);
15141 if (i
< fip
->baseclasses
.size ())
15143 switch (field
.virtuality
)
15145 case DW_VIRTUALITY_virtual
:
15146 case DW_VIRTUALITY_pure_virtual
:
15147 if (cu
->language
== language_ada
)
15148 error (_("unexpected virtuality in component of Ada type"));
15149 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15156 /* Return true if this member function is a constructor, false
15160 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15162 const char *fieldname
;
15163 const char *type_name
;
15166 if (die
->parent
== NULL
)
15169 if (die
->parent
->tag
!= DW_TAG_structure_type
15170 && die
->parent
->tag
!= DW_TAG_union_type
15171 && die
->parent
->tag
!= DW_TAG_class_type
)
15174 fieldname
= dwarf2_name (die
, cu
);
15175 type_name
= dwarf2_name (die
->parent
, cu
);
15176 if (fieldname
== NULL
|| type_name
== NULL
)
15179 len
= strlen (fieldname
);
15180 return (strncmp (fieldname
, type_name
, len
) == 0
15181 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15184 /* Add a member function to the proper fieldlist. */
15187 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15188 struct type
*type
, struct dwarf2_cu
*cu
)
15190 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15191 struct attribute
*attr
;
15193 struct fnfieldlist
*flp
= nullptr;
15194 struct fn_field
*fnp
;
15195 const char *fieldname
;
15196 struct type
*this_type
;
15198 if (cu
->language
== language_ada
)
15199 error (_("unexpected member function in Ada type"));
15201 /* Get name of member function. */
15202 fieldname
= dwarf2_name (die
, cu
);
15203 if (fieldname
== NULL
)
15206 /* Look up member function name in fieldlist. */
15207 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15209 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15211 flp
= &fip
->fnfieldlists
[i
];
15216 /* Create a new fnfieldlist if necessary. */
15217 if (flp
== nullptr)
15219 fip
->fnfieldlists
.emplace_back ();
15220 flp
= &fip
->fnfieldlists
.back ();
15221 flp
->name
= fieldname
;
15222 i
= fip
->fnfieldlists
.size () - 1;
15225 /* Create a new member function field and add it to the vector of
15227 flp
->fnfields
.emplace_back ();
15228 fnp
= &flp
->fnfields
.back ();
15230 /* Delay processing of the physname until later. */
15231 if (cu
->language
== language_cplus
)
15232 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15236 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15237 fnp
->physname
= physname
? physname
: "";
15240 fnp
->type
= alloc_type (objfile
);
15241 this_type
= read_type_die (die
, cu
);
15242 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15244 int nparams
= this_type
->num_fields ();
15246 /* TYPE is the domain of this method, and THIS_TYPE is the type
15247 of the method itself (TYPE_CODE_METHOD). */
15248 smash_to_method_type (fnp
->type
, type
,
15249 TYPE_TARGET_TYPE (this_type
),
15250 this_type
->fields (),
15251 this_type
->num_fields (),
15252 this_type
->has_varargs ());
15254 /* Handle static member functions.
15255 Dwarf2 has no clean way to discern C++ static and non-static
15256 member functions. G++ helps GDB by marking the first
15257 parameter for non-static member functions (which is the this
15258 pointer) as artificial. We obtain this information from
15259 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15260 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15261 fnp
->voffset
= VOFFSET_STATIC
;
15264 complaint (_("member function type missing for '%s'"),
15265 dwarf2_full_name (fieldname
, die
, cu
));
15267 /* Get fcontext from DW_AT_containing_type if present. */
15268 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15269 fnp
->fcontext
= die_containing_type (die
, cu
);
15271 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15272 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15274 /* Get accessibility. */
15275 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15276 switch (accessibility
)
15278 case DW_ACCESS_private
:
15279 fnp
->is_private
= 1;
15281 case DW_ACCESS_protected
:
15282 fnp
->is_protected
= 1;
15286 /* Check for artificial methods. */
15287 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15288 if (attr
&& attr
->as_boolean ())
15289 fnp
->is_artificial
= 1;
15291 /* Check for defaulted methods. */
15292 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15293 if (attr
!= nullptr)
15294 fnp
->defaulted
= attr
->defaulted ();
15296 /* Check for deleted methods. */
15297 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15298 if (attr
!= nullptr && attr
->as_boolean ())
15299 fnp
->is_deleted
= 1;
15301 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15303 /* Get index in virtual function table if it is a virtual member
15304 function. For older versions of GCC, this is an offset in the
15305 appropriate virtual table, as specified by DW_AT_containing_type.
15306 For everyone else, it is an expression to be evaluated relative
15307 to the object address. */
15309 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15310 if (attr
!= nullptr)
15312 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15314 struct dwarf_block
*block
= attr
->as_block ();
15316 if (block
->data
[0] == DW_OP_constu
)
15318 /* Old-style GCC. */
15319 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15321 else if (block
->data
[0] == DW_OP_deref
15322 || (block
->size
> 1
15323 && block
->data
[0] == DW_OP_deref_size
15324 && block
->data
[1] == cu
->header
.addr_size
))
15326 fnp
->voffset
= decode_locdesc (block
, cu
);
15327 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15328 dwarf2_complex_location_expr_complaint ();
15330 fnp
->voffset
/= cu
->header
.addr_size
;
15334 dwarf2_complex_location_expr_complaint ();
15336 if (!fnp
->fcontext
)
15338 /* If there is no `this' field and no DW_AT_containing_type,
15339 we cannot actually find a base class context for the
15341 if (this_type
->num_fields () == 0
15342 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15344 complaint (_("cannot determine context for virtual member "
15345 "function \"%s\" (offset %s)"),
15346 fieldname
, sect_offset_str (die
->sect_off
));
15351 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15355 else if (attr
->form_is_section_offset ())
15357 dwarf2_complex_location_expr_complaint ();
15361 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15367 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15368 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15370 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15371 complaint (_("Member function \"%s\" (offset %s) is virtual "
15372 "but the vtable offset is not specified"),
15373 fieldname
, sect_offset_str (die
->sect_off
));
15374 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15375 TYPE_CPLUS_DYNAMIC (type
) = 1;
15380 /* Create the vector of member function fields, and attach it to the type. */
15383 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15384 struct dwarf2_cu
*cu
)
15386 if (cu
->language
== language_ada
)
15387 error (_("unexpected member functions in Ada type"));
15389 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15390 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15392 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15394 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15396 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15397 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15399 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15400 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15401 fn_flp
->fn_fields
= (struct fn_field
*)
15402 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15404 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15405 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15408 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15411 /* Returns non-zero if NAME is the name of a vtable member in CU's
15412 language, zero otherwise. */
15414 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15416 static const char vptr
[] = "_vptr";
15418 /* Look for the C++ form of the vtable. */
15419 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15425 /* GCC outputs unnamed structures that are really pointers to member
15426 functions, with the ABI-specified layout. If TYPE describes
15427 such a structure, smash it into a member function type.
15429 GCC shouldn't do this; it should just output pointer to member DIEs.
15430 This is GCC PR debug/28767. */
15433 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15435 struct type
*pfn_type
, *self_type
, *new_type
;
15437 /* Check for a structure with no name and two children. */
15438 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15441 /* Check for __pfn and __delta members. */
15442 if (TYPE_FIELD_NAME (type
, 0) == NULL
15443 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15444 || TYPE_FIELD_NAME (type
, 1) == NULL
15445 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15448 /* Find the type of the method. */
15449 pfn_type
= type
->field (0).type ();
15450 if (pfn_type
== NULL
15451 || pfn_type
->code () != TYPE_CODE_PTR
15452 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15455 /* Look for the "this" argument. */
15456 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15457 if (pfn_type
->num_fields () == 0
15458 /* || pfn_type->field (0).type () == NULL */
15459 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15462 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15463 new_type
= alloc_type (objfile
);
15464 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15465 pfn_type
->fields (), pfn_type
->num_fields (),
15466 pfn_type
->has_varargs ());
15467 smash_to_methodptr_type (type
, new_type
);
15470 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15471 requires rewriting, then copy it and return the updated copy.
15472 Otherwise return nullptr. */
15474 static struct type
*
15475 rewrite_array_type (struct type
*type
)
15477 if (type
->code () != TYPE_CODE_ARRAY
)
15480 struct type
*index_type
= type
->index_type ();
15481 range_bounds
*current_bounds
= index_type
->bounds ();
15483 /* Handle multi-dimensional arrays. */
15484 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15485 if (new_target
== nullptr)
15487 /* Maybe we don't need to rewrite this array. */
15488 if (current_bounds
->low
.kind () == PROP_CONST
15489 && current_bounds
->high
.kind () == PROP_CONST
)
15493 /* Either the target type was rewritten, or the bounds have to be
15494 updated. Either way we want to copy the type and update
15496 struct type
*copy
= copy_type (type
);
15497 int nfields
= copy
->num_fields ();
15499 = ((struct field
*) TYPE_ZALLOC (copy
,
15500 nfields
* sizeof (struct field
)));
15501 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15502 copy
->set_fields (new_fields
);
15503 if (new_target
!= nullptr)
15504 TYPE_TARGET_TYPE (copy
) = new_target
;
15506 struct type
*index_copy
= copy_type (index_type
);
15507 range_bounds
*bounds
15508 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15509 sizeof (range_bounds
));
15510 *bounds
= *current_bounds
;
15511 bounds
->low
.set_const_val (1);
15512 bounds
->high
.set_const_val (0);
15513 index_copy
->set_bounds (bounds
);
15514 copy
->set_index_type (index_copy
);
15519 /* While some versions of GCC will generate complicated DWARF for an
15520 array (see quirk_ada_thick_pointer), more recent versions were
15521 modified to emit an explicit thick pointer structure. However, in
15522 this case, the array still has DWARF expressions for its ranges,
15523 and these must be ignored. */
15526 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15529 gdb_assert (cu
->language
== language_ada
);
15531 /* Check for a structure with two children. */
15532 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15535 /* Check for P_ARRAY and P_BOUNDS members. */
15536 if (TYPE_FIELD_NAME (type
, 0) == NULL
15537 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
15538 || TYPE_FIELD_NAME (type
, 1) == NULL
15539 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
15542 /* Make sure we're looking at a pointer to an array. */
15543 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15546 /* The Ada code already knows how to handle these types, so all that
15547 we need to do is turn the bounds into static bounds. However, we
15548 don't want to rewrite existing array or index types in-place,
15549 because those may be referenced in other contexts where this
15550 rewriting is undesirable. */
15551 struct type
*new_ary_type
15552 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15553 if (new_ary_type
!= nullptr)
15554 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15557 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15558 appropriate error checking and issuing complaints if there is a
15562 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15564 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15566 if (attr
== nullptr)
15569 if (!attr
->form_is_constant ())
15571 complaint (_("DW_AT_alignment must have constant form"
15572 " - DIE at %s [in module %s]"),
15573 sect_offset_str (die
->sect_off
),
15574 objfile_name (cu
->per_objfile
->objfile
));
15578 LONGEST val
= attr
->constant_value (0);
15581 complaint (_("DW_AT_alignment value must not be negative"
15582 " - DIE at %s [in module %s]"),
15583 sect_offset_str (die
->sect_off
),
15584 objfile_name (cu
->per_objfile
->objfile
));
15587 ULONGEST align
= val
;
15591 complaint (_("DW_AT_alignment value must not be zero"
15592 " - DIE at %s [in module %s]"),
15593 sect_offset_str (die
->sect_off
),
15594 objfile_name (cu
->per_objfile
->objfile
));
15597 if ((align
& (align
- 1)) != 0)
15599 complaint (_("DW_AT_alignment value must be a power of 2"
15600 " - DIE at %s [in module %s]"),
15601 sect_offset_str (die
->sect_off
),
15602 objfile_name (cu
->per_objfile
->objfile
));
15609 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15610 the alignment for TYPE. */
15613 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15616 if (!set_type_align (type
, get_alignment (cu
, die
)))
15617 complaint (_("DW_AT_alignment value too large"
15618 " - DIE at %s [in module %s]"),
15619 sect_offset_str (die
->sect_off
),
15620 objfile_name (cu
->per_objfile
->objfile
));
15623 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15624 constant for a type, according to DWARF5 spec, Table 5.5. */
15627 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15632 case DW_CC_pass_by_reference
:
15633 case DW_CC_pass_by_value
:
15637 complaint (_("unrecognized DW_AT_calling_convention value "
15638 "(%s) for a type"), pulongest (value
));
15643 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15644 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15645 also according to GNU-specific values (see include/dwarf2.h). */
15648 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15653 case DW_CC_program
:
15657 case DW_CC_GNU_renesas_sh
:
15658 case DW_CC_GNU_borland_fastcall_i386
:
15659 case DW_CC_GDB_IBM_OpenCL
:
15663 complaint (_("unrecognized DW_AT_calling_convention value "
15664 "(%s) for a subroutine"), pulongest (value
));
15669 /* Called when we find the DIE that starts a structure or union scope
15670 (definition) to create a type for the structure or union. Fill in
15671 the type's name and general properties; the members will not be
15672 processed until process_structure_scope. A symbol table entry for
15673 the type will also not be done until process_structure_scope (assuming
15674 the type has a name).
15676 NOTE: we need to call these functions regardless of whether or not the
15677 DIE has a DW_AT_name attribute, since it might be an anonymous
15678 structure or union. This gets the type entered into our set of
15679 user defined types. */
15681 static struct type
*
15682 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15684 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15686 struct attribute
*attr
;
15689 /* If the definition of this type lives in .debug_types, read that type.
15690 Don't follow DW_AT_specification though, that will take us back up
15691 the chain and we want to go down. */
15692 attr
= die
->attr (DW_AT_signature
);
15693 if (attr
!= nullptr)
15695 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15697 /* The type's CU may not be the same as CU.
15698 Ensure TYPE is recorded with CU in die_type_hash. */
15699 return set_die_type (die
, type
, cu
);
15702 type
= alloc_type (objfile
);
15703 INIT_CPLUS_SPECIFIC (type
);
15705 name
= dwarf2_name (die
, cu
);
15708 if (cu
->language
== language_cplus
15709 || cu
->language
== language_d
15710 || cu
->language
== language_rust
)
15712 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15714 /* dwarf2_full_name might have already finished building the DIE's
15715 type. If so, there is no need to continue. */
15716 if (get_die_type (die
, cu
) != NULL
)
15717 return get_die_type (die
, cu
);
15719 type
->set_name (full_name
);
15723 /* The name is already allocated along with this objfile, so
15724 we don't need to duplicate it for the type. */
15725 type
->set_name (name
);
15729 if (die
->tag
== DW_TAG_structure_type
)
15731 type
->set_code (TYPE_CODE_STRUCT
);
15733 else if (die
->tag
== DW_TAG_union_type
)
15735 type
->set_code (TYPE_CODE_UNION
);
15739 type
->set_code (TYPE_CODE_STRUCT
);
15742 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15743 type
->set_is_declared_class (true);
15745 /* Store the calling convention in the type if it's available in
15746 the die. Otherwise the calling convention remains set to
15747 the default value DW_CC_normal. */
15748 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15749 if (attr
!= nullptr
15750 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
15752 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15753 TYPE_CPLUS_CALLING_CONVENTION (type
)
15754 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
15757 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15758 if (attr
!= nullptr)
15760 if (attr
->form_is_constant ())
15761 TYPE_LENGTH (type
) = attr
->constant_value (0);
15764 struct dynamic_prop prop
;
15765 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15766 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15767 TYPE_LENGTH (type
) = 0;
15772 TYPE_LENGTH (type
) = 0;
15775 maybe_set_alignment (cu
, die
, type
);
15777 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15779 /* ICC<14 does not output the required DW_AT_declaration on
15780 incomplete types, but gives them a size of zero. */
15781 type
->set_is_stub (true);
15784 type
->set_stub_is_supported (true);
15786 if (die_is_declaration (die
, cu
))
15787 type
->set_is_stub (true);
15788 else if (attr
== NULL
&& die
->child
== NULL
15789 && producer_is_realview (cu
->producer
))
15790 /* RealView does not output the required DW_AT_declaration
15791 on incomplete types. */
15792 type
->set_is_stub (true);
15794 /* We need to add the type field to the die immediately so we don't
15795 infinitely recurse when dealing with pointers to the structure
15796 type within the structure itself. */
15797 set_die_type (die
, type
, cu
);
15799 /* set_die_type should be already done. */
15800 set_descriptive_type (type
, die
, cu
);
15805 static void handle_struct_member_die
15806 (struct die_info
*child_die
,
15808 struct field_info
*fi
,
15809 std::vector
<struct symbol
*> *template_args
,
15810 struct dwarf2_cu
*cu
);
15812 /* A helper for handle_struct_member_die that handles
15813 DW_TAG_variant_part. */
15816 handle_variant_part (struct die_info
*die
, struct type
*type
,
15817 struct field_info
*fi
,
15818 std::vector
<struct symbol
*> *template_args
,
15819 struct dwarf2_cu
*cu
)
15821 variant_part_builder
*new_part
;
15822 if (fi
->current_variant_part
== nullptr)
15824 fi
->variant_parts
.emplace_back ();
15825 new_part
= &fi
->variant_parts
.back ();
15827 else if (!fi
->current_variant_part
->processing_variant
)
15829 complaint (_("nested DW_TAG_variant_part seen "
15830 "- DIE at %s [in module %s]"),
15831 sect_offset_str (die
->sect_off
),
15832 objfile_name (cu
->per_objfile
->objfile
));
15837 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15838 current
.variant_parts
.emplace_back ();
15839 new_part
= ¤t
.variant_parts
.back ();
15842 /* When we recurse, we want callees to add to this new variant
15844 scoped_restore save_current_variant_part
15845 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15847 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15850 /* It's a univariant form, an extension we support. */
15852 else if (discr
->form_is_ref ())
15854 struct dwarf2_cu
*target_cu
= cu
;
15855 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15857 new_part
->discriminant_offset
= target_die
->sect_off
;
15861 complaint (_("DW_AT_discr does not have DIE reference form"
15862 " - DIE at %s [in module %s]"),
15863 sect_offset_str (die
->sect_off
),
15864 objfile_name (cu
->per_objfile
->objfile
));
15867 for (die_info
*child_die
= die
->child
;
15869 child_die
= child_die
->sibling
)
15870 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15873 /* A helper for handle_struct_member_die that handles
15877 handle_variant (struct die_info
*die
, struct type
*type
,
15878 struct field_info
*fi
,
15879 std::vector
<struct symbol
*> *template_args
,
15880 struct dwarf2_cu
*cu
)
15882 if (fi
->current_variant_part
== nullptr)
15884 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15885 "- DIE at %s [in module %s]"),
15886 sect_offset_str (die
->sect_off
),
15887 objfile_name (cu
->per_objfile
->objfile
));
15890 if (fi
->current_variant_part
->processing_variant
)
15892 complaint (_("nested DW_TAG_variant seen "
15893 "- DIE at %s [in module %s]"),
15894 sect_offset_str (die
->sect_off
),
15895 objfile_name (cu
->per_objfile
->objfile
));
15899 scoped_restore save_processing_variant
15900 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15903 fi
->current_variant_part
->variants
.emplace_back ();
15904 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15905 variant
.first_field
= fi
->fields
.size ();
15907 /* In a variant we want to get the discriminant and also add a
15908 field for our sole member child. */
15909 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15910 if (discr
== nullptr || !discr
->form_is_constant ())
15912 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15913 if (discr
== nullptr || discr
->as_block ()->size
== 0)
15914 variant
.default_branch
= true;
15916 variant
.discr_list_data
= discr
->as_block ();
15919 variant
.discriminant_value
= discr
->constant_value (0);
15921 for (die_info
*variant_child
= die
->child
;
15922 variant_child
!= NULL
;
15923 variant_child
= variant_child
->sibling
)
15924 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15926 variant
.last_field
= fi
->fields
.size ();
15929 /* A helper for process_structure_scope that handles a single member
15933 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15934 struct field_info
*fi
,
15935 std::vector
<struct symbol
*> *template_args
,
15936 struct dwarf2_cu
*cu
)
15938 if (child_die
->tag
== DW_TAG_member
15939 || child_die
->tag
== DW_TAG_variable
)
15941 /* NOTE: carlton/2002-11-05: A C++ static data member
15942 should be a DW_TAG_member that is a declaration, but
15943 all versions of G++ as of this writing (so through at
15944 least 3.2.1) incorrectly generate DW_TAG_variable
15945 tags for them instead. */
15946 dwarf2_add_field (fi
, child_die
, cu
);
15948 else if (child_die
->tag
== DW_TAG_subprogram
)
15950 /* Rust doesn't have member functions in the C++ sense.
15951 However, it does emit ordinary functions as children
15952 of a struct DIE. */
15953 if (cu
->language
== language_rust
)
15954 read_func_scope (child_die
, cu
);
15957 /* C++ member function. */
15958 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15961 else if (child_die
->tag
== DW_TAG_inheritance
)
15963 /* C++ base class field. */
15964 dwarf2_add_field (fi
, child_die
, cu
);
15966 else if (type_can_define_types (child_die
))
15967 dwarf2_add_type_defn (fi
, child_die
, cu
);
15968 else if (child_die
->tag
== DW_TAG_template_type_param
15969 || child_die
->tag
== DW_TAG_template_value_param
)
15971 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15974 template_args
->push_back (arg
);
15976 else if (child_die
->tag
== DW_TAG_variant_part
)
15977 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15978 else if (child_die
->tag
== DW_TAG_variant
)
15979 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15982 /* Finish creating a structure or union type, including filling in
15983 its members and creating a symbol for it. */
15986 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15988 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15989 struct die_info
*child_die
;
15992 type
= get_die_type (die
, cu
);
15994 type
= read_structure_type (die
, cu
);
15996 bool has_template_parameters
= false;
15997 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15999 struct field_info fi
;
16000 std::vector
<struct symbol
*> template_args
;
16002 child_die
= die
->child
;
16004 while (child_die
&& child_die
->tag
)
16006 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16007 child_die
= child_die
->sibling
;
16010 /* Attach template arguments to type. */
16011 if (!template_args
.empty ())
16013 has_template_parameters
= true;
16014 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16015 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16016 TYPE_TEMPLATE_ARGUMENTS (type
)
16017 = XOBNEWVEC (&objfile
->objfile_obstack
,
16019 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16020 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16021 template_args
.data (),
16022 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16023 * sizeof (struct symbol
*)));
16026 /* Attach fields and member functions to the type. */
16027 if (fi
.nfields () > 0)
16028 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16029 if (!fi
.fnfieldlists
.empty ())
16031 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16033 /* Get the type which refers to the base class (possibly this
16034 class itself) which contains the vtable pointer for the current
16035 class from the DW_AT_containing_type attribute. This use of
16036 DW_AT_containing_type is a GNU extension. */
16038 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16040 struct type
*t
= die_containing_type (die
, cu
);
16042 set_type_vptr_basetype (type
, t
);
16047 /* Our own class provides vtbl ptr. */
16048 for (i
= t
->num_fields () - 1;
16049 i
>= TYPE_N_BASECLASSES (t
);
16052 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16054 if (is_vtable_name (fieldname
, cu
))
16056 set_type_vptr_fieldno (type
, i
);
16061 /* Complain if virtual function table field not found. */
16062 if (i
< TYPE_N_BASECLASSES (t
))
16063 complaint (_("virtual function table pointer "
16064 "not found when defining class '%s'"),
16065 type
->name () ? type
->name () : "");
16069 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16072 else if (cu
->producer
16073 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16075 /* The IBM XLC compiler does not provide direct indication
16076 of the containing type, but the vtable pointer is
16077 always named __vfp. */
16081 for (i
= type
->num_fields () - 1;
16082 i
>= TYPE_N_BASECLASSES (type
);
16085 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16087 set_type_vptr_fieldno (type
, i
);
16088 set_type_vptr_basetype (type
, type
);
16095 /* Copy fi.typedef_field_list linked list elements content into the
16096 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16097 if (!fi
.typedef_field_list
.empty ())
16099 int count
= fi
.typedef_field_list
.size ();
16101 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16102 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16103 = ((struct decl_field
*)
16105 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16106 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16108 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16109 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16112 /* Copy fi.nested_types_list linked list elements content into the
16113 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16114 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16116 int count
= fi
.nested_types_list
.size ();
16118 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16119 TYPE_NESTED_TYPES_ARRAY (type
)
16120 = ((struct decl_field
*)
16121 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16122 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16124 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16125 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16129 quirk_gcc_member_function_pointer (type
, objfile
);
16130 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16131 cu
->rust_unions
.push_back (type
);
16132 else if (cu
->language
== language_ada
)
16133 quirk_ada_thick_pointer_struct (die
, cu
, type
);
16135 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16136 snapshots) has been known to create a die giving a declaration
16137 for a class that has, as a child, a die giving a definition for a
16138 nested class. So we have to process our children even if the
16139 current die is a declaration. Normally, of course, a declaration
16140 won't have any children at all. */
16142 child_die
= die
->child
;
16144 while (child_die
!= NULL
&& child_die
->tag
)
16146 if (child_die
->tag
== DW_TAG_member
16147 || child_die
->tag
== DW_TAG_variable
16148 || child_die
->tag
== DW_TAG_inheritance
16149 || child_die
->tag
== DW_TAG_template_value_param
16150 || child_die
->tag
== DW_TAG_template_type_param
)
16155 process_die (child_die
, cu
);
16157 child_die
= child_die
->sibling
;
16160 /* Do not consider external references. According to the DWARF standard,
16161 these DIEs are identified by the fact that they have no byte_size
16162 attribute, and a declaration attribute. */
16163 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16164 || !die_is_declaration (die
, cu
)
16165 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16167 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16169 if (has_template_parameters
)
16171 struct symtab
*symtab
;
16172 if (sym
!= nullptr)
16173 symtab
= symbol_symtab (sym
);
16174 else if (cu
->line_header
!= nullptr)
16176 /* Any related symtab will do. */
16178 = cu
->line_header
->file_names ()[0].symtab
;
16183 complaint (_("could not find suitable "
16184 "symtab for template parameter"
16185 " - DIE at %s [in module %s]"),
16186 sect_offset_str (die
->sect_off
),
16187 objfile_name (objfile
));
16190 if (symtab
!= nullptr)
16192 /* Make sure that the symtab is set on the new symbols.
16193 Even though they don't appear in this symtab directly,
16194 other parts of gdb assume that symbols do, and this is
16195 reasonably true. */
16196 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16197 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16203 /* Assuming DIE is an enumeration type, and TYPE is its associated
16204 type, update TYPE using some information only available in DIE's
16205 children. In particular, the fields are computed. */
16208 update_enumeration_type_from_children (struct die_info
*die
,
16210 struct dwarf2_cu
*cu
)
16212 struct die_info
*child_die
;
16213 int unsigned_enum
= 1;
16216 auto_obstack obstack
;
16217 std::vector
<struct field
> fields
;
16219 for (child_die
= die
->child
;
16220 child_die
!= NULL
&& child_die
->tag
;
16221 child_die
= child_die
->sibling
)
16223 struct attribute
*attr
;
16225 const gdb_byte
*bytes
;
16226 struct dwarf2_locexpr_baton
*baton
;
16229 if (child_die
->tag
!= DW_TAG_enumerator
)
16232 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16236 name
= dwarf2_name (child_die
, cu
);
16238 name
= "<anonymous enumerator>";
16240 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16241 &value
, &bytes
, &baton
);
16249 if (count_one_bits_ll (value
) >= 2)
16253 fields
.emplace_back ();
16254 struct field
&field
= fields
.back ();
16255 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16256 SET_FIELD_ENUMVAL (field
, value
);
16259 if (!fields
.empty ())
16261 type
->set_num_fields (fields
.size ());
16264 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16265 memcpy (type
->fields (), fields
.data (),
16266 sizeof (struct field
) * fields
.size ());
16270 type
->set_is_unsigned (true);
16273 type
->set_is_flag_enum (true);
16276 /* Given a DW_AT_enumeration_type die, set its type. We do not
16277 complete the type's fields yet, or create any symbols. */
16279 static struct type
*
16280 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16282 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16284 struct attribute
*attr
;
16287 /* If the definition of this type lives in .debug_types, read that type.
16288 Don't follow DW_AT_specification though, that will take us back up
16289 the chain and we want to go down. */
16290 attr
= die
->attr (DW_AT_signature
);
16291 if (attr
!= nullptr)
16293 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16295 /* The type's CU may not be the same as CU.
16296 Ensure TYPE is recorded with CU in die_type_hash. */
16297 return set_die_type (die
, type
, cu
);
16300 type
= alloc_type (objfile
);
16302 type
->set_code (TYPE_CODE_ENUM
);
16303 name
= dwarf2_full_name (NULL
, die
, cu
);
16305 type
->set_name (name
);
16307 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16310 struct type
*underlying_type
= die_type (die
, cu
);
16312 TYPE_TARGET_TYPE (type
) = underlying_type
;
16315 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16316 if (attr
!= nullptr)
16318 TYPE_LENGTH (type
) = attr
->constant_value (0);
16322 TYPE_LENGTH (type
) = 0;
16325 maybe_set_alignment (cu
, die
, type
);
16327 /* The enumeration DIE can be incomplete. In Ada, any type can be
16328 declared as private in the package spec, and then defined only
16329 inside the package body. Such types are known as Taft Amendment
16330 Types. When another package uses such a type, an incomplete DIE
16331 may be generated by the compiler. */
16332 if (die_is_declaration (die
, cu
))
16333 type
->set_is_stub (true);
16335 /* If this type has an underlying type that is not a stub, then we
16336 may use its attributes. We always use the "unsigned" attribute
16337 in this situation, because ordinarily we guess whether the type
16338 is unsigned -- but the guess can be wrong and the underlying type
16339 can tell us the reality. However, we defer to a local size
16340 attribute if one exists, because this lets the compiler override
16341 the underlying type if needed. */
16342 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16344 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16345 underlying_type
= check_typedef (underlying_type
);
16347 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16349 if (TYPE_LENGTH (type
) == 0)
16350 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16352 if (TYPE_RAW_ALIGN (type
) == 0
16353 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16354 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16357 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
16359 set_die_type (die
, type
, cu
);
16361 /* Finish the creation of this type by using the enum's children.
16362 Note that, as usual, this must come after set_die_type to avoid
16363 infinite recursion when trying to compute the names of the
16365 update_enumeration_type_from_children (die
, type
, cu
);
16370 /* Given a pointer to a die which begins an enumeration, process all
16371 the dies that define the members of the enumeration, and create the
16372 symbol for the enumeration type.
16374 NOTE: We reverse the order of the element list. */
16377 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16379 struct type
*this_type
;
16381 this_type
= get_die_type (die
, cu
);
16382 if (this_type
== NULL
)
16383 this_type
= read_enumeration_type (die
, cu
);
16385 if (die
->child
!= NULL
)
16387 struct die_info
*child_die
;
16390 child_die
= die
->child
;
16391 while (child_die
&& child_die
->tag
)
16393 if (child_die
->tag
!= DW_TAG_enumerator
)
16395 process_die (child_die
, cu
);
16399 name
= dwarf2_name (child_die
, cu
);
16401 new_symbol (child_die
, this_type
, cu
);
16404 child_die
= child_die
->sibling
;
16408 /* If we are reading an enum from a .debug_types unit, and the enum
16409 is a declaration, and the enum is not the signatured type in the
16410 unit, then we do not want to add a symbol for it. Adding a
16411 symbol would in some cases obscure the true definition of the
16412 enum, giving users an incomplete type when the definition is
16413 actually available. Note that we do not want to do this for all
16414 enums which are just declarations, because C++0x allows forward
16415 enum declarations. */
16416 if (cu
->per_cu
->is_debug_types
16417 && die_is_declaration (die
, cu
))
16419 struct signatured_type
*sig_type
;
16421 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16422 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16423 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16427 new_symbol (die
, this_type
, cu
);
16430 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16431 expression for an index type and finds the corresponding field
16432 offset in the hidden "P_BOUNDS" structure. Returns true on success
16433 and updates *FIELD, false if it fails to recognize an
16437 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16438 int *bounds_offset
, struct field
*field
,
16439 struct dwarf2_cu
*cu
)
16441 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16442 if (attr
== nullptr || !attr
->form_is_block ())
16445 const struct dwarf_block
*block
= attr
->as_block ();
16446 const gdb_byte
*start
= block
->data
;
16447 const gdb_byte
*end
= block
->data
+ block
->size
;
16449 /* The expression to recognize generally looks like:
16451 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16452 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16454 However, the second "plus_uconst" may be missing:
16456 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16457 DW_OP_deref_size: 4)
16459 This happens when the field is at the start of the structure.
16461 Also, the final deref may not be sized:
16463 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16466 This happens when the size of the index type happens to be the
16467 same as the architecture's word size. This can occur with or
16468 without the second plus_uconst. */
16470 if (end
- start
< 2)
16472 if (*start
++ != DW_OP_push_object_address
)
16474 if (*start
++ != DW_OP_plus_uconst
)
16477 uint64_t this_bound_off
;
16478 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16479 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16481 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16482 is consistent among all bounds. */
16483 if (*bounds_offset
== -1)
16484 *bounds_offset
= this_bound_off
;
16485 else if (*bounds_offset
!= this_bound_off
)
16488 if (start
== end
|| *start
++ != DW_OP_deref
)
16494 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16496 /* This means an offset of 0. */
16498 else if (*start
++ != DW_OP_plus_uconst
)
16502 /* The size is the parameter to DW_OP_plus_uconst. */
16504 start
= gdb_read_uleb128 (start
, end
, &val
);
16505 if (start
== nullptr)
16507 if ((int) val
!= val
)
16516 if (*start
== DW_OP_deref_size
)
16518 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16519 if (start
== nullptr)
16522 else if (*start
== DW_OP_deref
)
16524 size
= cu
->header
.addr_size
;
16530 SET_FIELD_BITPOS (*field
, 8 * offset
);
16531 if (size
!= TYPE_LENGTH (field
->type ()))
16532 FIELD_BITSIZE (*field
) = 8 * size
;
16537 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16538 some kinds of Ada arrays:
16540 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16541 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16542 <11e0> DW_AT_data_location: 2 byte block: 97 6
16543 (DW_OP_push_object_address; DW_OP_deref)
16544 <11e3> DW_AT_type : <0x1173>
16545 <11e7> DW_AT_sibling : <0x1201>
16546 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16547 <11ec> DW_AT_type : <0x1206>
16548 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16549 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16550 DW_OP_deref_size: 4)
16551 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16552 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16553 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16555 This actually represents a "thick pointer", which is a structure
16556 with two elements: one that is a pointer to the array data, and one
16557 that is a pointer to another structure; this second structure holds
16560 This returns a new type on success, or nullptr if this didn't
16561 recognize the type. */
16563 static struct type
*
16564 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16567 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16568 /* So far we've only seen this with block form. */
16569 if (attr
== nullptr || !attr
->form_is_block ())
16572 /* Note that this will fail if the structure layout is changed by
16573 the compiler. However, we have no good way to recognize some
16574 other layout, because we don't know what expression the compiler
16575 might choose to emit should this happen. */
16576 struct dwarf_block
*blk
= attr
->as_block ();
16578 || blk
->data
[0] != DW_OP_push_object_address
16579 || blk
->data
[1] != DW_OP_deref
)
16582 int bounds_offset
= -1;
16583 int max_align
= -1;
16584 std::vector
<struct field
> range_fields
;
16585 for (struct die_info
*child_die
= die
->child
;
16587 child_die
= child_die
->sibling
)
16589 if (child_die
->tag
== DW_TAG_subrange_type
)
16591 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16593 int this_align
= type_align (underlying
);
16594 if (this_align
> max_align
)
16595 max_align
= this_align
;
16597 range_fields
.emplace_back ();
16598 range_fields
.emplace_back ();
16600 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16601 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16603 lower
.set_type (underlying
);
16604 FIELD_ARTIFICIAL (lower
) = 1;
16606 upper
.set_type (underlying
);
16607 FIELD_ARTIFICIAL (upper
) = 1;
16609 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16610 &bounds_offset
, &lower
, cu
)
16611 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16612 &bounds_offset
, &upper
, cu
))
16617 /* This shouldn't really happen, but double-check that we found
16618 where the bounds are stored. */
16619 if (bounds_offset
== -1)
16622 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16623 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16627 /* Set the name of each field in the bounds. */
16628 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16629 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
16630 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16631 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
16634 struct type
*bounds
= alloc_type (objfile
);
16635 bounds
->set_code (TYPE_CODE_STRUCT
);
16637 bounds
->set_num_fields (range_fields
.size ());
16639 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16640 * sizeof (struct field
))));
16641 memcpy (bounds
->fields (), range_fields
.data (),
16642 bounds
->num_fields () * sizeof (struct field
));
16644 int last_fieldno
= range_fields
.size () - 1;
16645 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
16646 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16647 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16649 /* Rewrite the existing array type in place. Specifically, we
16650 remove any dynamic properties we might have read, and we replace
16651 the index types. */
16652 struct type
*iter
= type
;
16653 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16655 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16656 iter
->main_type
->dyn_prop_list
= nullptr;
16657 iter
->set_index_type
16658 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16659 iter
= TYPE_TARGET_TYPE (iter
);
16662 struct type
*result
= alloc_type (objfile
);
16663 result
->set_code (TYPE_CODE_STRUCT
);
16665 result
->set_num_fields (2);
16667 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16668 * sizeof (struct field
))));
16670 /* The names are chosen to coincide with what the compiler does with
16671 -fgnat-encodings=all, which the Ada code in gdb already
16673 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
16674 result
->field (0).set_type (lookup_pointer_type (type
));
16676 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
16677 result
->field (1).set_type (lookup_pointer_type (bounds
));
16678 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
16680 result
->set_name (type
->name ());
16681 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16682 + TYPE_LENGTH (result
->field (1).type ()));
16687 /* Extract all information from a DW_TAG_array_type DIE and put it in
16688 the DIE's type field. For now, this only handles one dimensional
16691 static struct type
*
16692 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16694 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16695 struct die_info
*child_die
;
16697 struct type
*element_type
, *range_type
, *index_type
;
16698 struct attribute
*attr
;
16700 struct dynamic_prop
*byte_stride_prop
= NULL
;
16701 unsigned int bit_stride
= 0;
16703 element_type
= die_type (die
, cu
);
16705 /* The die_type call above may have already set the type for this DIE. */
16706 type
= get_die_type (die
, cu
);
16710 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16714 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16717 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16718 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16722 complaint (_("unable to read array DW_AT_byte_stride "
16723 " - DIE at %s [in module %s]"),
16724 sect_offset_str (die
->sect_off
),
16725 objfile_name (cu
->per_objfile
->objfile
));
16726 /* Ignore this attribute. We will likely not be able to print
16727 arrays of this type correctly, but there is little we can do
16728 to help if we cannot read the attribute's value. */
16729 byte_stride_prop
= NULL
;
16733 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16735 bit_stride
= attr
->constant_value (0);
16737 /* Irix 6.2 native cc creates array types without children for
16738 arrays with unspecified length. */
16739 if (die
->child
== NULL
)
16741 index_type
= objfile_type (objfile
)->builtin_int
;
16742 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16743 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16744 byte_stride_prop
, bit_stride
);
16745 return set_die_type (die
, type
, cu
);
16748 std::vector
<struct type
*> range_types
;
16749 child_die
= die
->child
;
16750 while (child_die
&& child_die
->tag
)
16752 if (child_die
->tag
== DW_TAG_subrange_type
)
16754 struct type
*child_type
= read_type_die (child_die
, cu
);
16756 if (child_type
!= NULL
)
16758 /* The range type was succesfully read. Save it for the
16759 array type creation. */
16760 range_types
.push_back (child_type
);
16763 child_die
= child_die
->sibling
;
16766 if (range_types
.empty ())
16768 complaint (_("unable to find array range - DIE at %s [in module %s]"),
16769 sect_offset_str (die
->sect_off
),
16770 objfile_name (cu
->per_objfile
->objfile
));
16774 /* Dwarf2 dimensions are output from left to right, create the
16775 necessary array types in backwards order. */
16777 type
= element_type
;
16779 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16783 while (i
< range_types
.size ())
16785 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16786 byte_stride_prop
, bit_stride
);
16788 byte_stride_prop
= nullptr;
16793 size_t ndim
= range_types
.size ();
16796 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16797 byte_stride_prop
, bit_stride
);
16799 byte_stride_prop
= nullptr;
16803 gdb_assert (type
!= element_type
);
16805 /* Understand Dwarf2 support for vector types (like they occur on
16806 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16807 array type. This is not part of the Dwarf2/3 standard yet, but a
16808 custom vendor extension. The main difference between a regular
16809 array and the vector variant is that vectors are passed by value
16811 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16812 if (attr
!= nullptr)
16813 make_vector_type (type
);
16815 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16816 implementation may choose to implement triple vectors using this
16818 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16819 if (attr
!= nullptr && attr
->form_is_unsigned ())
16821 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
16822 TYPE_LENGTH (type
) = attr
->as_unsigned ();
16824 complaint (_("DW_AT_byte_size for array type smaller "
16825 "than the total size of elements"));
16828 name
= dwarf2_name (die
, cu
);
16830 type
->set_name (name
);
16832 maybe_set_alignment (cu
, die
, type
);
16834 struct type
*replacement_type
= nullptr;
16835 if (cu
->language
== language_ada
)
16837 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
16838 if (replacement_type
!= nullptr)
16839 type
= replacement_type
;
16842 /* Install the type in the die. */
16843 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
16845 /* set_die_type should be already done. */
16846 set_descriptive_type (type
, die
, cu
);
16851 static enum dwarf_array_dim_ordering
16852 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16854 struct attribute
*attr
;
16856 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16858 if (attr
!= nullptr)
16860 LONGEST val
= attr
->constant_value (-1);
16861 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
16862 return (enum dwarf_array_dim_ordering
) val
;
16865 /* GNU F77 is a special case, as at 08/2004 array type info is the
16866 opposite order to the dwarf2 specification, but data is still
16867 laid out as per normal fortran.
16869 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16870 version checking. */
16872 if (cu
->language
== language_fortran
16873 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16875 return DW_ORD_row_major
;
16878 switch (cu
->language_defn
->array_ordering ())
16880 case array_column_major
:
16881 return DW_ORD_col_major
;
16882 case array_row_major
:
16884 return DW_ORD_row_major
;
16888 /* Extract all information from a DW_TAG_set_type DIE and put it in
16889 the DIE's type field. */
16891 static struct type
*
16892 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16894 struct type
*domain_type
, *set_type
;
16895 struct attribute
*attr
;
16897 domain_type
= die_type (die
, cu
);
16899 /* The die_type call above may have already set the type for this DIE. */
16900 set_type
= get_die_type (die
, cu
);
16904 set_type
= create_set_type (NULL
, domain_type
);
16906 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16907 if (attr
!= nullptr && attr
->form_is_unsigned ())
16908 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
16910 maybe_set_alignment (cu
, die
, set_type
);
16912 return set_die_type (die
, set_type
, cu
);
16915 /* A helper for read_common_block that creates a locexpr baton.
16916 SYM is the symbol which we are marking as computed.
16917 COMMON_DIE is the DIE for the common block.
16918 COMMON_LOC is the location expression attribute for the common
16920 MEMBER_LOC is the location expression attribute for the particular
16921 member of the common block that we are processing.
16922 CU is the CU from which the above come. */
16925 mark_common_block_symbol_computed (struct symbol
*sym
,
16926 struct die_info
*common_die
,
16927 struct attribute
*common_loc
,
16928 struct attribute
*member_loc
,
16929 struct dwarf2_cu
*cu
)
16931 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16932 struct objfile
*objfile
= per_objfile
->objfile
;
16933 struct dwarf2_locexpr_baton
*baton
;
16935 unsigned int cu_off
;
16936 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16937 LONGEST offset
= 0;
16939 gdb_assert (common_loc
&& member_loc
);
16940 gdb_assert (common_loc
->form_is_block ());
16941 gdb_assert (member_loc
->form_is_block ()
16942 || member_loc
->form_is_constant ());
16944 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16945 baton
->per_objfile
= per_objfile
;
16946 baton
->per_cu
= cu
->per_cu
;
16947 gdb_assert (baton
->per_cu
);
16949 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16951 if (member_loc
->form_is_constant ())
16953 offset
= member_loc
->constant_value (0);
16954 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16957 baton
->size
+= member_loc
->as_block ()->size
;
16959 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16962 *ptr
++ = DW_OP_call4
;
16963 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16964 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16967 if (member_loc
->form_is_constant ())
16969 *ptr
++ = DW_OP_addr
;
16970 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16971 ptr
+= cu
->header
.addr_size
;
16975 /* We have to copy the data here, because DW_OP_call4 will only
16976 use a DW_AT_location attribute. */
16977 struct dwarf_block
*block
= member_loc
->as_block ();
16978 memcpy (ptr
, block
->data
, block
->size
);
16979 ptr
+= block
->size
;
16982 *ptr
++ = DW_OP_plus
;
16983 gdb_assert (ptr
- baton
->data
== baton
->size
);
16985 SYMBOL_LOCATION_BATON (sym
) = baton
;
16986 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16989 /* Create appropriate locally-scoped variables for all the
16990 DW_TAG_common_block entries. Also create a struct common_block
16991 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16992 is used to separate the common blocks name namespace from regular
16996 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16998 struct attribute
*attr
;
17000 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17001 if (attr
!= nullptr)
17003 /* Support the .debug_loc offsets. */
17004 if (attr
->form_is_block ())
17008 else if (attr
->form_is_section_offset ())
17010 dwarf2_complex_location_expr_complaint ();
17015 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17016 "common block member");
17021 if (die
->child
!= NULL
)
17023 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17024 struct die_info
*child_die
;
17025 size_t n_entries
= 0, size
;
17026 struct common_block
*common_block
;
17027 struct symbol
*sym
;
17029 for (child_die
= die
->child
;
17030 child_die
&& child_die
->tag
;
17031 child_die
= child_die
->sibling
)
17034 size
= (sizeof (struct common_block
)
17035 + (n_entries
- 1) * sizeof (struct symbol
*));
17037 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17039 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17040 common_block
->n_entries
= 0;
17042 for (child_die
= die
->child
;
17043 child_die
&& child_die
->tag
;
17044 child_die
= child_die
->sibling
)
17046 /* Create the symbol in the DW_TAG_common_block block in the current
17048 sym
= new_symbol (child_die
, NULL
, cu
);
17051 struct attribute
*member_loc
;
17053 common_block
->contents
[common_block
->n_entries
++] = sym
;
17055 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17059 /* GDB has handled this for a long time, but it is
17060 not specified by DWARF. It seems to have been
17061 emitted by gfortran at least as recently as:
17062 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17063 complaint (_("Variable in common block has "
17064 "DW_AT_data_member_location "
17065 "- DIE at %s [in module %s]"),
17066 sect_offset_str (child_die
->sect_off
),
17067 objfile_name (objfile
));
17069 if (member_loc
->form_is_section_offset ())
17070 dwarf2_complex_location_expr_complaint ();
17071 else if (member_loc
->form_is_constant ()
17072 || member_loc
->form_is_block ())
17074 if (attr
!= nullptr)
17075 mark_common_block_symbol_computed (sym
, die
, attr
,
17079 dwarf2_complex_location_expr_complaint ();
17084 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17085 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17089 /* Create a type for a C++ namespace. */
17091 static struct type
*
17092 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17094 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17095 const char *previous_prefix
, *name
;
17099 /* For extensions, reuse the type of the original namespace. */
17100 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17102 struct die_info
*ext_die
;
17103 struct dwarf2_cu
*ext_cu
= cu
;
17105 ext_die
= dwarf2_extension (die
, &ext_cu
);
17106 type
= read_type_die (ext_die
, ext_cu
);
17108 /* EXT_CU may not be the same as CU.
17109 Ensure TYPE is recorded with CU in die_type_hash. */
17110 return set_die_type (die
, type
, cu
);
17113 name
= namespace_name (die
, &is_anonymous
, cu
);
17115 /* Now build the name of the current namespace. */
17117 previous_prefix
= determine_prefix (die
, cu
);
17118 if (previous_prefix
[0] != '\0')
17119 name
= typename_concat (&objfile
->objfile_obstack
,
17120 previous_prefix
, name
, 0, cu
);
17122 /* Create the type. */
17123 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17125 return set_die_type (die
, type
, cu
);
17128 /* Read a namespace scope. */
17131 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17133 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17136 /* Add a symbol associated to this if we haven't seen the namespace
17137 before. Also, add a using directive if it's an anonymous
17140 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17144 type
= read_type_die (die
, cu
);
17145 new_symbol (die
, type
, cu
);
17147 namespace_name (die
, &is_anonymous
, cu
);
17150 const char *previous_prefix
= determine_prefix (die
, cu
);
17152 std::vector
<const char *> excludes
;
17153 add_using_directive (using_directives (cu
),
17154 previous_prefix
, type
->name (), NULL
,
17155 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17159 if (die
->child
!= NULL
)
17161 struct die_info
*child_die
= die
->child
;
17163 while (child_die
&& child_die
->tag
)
17165 process_die (child_die
, cu
);
17166 child_die
= child_die
->sibling
;
17171 /* Read a Fortran module as type. This DIE can be only a declaration used for
17172 imported module. Still we need that type as local Fortran "use ... only"
17173 declaration imports depend on the created type in determine_prefix. */
17175 static struct type
*
17176 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17178 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17179 const char *module_name
;
17182 module_name
= dwarf2_name (die
, cu
);
17183 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17185 return set_die_type (die
, type
, cu
);
17188 /* Read a Fortran module. */
17191 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17193 struct die_info
*child_die
= die
->child
;
17196 type
= read_type_die (die
, cu
);
17197 new_symbol (die
, type
, cu
);
17199 while (child_die
&& child_die
->tag
)
17201 process_die (child_die
, cu
);
17202 child_die
= child_die
->sibling
;
17206 /* Return the name of the namespace represented by DIE. Set
17207 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17210 static const char *
17211 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17213 struct die_info
*current_die
;
17214 const char *name
= NULL
;
17216 /* Loop through the extensions until we find a name. */
17218 for (current_die
= die
;
17219 current_die
!= NULL
;
17220 current_die
= dwarf2_extension (die
, &cu
))
17222 /* We don't use dwarf2_name here so that we can detect the absence
17223 of a name -> anonymous namespace. */
17224 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17230 /* Is it an anonymous namespace? */
17232 *is_anonymous
= (name
== NULL
);
17234 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17239 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17240 the user defined type vector. */
17242 static struct type
*
17243 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17245 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17246 struct comp_unit_head
*cu_header
= &cu
->header
;
17248 struct attribute
*attr_byte_size
;
17249 struct attribute
*attr_address_class
;
17250 int byte_size
, addr_class
;
17251 struct type
*target_type
;
17253 target_type
= die_type (die
, cu
);
17255 /* The die_type call above may have already set the type for this DIE. */
17256 type
= get_die_type (die
, cu
);
17260 type
= lookup_pointer_type (target_type
);
17262 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17263 if (attr_byte_size
)
17264 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17266 byte_size
= cu_header
->addr_size
;
17268 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17269 if (attr_address_class
)
17270 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17272 addr_class
= DW_ADDR_none
;
17274 ULONGEST alignment
= get_alignment (cu
, die
);
17276 /* If the pointer size, alignment, or address class is different
17277 than the default, create a type variant marked as such and set
17278 the length accordingly. */
17279 if (TYPE_LENGTH (type
) != byte_size
17280 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17281 && alignment
!= TYPE_RAW_ALIGN (type
))
17282 || addr_class
!= DW_ADDR_none
)
17284 if (gdbarch_address_class_type_flags_p (gdbarch
))
17286 type_instance_flags type_flags
17287 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17289 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17291 type
= make_type_with_address_space (type
, type_flags
);
17293 else if (TYPE_LENGTH (type
) != byte_size
)
17295 complaint (_("invalid pointer size %d"), byte_size
);
17297 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17299 complaint (_("Invalid DW_AT_alignment"
17300 " - DIE at %s [in module %s]"),
17301 sect_offset_str (die
->sect_off
),
17302 objfile_name (cu
->per_objfile
->objfile
));
17306 /* Should we also complain about unhandled address classes? */
17310 TYPE_LENGTH (type
) = byte_size
;
17311 set_type_align (type
, alignment
);
17312 return set_die_type (die
, type
, cu
);
17315 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17316 the user defined type vector. */
17318 static struct type
*
17319 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17322 struct type
*to_type
;
17323 struct type
*domain
;
17325 to_type
= die_type (die
, cu
);
17326 domain
= die_containing_type (die
, cu
);
17328 /* The calls above may have already set the type for this DIE. */
17329 type
= get_die_type (die
, cu
);
17333 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17334 type
= lookup_methodptr_type (to_type
);
17335 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17337 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17339 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17340 to_type
->fields (), to_type
->num_fields (),
17341 to_type
->has_varargs ());
17342 type
= lookup_methodptr_type (new_type
);
17345 type
= lookup_memberptr_type (to_type
, domain
);
17347 return set_die_type (die
, type
, cu
);
17350 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17351 the user defined type vector. */
17353 static struct type
*
17354 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17355 enum type_code refcode
)
17357 struct comp_unit_head
*cu_header
= &cu
->header
;
17358 struct type
*type
, *target_type
;
17359 struct attribute
*attr
;
17361 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17363 target_type
= die_type (die
, cu
);
17365 /* The die_type call above may have already set the type for this DIE. */
17366 type
= get_die_type (die
, cu
);
17370 type
= lookup_reference_type (target_type
, refcode
);
17371 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17372 if (attr
!= nullptr)
17374 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17378 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17380 maybe_set_alignment (cu
, die
, type
);
17381 return set_die_type (die
, type
, cu
);
17384 /* Add the given cv-qualifiers to the element type of the array. GCC
17385 outputs DWARF type qualifiers that apply to an array, not the
17386 element type. But GDB relies on the array element type to carry
17387 the cv-qualifiers. This mimics section 6.7.3 of the C99
17390 static struct type
*
17391 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17392 struct type
*base_type
, int cnst
, int voltl
)
17394 struct type
*el_type
, *inner_array
;
17396 base_type
= copy_type (base_type
);
17397 inner_array
= base_type
;
17399 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17401 TYPE_TARGET_TYPE (inner_array
) =
17402 copy_type (TYPE_TARGET_TYPE (inner_array
));
17403 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17406 el_type
= TYPE_TARGET_TYPE (inner_array
);
17407 cnst
|= TYPE_CONST (el_type
);
17408 voltl
|= TYPE_VOLATILE (el_type
);
17409 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17411 return set_die_type (die
, base_type
, cu
);
17414 static struct type
*
17415 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17417 struct type
*base_type
, *cv_type
;
17419 base_type
= die_type (die
, cu
);
17421 /* The die_type call above may have already set the type for this DIE. */
17422 cv_type
= get_die_type (die
, cu
);
17426 /* In case the const qualifier is applied to an array type, the element type
17427 is so qualified, not the array type (section 6.7.3 of C99). */
17428 if (base_type
->code () == TYPE_CODE_ARRAY
)
17429 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17431 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17432 return set_die_type (die
, cv_type
, cu
);
17435 static struct type
*
17436 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17438 struct type
*base_type
, *cv_type
;
17440 base_type
= die_type (die
, cu
);
17442 /* The die_type call above may have already set the type for this DIE. */
17443 cv_type
= get_die_type (die
, cu
);
17447 /* In case the volatile qualifier is applied to an array type, the
17448 element type is so qualified, not the array type (section 6.7.3
17450 if (base_type
->code () == TYPE_CODE_ARRAY
)
17451 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17453 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17454 return set_die_type (die
, cv_type
, cu
);
17457 /* Handle DW_TAG_restrict_type. */
17459 static struct type
*
17460 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17462 struct type
*base_type
, *cv_type
;
17464 base_type
= die_type (die
, cu
);
17466 /* The die_type call above may have already set the type for this DIE. */
17467 cv_type
= get_die_type (die
, cu
);
17471 cv_type
= make_restrict_type (base_type
);
17472 return set_die_type (die
, cv_type
, cu
);
17475 /* Handle DW_TAG_atomic_type. */
17477 static struct type
*
17478 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17480 struct type
*base_type
, *cv_type
;
17482 base_type
= die_type (die
, cu
);
17484 /* The die_type call above may have already set the type for this DIE. */
17485 cv_type
= get_die_type (die
, cu
);
17489 cv_type
= make_atomic_type (base_type
);
17490 return set_die_type (die
, cv_type
, cu
);
17493 /* Extract all information from a DW_TAG_string_type DIE and add to
17494 the user defined type vector. It isn't really a user defined type,
17495 but it behaves like one, with other DIE's using an AT_user_def_type
17496 attribute to reference it. */
17498 static struct type
*
17499 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17501 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17502 struct gdbarch
*gdbarch
= objfile
->arch ();
17503 struct type
*type
, *range_type
, *index_type
, *char_type
;
17504 struct attribute
*attr
;
17505 struct dynamic_prop prop
;
17506 bool length_is_constant
= true;
17509 /* There are a couple of places where bit sizes might be made use of
17510 when parsing a DW_TAG_string_type, however, no producer that we know
17511 of make use of these. Handling bit sizes that are a multiple of the
17512 byte size is easy enough, but what about other bit sizes? Lets deal
17513 with that problem when we have to. Warn about these attributes being
17514 unsupported, then parse the type and ignore them like we always
17516 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17517 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17519 static bool warning_printed
= false;
17520 if (!warning_printed
)
17522 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17523 "currently supported on DW_TAG_string_type."));
17524 warning_printed
= true;
17528 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17529 if (attr
!= nullptr && !attr
->form_is_constant ())
17531 /* The string length describes the location at which the length of
17532 the string can be found. The size of the length field can be
17533 specified with one of the attributes below. */
17534 struct type
*prop_type
;
17535 struct attribute
*len
17536 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17537 if (len
== nullptr)
17538 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17539 if (len
!= nullptr && len
->form_is_constant ())
17541 /* Pass 0 as the default as we know this attribute is constant
17542 and the default value will not be returned. */
17543 LONGEST sz
= len
->constant_value (0);
17544 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17548 /* If the size is not specified then we assume it is the size of
17549 an address on this target. */
17550 prop_type
= cu
->addr_sized_int_type (true);
17553 /* Convert the attribute into a dynamic property. */
17554 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17557 length_is_constant
= false;
17559 else if (attr
!= nullptr)
17561 /* This DW_AT_string_length just contains the length with no
17562 indirection. There's no need to create a dynamic property in this
17563 case. Pass 0 for the default value as we know it will not be
17564 returned in this case. */
17565 length
= attr
->constant_value (0);
17567 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17569 /* We don't currently support non-constant byte sizes for strings. */
17570 length
= attr
->constant_value (1);
17574 /* Use 1 as a fallback length if we have nothing else. */
17578 index_type
= objfile_type (objfile
)->builtin_int
;
17579 if (length_is_constant
)
17580 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17583 struct dynamic_prop low_bound
;
17585 low_bound
.set_const_val (1);
17586 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17588 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17589 type
= create_string_type (NULL
, char_type
, range_type
);
17591 return set_die_type (die
, type
, cu
);
17594 /* Assuming that DIE corresponds to a function, returns nonzero
17595 if the function is prototyped. */
17598 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17600 struct attribute
*attr
;
17602 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17603 if (attr
&& attr
->as_boolean ())
17606 /* The DWARF standard implies that the DW_AT_prototyped attribute
17607 is only meaningful for C, but the concept also extends to other
17608 languages that allow unprototyped functions (Eg: Objective C).
17609 For all other languages, assume that functions are always
17611 if (cu
->language
!= language_c
17612 && cu
->language
!= language_objc
17613 && cu
->language
!= language_opencl
)
17616 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17617 prototyped and unprototyped functions; default to prototyped,
17618 since that is more common in modern code (and RealView warns
17619 about unprototyped functions). */
17620 if (producer_is_realview (cu
->producer
))
17626 /* Handle DIES due to C code like:
17630 int (*funcp)(int a, long l);
17634 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17636 static struct type
*
17637 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17639 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17640 struct type
*type
; /* Type that this function returns. */
17641 struct type
*ftype
; /* Function that returns above type. */
17642 struct attribute
*attr
;
17644 type
= die_type (die
, cu
);
17646 /* The die_type call above may have already set the type for this DIE. */
17647 ftype
= get_die_type (die
, cu
);
17651 ftype
= lookup_function_type (type
);
17653 if (prototyped_function_p (die
, cu
))
17654 ftype
->set_is_prototyped (true);
17656 /* Store the calling convention in the type if it's available in
17657 the subroutine die. Otherwise set the calling convention to
17658 the default value DW_CC_normal. */
17659 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17660 if (attr
!= nullptr
17661 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17662 TYPE_CALLING_CONVENTION (ftype
)
17663 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17664 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17665 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17667 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17669 /* Record whether the function returns normally to its caller or not
17670 if the DWARF producer set that information. */
17671 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17672 if (attr
&& attr
->as_boolean ())
17673 TYPE_NO_RETURN (ftype
) = 1;
17675 /* We need to add the subroutine type to the die immediately so
17676 we don't infinitely recurse when dealing with parameters
17677 declared as the same subroutine type. */
17678 set_die_type (die
, ftype
, cu
);
17680 if (die
->child
!= NULL
)
17682 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17683 struct die_info
*child_die
;
17684 int nparams
, iparams
;
17686 /* Count the number of parameters.
17687 FIXME: GDB currently ignores vararg functions, but knows about
17688 vararg member functions. */
17690 child_die
= die
->child
;
17691 while (child_die
&& child_die
->tag
)
17693 if (child_die
->tag
== DW_TAG_formal_parameter
)
17695 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17696 ftype
->set_has_varargs (true);
17698 child_die
= child_die
->sibling
;
17701 /* Allocate storage for parameters and fill them in. */
17702 ftype
->set_num_fields (nparams
);
17704 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17706 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17707 even if we error out during the parameters reading below. */
17708 for (iparams
= 0; iparams
< nparams
; iparams
++)
17709 ftype
->field (iparams
).set_type (void_type
);
17712 child_die
= die
->child
;
17713 while (child_die
&& child_die
->tag
)
17715 if (child_die
->tag
== DW_TAG_formal_parameter
)
17717 struct type
*arg_type
;
17719 /* DWARF version 2 has no clean way to discern C++
17720 static and non-static member functions. G++ helps
17721 GDB by marking the first parameter for non-static
17722 member functions (which is the this pointer) as
17723 artificial. We pass this information to
17724 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17726 DWARF version 3 added DW_AT_object_pointer, which GCC
17727 4.5 does not yet generate. */
17728 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17729 if (attr
!= nullptr)
17730 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17732 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17733 arg_type
= die_type (child_die
, cu
);
17735 /* RealView does not mark THIS as const, which the testsuite
17736 expects. GCC marks THIS as const in method definitions,
17737 but not in the class specifications (GCC PR 43053). */
17738 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17739 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17742 struct dwarf2_cu
*arg_cu
= cu
;
17743 const char *name
= dwarf2_name (child_die
, cu
);
17745 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17746 if (attr
!= nullptr)
17748 /* If the compiler emits this, use it. */
17749 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17752 else if (name
&& strcmp (name
, "this") == 0)
17753 /* Function definitions will have the argument names. */
17755 else if (name
== NULL
&& iparams
== 0)
17756 /* Declarations may not have the names, so like
17757 elsewhere in GDB, assume an artificial first
17758 argument is "this". */
17762 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17766 ftype
->field (iparams
).set_type (arg_type
);
17769 child_die
= child_die
->sibling
;
17776 static struct type
*
17777 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17779 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17780 const char *name
= NULL
;
17781 struct type
*this_type
, *target_type
;
17783 name
= dwarf2_full_name (NULL
, die
, cu
);
17784 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17785 this_type
->set_target_is_stub (true);
17786 set_die_type (die
, this_type
, cu
);
17787 target_type
= die_type (die
, cu
);
17788 if (target_type
!= this_type
)
17789 TYPE_TARGET_TYPE (this_type
) = target_type
;
17792 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17793 spec and cause infinite loops in GDB. */
17794 complaint (_("Self-referential DW_TAG_typedef "
17795 "- DIE at %s [in module %s]"),
17796 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17797 TYPE_TARGET_TYPE (this_type
) = NULL
;
17801 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17802 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17803 Handle these by just returning the target type, rather than
17804 constructing an anonymous typedef type and trying to handle this
17806 set_die_type (die
, target_type
, cu
);
17807 return target_type
;
17812 /* Helper for get_dwarf2_rational_constant that computes the value of
17813 a given gmp_mpz given an attribute. */
17816 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
17818 /* GCC will sometimes emit a 16-byte constant value as a DWARF
17819 location expression that pushes an implicit value. */
17820 if (attr
->form
== DW_FORM_exprloc
)
17822 dwarf_block
*blk
= attr
->as_block ();
17823 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
17826 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
17827 blk
->data
+ blk
->size
,
17829 if (ptr
- blk
->data
+ len
<= blk
->size
)
17831 mpz_import (value
->val
, len
,
17832 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17838 /* On failure set it to 1. */
17839 *value
= gdb_mpz (1);
17841 else if (attr
->form_is_block ())
17843 dwarf_block
*blk
= attr
->as_block ();
17844 mpz_import (value
->val
, blk
->size
,
17845 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17846 1, 0, 0, blk
->data
);
17849 *value
= gdb_mpz (attr
->constant_value (1));
17852 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
17853 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
17855 If the numerator and/or numerator attribute is missing,
17856 a complaint is filed, and NUMERATOR and DENOMINATOR are left
17860 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
17861 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
17863 struct attribute
*num_attr
, *denom_attr
;
17865 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
17866 if (num_attr
== nullptr)
17867 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
17868 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17870 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
17871 if (denom_attr
== nullptr)
17872 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
17873 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17875 if (num_attr
== nullptr || denom_attr
== nullptr)
17878 get_mpz (cu
, numerator
, num_attr
);
17879 get_mpz (cu
, denominator
, denom_attr
);
17882 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
17883 rational constant, rather than a signed one.
17885 If the rational constant has a negative value, a complaint
17886 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
17889 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
17890 struct dwarf2_cu
*cu
,
17891 gdb_mpz
*numerator
,
17892 gdb_mpz
*denominator
)
17897 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
17898 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
17900 mpz_neg (num
.val
, num
.val
);
17901 mpz_neg (denom
.val
, denom
.val
);
17903 else if (mpz_sgn (num
.val
) == -1)
17905 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
17907 sect_offset_str (die
->sect_off
));
17910 else if (mpz_sgn (denom
.val
) == -1)
17912 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
17914 sect_offset_str (die
->sect_off
));
17918 *numerator
= std::move (num
);
17919 *denominator
= std::move (denom
);
17922 /* Assuming that ENCODING is a string whose contents starting at the
17923 K'th character is "_nn" where "nn" is a decimal number, scan that
17924 number and set RESULT to the value. K is updated to point to the
17925 character immediately following the number.
17927 If the string does not conform to the format described above, false
17928 is returned, and K may or may not be changed. */
17931 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
17933 /* The next character should be an underscore ('_') followed
17935 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
17938 /* Skip the underscore. */
17942 /* Determine the number of digits for our number. */
17943 while (isdigit (encoding
[k
]))
17948 std::string
copy (&encoding
[start
], k
- start
);
17949 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
17955 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
17956 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
17957 DENOM, update OFFSET, and return true on success. Return false on
17961 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
17962 gdb_mpz
*num
, gdb_mpz
*denom
)
17964 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
17966 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
17969 /* Assuming DIE corresponds to a fixed point type, finish the creation
17970 of the corresponding TYPE by setting its type-specific data. CU is
17971 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
17972 encodings. It is nullptr if the GNAT encoding should be
17976 finish_fixed_point_type (struct type
*type
, const char *suffix
,
17977 struct die_info
*die
, struct dwarf2_cu
*cu
)
17979 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
17980 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
17982 /* If GNAT encodings are preferred, don't examine the
17984 struct attribute
*attr
= nullptr;
17985 if (suffix
== nullptr)
17987 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
17988 if (attr
== nullptr)
17989 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
17990 if (attr
== nullptr)
17991 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
17994 /* Numerator and denominator of our fixed-point type's scaling factor.
17995 The default is a scaling factor of 1, which we use as a fallback
17996 when we are not able to decode it (problem with the debugging info,
17997 unsupported forms, bug in GDB, etc...). Using that as the default
17998 allows us to at least print the unscaled value, which might still
17999 be useful to a user. */
18000 gdb_mpz
scale_num (1);
18001 gdb_mpz
scale_denom (1);
18003 if (attr
== nullptr)
18006 if (suffix
!= nullptr
18007 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
18009 /* The number might be encoded as _nn_dd_nn_dd, where the
18010 second ratio is the 'small value. In this situation, we
18011 want the second value. */
18012 && (suffix
[offset
] != '_'
18013 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
18020 /* Scaling factor not found. Assume a scaling factor of 1,
18021 and hope for the best. At least the user will be able to
18022 see the encoded value. */
18025 complaint (_("no scale found for fixed-point type (DIE at %s)"),
18026 sect_offset_str (die
->sect_off
));
18029 else if (attr
->name
== DW_AT_binary_scale
)
18031 LONGEST scale_exp
= attr
->constant_value (0);
18032 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18034 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
18036 else if (attr
->name
== DW_AT_decimal_scale
)
18038 LONGEST scale_exp
= attr
->constant_value (0);
18039 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18041 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
18043 else if (attr
->name
== DW_AT_small
)
18045 struct die_info
*scale_die
;
18046 struct dwarf2_cu
*scale_cu
= cu
;
18048 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
18049 if (scale_die
->tag
== DW_TAG_constant
)
18050 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
18051 &scale_num
, &scale_denom
);
18053 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
18055 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18059 complaint (_("unsupported scale attribute %s for fixed-point type"
18061 dwarf_attr_name (attr
->name
),
18062 sect_offset_str (die
->sect_off
));
18065 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
18066 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
18067 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
18068 mpq_canonicalize (scaling_factor
.val
);
18071 /* The gnat-encoding suffix for fixed point. */
18073 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
18075 /* If NAME encodes an Ada fixed-point type, return a pointer to the
18076 "XF" suffix of the name. The text after this is what encodes the
18077 'small and 'delta information. Otherwise, return nullptr. */
18079 static const char *
18080 gnat_encoded_fixed_point_type_info (const char *name
)
18082 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
18085 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
18086 (which may be different from NAME) to the architecture back-end to allow
18087 it to guess the correct format if necessary. */
18089 static struct type
*
18090 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
18091 const char *name_hint
, enum bfd_endian byte_order
)
18093 struct gdbarch
*gdbarch
= objfile
->arch ();
18094 const struct floatformat
**format
;
18097 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
18099 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
18101 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18106 /* Allocate an integer type of size BITS and name NAME. */
18108 static struct type
*
18109 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
18110 int bits
, int unsigned_p
, const char *name
)
18114 /* Versions of Intel's C Compiler generate an integer type called "void"
18115 instead of using DW_TAG_unspecified_type. This has been seen on
18116 at least versions 14, 17, and 18. */
18117 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18118 && strcmp (name
, "void") == 0)
18119 type
= objfile_type (objfile
)->builtin_void
;
18121 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18126 /* Return true if DIE has a DW_AT_small attribute whose value is
18127 a constant rational, where both the numerator and denominator
18130 CU is the DIE's Compilation Unit. */
18133 has_zero_over_zero_small_attribute (struct die_info
*die
,
18134 struct dwarf2_cu
*cu
)
18136 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18137 if (attr
== nullptr)
18140 struct dwarf2_cu
*scale_cu
= cu
;
18141 struct die_info
*scale_die
18142 = follow_die_ref (die
, attr
, &scale_cu
);
18144 if (scale_die
->tag
!= DW_TAG_constant
)
18147 gdb_mpz
num (1), denom (1);
18148 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18149 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
18152 /* Initialise and return a floating point type of size BITS suitable for
18153 use as a component of a complex number. The NAME_HINT is passed through
18154 when initialising the floating point type and is the name of the complex
18157 As DWARF doesn't currently provide an explicit name for the components
18158 of a complex number, but it can be helpful to have these components
18159 named, we try to select a suitable name based on the size of the
18161 static struct type
*
18162 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18163 struct objfile
*objfile
,
18164 int bits
, const char *name_hint
,
18165 enum bfd_endian byte_order
)
18167 gdbarch
*gdbarch
= objfile
->arch ();
18168 struct type
*tt
= nullptr;
18170 /* Try to find a suitable floating point builtin type of size BITS.
18171 We're going to use the name of this type as the name for the complex
18172 target type that we are about to create. */
18173 switch (cu
->language
)
18175 case language_fortran
:
18179 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18182 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18184 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18186 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18194 tt
= builtin_type (gdbarch
)->builtin_float
;
18197 tt
= builtin_type (gdbarch
)->builtin_double
;
18199 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18201 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18207 /* If the type we found doesn't match the size we were looking for, then
18208 pretend we didn't find a type at all, the complex target type we
18209 create will then be nameless. */
18210 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18213 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18214 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18217 /* Find a representation of a given base type and install
18218 it in the TYPE field of the die. */
18220 static struct type
*
18221 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18223 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18225 struct attribute
*attr
;
18226 int encoding
= 0, bits
= 0;
18230 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18231 if (attr
!= nullptr && attr
->form_is_constant ())
18232 encoding
= attr
->constant_value (0);
18233 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18234 if (attr
!= nullptr)
18235 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18236 name
= dwarf2_name (die
, cu
);
18238 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18240 arch
= objfile
->arch ();
18241 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18243 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18244 if (attr
!= nullptr && attr
->form_is_constant ())
18246 int endianity
= attr
->constant_value (0);
18251 byte_order
= BFD_ENDIAN_BIG
;
18253 case DW_END_little
:
18254 byte_order
= BFD_ENDIAN_LITTLE
;
18257 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18262 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18263 && cu
->language
== language_ada
18264 && has_zero_over_zero_small_attribute (die
, cu
))
18266 /* brobecker/2018-02-24: This is a fixed point type for which
18267 the scaling factor is represented as fraction whose value
18268 does not make sense (zero divided by zero), so we should
18269 normally never see these. However, there is a small category
18270 of fixed point types for which GNAT is unable to provide
18271 the scaling factor via the standard DWARF mechanisms, and
18272 for which the info is provided via the GNAT encodings instead.
18273 This is likely what this DIE is about. */
18274 encoding
= (encoding
== DW_ATE_signed_fixed
18276 : DW_ATE_unsigned
);
18279 /* With GNAT encodings, fixed-point information will be encoded in
18280 the type name. Note that this can also occur with the above
18281 zero-over-zero case, which is why this is a separate "if" rather
18282 than an "else if". */
18283 const char *gnat_encoding_suffix
= nullptr;
18284 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18285 && cu
->language
== language_ada
18286 && name
!= nullptr)
18288 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18289 if (gnat_encoding_suffix
!= nullptr)
18291 gdb_assert (startswith (gnat_encoding_suffix
,
18292 GNAT_FIXED_POINT_SUFFIX
));
18293 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18294 name
, gnat_encoding_suffix
- name
);
18295 /* Use -1 here so that SUFFIX points at the "_" after the
18297 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18299 encoding
= (encoding
== DW_ATE_signed
18300 ? DW_ATE_signed_fixed
18301 : DW_ATE_unsigned_fixed
);
18307 case DW_ATE_address
:
18308 /* Turn DW_ATE_address into a void * pointer. */
18309 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18310 type
= init_pointer_type (objfile
, bits
, name
, type
);
18312 case DW_ATE_boolean
:
18313 type
= init_boolean_type (objfile
, bits
, 1, name
);
18315 case DW_ATE_complex_float
:
18316 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18318 if (type
->code () == TYPE_CODE_ERROR
)
18320 if (name
== nullptr)
18322 struct obstack
*obstack
18323 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18324 name
= obconcat (obstack
, "_Complex ", type
->name (),
18327 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18330 type
= init_complex_type (name
, type
);
18332 case DW_ATE_decimal_float
:
18333 type
= init_decfloat_type (objfile
, bits
, name
);
18336 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18338 case DW_ATE_signed
:
18339 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18341 case DW_ATE_unsigned
:
18342 if (cu
->language
== language_fortran
18344 && startswith (name
, "character("))
18345 type
= init_character_type (objfile
, bits
, 1, name
);
18347 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18349 case DW_ATE_signed_char
:
18350 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18351 || cu
->language
== language_pascal
18352 || cu
->language
== language_fortran
)
18353 type
= init_character_type (objfile
, bits
, 0, name
);
18355 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18357 case DW_ATE_unsigned_char
:
18358 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18359 || cu
->language
== language_pascal
18360 || cu
->language
== language_fortran
18361 || cu
->language
== language_rust
)
18362 type
= init_character_type (objfile
, bits
, 1, name
);
18364 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18369 type
= builtin_type (arch
)->builtin_char16
;
18370 else if (bits
== 32)
18371 type
= builtin_type (arch
)->builtin_char32
;
18374 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18376 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18378 return set_die_type (die
, type
, cu
);
18381 case DW_ATE_signed_fixed
:
18382 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18383 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18385 case DW_ATE_unsigned_fixed
:
18386 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18387 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18391 complaint (_("unsupported DW_AT_encoding: '%s'"),
18392 dwarf_type_encoding_name (encoding
));
18393 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18397 if (name
&& strcmp (name
, "char") == 0)
18398 type
->set_has_no_signedness (true);
18400 maybe_set_alignment (cu
, die
, type
);
18402 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18404 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18406 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18407 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18409 unsigned real_bit_size
= attr
->as_unsigned ();
18410 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18411 /* Only use the attributes if they make sense together. */
18412 if (attr
== nullptr
18413 || (attr
->as_unsigned () + real_bit_size
18414 <= 8 * TYPE_LENGTH (type
)))
18416 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18418 if (attr
!= nullptr)
18419 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18420 = attr
->as_unsigned ();
18425 return set_die_type (die
, type
, cu
);
18428 /* Parse dwarf attribute if it's a block, reference or constant and put the
18429 resulting value of the attribute into struct bound_prop.
18430 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18433 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18434 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18435 struct type
*default_type
)
18437 struct dwarf2_property_baton
*baton
;
18438 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18439 struct objfile
*objfile
= per_objfile
->objfile
;
18440 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18442 gdb_assert (default_type
!= NULL
);
18444 if (attr
== NULL
|| prop
== NULL
)
18447 if (attr
->form_is_block ())
18449 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18450 baton
->property_type
= default_type
;
18451 baton
->locexpr
.per_cu
= cu
->per_cu
;
18452 baton
->locexpr
.per_objfile
= per_objfile
;
18454 struct dwarf_block
*block
= attr
->as_block ();
18455 baton
->locexpr
.size
= block
->size
;
18456 baton
->locexpr
.data
= block
->data
;
18457 switch (attr
->name
)
18459 case DW_AT_string_length
:
18460 baton
->locexpr
.is_reference
= true;
18463 baton
->locexpr
.is_reference
= false;
18467 prop
->set_locexpr (baton
);
18468 gdb_assert (prop
->baton () != NULL
);
18470 else if (attr
->form_is_ref ())
18472 struct dwarf2_cu
*target_cu
= cu
;
18473 struct die_info
*target_die
;
18474 struct attribute
*target_attr
;
18476 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18477 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18478 if (target_attr
== NULL
)
18479 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18481 if (target_attr
== NULL
)
18484 switch (target_attr
->name
)
18486 case DW_AT_location
:
18487 if (target_attr
->form_is_section_offset ())
18489 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18490 baton
->property_type
= die_type (target_die
, target_cu
);
18491 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18492 prop
->set_loclist (baton
);
18493 gdb_assert (prop
->baton () != NULL
);
18495 else if (target_attr
->form_is_block ())
18497 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18498 baton
->property_type
= die_type (target_die
, target_cu
);
18499 baton
->locexpr
.per_cu
= cu
->per_cu
;
18500 baton
->locexpr
.per_objfile
= per_objfile
;
18501 struct dwarf_block
*block
= target_attr
->as_block ();
18502 baton
->locexpr
.size
= block
->size
;
18503 baton
->locexpr
.data
= block
->data
;
18504 baton
->locexpr
.is_reference
= true;
18505 prop
->set_locexpr (baton
);
18506 gdb_assert (prop
->baton () != NULL
);
18510 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18511 "dynamic property");
18515 case DW_AT_data_member_location
:
18519 if (!handle_data_member_location (target_die
, target_cu
,
18523 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18524 baton
->property_type
= read_type_die (target_die
->parent
,
18526 baton
->offset_info
.offset
= offset
;
18527 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18528 prop
->set_addr_offset (baton
);
18533 else if (attr
->form_is_constant ())
18534 prop
->set_const_val (attr
->constant_value (0));
18537 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18538 dwarf2_name (die
, cu
));
18548 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18550 struct type
*int_type
;
18552 /* Helper macro to examine the various builtin types. */
18553 #define TRY_TYPE(F) \
18554 int_type = (unsigned_p \
18555 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18556 : objfile_type (objfile)->builtin_ ## F); \
18557 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18564 TRY_TYPE (long_long
);
18568 gdb_assert_not_reached ("unable to find suitable integer type");
18574 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
18576 int addr_size
= this->per_cu
->addr_size ();
18577 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
18580 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18581 present (which is valid) then compute the default type based on the
18582 compilation units address size. */
18584 static struct type
*
18585 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18587 struct type
*index_type
= die_type (die
, cu
);
18589 /* Dwarf-2 specifications explicitly allows to create subrange types
18590 without specifying a base type.
18591 In that case, the base type must be set to the type of
18592 the lower bound, upper bound or count, in that order, if any of these
18593 three attributes references an object that has a type.
18594 If no base type is found, the Dwarf-2 specifications say that
18595 a signed integer type of size equal to the size of an address should
18597 For the following C code: `extern char gdb_int [];'
18598 GCC produces an empty range DIE.
18599 FIXME: muller/2010-05-28: Possible references to object for low bound,
18600 high bound or count are not yet handled by this code. */
18601 if (index_type
->code () == TYPE_CODE_VOID
)
18602 index_type
= cu
->addr_sized_int_type (false);
18607 /* Read the given DW_AT_subrange DIE. */
18609 static struct type
*
18610 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18612 struct type
*base_type
, *orig_base_type
;
18613 struct type
*range_type
;
18614 struct attribute
*attr
;
18615 struct dynamic_prop low
, high
;
18616 int low_default_is_valid
;
18617 int high_bound_is_count
= 0;
18619 ULONGEST negative_mask
;
18621 orig_base_type
= read_subrange_index_type (die
, cu
);
18623 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18624 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18625 creating the range type, but we use the result of check_typedef
18626 when examining properties of the type. */
18627 base_type
= check_typedef (orig_base_type
);
18629 /* The die_type call above may have already set the type for this DIE. */
18630 range_type
= get_die_type (die
, cu
);
18634 high
.set_const_val (0);
18636 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18637 omitting DW_AT_lower_bound. */
18638 switch (cu
->language
)
18641 case language_cplus
:
18642 low
.set_const_val (0);
18643 low_default_is_valid
= 1;
18645 case language_fortran
:
18646 low
.set_const_val (1);
18647 low_default_is_valid
= 1;
18650 case language_objc
:
18651 case language_rust
:
18652 low
.set_const_val (0);
18653 low_default_is_valid
= (cu
->header
.version
>= 4);
18657 case language_pascal
:
18658 low
.set_const_val (1);
18659 low_default_is_valid
= (cu
->header
.version
>= 4);
18662 low
.set_const_val (0);
18663 low_default_is_valid
= 0;
18667 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18668 if (attr
!= nullptr)
18669 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18670 else if (!low_default_is_valid
)
18671 complaint (_("Missing DW_AT_lower_bound "
18672 "- DIE at %s [in module %s]"),
18673 sect_offset_str (die
->sect_off
),
18674 objfile_name (cu
->per_objfile
->objfile
));
18676 struct attribute
*attr_ub
, *attr_count
;
18677 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18678 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18680 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18681 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18683 /* If bounds are constant do the final calculation here. */
18684 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18685 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18687 high_bound_is_count
= 1;
18691 if (attr_ub
!= NULL
)
18692 complaint (_("Unresolved DW_AT_upper_bound "
18693 "- DIE at %s [in module %s]"),
18694 sect_offset_str (die
->sect_off
),
18695 objfile_name (cu
->per_objfile
->objfile
));
18696 if (attr_count
!= NULL
)
18697 complaint (_("Unresolved DW_AT_count "
18698 "- DIE at %s [in module %s]"),
18699 sect_offset_str (die
->sect_off
),
18700 objfile_name (cu
->per_objfile
->objfile
));
18705 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18706 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18707 bias
= bias_attr
->constant_value (0);
18709 /* Normally, the DWARF producers are expected to use a signed
18710 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18711 But this is unfortunately not always the case, as witnessed
18712 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18713 is used instead. To work around that ambiguity, we treat
18714 the bounds as signed, and thus sign-extend their values, when
18715 the base type is signed. */
18717 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18718 if (low
.kind () == PROP_CONST
18719 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18720 low
.set_const_val (low
.const_val () | negative_mask
);
18721 if (high
.kind () == PROP_CONST
18722 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18723 high
.set_const_val (high
.const_val () | negative_mask
);
18725 /* Check for bit and byte strides. */
18726 struct dynamic_prop byte_stride_prop
;
18727 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18728 if (attr_byte_stride
!= nullptr)
18730 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18731 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18735 struct dynamic_prop bit_stride_prop
;
18736 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18737 if (attr_bit_stride
!= nullptr)
18739 /* It only makes sense to have either a bit or byte stride. */
18740 if (attr_byte_stride
!= nullptr)
18742 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18743 "- DIE at %s [in module %s]"),
18744 sect_offset_str (die
->sect_off
),
18745 objfile_name (cu
->per_objfile
->objfile
));
18746 attr_bit_stride
= nullptr;
18750 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18751 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18756 if (attr_byte_stride
!= nullptr
18757 || attr_bit_stride
!= nullptr)
18759 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18760 struct dynamic_prop
*stride
18761 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18764 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18765 &high
, bias
, stride
, byte_stride_p
);
18768 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18770 if (high_bound_is_count
)
18771 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18773 /* Ada expects an empty array on no boundary attributes. */
18774 if (attr
== NULL
&& cu
->language
!= language_ada
)
18775 range_type
->bounds ()->high
.set_undefined ();
18777 name
= dwarf2_name (die
, cu
);
18779 range_type
->set_name (name
);
18781 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18782 if (attr
!= nullptr)
18783 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18785 maybe_set_alignment (cu
, die
, range_type
);
18787 set_die_type (die
, range_type
, cu
);
18789 /* set_die_type should be already done. */
18790 set_descriptive_type (range_type
, die
, cu
);
18795 static struct type
*
18796 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18800 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18801 type
->set_name (dwarf2_name (die
, cu
));
18803 /* In Ada, an unspecified type is typically used when the description
18804 of the type is deferred to a different unit. When encountering
18805 such a type, we treat it as a stub, and try to resolve it later on,
18807 if (cu
->language
== language_ada
)
18808 type
->set_is_stub (true);
18810 return set_die_type (die
, type
, cu
);
18813 /* Read a single die and all its descendents. Set the die's sibling
18814 field to NULL; set other fields in the die correctly, and set all
18815 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18816 location of the info_ptr after reading all of those dies. PARENT
18817 is the parent of the die in question. */
18819 static struct die_info
*
18820 read_die_and_children (const struct die_reader_specs
*reader
,
18821 const gdb_byte
*info_ptr
,
18822 const gdb_byte
**new_info_ptr
,
18823 struct die_info
*parent
)
18825 struct die_info
*die
;
18826 const gdb_byte
*cur_ptr
;
18828 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18831 *new_info_ptr
= cur_ptr
;
18834 store_in_ref_table (die
, reader
->cu
);
18836 if (die
->has_children
)
18837 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18841 *new_info_ptr
= cur_ptr
;
18844 die
->sibling
= NULL
;
18845 die
->parent
= parent
;
18849 /* Read a die, all of its descendents, and all of its siblings; set
18850 all of the fields of all of the dies correctly. Arguments are as
18851 in read_die_and_children. */
18853 static struct die_info
*
18854 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18855 const gdb_byte
*info_ptr
,
18856 const gdb_byte
**new_info_ptr
,
18857 struct die_info
*parent
)
18859 struct die_info
*first_die
, *last_sibling
;
18860 const gdb_byte
*cur_ptr
;
18862 cur_ptr
= info_ptr
;
18863 first_die
= last_sibling
= NULL
;
18867 struct die_info
*die
18868 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18872 *new_info_ptr
= cur_ptr
;
18879 last_sibling
->sibling
= die
;
18881 last_sibling
= die
;
18885 /* Read a die, all of its descendents, and all of its siblings; set
18886 all of the fields of all of the dies correctly. Arguments are as
18887 in read_die_and_children.
18888 This the main entry point for reading a DIE and all its children. */
18890 static struct die_info
*
18891 read_die_and_siblings (const struct die_reader_specs
*reader
,
18892 const gdb_byte
*info_ptr
,
18893 const gdb_byte
**new_info_ptr
,
18894 struct die_info
*parent
)
18896 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18897 new_info_ptr
, parent
);
18899 if (dwarf_die_debug
)
18901 fprintf_unfiltered (gdb_stdlog
,
18902 "Read die from %s@0x%x of %s:\n",
18903 reader
->die_section
->get_name (),
18904 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18905 bfd_get_filename (reader
->abfd
));
18906 dump_die (die
, dwarf_die_debug
);
18912 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18914 The caller is responsible for filling in the extra attributes
18915 and updating (*DIEP)->num_attrs.
18916 Set DIEP to point to a newly allocated die with its information,
18917 except for its child, sibling, and parent fields. */
18919 static const gdb_byte
*
18920 read_full_die_1 (const struct die_reader_specs
*reader
,
18921 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18922 int num_extra_attrs
)
18924 unsigned int abbrev_number
, bytes_read
, i
;
18925 const struct abbrev_info
*abbrev
;
18926 struct die_info
*die
;
18927 struct dwarf2_cu
*cu
= reader
->cu
;
18928 bfd
*abfd
= reader
->abfd
;
18930 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18931 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18932 info_ptr
+= bytes_read
;
18933 if (!abbrev_number
)
18939 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18941 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18943 bfd_get_filename (abfd
));
18945 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18946 die
->sect_off
= sect_off
;
18947 die
->tag
= abbrev
->tag
;
18948 die
->abbrev
= abbrev_number
;
18949 die
->has_children
= abbrev
->has_children
;
18951 /* Make the result usable.
18952 The caller needs to update num_attrs after adding the extra
18954 die
->num_attrs
= abbrev
->num_attrs
;
18956 bool any_need_reprocess
= false;
18957 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18959 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18961 if (die
->attrs
[i
].requires_reprocessing_p ())
18962 any_need_reprocess
= true;
18965 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18966 if (attr
!= nullptr && attr
->form_is_unsigned ())
18967 cu
->str_offsets_base
= attr
->as_unsigned ();
18969 attr
= die
->attr (DW_AT_loclists_base
);
18970 if (attr
!= nullptr)
18971 cu
->loclist_base
= attr
->as_unsigned ();
18973 auto maybe_addr_base
= die
->addr_base ();
18974 if (maybe_addr_base
.has_value ())
18975 cu
->addr_base
= *maybe_addr_base
;
18977 attr
= die
->attr (DW_AT_rnglists_base
);
18978 if (attr
!= nullptr)
18979 cu
->rnglists_base
= attr
->as_unsigned ();
18981 if (any_need_reprocess
)
18983 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18985 if (die
->attrs
[i
].requires_reprocessing_p ())
18986 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
18993 /* Read a die and all its attributes.
18994 Set DIEP to point to a newly allocated die with its information,
18995 except for its child, sibling, and parent fields. */
18997 static const gdb_byte
*
18998 read_full_die (const struct die_reader_specs
*reader
,
18999 struct die_info
**diep
, const gdb_byte
*info_ptr
)
19001 const gdb_byte
*result
;
19003 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
19005 if (dwarf_die_debug
)
19007 fprintf_unfiltered (gdb_stdlog
,
19008 "Read die from %s@0x%x of %s:\n",
19009 reader
->die_section
->get_name (),
19010 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19011 bfd_get_filename (reader
->abfd
));
19012 dump_die (*diep
, dwarf_die_debug
);
19019 /* Returns nonzero if TAG represents a type that we might generate a partial
19023 is_type_tag_for_partial (int tag
, enum language lang
)
19028 /* Some types that would be reasonable to generate partial symbols for,
19029 that we don't at present. Note that normally this does not
19030 matter, mainly because C compilers don't give names to these
19031 types, but instead emit DW_TAG_typedef. */
19032 case DW_TAG_file_type
:
19033 case DW_TAG_ptr_to_member_type
:
19034 case DW_TAG_set_type
:
19035 case DW_TAG_string_type
:
19036 case DW_TAG_subroutine_type
:
19039 /* GNAT may emit an array with a name, but no typedef, so we
19040 need to make a symbol in this case. */
19041 case DW_TAG_array_type
:
19042 return lang
== language_ada
;
19044 case DW_TAG_base_type
:
19045 case DW_TAG_class_type
:
19046 case DW_TAG_interface_type
:
19047 case DW_TAG_enumeration_type
:
19048 case DW_TAG_structure_type
:
19049 case DW_TAG_subrange_type
:
19050 case DW_TAG_typedef
:
19051 case DW_TAG_union_type
:
19058 /* Load all DIEs that are interesting for partial symbols into memory. */
19060 static struct partial_die_info
*
19061 load_partial_dies (const struct die_reader_specs
*reader
,
19062 const gdb_byte
*info_ptr
, int building_psymtab
)
19064 struct dwarf2_cu
*cu
= reader
->cu
;
19065 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19066 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
19067 unsigned int bytes_read
;
19068 unsigned int load_all
= 0;
19069 int nesting_level
= 1;
19074 gdb_assert (cu
->per_cu
!= NULL
);
19075 if (cu
->per_cu
->load_all_dies
)
19079 = htab_create_alloc_ex (cu
->header
.length
/ 12,
19083 &cu
->comp_unit_obstack
,
19084 hashtab_obstack_allocate
,
19085 dummy_obstack_deallocate
);
19089 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
19092 /* A NULL abbrev means the end of a series of children. */
19093 if (abbrev
== NULL
)
19095 if (--nesting_level
== 0)
19098 info_ptr
+= bytes_read
;
19099 last_die
= parent_die
;
19100 parent_die
= parent_die
->die_parent
;
19104 /* Check for template arguments. We never save these; if
19105 they're seen, we just mark the parent, and go on our way. */
19106 if (parent_die
!= NULL
19107 && cu
->language
== language_cplus
19108 && (abbrev
->tag
== DW_TAG_template_type_param
19109 || abbrev
->tag
== DW_TAG_template_value_param
))
19111 parent_die
->has_template_arguments
= 1;
19115 /* We don't need a partial DIE for the template argument. */
19116 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19121 /* We only recurse into c++ subprograms looking for template arguments.
19122 Skip their other children. */
19124 && cu
->language
== language_cplus
19125 && parent_die
!= NULL
19126 && parent_die
->tag
== DW_TAG_subprogram
19127 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19129 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19133 /* Check whether this DIE is interesting enough to save. Normally
19134 we would not be interested in members here, but there may be
19135 later variables referencing them via DW_AT_specification (for
19136 static members). */
19138 && !is_type_tag_for_partial (abbrev
->tag
, cu
->language
)
19139 && abbrev
->tag
!= DW_TAG_constant
19140 && abbrev
->tag
!= DW_TAG_enumerator
19141 && abbrev
->tag
!= DW_TAG_subprogram
19142 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19143 && abbrev
->tag
!= DW_TAG_lexical_block
19144 && abbrev
->tag
!= DW_TAG_variable
19145 && abbrev
->tag
!= DW_TAG_namespace
19146 && abbrev
->tag
!= DW_TAG_module
19147 && abbrev
->tag
!= DW_TAG_member
19148 && abbrev
->tag
!= DW_TAG_imported_unit
19149 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19151 /* Otherwise we skip to the next sibling, if any. */
19152 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19156 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19159 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19161 /* This two-pass algorithm for processing partial symbols has a
19162 high cost in cache pressure. Thus, handle some simple cases
19163 here which cover the majority of C partial symbols. DIEs
19164 which neither have specification tags in them, nor could have
19165 specification tags elsewhere pointing at them, can simply be
19166 processed and discarded.
19168 This segment is also optional; scan_partial_symbols and
19169 add_partial_symbol will handle these DIEs if we chain
19170 them in normally. When compilers which do not emit large
19171 quantities of duplicate debug information are more common,
19172 this code can probably be removed. */
19174 /* Any complete simple types at the top level (pretty much all
19175 of them, for a language without namespaces), can be processed
19177 if (parent_die
== NULL
19178 && pdi
.has_specification
== 0
19179 && pdi
.is_declaration
== 0
19180 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19181 || pdi
.tag
== DW_TAG_base_type
19182 || pdi
.tag
== DW_TAG_array_type
19183 || pdi
.tag
== DW_TAG_subrange_type
))
19185 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19186 add_partial_symbol (&pdi
, cu
);
19188 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19192 /* The exception for DW_TAG_typedef with has_children above is
19193 a workaround of GCC PR debug/47510. In the case of this complaint
19194 type_name_or_error will error on such types later.
19196 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19197 it could not find the child DIEs referenced later, this is checked
19198 above. In correct DWARF DW_TAG_typedef should have no children. */
19200 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19201 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19202 "- DIE at %s [in module %s]"),
19203 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19205 /* If we're at the second level, and we're an enumerator, and
19206 our parent has no specification (meaning possibly lives in a
19207 namespace elsewhere), then we can add the partial symbol now
19208 instead of queueing it. */
19209 if (pdi
.tag
== DW_TAG_enumerator
19210 && parent_die
!= NULL
19211 && parent_die
->die_parent
== NULL
19212 && parent_die
->tag
== DW_TAG_enumeration_type
19213 && parent_die
->has_specification
== 0)
19215 if (pdi
.raw_name
== NULL
)
19216 complaint (_("malformed enumerator DIE ignored"));
19217 else if (building_psymtab
)
19218 add_partial_symbol (&pdi
, cu
);
19220 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19224 struct partial_die_info
*part_die
19225 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19227 /* We'll save this DIE so link it in. */
19228 part_die
->die_parent
= parent_die
;
19229 part_die
->die_sibling
= NULL
;
19230 part_die
->die_child
= NULL
;
19232 if (last_die
&& last_die
== parent_die
)
19233 last_die
->die_child
= part_die
;
19235 last_die
->die_sibling
= part_die
;
19237 last_die
= part_die
;
19239 if (first_die
== NULL
)
19240 first_die
= part_die
;
19242 /* Maybe add the DIE to the hash table. Not all DIEs that we
19243 find interesting need to be in the hash table, because we
19244 also have the parent/sibling/child chains; only those that we
19245 might refer to by offset later during partial symbol reading.
19247 For now this means things that might have be the target of a
19248 DW_AT_specification, DW_AT_abstract_origin, or
19249 DW_AT_extension. DW_AT_extension will refer only to
19250 namespaces; DW_AT_abstract_origin refers to functions (and
19251 many things under the function DIE, but we do not recurse
19252 into function DIEs during partial symbol reading) and
19253 possibly variables as well; DW_AT_specification refers to
19254 declarations. Declarations ought to have the DW_AT_declaration
19255 flag. It happens that GCC forgets to put it in sometimes, but
19256 only for functions, not for types.
19258 Adding more things than necessary to the hash table is harmless
19259 except for the performance cost. Adding too few will result in
19260 wasted time in find_partial_die, when we reread the compilation
19261 unit with load_all_dies set. */
19264 || abbrev
->tag
== DW_TAG_constant
19265 || abbrev
->tag
== DW_TAG_subprogram
19266 || abbrev
->tag
== DW_TAG_variable
19267 || abbrev
->tag
== DW_TAG_namespace
19268 || part_die
->is_declaration
)
19272 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19273 to_underlying (part_die
->sect_off
),
19278 /* For some DIEs we want to follow their children (if any). For C
19279 we have no reason to follow the children of structures; for other
19280 languages we have to, so that we can get at method physnames
19281 to infer fully qualified class names, for DW_AT_specification,
19282 and for C++ template arguments. For C++, we also look one level
19283 inside functions to find template arguments (if the name of the
19284 function does not already contain the template arguments).
19286 For Ada and Fortran, we need to scan the children of subprograms
19287 and lexical blocks as well because these languages allow the
19288 definition of nested entities that could be interesting for the
19289 debugger, such as nested subprograms for instance. */
19290 if (last_die
->has_children
19292 || last_die
->tag
== DW_TAG_namespace
19293 || last_die
->tag
== DW_TAG_module
19294 || last_die
->tag
== DW_TAG_enumeration_type
19295 || (cu
->language
== language_cplus
19296 && last_die
->tag
== DW_TAG_subprogram
19297 && (last_die
->raw_name
== NULL
19298 || strchr (last_die
->raw_name
, '<') == NULL
))
19299 || (cu
->language
!= language_c
19300 && (last_die
->tag
== DW_TAG_class_type
19301 || last_die
->tag
== DW_TAG_interface_type
19302 || last_die
->tag
== DW_TAG_structure_type
19303 || last_die
->tag
== DW_TAG_union_type
))
19304 || ((cu
->language
== language_ada
19305 || cu
->language
== language_fortran
)
19306 && (last_die
->tag
== DW_TAG_subprogram
19307 || last_die
->tag
== DW_TAG_lexical_block
))))
19310 parent_die
= last_die
;
19314 /* Otherwise we skip to the next sibling, if any. */
19315 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19317 /* Back to the top, do it again. */
19321 partial_die_info::partial_die_info (sect_offset sect_off_
,
19322 const struct abbrev_info
*abbrev
)
19323 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19327 /* See class definition. */
19330 partial_die_info::name (dwarf2_cu
*cu
)
19332 if (!canonical_name
&& raw_name
!= nullptr)
19334 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19335 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19336 canonical_name
= 1;
19342 /* Read a minimal amount of information into the minimal die structure.
19343 INFO_PTR should point just after the initial uleb128 of a DIE. */
19346 partial_die_info::read (const struct die_reader_specs
*reader
,
19347 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19349 struct dwarf2_cu
*cu
= reader
->cu
;
19350 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19352 int has_low_pc_attr
= 0;
19353 int has_high_pc_attr
= 0;
19354 int high_pc_relative
= 0;
19356 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19359 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19360 /* String and address offsets that need to do the reprocessing have
19361 already been read at this point, so there is no need to wait until
19362 the loop terminates to do the reprocessing. */
19363 if (attr
.requires_reprocessing_p ())
19364 read_attribute_reprocess (reader
, &attr
, tag
);
19365 /* Store the data if it is of an attribute we want to keep in a
19366 partial symbol table. */
19372 case DW_TAG_compile_unit
:
19373 case DW_TAG_partial_unit
:
19374 case DW_TAG_type_unit
:
19375 /* Compilation units have a DW_AT_name that is a filename, not
19376 a source language identifier. */
19377 case DW_TAG_enumeration_type
:
19378 case DW_TAG_enumerator
:
19379 /* These tags always have simple identifiers already; no need
19380 to canonicalize them. */
19381 canonical_name
= 1;
19382 raw_name
= attr
.as_string ();
19385 canonical_name
= 0;
19386 raw_name
= attr
.as_string ();
19390 case DW_AT_linkage_name
:
19391 case DW_AT_MIPS_linkage_name
:
19392 /* Note that both forms of linkage name might appear. We
19393 assume they will be the same, and we only store the last
19395 linkage_name
= attr
.as_string ();
19398 has_low_pc_attr
= 1;
19399 lowpc
= attr
.as_address ();
19401 case DW_AT_high_pc
:
19402 has_high_pc_attr
= 1;
19403 highpc
= attr
.as_address ();
19404 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19405 high_pc_relative
= 1;
19407 case DW_AT_location
:
19408 /* Support the .debug_loc offsets. */
19409 if (attr
.form_is_block ())
19411 d
.locdesc
= attr
.as_block ();
19413 else if (attr
.form_is_section_offset ())
19415 dwarf2_complex_location_expr_complaint ();
19419 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19420 "partial symbol information");
19423 case DW_AT_external
:
19424 is_external
= attr
.as_boolean ();
19426 case DW_AT_declaration
:
19427 is_declaration
= attr
.as_boolean ();
19432 case DW_AT_abstract_origin
:
19433 case DW_AT_specification
:
19434 case DW_AT_extension
:
19435 has_specification
= 1;
19436 spec_offset
= attr
.get_ref_die_offset ();
19437 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19438 || cu
->per_cu
->is_dwz
);
19440 case DW_AT_sibling
:
19441 /* Ignore absolute siblings, they might point outside of
19442 the current compile unit. */
19443 if (attr
.form
== DW_FORM_ref_addr
)
19444 complaint (_("ignoring absolute DW_AT_sibling"));
19447 const gdb_byte
*buffer
= reader
->buffer
;
19448 sect_offset off
= attr
.get_ref_die_offset ();
19449 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19451 if (sibling_ptr
< info_ptr
)
19452 complaint (_("DW_AT_sibling points backwards"));
19453 else if (sibling_ptr
> reader
->buffer_end
)
19454 reader
->die_section
->overflow_complaint ();
19456 sibling
= sibling_ptr
;
19459 case DW_AT_byte_size
:
19462 case DW_AT_const_value
:
19463 has_const_value
= 1;
19465 case DW_AT_calling_convention
:
19466 /* DWARF doesn't provide a way to identify a program's source-level
19467 entry point. DW_AT_calling_convention attributes are only meant
19468 to describe functions' calling conventions.
19470 However, because it's a necessary piece of information in
19471 Fortran, and before DWARF 4 DW_CC_program was the only
19472 piece of debugging information whose definition refers to
19473 a 'main program' at all, several compilers marked Fortran
19474 main programs with DW_CC_program --- even when those
19475 functions use the standard calling conventions.
19477 Although DWARF now specifies a way to provide this
19478 information, we support this practice for backward
19480 if (attr
.constant_value (0) == DW_CC_program
19481 && cu
->language
== language_fortran
)
19482 main_subprogram
= 1;
19486 LONGEST value
= attr
.constant_value (-1);
19487 if (value
== DW_INL_inlined
19488 || value
== DW_INL_declared_inlined
)
19489 may_be_inlined
= 1;
19494 if (tag
== DW_TAG_imported_unit
)
19496 d
.sect_off
= attr
.get_ref_die_offset ();
19497 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19498 || cu
->per_cu
->is_dwz
);
19502 case DW_AT_main_subprogram
:
19503 main_subprogram
= attr
.as_boolean ();
19508 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19509 on DWARF version). */
19510 ULONGEST ranges_offset
= attr
.as_unsigned ();
19512 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19514 if (tag
!= DW_TAG_compile_unit
)
19515 ranges_offset
+= cu
->gnu_ranges_base
;
19517 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19528 /* For Ada, if both the name and the linkage name appear, we prefer
19529 the latter. This lets "catch exception" work better, regardless
19530 of the order in which the name and linkage name were emitted.
19531 Really, though, this is just a workaround for the fact that gdb
19532 doesn't store both the name and the linkage name. */
19533 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19534 raw_name
= linkage_name
;
19536 if (high_pc_relative
)
19539 if (has_low_pc_attr
&& has_high_pc_attr
)
19541 /* When using the GNU linker, .gnu.linkonce. sections are used to
19542 eliminate duplicate copies of functions and vtables and such.
19543 The linker will arbitrarily choose one and discard the others.
19544 The AT_*_pc values for such functions refer to local labels in
19545 these sections. If the section from that file was discarded, the
19546 labels are not in the output, so the relocs get a value of 0.
19547 If this is a discarded function, mark the pc bounds as invalid,
19548 so that GDB will ignore it. */
19549 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19551 struct objfile
*objfile
= per_objfile
->objfile
;
19552 struct gdbarch
*gdbarch
= objfile
->arch ();
19554 complaint (_("DW_AT_low_pc %s is zero "
19555 "for DIE at %s [in module %s]"),
19556 paddress (gdbarch
, lowpc
),
19557 sect_offset_str (sect_off
),
19558 objfile_name (objfile
));
19560 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19561 else if (lowpc
>= highpc
)
19563 struct objfile
*objfile
= per_objfile
->objfile
;
19564 struct gdbarch
*gdbarch
= objfile
->arch ();
19566 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19567 "for DIE at %s [in module %s]"),
19568 paddress (gdbarch
, lowpc
),
19569 paddress (gdbarch
, highpc
),
19570 sect_offset_str (sect_off
),
19571 objfile_name (objfile
));
19580 /* Find a cached partial DIE at OFFSET in CU. */
19582 struct partial_die_info
*
19583 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19585 struct partial_die_info
*lookup_die
= NULL
;
19586 struct partial_die_info
part_die (sect_off
);
19588 lookup_die
= ((struct partial_die_info
*)
19589 htab_find_with_hash (partial_dies
, &part_die
,
19590 to_underlying (sect_off
)));
19595 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19596 except in the case of .debug_types DIEs which do not reference
19597 outside their CU (they do however referencing other types via
19598 DW_FORM_ref_sig8). */
19600 static const struct cu_partial_die_info
19601 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19603 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19604 struct objfile
*objfile
= per_objfile
->objfile
;
19605 struct partial_die_info
*pd
= NULL
;
19607 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19608 && cu
->header
.offset_in_cu_p (sect_off
))
19610 pd
= cu
->find_partial_die (sect_off
);
19613 /* We missed recording what we needed.
19614 Load all dies and try again. */
19618 /* TUs don't reference other CUs/TUs (except via type signatures). */
19619 if (cu
->per_cu
->is_debug_types
)
19621 error (_("Dwarf Error: Type Unit at offset %s contains"
19622 " external reference to offset %s [in module %s].\n"),
19623 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19624 bfd_get_filename (objfile
->obfd
));
19626 dwarf2_per_cu_data
*per_cu
19627 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19630 cu
= per_objfile
->get_cu (per_cu
);
19631 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19632 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19634 cu
= per_objfile
->get_cu (per_cu
);
19637 pd
= cu
->find_partial_die (sect_off
);
19640 /* If we didn't find it, and not all dies have been loaded,
19641 load them all and try again. */
19643 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
19645 cu
->per_cu
->load_all_dies
= 1;
19647 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19648 THIS_CU->cu may already be in use. So we can't just free it and
19649 replace its DIEs with the ones we read in. Instead, we leave those
19650 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19651 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19653 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19655 pd
= cu
->find_partial_die (sect_off
);
19659 error (_("Dwarf Error: Cannot not find DIE at %s [from module %s]\n"),
19660 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19664 /* See if we can figure out if the class lives in a namespace. We do
19665 this by looking for a member function; its demangled name will
19666 contain namespace info, if there is any. */
19669 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19670 struct dwarf2_cu
*cu
)
19672 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19673 what template types look like, because the demangler
19674 frequently doesn't give the same name as the debug info. We
19675 could fix this by only using the demangled name to get the
19676 prefix (but see comment in read_structure_type). */
19678 struct partial_die_info
*real_pdi
;
19679 struct partial_die_info
*child_pdi
;
19681 /* If this DIE (this DIE's specification, if any) has a parent, then
19682 we should not do this. We'll prepend the parent's fully qualified
19683 name when we create the partial symbol. */
19685 real_pdi
= struct_pdi
;
19686 while (real_pdi
->has_specification
)
19688 auto res
= find_partial_die (real_pdi
->spec_offset
,
19689 real_pdi
->spec_is_dwz
, cu
);
19690 real_pdi
= res
.pdi
;
19694 if (real_pdi
->die_parent
!= NULL
)
19697 for (child_pdi
= struct_pdi
->die_child
;
19699 child_pdi
= child_pdi
->die_sibling
)
19701 if (child_pdi
->tag
== DW_TAG_subprogram
19702 && child_pdi
->linkage_name
!= NULL
)
19704 gdb::unique_xmalloc_ptr
<char> actual_class_name
19705 (cu
->language_defn
->class_name_from_physname
19706 (child_pdi
->linkage_name
));
19707 if (actual_class_name
!= NULL
)
19709 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19710 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19711 struct_pdi
->canonical_name
= 1;
19718 /* Return true if a DIE with TAG may have the DW_AT_const_value
19722 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19726 case DW_TAG_constant
:
19727 case DW_TAG_enumerator
:
19728 case DW_TAG_formal_parameter
:
19729 case DW_TAG_template_value_param
:
19730 case DW_TAG_variable
:
19738 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19740 /* Once we've fixed up a die, there's no point in doing so again.
19741 This also avoids a memory leak if we were to call
19742 guess_partial_die_structure_name multiple times. */
19746 /* If we found a reference attribute and the DIE has no name, try
19747 to find a name in the referred to DIE. */
19749 if (raw_name
== NULL
&& has_specification
)
19751 struct partial_die_info
*spec_die
;
19753 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19754 spec_die
= res
.pdi
;
19757 spec_die
->fixup (cu
);
19759 if (spec_die
->raw_name
)
19761 raw_name
= spec_die
->raw_name
;
19762 canonical_name
= spec_die
->canonical_name
;
19764 /* Copy DW_AT_external attribute if it is set. */
19765 if (spec_die
->is_external
)
19766 is_external
= spec_die
->is_external
;
19770 if (!has_const_value
&& has_specification
19771 && can_have_DW_AT_const_value_p (tag
))
19773 struct partial_die_info
*spec_die
;
19775 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19776 spec_die
= res
.pdi
;
19779 spec_die
->fixup (cu
);
19781 if (spec_die
->has_const_value
)
19783 /* Copy DW_AT_const_value attribute if it is set. */
19784 has_const_value
= spec_die
->has_const_value
;
19788 /* Set default names for some unnamed DIEs. */
19790 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19792 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19793 canonical_name
= 1;
19796 /* If there is no parent die to provide a namespace, and there are
19797 children, see if we can determine the namespace from their linkage
19799 if (cu
->language
== language_cplus
19800 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19801 && die_parent
== NULL
19803 && (tag
== DW_TAG_class_type
19804 || tag
== DW_TAG_structure_type
19805 || tag
== DW_TAG_union_type
))
19806 guess_partial_die_structure_name (this, cu
);
19808 /* GCC might emit a nameless struct or union that has a linkage
19809 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19810 if (raw_name
== NULL
19811 && (tag
== DW_TAG_class_type
19812 || tag
== DW_TAG_interface_type
19813 || tag
== DW_TAG_structure_type
19814 || tag
== DW_TAG_union_type
)
19815 && linkage_name
!= NULL
)
19817 gdb::unique_xmalloc_ptr
<char> demangled
19818 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19819 if (demangled
!= nullptr)
19823 /* Strip any leading namespaces/classes, keep only the base name.
19824 DW_AT_name for named DIEs does not contain the prefixes. */
19825 base
= strrchr (demangled
.get (), ':');
19826 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19829 base
= demangled
.get ();
19831 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19832 raw_name
= objfile
->intern (base
);
19833 canonical_name
= 1;
19840 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19841 contents from the given SECTION in the HEADER.
19843 HEADER_OFFSET is the offset of the header in the section. */
19845 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19846 struct dwarf2_section_info
*section
,
19847 sect_offset header_offset
)
19849 unsigned int bytes_read
;
19850 bfd
*abfd
= section
->get_bfd_owner ();
19851 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
19853 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19854 info_ptr
+= bytes_read
;
19856 header
->version
= read_2_bytes (abfd
, info_ptr
);
19859 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19862 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19865 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19868 /* Return the DW_AT_loclists_base value for the CU. */
19870 lookup_loclist_base (struct dwarf2_cu
*cu
)
19872 /* For the .dwo unit, the loclist_base points to the first offset following
19873 the header. The header consists of the following entities-
19874 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19876 2. version (2 bytes)
19877 3. address size (1 byte)
19878 4. segment selector size (1 byte)
19879 5. offset entry count (4 bytes)
19880 These sizes are derived as per the DWARFv5 standard. */
19881 if (cu
->dwo_unit
!= nullptr)
19883 if (cu
->header
.initial_length_size
== 4)
19884 return LOCLIST_HEADER_SIZE32
;
19885 return LOCLIST_HEADER_SIZE64
;
19887 return cu
->loclist_base
;
19890 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19891 array of offsets in the .debug_loclists section. */
19894 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19896 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19897 struct objfile
*objfile
= per_objfile
->objfile
;
19898 bfd
*abfd
= objfile
->obfd
;
19899 ULONGEST loclist_header_size
=
19900 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
19901 : LOCLIST_HEADER_SIZE64
);
19902 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19904 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
19905 ULONGEST start_offset
=
19906 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19908 /* Get loclists section. */
19909 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19911 /* Read the loclists section content. */
19912 section
->read (objfile
);
19913 if (section
->buffer
== NULL
)
19914 error (_("DW_FORM_loclistx used without .debug_loclists "
19915 "section [in module %s]"), objfile_name (objfile
));
19917 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
19918 so if loclist_base is smaller than the header size, we have a problem. */
19919 if (loclist_base
< loclist_header_size
)
19920 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
19921 objfile_name (objfile
));
19923 /* Read the header of the loclists contribution. */
19924 struct loclists_rnglists_header header
;
19925 read_loclists_rnglists_header (&header
, section
,
19926 (sect_offset
) (loclist_base
- loclist_header_size
));
19928 /* Verify the loclist index is valid. */
19929 if (loclist_index
>= header
.offset_entry_count
)
19930 error (_("DW_FORM_loclistx pointing outside of "
19931 ".debug_loclists offset array [in module %s]"),
19932 objfile_name (objfile
));
19934 /* Validate that reading won't go beyond the end of the section. */
19935 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19936 error (_("Reading DW_FORM_loclistx index beyond end of"
19937 ".debug_loclists section [in module %s]"),
19938 objfile_name (objfile
));
19940 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19942 if (cu
->header
.offset_size
== 4)
19943 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
19945 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
19948 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19949 array of offsets in the .debug_rnglists section. */
19952 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19955 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19956 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19957 bfd
*abfd
= objfile
->obfd
;
19958 ULONGEST rnglist_header_size
=
19959 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19960 : RNGLIST_HEADER_SIZE64
);
19962 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
19963 .debug_rnglists.dwo section. The rnglists base given in the skeleton
19965 ULONGEST rnglist_base
=
19966 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
19968 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
19969 ULONGEST start_offset
=
19970 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19972 /* Get rnglists section. */
19973 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19975 /* Read the rnglists section content. */
19976 section
->read (objfile
);
19977 if (section
->buffer
== nullptr)
19978 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19980 objfile_name (objfile
));
19982 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
19983 so if rnglist_base is smaller than the header size, we have a problem. */
19984 if (rnglist_base
< rnglist_header_size
)
19985 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
19986 objfile_name (objfile
));
19988 /* Read the header of the rnglists contribution. */
19989 struct loclists_rnglists_header header
;
19990 read_loclists_rnglists_header (&header
, section
,
19991 (sect_offset
) (rnglist_base
- rnglist_header_size
));
19993 /* Verify the rnglist index is valid. */
19994 if (rnglist_index
>= header
.offset_entry_count
)
19995 error (_("DW_FORM_rnglistx index pointing outside of "
19996 ".debug_rnglists offset array [in module %s]"),
19997 objfile_name (objfile
));
19999 /* Validate that reading won't go beyond the end of the section. */
20000 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
20001 error (_("Reading DW_FORM_rnglistx index beyond end of"
20002 ".debug_rnglists section [in module %s]"),
20003 objfile_name (objfile
));
20005 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20007 if (cu
->header
.offset_size
== 4)
20008 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
20010 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
20013 /* Process the attributes that had to be skipped in the first round. These
20014 attributes are the ones that need str_offsets_base or addr_base attributes.
20015 They could not have been processed in the first round, because at the time
20016 the values of str_offsets_base or addr_base may not have been known. */
20018 read_attribute_reprocess (const struct die_reader_specs
*reader
,
20019 struct attribute
*attr
, dwarf_tag tag
)
20021 struct dwarf2_cu
*cu
= reader
->cu
;
20022 switch (attr
->form
)
20024 case DW_FORM_addrx
:
20025 case DW_FORM_GNU_addr_index
:
20026 attr
->set_address (read_addr_index (cu
,
20027 attr
->as_unsigned_reprocess ()));
20029 case DW_FORM_loclistx
:
20031 sect_offset loclists_sect_off
20032 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
20034 attr
->set_unsigned (to_underlying (loclists_sect_off
));
20037 case DW_FORM_rnglistx
:
20039 sect_offset rnglists_sect_off
20040 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
20042 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
20046 case DW_FORM_strx1
:
20047 case DW_FORM_strx2
:
20048 case DW_FORM_strx3
:
20049 case DW_FORM_strx4
:
20050 case DW_FORM_GNU_str_index
:
20052 unsigned int str_index
= attr
->as_unsigned_reprocess ();
20053 gdb_assert (!attr
->canonical_string_p ());
20054 if (reader
->dwo_file
!= NULL
)
20055 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
20058 attr
->set_string_noncanonical (read_stub_str_index (cu
,
20063 gdb_assert_not_reached (_("Unexpected DWARF form."));
20067 /* Read an attribute value described by an attribute form. */
20069 static const gdb_byte
*
20070 read_attribute_value (const struct die_reader_specs
*reader
,
20071 struct attribute
*attr
, unsigned form
,
20072 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
20074 struct dwarf2_cu
*cu
= reader
->cu
;
20075 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20076 struct objfile
*objfile
= per_objfile
->objfile
;
20077 bfd
*abfd
= reader
->abfd
;
20078 struct comp_unit_head
*cu_header
= &cu
->header
;
20079 unsigned int bytes_read
;
20080 struct dwarf_block
*blk
;
20082 attr
->form
= (enum dwarf_form
) form
;
20085 case DW_FORM_ref_addr
:
20086 if (cu_header
->version
== 2)
20087 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
20090 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20092 info_ptr
+= bytes_read
;
20094 case DW_FORM_GNU_ref_alt
:
20095 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20097 info_ptr
+= bytes_read
;
20101 struct gdbarch
*gdbarch
= objfile
->arch ();
20102 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
20103 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
20104 attr
->set_address (addr
);
20105 info_ptr
+= bytes_read
;
20108 case DW_FORM_block2
:
20109 blk
= dwarf_alloc_block (cu
);
20110 blk
->size
= read_2_bytes (abfd
, info_ptr
);
20112 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20113 info_ptr
+= blk
->size
;
20114 attr
->set_block (blk
);
20116 case DW_FORM_block4
:
20117 blk
= dwarf_alloc_block (cu
);
20118 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20120 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20121 info_ptr
+= blk
->size
;
20122 attr
->set_block (blk
);
20124 case DW_FORM_data2
:
20125 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20128 case DW_FORM_data4
:
20129 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20132 case DW_FORM_data8
:
20133 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20136 case DW_FORM_data16
:
20137 blk
= dwarf_alloc_block (cu
);
20139 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20141 attr
->set_block (blk
);
20143 case DW_FORM_sec_offset
:
20144 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20146 info_ptr
+= bytes_read
;
20148 case DW_FORM_loclistx
:
20150 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20152 info_ptr
+= bytes_read
;
20155 case DW_FORM_string
:
20156 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20158 info_ptr
+= bytes_read
;
20161 if (!cu
->per_cu
->is_dwz
)
20163 attr
->set_string_noncanonical
20164 (read_indirect_string (per_objfile
,
20165 abfd
, info_ptr
, cu_header
,
20167 info_ptr
+= bytes_read
;
20171 case DW_FORM_line_strp
:
20172 if (!cu
->per_cu
->is_dwz
)
20174 attr
->set_string_noncanonical
20175 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20177 info_ptr
+= bytes_read
;
20181 case DW_FORM_GNU_strp_alt
:
20183 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20184 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20187 attr
->set_string_noncanonical
20188 (dwz
->read_string (objfile
, str_offset
));
20189 info_ptr
+= bytes_read
;
20192 case DW_FORM_exprloc
:
20193 case DW_FORM_block
:
20194 blk
= dwarf_alloc_block (cu
);
20195 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20196 info_ptr
+= bytes_read
;
20197 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20198 info_ptr
+= blk
->size
;
20199 attr
->set_block (blk
);
20201 case DW_FORM_block1
:
20202 blk
= dwarf_alloc_block (cu
);
20203 blk
->size
= read_1_byte (abfd
, info_ptr
);
20205 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20206 info_ptr
+= blk
->size
;
20207 attr
->set_block (blk
);
20209 case DW_FORM_data1
:
20211 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20214 case DW_FORM_flag_present
:
20215 attr
->set_unsigned (1);
20217 case DW_FORM_sdata
:
20218 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20219 info_ptr
+= bytes_read
;
20221 case DW_FORM_rnglistx
:
20223 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20225 info_ptr
+= bytes_read
;
20228 case DW_FORM_udata
:
20229 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20230 info_ptr
+= bytes_read
;
20233 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20234 + read_1_byte (abfd
, info_ptr
)));
20238 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20239 + read_2_bytes (abfd
, info_ptr
)));
20243 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20244 + read_4_bytes (abfd
, info_ptr
)));
20248 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20249 + read_8_bytes (abfd
, info_ptr
)));
20252 case DW_FORM_ref_sig8
:
20253 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20256 case DW_FORM_ref_udata
:
20257 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20258 + read_unsigned_leb128 (abfd
, info_ptr
,
20260 info_ptr
+= bytes_read
;
20262 case DW_FORM_indirect
:
20263 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20264 info_ptr
+= bytes_read
;
20265 if (form
== DW_FORM_implicit_const
)
20267 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20268 info_ptr
+= bytes_read
;
20270 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20273 case DW_FORM_implicit_const
:
20274 attr
->set_signed (implicit_const
);
20276 case DW_FORM_addrx
:
20277 case DW_FORM_GNU_addr_index
:
20278 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20280 info_ptr
+= bytes_read
;
20283 case DW_FORM_strx1
:
20284 case DW_FORM_strx2
:
20285 case DW_FORM_strx3
:
20286 case DW_FORM_strx4
:
20287 case DW_FORM_GNU_str_index
:
20289 ULONGEST str_index
;
20290 if (form
== DW_FORM_strx1
)
20292 str_index
= read_1_byte (abfd
, info_ptr
);
20295 else if (form
== DW_FORM_strx2
)
20297 str_index
= read_2_bytes (abfd
, info_ptr
);
20300 else if (form
== DW_FORM_strx3
)
20302 str_index
= read_3_bytes (abfd
, info_ptr
);
20305 else if (form
== DW_FORM_strx4
)
20307 str_index
= read_4_bytes (abfd
, info_ptr
);
20312 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20313 info_ptr
+= bytes_read
;
20315 attr
->set_unsigned_reprocess (str_index
);
20319 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20320 dwarf_form_name (form
),
20321 bfd_get_filename (abfd
));
20325 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20326 attr
->form
= DW_FORM_GNU_ref_alt
;
20328 /* We have seen instances where the compiler tried to emit a byte
20329 size attribute of -1 which ended up being encoded as an unsigned
20330 0xffffffff. Although 0xffffffff is technically a valid size value,
20331 an object of this size seems pretty unlikely so we can relatively
20332 safely treat these cases as if the size attribute was invalid and
20333 treat them as zero by default. */
20334 if (attr
->name
== DW_AT_byte_size
20335 && form
== DW_FORM_data4
20336 && attr
->as_unsigned () >= 0xffffffff)
20339 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20340 hex_string (attr
->as_unsigned ()));
20341 attr
->set_unsigned (0);
20347 /* Read an attribute described by an abbreviated attribute. */
20349 static const gdb_byte
*
20350 read_attribute (const struct die_reader_specs
*reader
,
20351 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20352 const gdb_byte
*info_ptr
)
20354 attr
->name
= abbrev
->name
;
20355 attr
->string_is_canonical
= 0;
20356 attr
->requires_reprocessing
= 0;
20357 return read_attribute_value (reader
, attr
, abbrev
->form
,
20358 abbrev
->implicit_const
, info_ptr
);
20361 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20363 static const char *
20364 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20365 LONGEST str_offset
)
20367 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20368 str_offset
, "DW_FORM_strp");
20371 /* Return pointer to string at .debug_str offset as read from BUF.
20372 BUF is assumed to be in a compilation unit described by CU_HEADER.
20373 Return *BYTES_READ_PTR count of bytes read from BUF. */
20375 static const char *
20376 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20377 const gdb_byte
*buf
,
20378 const struct comp_unit_head
*cu_header
,
20379 unsigned int *bytes_read_ptr
)
20381 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20383 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20389 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20390 const struct comp_unit_head
*cu_header
,
20391 unsigned int *bytes_read_ptr
)
20393 bfd
*abfd
= objfile
->obfd
;
20394 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20396 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20399 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20400 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20401 ADDR_SIZE is the size of addresses from the CU header. */
20404 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20405 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20407 struct objfile
*objfile
= per_objfile
->objfile
;
20408 bfd
*abfd
= objfile
->obfd
;
20409 const gdb_byte
*info_ptr
;
20410 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20412 per_objfile
->per_bfd
->addr
.read (objfile
);
20413 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20414 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20415 objfile_name (objfile
));
20416 if (addr_base_or_zero
+ addr_index
* addr_size
20417 >= per_objfile
->per_bfd
->addr
.size
)
20418 error (_("DW_FORM_addr_index pointing outside of "
20419 ".debug_addr section [in module %s]"),
20420 objfile_name (objfile
));
20421 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20422 + addr_index
* addr_size
);
20423 if (addr_size
== 4)
20424 return bfd_get_32 (abfd
, info_ptr
);
20426 return bfd_get_64 (abfd
, info_ptr
);
20429 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20432 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20434 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20435 cu
->addr_base
, cu
->header
.addr_size
);
20438 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20441 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20442 unsigned int *bytes_read
)
20444 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20445 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20447 return read_addr_index (cu
, addr_index
);
20453 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20454 dwarf2_per_objfile
*per_objfile
,
20455 unsigned int addr_index
)
20457 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20458 gdb::optional
<ULONGEST
> addr_base
;
20461 /* We need addr_base and addr_size.
20462 If we don't have PER_CU->cu, we have to get it.
20463 Nasty, but the alternative is storing the needed info in PER_CU,
20464 which at this point doesn't seem justified: it's not clear how frequently
20465 it would get used and it would increase the size of every PER_CU.
20466 Entry points like dwarf2_per_cu_addr_size do a similar thing
20467 so we're not in uncharted territory here.
20468 Alas we need to be a bit more complicated as addr_base is contained
20471 We don't need to read the entire CU(/TU).
20472 We just need the header and top level die.
20474 IWBN to use the aging mechanism to let us lazily later discard the CU.
20475 For now we skip this optimization. */
20479 addr_base
= cu
->addr_base
;
20480 addr_size
= cu
->header
.addr_size
;
20484 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20485 addr_base
= reader
.cu
->addr_base
;
20486 addr_size
= reader
.cu
->header
.addr_size
;
20489 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20492 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20493 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20496 static const char *
20497 read_str_index (struct dwarf2_cu
*cu
,
20498 struct dwarf2_section_info
*str_section
,
20499 struct dwarf2_section_info
*str_offsets_section
,
20500 ULONGEST str_offsets_base
, ULONGEST str_index
)
20502 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20503 struct objfile
*objfile
= per_objfile
->objfile
;
20504 const char *objf_name
= objfile_name (objfile
);
20505 bfd
*abfd
= objfile
->obfd
;
20506 const gdb_byte
*info_ptr
;
20507 ULONGEST str_offset
;
20508 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20510 str_section
->read (objfile
);
20511 str_offsets_section
->read (objfile
);
20512 if (str_section
->buffer
== NULL
)
20513 error (_("%s used without %s section"
20514 " in CU at offset %s [in module %s]"),
20515 form_name
, str_section
->get_name (),
20516 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20517 if (str_offsets_section
->buffer
== NULL
)
20518 error (_("%s used without %s section"
20519 " in CU at offset %s [in module %s]"),
20520 form_name
, str_section
->get_name (),
20521 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20522 info_ptr
= (str_offsets_section
->buffer
20524 + str_index
* cu
->header
.offset_size
);
20525 if (cu
->header
.offset_size
== 4)
20526 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20528 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20529 if (str_offset
>= str_section
->size
)
20530 error (_("Offset from %s pointing outside of"
20531 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20532 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20533 return (const char *) (str_section
->buffer
+ str_offset
);
20536 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20538 static const char *
20539 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20541 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20542 ? reader
->cu
->header
.addr_size
: 0;
20543 return read_str_index (reader
->cu
,
20544 &reader
->dwo_file
->sections
.str
,
20545 &reader
->dwo_file
->sections
.str_offsets
,
20546 str_offsets_base
, str_index
);
20549 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20551 static const char *
20552 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20554 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20555 const char *objf_name
= objfile_name (objfile
);
20556 static const char form_name
[] = "DW_FORM_GNU_str_index";
20557 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20559 if (!cu
->str_offsets_base
.has_value ())
20560 error (_("%s used in Fission stub without %s"
20561 " in CU at offset 0x%lx [in module %s]"),
20562 form_name
, str_offsets_attr_name
,
20563 (long) cu
->header
.offset_size
, objf_name
);
20565 return read_str_index (cu
,
20566 &cu
->per_objfile
->per_bfd
->str
,
20567 &cu
->per_objfile
->per_bfd
->str_offsets
,
20568 *cu
->str_offsets_base
, str_index
);
20571 /* Return the length of an LEB128 number in BUF. */
20574 leb128_size (const gdb_byte
*buf
)
20576 const gdb_byte
*begin
= buf
;
20582 if ((byte
& 128) == 0)
20583 return buf
- begin
;
20588 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20597 cu
->language
= language_c
;
20600 case DW_LANG_C_plus_plus
:
20601 case DW_LANG_C_plus_plus_11
:
20602 case DW_LANG_C_plus_plus_14
:
20603 cu
->language
= language_cplus
;
20606 cu
->language
= language_d
;
20608 case DW_LANG_Fortran77
:
20609 case DW_LANG_Fortran90
:
20610 case DW_LANG_Fortran95
:
20611 case DW_LANG_Fortran03
:
20612 case DW_LANG_Fortran08
:
20613 cu
->language
= language_fortran
;
20616 cu
->language
= language_go
;
20618 case DW_LANG_Mips_Assembler
:
20619 cu
->language
= language_asm
;
20621 case DW_LANG_Ada83
:
20622 case DW_LANG_Ada95
:
20623 cu
->language
= language_ada
;
20625 case DW_LANG_Modula2
:
20626 cu
->language
= language_m2
;
20628 case DW_LANG_Pascal83
:
20629 cu
->language
= language_pascal
;
20632 cu
->language
= language_objc
;
20635 case DW_LANG_Rust_old
:
20636 cu
->language
= language_rust
;
20638 case DW_LANG_Cobol74
:
20639 case DW_LANG_Cobol85
:
20641 cu
->language
= language_minimal
;
20644 cu
->language_defn
= language_def (cu
->language
);
20647 /* Return the named attribute or NULL if not there. */
20649 static struct attribute
*
20650 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20655 struct attribute
*spec
= NULL
;
20657 for (i
= 0; i
< die
->num_attrs
; ++i
)
20659 if (die
->attrs
[i
].name
== name
)
20660 return &die
->attrs
[i
];
20661 if (die
->attrs
[i
].name
== DW_AT_specification
20662 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20663 spec
= &die
->attrs
[i
];
20669 die
= follow_die_ref (die
, spec
, &cu
);
20675 /* Return the string associated with a string-typed attribute, or NULL if it
20676 is either not found or is of an incorrect type. */
20678 static const char *
20679 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20681 struct attribute
*attr
;
20682 const char *str
= NULL
;
20684 attr
= dwarf2_attr (die
, name
, cu
);
20688 str
= attr
->as_string ();
20689 if (str
== nullptr)
20690 complaint (_("string type expected for attribute %s for "
20691 "DIE at %s in module %s"),
20692 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20693 objfile_name (cu
->per_objfile
->objfile
));
20699 /* Return the dwo name or NULL if not present. If present, it is in either
20700 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20701 static const char *
20702 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20704 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20705 if (dwo_name
== nullptr)
20706 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20710 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20711 and holds a non-zero value. This function should only be used for
20712 DW_FORM_flag or DW_FORM_flag_present attributes. */
20715 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20717 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20719 return attr
!= nullptr && attr
->as_boolean ();
20723 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20725 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20726 which value is non-zero. However, we have to be careful with
20727 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20728 (via dwarf2_flag_true_p) follows this attribute. So we may
20729 end up accidently finding a declaration attribute that belongs
20730 to a different DIE referenced by the specification attribute,
20731 even though the given DIE does not have a declaration attribute. */
20732 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20733 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20736 /* Return the die giving the specification for DIE, if there is
20737 one. *SPEC_CU is the CU containing DIE on input, and the CU
20738 containing the return value on output. If there is no
20739 specification, but there is an abstract origin, that is
20742 static struct die_info
*
20743 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20745 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20748 if (spec_attr
== NULL
)
20749 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20751 if (spec_attr
== NULL
)
20754 return follow_die_ref (die
, spec_attr
, spec_cu
);
20757 /* Stub for free_line_header to match void * callback types. */
20760 free_line_header_voidp (void *arg
)
20762 struct line_header
*lh
= (struct line_header
*) arg
;
20767 /* A convenience function to find the proper .debug_line section for a CU. */
20769 static struct dwarf2_section_info
*
20770 get_debug_line_section (struct dwarf2_cu
*cu
)
20772 struct dwarf2_section_info
*section
;
20773 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20775 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20777 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20778 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20779 else if (cu
->per_cu
->is_dwz
)
20781 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20783 section
= &dwz
->line
;
20786 section
= &per_objfile
->per_bfd
->line
;
20791 /* Read the statement program header starting at OFFSET in
20792 .debug_line, or .debug_line.dwo. Return a pointer
20793 to a struct line_header, allocated using xmalloc.
20794 Returns NULL if there is a problem reading the header, e.g., if it
20795 has a version we don't understand.
20797 NOTE: the strings in the include directory and file name tables of
20798 the returned object point into the dwarf line section buffer,
20799 and must not be freed. */
20801 static line_header_up
20802 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20804 struct dwarf2_section_info
*section
;
20805 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20807 section
= get_debug_line_section (cu
);
20808 section
->read (per_objfile
->objfile
);
20809 if (section
->buffer
== NULL
)
20811 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20812 complaint (_("missing .debug_line.dwo section"));
20814 complaint (_("missing .debug_line section"));
20818 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20819 per_objfile
, section
, &cu
->header
);
20822 /* Subroutine of dwarf_decode_lines to simplify it.
20823 Return the file name of the psymtab for the given file_entry.
20824 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20825 If space for the result is malloc'd, *NAME_HOLDER will be set.
20826 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20828 static const char *
20829 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20830 const dwarf2_psymtab
*pst
,
20831 const char *comp_dir
,
20832 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20834 const char *include_name
= fe
.name
;
20835 const char *include_name_to_compare
= include_name
;
20836 const char *pst_filename
;
20839 const char *dir_name
= fe
.include_dir (lh
);
20841 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20842 if (!IS_ABSOLUTE_PATH (include_name
)
20843 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20845 /* Avoid creating a duplicate psymtab for PST.
20846 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20847 Before we do the comparison, however, we need to account
20848 for DIR_NAME and COMP_DIR.
20849 First prepend dir_name (if non-NULL). If we still don't
20850 have an absolute path prepend comp_dir (if non-NULL).
20851 However, the directory we record in the include-file's
20852 psymtab does not contain COMP_DIR (to match the
20853 corresponding symtab(s)).
20858 bash$ gcc -g ./hello.c
20859 include_name = "hello.c"
20861 DW_AT_comp_dir = comp_dir = "/tmp"
20862 DW_AT_name = "./hello.c"
20866 if (dir_name
!= NULL
)
20868 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20869 include_name
, (char *) NULL
));
20870 include_name
= name_holder
->get ();
20871 include_name_to_compare
= include_name
;
20873 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20875 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20876 include_name
, (char *) NULL
));
20877 include_name_to_compare
= hold_compare
.get ();
20881 pst_filename
= pst
->filename
;
20882 gdb::unique_xmalloc_ptr
<char> copied_name
;
20883 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20885 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20886 pst_filename
, (char *) NULL
));
20887 pst_filename
= copied_name
.get ();
20890 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20894 return include_name
;
20897 /* State machine to track the state of the line number program. */
20899 class lnp_state_machine
20902 /* Initialize a machine state for the start of a line number
20904 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20905 bool record_lines_p
);
20907 file_entry
*current_file ()
20909 /* lh->file_names is 0-based, but the file name numbers in the
20910 statement program are 1-based. */
20911 return m_line_header
->file_name_at (m_file
);
20914 /* Record the line in the state machine. END_SEQUENCE is true if
20915 we're processing the end of a sequence. */
20916 void record_line (bool end_sequence
);
20918 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20919 nop-out rest of the lines in this sequence. */
20920 void check_line_address (struct dwarf2_cu
*cu
,
20921 const gdb_byte
*line_ptr
,
20922 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20924 void handle_set_discriminator (unsigned int discriminator
)
20926 m_discriminator
= discriminator
;
20927 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20930 /* Handle DW_LNE_set_address. */
20931 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20934 address
+= baseaddr
;
20935 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20938 /* Handle DW_LNS_advance_pc. */
20939 void handle_advance_pc (CORE_ADDR adjust
);
20941 /* Handle a special opcode. */
20942 void handle_special_opcode (unsigned char op_code
);
20944 /* Handle DW_LNS_advance_line. */
20945 void handle_advance_line (int line_delta
)
20947 advance_line (line_delta
);
20950 /* Handle DW_LNS_set_file. */
20951 void handle_set_file (file_name_index file
);
20953 /* Handle DW_LNS_negate_stmt. */
20954 void handle_negate_stmt ()
20956 m_is_stmt
= !m_is_stmt
;
20959 /* Handle DW_LNS_const_add_pc. */
20960 void handle_const_add_pc ();
20962 /* Handle DW_LNS_fixed_advance_pc. */
20963 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20965 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20969 /* Handle DW_LNS_copy. */
20970 void handle_copy ()
20972 record_line (false);
20973 m_discriminator
= 0;
20976 /* Handle DW_LNE_end_sequence. */
20977 void handle_end_sequence ()
20979 m_currently_recording_lines
= true;
20983 /* Advance the line by LINE_DELTA. */
20984 void advance_line (int line_delta
)
20986 m_line
+= line_delta
;
20988 if (line_delta
!= 0)
20989 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20992 struct dwarf2_cu
*m_cu
;
20994 gdbarch
*m_gdbarch
;
20996 /* True if we're recording lines.
20997 Otherwise we're building partial symtabs and are just interested in
20998 finding include files mentioned by the line number program. */
20999 bool m_record_lines_p
;
21001 /* The line number header. */
21002 line_header
*m_line_header
;
21004 /* These are part of the standard DWARF line number state machine,
21005 and initialized according to the DWARF spec. */
21007 unsigned char m_op_index
= 0;
21008 /* The line table index of the current file. */
21009 file_name_index m_file
= 1;
21010 unsigned int m_line
= 1;
21012 /* These are initialized in the constructor. */
21014 CORE_ADDR m_address
;
21016 unsigned int m_discriminator
;
21018 /* Additional bits of state we need to track. */
21020 /* The last file that we called dwarf2_start_subfile for.
21021 This is only used for TLLs. */
21022 unsigned int m_last_file
= 0;
21023 /* The last file a line number was recorded for. */
21024 struct subfile
*m_last_subfile
= NULL
;
21026 /* The address of the last line entry. */
21027 CORE_ADDR m_last_address
;
21029 /* Set to true when a previous line at the same address (using
21030 m_last_address) had m_is_stmt true. This is reset to false when a
21031 line entry at a new address (m_address different to m_last_address) is
21033 bool m_stmt_at_address
= false;
21035 /* When true, record the lines we decode. */
21036 bool m_currently_recording_lines
= false;
21038 /* The last line number that was recorded, used to coalesce
21039 consecutive entries for the same line. This can happen, for
21040 example, when discriminators are present. PR 17276. */
21041 unsigned int m_last_line
= 0;
21042 bool m_line_has_non_zero_discriminator
= false;
21046 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21048 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21049 / m_line_header
->maximum_ops_per_instruction
)
21050 * m_line_header
->minimum_instruction_length
);
21051 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21052 m_op_index
= ((m_op_index
+ adjust
)
21053 % m_line_header
->maximum_ops_per_instruction
);
21057 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21059 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21060 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
21061 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
21062 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
21063 / m_line_header
->maximum_ops_per_instruction
)
21064 * m_line_header
->minimum_instruction_length
);
21065 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21066 m_op_index
= ((m_op_index
+ adj_opcode_d
)
21067 % m_line_header
->maximum_ops_per_instruction
);
21069 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
21070 advance_line (line_delta
);
21071 record_line (false);
21072 m_discriminator
= 0;
21076 lnp_state_machine::handle_set_file (file_name_index file
)
21080 const file_entry
*fe
= current_file ();
21082 dwarf2_debug_line_missing_file_complaint ();
21083 else if (m_record_lines_p
)
21085 const char *dir
= fe
->include_dir (m_line_header
);
21087 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21088 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21089 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21094 lnp_state_machine::handle_const_add_pc ()
21097 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21100 = (((m_op_index
+ adjust
)
21101 / m_line_header
->maximum_ops_per_instruction
)
21102 * m_line_header
->minimum_instruction_length
);
21104 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21105 m_op_index
= ((m_op_index
+ adjust
)
21106 % m_line_header
->maximum_ops_per_instruction
);
21109 /* Return non-zero if we should add LINE to the line number table.
21110 LINE is the line to add, LAST_LINE is the last line that was added,
21111 LAST_SUBFILE is the subfile for LAST_LINE.
21112 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21113 had a non-zero discriminator.
21115 We have to be careful in the presence of discriminators.
21116 E.g., for this line:
21118 for (i = 0; i < 100000; i++);
21120 clang can emit four line number entries for that one line,
21121 each with a different discriminator.
21122 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21124 However, we want gdb to coalesce all four entries into one.
21125 Otherwise the user could stepi into the middle of the line and
21126 gdb would get confused about whether the pc really was in the
21127 middle of the line.
21129 Things are further complicated by the fact that two consecutive
21130 line number entries for the same line is a heuristic used by gcc
21131 to denote the end of the prologue. So we can't just discard duplicate
21132 entries, we have to be selective about it. The heuristic we use is
21133 that we only collapse consecutive entries for the same line if at least
21134 one of those entries has a non-zero discriminator. PR 17276.
21136 Note: Addresses in the line number state machine can never go backwards
21137 within one sequence, thus this coalescing is ok. */
21140 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21141 unsigned int line
, unsigned int last_line
,
21142 int line_has_non_zero_discriminator
,
21143 struct subfile
*last_subfile
)
21145 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21147 if (line
!= last_line
)
21149 /* Same line for the same file that we've seen already.
21150 As a last check, for pr 17276, only record the line if the line
21151 has never had a non-zero discriminator. */
21152 if (!line_has_non_zero_discriminator
)
21157 /* Use the CU's builder to record line number LINE beginning at
21158 address ADDRESS in the line table of subfile SUBFILE. */
21161 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21162 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
21163 struct dwarf2_cu
*cu
)
21165 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21167 if (dwarf_line_debug
)
21169 fprintf_unfiltered (gdb_stdlog
,
21170 "Recording line %u, file %s, address %s\n",
21171 line
, lbasename (subfile
->name
),
21172 paddress (gdbarch
, address
));
21176 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21179 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21180 Mark the end of a set of line number records.
21181 The arguments are the same as for dwarf_record_line_1.
21182 If SUBFILE is NULL the request is ignored. */
21185 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21186 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21188 if (subfile
== NULL
)
21191 if (dwarf_line_debug
)
21193 fprintf_unfiltered (gdb_stdlog
,
21194 "Finishing current line, file %s, address %s\n",
21195 lbasename (subfile
->name
),
21196 paddress (gdbarch
, address
));
21199 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21203 lnp_state_machine::record_line (bool end_sequence
)
21205 if (dwarf_line_debug
)
21207 fprintf_unfiltered (gdb_stdlog
,
21208 "Processing actual line %u: file %u,"
21209 " address %s, is_stmt %u, discrim %u%s\n",
21211 paddress (m_gdbarch
, m_address
),
21212 m_is_stmt
, m_discriminator
,
21213 (end_sequence
? "\t(end sequence)" : ""));
21216 file_entry
*fe
= current_file ();
21219 dwarf2_debug_line_missing_file_complaint ();
21220 /* For now we ignore lines not starting on an instruction boundary.
21221 But not when processing end_sequence for compatibility with the
21222 previous version of the code. */
21223 else if (m_op_index
== 0 || end_sequence
)
21225 fe
->included_p
= 1;
21226 if (m_record_lines_p
)
21228 /* When we switch files we insert an end maker in the first file,
21229 switch to the second file and add a new line entry. The
21230 problem is that the end marker inserted in the first file will
21231 discard any previous line entries at the same address. If the
21232 line entries in the first file are marked as is-stmt, while
21233 the new line in the second file is non-stmt, then this means
21234 the end marker will discard is-stmt lines so we can have a
21235 non-stmt line. This means that there are less addresses at
21236 which the user can insert a breakpoint.
21238 To improve this we track the last address in m_last_address,
21239 and whether we have seen an is-stmt at this address. Then
21240 when switching files, if we have seen a stmt at the current
21241 address, and we are switching to create a non-stmt line, then
21242 discard the new line. */
21244 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21245 bool ignore_this_line
21246 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21247 && !m_is_stmt
&& m_stmt_at_address
)
21248 || (!end_sequence
&& m_line
== 0));
21250 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21252 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21253 m_currently_recording_lines
? m_cu
: nullptr);
21256 if (!end_sequence
&& !ignore_this_line
)
21258 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21260 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21261 m_line_has_non_zero_discriminator
,
21264 buildsym_compunit
*builder
= m_cu
->get_builder ();
21265 dwarf_record_line_1 (m_gdbarch
,
21266 builder
->get_current_subfile (),
21267 m_line
, m_address
, is_stmt
,
21268 m_currently_recording_lines
? m_cu
: nullptr);
21270 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21271 m_last_line
= m_line
;
21276 /* Track whether we have seen any m_is_stmt true at m_address in case we
21277 have multiple line table entries all at m_address. */
21278 if (m_last_address
!= m_address
)
21280 m_stmt_at_address
= false;
21281 m_last_address
= m_address
;
21283 m_stmt_at_address
|= m_is_stmt
;
21286 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21287 line_header
*lh
, bool record_lines_p
)
21291 m_record_lines_p
= record_lines_p
;
21292 m_line_header
= lh
;
21294 m_currently_recording_lines
= true;
21296 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21297 was a line entry for it so that the backend has a chance to adjust it
21298 and also record it in case it needs it. This is currently used by MIPS
21299 code, cf. `mips_adjust_dwarf2_line'. */
21300 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21301 m_is_stmt
= lh
->default_is_stmt
;
21302 m_discriminator
= 0;
21304 m_last_address
= m_address
;
21305 m_stmt_at_address
= false;
21309 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21310 const gdb_byte
*line_ptr
,
21311 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21313 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21314 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21315 located at 0x0. In this case, additionally check that if
21316 ADDRESS < UNRELOCATED_LOWPC. */
21318 if ((address
== 0 && address
< unrelocated_lowpc
)
21319 || address
== (CORE_ADDR
) -1)
21321 /* This line table is for a function which has been
21322 GCd by the linker. Ignore it. PR gdb/12528 */
21324 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21325 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21327 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21328 line_offset
, objfile_name (objfile
));
21329 m_currently_recording_lines
= false;
21330 /* Note: m_currently_recording_lines is left as false until we see
21331 DW_LNE_end_sequence. */
21335 /* Subroutine of dwarf_decode_lines to simplify it.
21336 Process the line number information in LH.
21337 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21338 program in order to set included_p for every referenced header. */
21341 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21342 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21344 const gdb_byte
*line_ptr
, *extended_end
;
21345 const gdb_byte
*line_end
;
21346 unsigned int bytes_read
, extended_len
;
21347 unsigned char op_code
, extended_op
;
21348 CORE_ADDR baseaddr
;
21349 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21350 bfd
*abfd
= objfile
->obfd
;
21351 struct gdbarch
*gdbarch
= objfile
->arch ();
21352 /* True if we're recording line info (as opposed to building partial
21353 symtabs and just interested in finding include files mentioned by
21354 the line number program). */
21355 bool record_lines_p
= !decode_for_pst_p
;
21357 baseaddr
= objfile
->text_section_offset ();
21359 line_ptr
= lh
->statement_program_start
;
21360 line_end
= lh
->statement_program_end
;
21362 /* Read the statement sequences until there's nothing left. */
21363 while (line_ptr
< line_end
)
21365 /* The DWARF line number program state machine. Reset the state
21366 machine at the start of each sequence. */
21367 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21368 bool end_sequence
= false;
21370 if (record_lines_p
)
21372 /* Start a subfile for the current file of the state
21374 const file_entry
*fe
= state_machine
.current_file ();
21377 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21380 /* Decode the table. */
21381 while (line_ptr
< line_end
&& !end_sequence
)
21383 op_code
= read_1_byte (abfd
, line_ptr
);
21386 if (op_code
>= lh
->opcode_base
)
21388 /* Special opcode. */
21389 state_machine
.handle_special_opcode (op_code
);
21391 else switch (op_code
)
21393 case DW_LNS_extended_op
:
21394 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21396 line_ptr
+= bytes_read
;
21397 extended_end
= line_ptr
+ extended_len
;
21398 extended_op
= read_1_byte (abfd
, line_ptr
);
21400 if (DW_LNE_lo_user
<= extended_op
21401 && extended_op
<= DW_LNE_hi_user
)
21403 /* Vendor extension, ignore. */
21404 line_ptr
= extended_end
;
21407 switch (extended_op
)
21409 case DW_LNE_end_sequence
:
21410 state_machine
.handle_end_sequence ();
21411 end_sequence
= true;
21413 case DW_LNE_set_address
:
21416 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21417 line_ptr
+= bytes_read
;
21419 state_machine
.check_line_address (cu
, line_ptr
,
21420 lowpc
- baseaddr
, address
);
21421 state_machine
.handle_set_address (baseaddr
, address
);
21424 case DW_LNE_define_file
:
21426 const char *cur_file
;
21427 unsigned int mod_time
, length
;
21430 cur_file
= read_direct_string (abfd
, line_ptr
,
21432 line_ptr
+= bytes_read
;
21433 dindex
= (dir_index
)
21434 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21435 line_ptr
+= bytes_read
;
21437 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21438 line_ptr
+= bytes_read
;
21440 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21441 line_ptr
+= bytes_read
;
21442 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21445 case DW_LNE_set_discriminator
:
21447 /* The discriminator is not interesting to the
21448 debugger; just ignore it. We still need to
21449 check its value though:
21450 if there are consecutive entries for the same
21451 (non-prologue) line we want to coalesce them.
21454 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21455 line_ptr
+= bytes_read
;
21457 state_machine
.handle_set_discriminator (discr
);
21461 complaint (_("mangled .debug_line section"));
21464 /* Make sure that we parsed the extended op correctly. If e.g.
21465 we expected a different address size than the producer used,
21466 we may have read the wrong number of bytes. */
21467 if (line_ptr
!= extended_end
)
21469 complaint (_("mangled .debug_line section"));
21474 state_machine
.handle_copy ();
21476 case DW_LNS_advance_pc
:
21479 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21480 line_ptr
+= bytes_read
;
21482 state_machine
.handle_advance_pc (adjust
);
21485 case DW_LNS_advance_line
:
21488 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21489 line_ptr
+= bytes_read
;
21491 state_machine
.handle_advance_line (line_delta
);
21494 case DW_LNS_set_file
:
21496 file_name_index file
21497 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21499 line_ptr
+= bytes_read
;
21501 state_machine
.handle_set_file (file
);
21504 case DW_LNS_set_column
:
21505 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21506 line_ptr
+= bytes_read
;
21508 case DW_LNS_negate_stmt
:
21509 state_machine
.handle_negate_stmt ();
21511 case DW_LNS_set_basic_block
:
21513 /* Add to the address register of the state machine the
21514 address increment value corresponding to special opcode
21515 255. I.e., this value is scaled by the minimum
21516 instruction length since special opcode 255 would have
21517 scaled the increment. */
21518 case DW_LNS_const_add_pc
:
21519 state_machine
.handle_const_add_pc ();
21521 case DW_LNS_fixed_advance_pc
:
21523 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21526 state_machine
.handle_fixed_advance_pc (addr_adj
);
21531 /* Unknown standard opcode, ignore it. */
21534 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21536 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21537 line_ptr
+= bytes_read
;
21544 dwarf2_debug_line_missing_end_sequence_complaint ();
21546 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21547 in which case we still finish recording the last line). */
21548 state_machine
.record_line (true);
21552 /* Decode the Line Number Program (LNP) for the given line_header
21553 structure and CU. The actual information extracted and the type
21554 of structures created from the LNP depends on the value of PST.
21556 1. If PST is NULL, then this procedure uses the data from the program
21557 to create all necessary symbol tables, and their linetables.
21559 2. If PST is not NULL, this procedure reads the program to determine
21560 the list of files included by the unit represented by PST, and
21561 builds all the associated partial symbol tables.
21563 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21564 It is used for relative paths in the line table.
21565 NOTE: When processing partial symtabs (pst != NULL),
21566 comp_dir == pst->dirname.
21568 NOTE: It is important that psymtabs have the same file name (via strcmp)
21569 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21570 symtab we don't use it in the name of the psymtabs we create.
21571 E.g. expand_line_sal requires this when finding psymtabs to expand.
21572 A good testcase for this is mb-inline.exp.
21574 LOWPC is the lowest address in CU (or 0 if not known).
21576 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21577 for its PC<->lines mapping information. Otherwise only the filename
21578 table is read in. */
21581 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21582 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21583 CORE_ADDR lowpc
, int decode_mapping
)
21585 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21586 const int decode_for_pst_p
= (pst
!= NULL
);
21588 if (decode_mapping
)
21589 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21591 if (decode_for_pst_p
)
21593 /* Now that we're done scanning the Line Header Program, we can
21594 create the psymtab of each included file. */
21595 for (auto &file_entry
: lh
->file_names ())
21596 if (file_entry
.included_p
== 1)
21598 gdb::unique_xmalloc_ptr
<char> name_holder
;
21599 const char *include_name
=
21600 psymtab_include_file_name (lh
, file_entry
, pst
,
21601 comp_dir
, &name_holder
);
21602 if (include_name
!= NULL
)
21603 dwarf2_create_include_psymtab
21604 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
21605 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
21611 /* Make sure a symtab is created for every file, even files
21612 which contain only variables (i.e. no code with associated
21614 buildsym_compunit
*builder
= cu
->get_builder ();
21615 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21617 for (auto &fe
: lh
->file_names ())
21619 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21620 if (builder
->get_current_subfile ()->symtab
== NULL
)
21622 builder
->get_current_subfile ()->symtab
21623 = allocate_symtab (cust
,
21624 builder
->get_current_subfile ()->name
);
21626 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21631 /* Start a subfile for DWARF. FILENAME is the name of the file and
21632 DIRNAME the name of the source directory which contains FILENAME
21633 or NULL if not known.
21634 This routine tries to keep line numbers from identical absolute and
21635 relative file names in a common subfile.
21637 Using the `list' example from the GDB testsuite, which resides in
21638 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21639 of /srcdir/list0.c yields the following debugging information for list0.c:
21641 DW_AT_name: /srcdir/list0.c
21642 DW_AT_comp_dir: /compdir
21643 files.files[0].name: list0.h
21644 files.files[0].dir: /srcdir
21645 files.files[1].name: list0.c
21646 files.files[1].dir: /srcdir
21648 The line number information for list0.c has to end up in a single
21649 subfile, so that `break /srcdir/list0.c:1' works as expected.
21650 start_subfile will ensure that this happens provided that we pass the
21651 concatenation of files.files[1].dir and files.files[1].name as the
21655 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21656 const char *dirname
)
21658 gdb::unique_xmalloc_ptr
<char> copy
;
21660 /* In order not to lose the line information directory,
21661 we concatenate it to the filename when it makes sense.
21662 Note that the Dwarf3 standard says (speaking of filenames in line
21663 information): ``The directory index is ignored for file names
21664 that represent full path names''. Thus ignoring dirname in the
21665 `else' branch below isn't an issue. */
21667 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21669 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21670 filename
= copy
.get ();
21673 cu
->get_builder ()->start_subfile (filename
);
21676 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21677 buildsym_compunit constructor. */
21679 struct compunit_symtab
*
21680 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21683 gdb_assert (m_builder
== nullptr);
21685 m_builder
.reset (new struct buildsym_compunit
21686 (this->per_objfile
->objfile
,
21687 name
, comp_dir
, language
, low_pc
));
21689 list_in_scope
= get_builder ()->get_file_symbols ();
21691 get_builder ()->record_debugformat ("DWARF 2");
21692 get_builder ()->record_producer (producer
);
21694 processing_has_namespace_info
= false;
21696 return get_builder ()->get_compunit_symtab ();
21700 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21701 struct dwarf2_cu
*cu
)
21703 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21704 struct comp_unit_head
*cu_header
= &cu
->header
;
21706 /* NOTE drow/2003-01-30: There used to be a comment and some special
21707 code here to turn a symbol with DW_AT_external and a
21708 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21709 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21710 with some versions of binutils) where shared libraries could have
21711 relocations against symbols in their debug information - the
21712 minimal symbol would have the right address, but the debug info
21713 would not. It's no longer necessary, because we will explicitly
21714 apply relocations when we read in the debug information now. */
21716 /* A DW_AT_location attribute with no contents indicates that a
21717 variable has been optimized away. */
21718 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21720 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21724 /* Handle one degenerate form of location expression specially, to
21725 preserve GDB's previous behavior when section offsets are
21726 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21727 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21729 if (attr
->form_is_block ())
21731 struct dwarf_block
*block
= attr
->as_block ();
21733 if ((block
->data
[0] == DW_OP_addr
21734 && block
->size
== 1 + cu_header
->addr_size
)
21735 || ((block
->data
[0] == DW_OP_GNU_addr_index
21736 || block
->data
[0] == DW_OP_addrx
)
21738 == 1 + leb128_size (&block
->data
[1]))))
21740 unsigned int dummy
;
21742 if (block
->data
[0] == DW_OP_addr
)
21743 SET_SYMBOL_VALUE_ADDRESS
21744 (sym
, cu
->header
.read_address (objfile
->obfd
,
21748 SET_SYMBOL_VALUE_ADDRESS
21749 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21751 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21752 fixup_symbol_section (sym
, objfile
);
21753 SET_SYMBOL_VALUE_ADDRESS
21755 SYMBOL_VALUE_ADDRESS (sym
)
21756 + objfile
->section_offsets
[sym
->section_index ()]);
21761 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21762 expression evaluator, and use LOC_COMPUTED only when necessary
21763 (i.e. when the value of a register or memory location is
21764 referenced, or a thread-local block, etc.). Then again, it might
21765 not be worthwhile. I'm assuming that it isn't unless performance
21766 or memory numbers show me otherwise. */
21768 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21770 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21771 cu
->has_loclist
= true;
21774 /* Given a pointer to a DWARF information entry, figure out if we need
21775 to make a symbol table entry for it, and if so, create a new entry
21776 and return a pointer to it.
21777 If TYPE is NULL, determine symbol type from the die, otherwise
21778 used the passed type.
21779 If SPACE is not NULL, use it to hold the new symbol. If it is
21780 NULL, allocate a new symbol on the objfile's obstack. */
21782 static struct symbol
*
21783 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21784 struct symbol
*space
)
21786 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21787 struct objfile
*objfile
= per_objfile
->objfile
;
21788 struct gdbarch
*gdbarch
= objfile
->arch ();
21789 struct symbol
*sym
= NULL
;
21791 struct attribute
*attr
= NULL
;
21792 struct attribute
*attr2
= NULL
;
21793 CORE_ADDR baseaddr
;
21794 struct pending
**list_to_add
= NULL
;
21796 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21798 baseaddr
= objfile
->text_section_offset ();
21800 name
= dwarf2_name (die
, cu
);
21803 int suppress_add
= 0;
21808 sym
= new (&objfile
->objfile_obstack
) symbol
;
21809 OBJSTAT (objfile
, n_syms
++);
21811 /* Cache this symbol's name and the name's demangled form (if any). */
21812 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21813 /* Fortran does not have mangling standard and the mangling does differ
21814 between gfortran, iFort etc. */
21815 const char *physname
21816 = (cu
->language
== language_fortran
21817 ? dwarf2_full_name (name
, die
, cu
)
21818 : dwarf2_physname (name
, die
, cu
));
21819 const char *linkagename
= dw2_linkage_name (die
, cu
);
21821 if (linkagename
== nullptr || cu
->language
== language_ada
)
21822 sym
->set_linkage_name (physname
);
21825 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21826 sym
->set_linkage_name (linkagename
);
21829 /* Default assumptions.
21830 Use the passed type or decode it from the die. */
21831 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21832 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21834 SYMBOL_TYPE (sym
) = type
;
21836 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21837 attr
= dwarf2_attr (die
,
21838 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21840 if (attr
!= nullptr)
21841 SYMBOL_LINE (sym
) = attr
->constant_value (0);
21843 attr
= dwarf2_attr (die
,
21844 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21846 if (attr
!= nullptr && attr
->is_nonnegative ())
21848 file_name_index file_index
21849 = (file_name_index
) attr
->as_nonnegative ();
21850 struct file_entry
*fe
;
21852 if (cu
->line_header
!= NULL
)
21853 fe
= cu
->line_header
->file_name_at (file_index
);
21858 complaint (_("file index out of range"));
21860 symbol_set_symtab (sym
, fe
->symtab
);
21866 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21867 if (attr
!= nullptr)
21871 addr
= attr
->as_address ();
21872 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21873 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21874 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21877 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21878 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21879 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21880 add_symbol_to_list (sym
, cu
->list_in_scope
);
21882 case DW_TAG_subprogram
:
21883 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21885 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21886 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21887 if ((attr2
!= nullptr && attr2
->as_boolean ())
21888 || cu
->language
== language_ada
21889 || cu
->language
== language_fortran
)
21891 /* Subprograms marked external are stored as a global symbol.
21892 Ada and Fortran subprograms, whether marked external or
21893 not, are always stored as a global symbol, because we want
21894 to be able to access them globally. For instance, we want
21895 to be able to break on a nested subprogram without having
21896 to specify the context. */
21897 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21901 list_to_add
= cu
->list_in_scope
;
21904 case DW_TAG_inlined_subroutine
:
21905 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21907 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21908 SYMBOL_INLINED (sym
) = 1;
21909 list_to_add
= cu
->list_in_scope
;
21911 case DW_TAG_template_value_param
:
21913 /* Fall through. */
21914 case DW_TAG_constant
:
21915 case DW_TAG_variable
:
21916 case DW_TAG_member
:
21917 /* Compilation with minimal debug info may result in
21918 variables with missing type entries. Change the
21919 misleading `void' type to something sensible. */
21920 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
21921 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21923 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21924 /* In the case of DW_TAG_member, we should only be called for
21925 static const members. */
21926 if (die
->tag
== DW_TAG_member
)
21928 /* dwarf2_add_field uses die_is_declaration,
21929 so we do the same. */
21930 gdb_assert (die_is_declaration (die
, cu
));
21933 if (attr
!= nullptr)
21935 dwarf2_const_value (attr
, sym
, cu
);
21936 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21939 if (attr2
!= nullptr && attr2
->as_boolean ())
21940 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21942 list_to_add
= cu
->list_in_scope
;
21946 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21947 if (attr
!= nullptr)
21949 var_decode_location (attr
, sym
, cu
);
21950 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21952 /* Fortran explicitly imports any global symbols to the local
21953 scope by DW_TAG_common_block. */
21954 if (cu
->language
== language_fortran
&& die
->parent
21955 && die
->parent
->tag
== DW_TAG_common_block
)
21958 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21959 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21960 && !per_objfile
->per_bfd
->has_section_at_zero
)
21962 /* When a static variable is eliminated by the linker,
21963 the corresponding debug information is not stripped
21964 out, but the variable address is set to null;
21965 do not add such variables into symbol table. */
21967 else if (attr2
!= nullptr && attr2
->as_boolean ())
21969 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21970 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21971 && per_objfile
->per_bfd
->can_copy
)
21973 /* A global static variable might be subject to
21974 copy relocation. We first check for a local
21975 minsym, though, because maybe the symbol was
21976 marked hidden, in which case this would not
21978 bound_minimal_symbol found
21979 = (lookup_minimal_symbol_linkage
21980 (sym
->linkage_name (), objfile
));
21981 if (found
.minsym
!= nullptr)
21982 sym
->maybe_copied
= 1;
21985 /* A variable with DW_AT_external is never static,
21986 but it may be block-scoped. */
21988 = ((cu
->list_in_scope
21989 == cu
->get_builder ()->get_file_symbols ())
21990 ? cu
->get_builder ()->get_global_symbols ()
21991 : cu
->list_in_scope
);
21994 list_to_add
= cu
->list_in_scope
;
21998 /* We do not know the address of this symbol.
21999 If it is an external symbol and we have type information
22000 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22001 The address of the variable will then be determined from
22002 the minimal symbol table whenever the variable is
22004 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22006 /* Fortran explicitly imports any global symbols to the local
22007 scope by DW_TAG_common_block. */
22008 if (cu
->language
== language_fortran
&& die
->parent
22009 && die
->parent
->tag
== DW_TAG_common_block
)
22011 /* SYMBOL_CLASS doesn't matter here because
22012 read_common_block is going to reset it. */
22014 list_to_add
= cu
->list_in_scope
;
22016 else if (attr2
!= nullptr && attr2
->as_boolean ()
22017 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22019 /* A variable with DW_AT_external is never static, but it
22020 may be block-scoped. */
22022 = ((cu
->list_in_scope
22023 == cu
->get_builder ()->get_file_symbols ())
22024 ? cu
->get_builder ()->get_global_symbols ()
22025 : cu
->list_in_scope
);
22027 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22029 else if (!die_is_declaration (die
, cu
))
22031 /* Use the default LOC_OPTIMIZED_OUT class. */
22032 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22034 list_to_add
= cu
->list_in_scope
;
22038 case DW_TAG_formal_parameter
:
22040 SYMBOL_IS_ARGUMENT (sym
) = 1;
22041 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22042 if (attr
!= nullptr)
22044 var_decode_location (attr
, sym
, cu
);
22046 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22047 if (attr
!= nullptr)
22049 dwarf2_const_value (attr
, sym
, cu
);
22052 list_to_add
= cu
->list_in_scope
;
22055 case DW_TAG_unspecified_parameters
:
22056 /* From varargs functions; gdb doesn't seem to have any
22057 interest in this information, so just ignore it for now.
22060 case DW_TAG_template_type_param
:
22062 /* Fall through. */
22063 case DW_TAG_class_type
:
22064 case DW_TAG_interface_type
:
22065 case DW_TAG_structure_type
:
22066 case DW_TAG_union_type
:
22067 case DW_TAG_set_type
:
22068 case DW_TAG_enumeration_type
:
22069 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22070 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22073 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22074 really ever be static objects: otherwise, if you try
22075 to, say, break of a class's method and you're in a file
22076 which doesn't mention that class, it won't work unless
22077 the check for all static symbols in lookup_symbol_aux
22078 saves you. See the OtherFileClass tests in
22079 gdb.c++/namespace.exp. */
22083 buildsym_compunit
*builder
= cu
->get_builder ();
22085 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22086 && cu
->language
== language_cplus
22087 ? builder
->get_global_symbols ()
22088 : cu
->list_in_scope
);
22090 /* The semantics of C++ state that "struct foo {
22091 ... }" also defines a typedef for "foo". */
22092 if (cu
->language
== language_cplus
22093 || cu
->language
== language_ada
22094 || cu
->language
== language_d
22095 || cu
->language
== language_rust
)
22097 /* The symbol's name is already allocated along
22098 with this objfile, so we don't need to
22099 duplicate it for the type. */
22100 if (SYMBOL_TYPE (sym
)->name () == 0)
22101 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
22106 case DW_TAG_typedef
:
22107 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22108 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22109 list_to_add
= cu
->list_in_scope
;
22111 case DW_TAG_array_type
:
22112 case DW_TAG_base_type
:
22113 case DW_TAG_subrange_type
:
22114 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22115 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22116 list_to_add
= cu
->list_in_scope
;
22118 case DW_TAG_enumerator
:
22119 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22120 if (attr
!= nullptr)
22122 dwarf2_const_value (attr
, sym
, cu
);
22125 /* NOTE: carlton/2003-11-10: See comment above in the
22126 DW_TAG_class_type, etc. block. */
22129 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22130 && cu
->language
== language_cplus
22131 ? cu
->get_builder ()->get_global_symbols ()
22132 : cu
->list_in_scope
);
22135 case DW_TAG_imported_declaration
:
22136 case DW_TAG_namespace
:
22137 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22138 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22140 case DW_TAG_module
:
22141 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22142 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22143 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22145 case DW_TAG_common_block
:
22146 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22147 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22148 add_symbol_to_list (sym
, cu
->list_in_scope
);
22151 /* Not a tag we recognize. Hopefully we aren't processing
22152 trash data, but since we must specifically ignore things
22153 we don't recognize, there is nothing else we should do at
22155 complaint (_("unsupported tag: '%s'"),
22156 dwarf_tag_name (die
->tag
));
22162 sym
->hash_next
= objfile
->template_symbols
;
22163 objfile
->template_symbols
= sym
;
22164 list_to_add
= NULL
;
22167 if (list_to_add
!= NULL
)
22168 add_symbol_to_list (sym
, list_to_add
);
22170 /* For the benefit of old versions of GCC, check for anonymous
22171 namespaces based on the demangled name. */
22172 if (!cu
->processing_has_namespace_info
22173 && cu
->language
== language_cplus
)
22174 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22179 /* Given an attr with a DW_FORM_dataN value in host byte order,
22180 zero-extend it as appropriate for the symbol's type. The DWARF
22181 standard (v4) is not entirely clear about the meaning of using
22182 DW_FORM_dataN for a constant with a signed type, where the type is
22183 wider than the data. The conclusion of a discussion on the DWARF
22184 list was that this is unspecified. We choose to always zero-extend
22185 because that is the interpretation long in use by GCC. */
22188 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22189 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22191 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22192 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22193 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22194 LONGEST l
= attr
->constant_value (0);
22196 if (bits
< sizeof (*value
) * 8)
22198 l
&= ((LONGEST
) 1 << bits
) - 1;
22201 else if (bits
== sizeof (*value
) * 8)
22205 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22206 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22213 /* Read a constant value from an attribute. Either set *VALUE, or if
22214 the value does not fit in *VALUE, set *BYTES - either already
22215 allocated on the objfile obstack, or newly allocated on OBSTACK,
22216 or, set *BATON, if we translated the constant to a location
22220 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22221 const char *name
, struct obstack
*obstack
,
22222 struct dwarf2_cu
*cu
,
22223 LONGEST
*value
, const gdb_byte
**bytes
,
22224 struct dwarf2_locexpr_baton
**baton
)
22226 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22227 struct objfile
*objfile
= per_objfile
->objfile
;
22228 struct comp_unit_head
*cu_header
= &cu
->header
;
22229 struct dwarf_block
*blk
;
22230 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22231 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22237 switch (attr
->form
)
22240 case DW_FORM_addrx
:
22241 case DW_FORM_GNU_addr_index
:
22245 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22246 dwarf2_const_value_length_mismatch_complaint (name
,
22247 cu_header
->addr_size
,
22248 TYPE_LENGTH (type
));
22249 /* Symbols of this form are reasonably rare, so we just
22250 piggyback on the existing location code rather than writing
22251 a new implementation of symbol_computed_ops. */
22252 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22253 (*baton
)->per_objfile
= per_objfile
;
22254 (*baton
)->per_cu
= cu
->per_cu
;
22255 gdb_assert ((*baton
)->per_cu
);
22257 (*baton
)->size
= 2 + cu_header
->addr_size
;
22258 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22259 (*baton
)->data
= data
;
22261 data
[0] = DW_OP_addr
;
22262 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22263 byte_order
, attr
->as_address ());
22264 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22267 case DW_FORM_string
:
22270 case DW_FORM_GNU_str_index
:
22271 case DW_FORM_GNU_strp_alt
:
22272 /* The string is already allocated on the objfile obstack, point
22274 *bytes
= (const gdb_byte
*) attr
->as_string ();
22276 case DW_FORM_block1
:
22277 case DW_FORM_block2
:
22278 case DW_FORM_block4
:
22279 case DW_FORM_block
:
22280 case DW_FORM_exprloc
:
22281 case DW_FORM_data16
:
22282 blk
= attr
->as_block ();
22283 if (TYPE_LENGTH (type
) != blk
->size
)
22284 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22285 TYPE_LENGTH (type
));
22286 *bytes
= blk
->data
;
22289 /* The DW_AT_const_value attributes are supposed to carry the
22290 symbol's value "represented as it would be on the target
22291 architecture." By the time we get here, it's already been
22292 converted to host endianness, so we just need to sign- or
22293 zero-extend it as appropriate. */
22294 case DW_FORM_data1
:
22295 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22297 case DW_FORM_data2
:
22298 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22300 case DW_FORM_data4
:
22301 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22303 case DW_FORM_data8
:
22304 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22307 case DW_FORM_sdata
:
22308 case DW_FORM_implicit_const
:
22309 *value
= attr
->as_signed ();
22312 case DW_FORM_udata
:
22313 *value
= attr
->as_unsigned ();
22317 complaint (_("unsupported const value attribute form: '%s'"),
22318 dwarf_form_name (attr
->form
));
22325 /* Copy constant value from an attribute to a symbol. */
22328 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22329 struct dwarf2_cu
*cu
)
22331 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22333 const gdb_byte
*bytes
;
22334 struct dwarf2_locexpr_baton
*baton
;
22336 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22337 sym
->print_name (),
22338 &objfile
->objfile_obstack
, cu
,
22339 &value
, &bytes
, &baton
);
22343 SYMBOL_LOCATION_BATON (sym
) = baton
;
22344 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22346 else if (bytes
!= NULL
)
22348 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22349 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22353 SYMBOL_VALUE (sym
) = value
;
22354 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22358 /* Return the type of the die in question using its DW_AT_type attribute. */
22360 static struct type
*
22361 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22363 struct attribute
*type_attr
;
22365 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22368 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22369 /* A missing DW_AT_type represents a void type. */
22370 return objfile_type (objfile
)->builtin_void
;
22373 return lookup_die_type (die
, type_attr
, cu
);
22376 /* True iff CU's producer generates GNAT Ada auxiliary information
22377 that allows to find parallel types through that information instead
22378 of having to do expensive parallel lookups by type name. */
22381 need_gnat_info (struct dwarf2_cu
*cu
)
22383 /* Assume that the Ada compiler was GNAT, which always produces
22384 the auxiliary information. */
22385 return (cu
->language
== language_ada
);
22388 /* Return the auxiliary type of the die in question using its
22389 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22390 attribute is not present. */
22392 static struct type
*
22393 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22395 struct attribute
*type_attr
;
22397 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22401 return lookup_die_type (die
, type_attr
, cu
);
22404 /* If DIE has a descriptive_type attribute, then set the TYPE's
22405 descriptive type accordingly. */
22408 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22409 struct dwarf2_cu
*cu
)
22411 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22413 if (descriptive_type
)
22415 ALLOCATE_GNAT_AUX_TYPE (type
);
22416 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22420 /* Return the containing type of the die in question using its
22421 DW_AT_containing_type attribute. */
22423 static struct type
*
22424 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22426 struct attribute
*type_attr
;
22427 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22429 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22431 error (_("Dwarf Error: Problem turning containing type into gdb type "
22432 "[in module %s]"), objfile_name (objfile
));
22434 return lookup_die_type (die
, type_attr
, cu
);
22437 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22439 static struct type
*
22440 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22442 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22443 struct objfile
*objfile
= per_objfile
->objfile
;
22446 std::string message
22447 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22448 objfile_name (objfile
),
22449 sect_offset_str (cu
->header
.sect_off
),
22450 sect_offset_str (die
->sect_off
));
22451 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22453 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22456 /* Look up the type of DIE in CU using its type attribute ATTR.
22457 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22458 DW_AT_containing_type.
22459 If there is no type substitute an error marker. */
22461 static struct type
*
22462 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22463 struct dwarf2_cu
*cu
)
22465 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22466 struct objfile
*objfile
= per_objfile
->objfile
;
22467 struct type
*this_type
;
22469 gdb_assert (attr
->name
== DW_AT_type
22470 || attr
->name
== DW_AT_GNAT_descriptive_type
22471 || attr
->name
== DW_AT_containing_type
);
22473 /* First see if we have it cached. */
22475 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22477 struct dwarf2_per_cu_data
*per_cu
;
22478 sect_offset sect_off
= attr
->get_ref_die_offset ();
22480 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22481 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22483 else if (attr
->form_is_ref ())
22485 sect_offset sect_off
= attr
->get_ref_die_offset ();
22487 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22489 else if (attr
->form
== DW_FORM_ref_sig8
)
22491 ULONGEST signature
= attr
->as_signature ();
22493 return get_signatured_type (die
, signature
, cu
);
22497 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22498 " at %s [in module %s]"),
22499 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22500 objfile_name (objfile
));
22501 return build_error_marker_type (cu
, die
);
22504 /* If not cached we need to read it in. */
22506 if (this_type
== NULL
)
22508 struct die_info
*type_die
= NULL
;
22509 struct dwarf2_cu
*type_cu
= cu
;
22511 if (attr
->form_is_ref ())
22512 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22513 if (type_die
== NULL
)
22514 return build_error_marker_type (cu
, die
);
22515 /* If we find the type now, it's probably because the type came
22516 from an inter-CU reference and the type's CU got expanded before
22518 this_type
= read_type_die (type_die
, type_cu
);
22521 /* If we still don't have a type use an error marker. */
22523 if (this_type
== NULL
)
22524 return build_error_marker_type (cu
, die
);
22529 /* Return the type in DIE, CU.
22530 Returns NULL for invalid types.
22532 This first does a lookup in die_type_hash,
22533 and only reads the die in if necessary.
22535 NOTE: This can be called when reading in partial or full symbols. */
22537 static struct type
*
22538 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22540 struct type
*this_type
;
22542 this_type
= get_die_type (die
, cu
);
22546 return read_type_die_1 (die
, cu
);
22549 /* Read the type in DIE, CU.
22550 Returns NULL for invalid types. */
22552 static struct type
*
22553 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22555 struct type
*this_type
= NULL
;
22559 case DW_TAG_class_type
:
22560 case DW_TAG_interface_type
:
22561 case DW_TAG_structure_type
:
22562 case DW_TAG_union_type
:
22563 this_type
= read_structure_type (die
, cu
);
22565 case DW_TAG_enumeration_type
:
22566 this_type
= read_enumeration_type (die
, cu
);
22568 case DW_TAG_subprogram
:
22569 case DW_TAG_subroutine_type
:
22570 case DW_TAG_inlined_subroutine
:
22571 this_type
= read_subroutine_type (die
, cu
);
22573 case DW_TAG_array_type
:
22574 this_type
= read_array_type (die
, cu
);
22576 case DW_TAG_set_type
:
22577 this_type
= read_set_type (die
, cu
);
22579 case DW_TAG_pointer_type
:
22580 this_type
= read_tag_pointer_type (die
, cu
);
22582 case DW_TAG_ptr_to_member_type
:
22583 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22585 case DW_TAG_reference_type
:
22586 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22588 case DW_TAG_rvalue_reference_type
:
22589 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22591 case DW_TAG_const_type
:
22592 this_type
= read_tag_const_type (die
, cu
);
22594 case DW_TAG_volatile_type
:
22595 this_type
= read_tag_volatile_type (die
, cu
);
22597 case DW_TAG_restrict_type
:
22598 this_type
= read_tag_restrict_type (die
, cu
);
22600 case DW_TAG_string_type
:
22601 this_type
= read_tag_string_type (die
, cu
);
22603 case DW_TAG_typedef
:
22604 this_type
= read_typedef (die
, cu
);
22606 case DW_TAG_subrange_type
:
22607 this_type
= read_subrange_type (die
, cu
);
22609 case DW_TAG_base_type
:
22610 this_type
= read_base_type (die
, cu
);
22612 case DW_TAG_unspecified_type
:
22613 this_type
= read_unspecified_type (die
, cu
);
22615 case DW_TAG_namespace
:
22616 this_type
= read_namespace_type (die
, cu
);
22618 case DW_TAG_module
:
22619 this_type
= read_module_type (die
, cu
);
22621 case DW_TAG_atomic_type
:
22622 this_type
= read_tag_atomic_type (die
, cu
);
22625 complaint (_("unexpected tag in read_type_die: '%s'"),
22626 dwarf_tag_name (die
->tag
));
22633 /* See if we can figure out if the class lives in a namespace. We do
22634 this by looking for a member function; its demangled name will
22635 contain namespace info, if there is any.
22636 Return the computed name or NULL.
22637 Space for the result is allocated on the objfile's obstack.
22638 This is the full-die version of guess_partial_die_structure_name.
22639 In this case we know DIE has no useful parent. */
22641 static const char *
22642 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22644 struct die_info
*spec_die
;
22645 struct dwarf2_cu
*spec_cu
;
22646 struct die_info
*child
;
22647 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22650 spec_die
= die_specification (die
, &spec_cu
);
22651 if (spec_die
!= NULL
)
22657 for (child
= die
->child
;
22659 child
= child
->sibling
)
22661 if (child
->tag
== DW_TAG_subprogram
)
22663 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22665 if (linkage_name
!= NULL
)
22667 gdb::unique_xmalloc_ptr
<char> actual_name
22668 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22669 const char *name
= NULL
;
22671 if (actual_name
!= NULL
)
22673 const char *die_name
= dwarf2_name (die
, cu
);
22675 if (die_name
!= NULL
22676 && strcmp (die_name
, actual_name
.get ()) != 0)
22678 /* Strip off the class name from the full name.
22679 We want the prefix. */
22680 int die_name_len
= strlen (die_name
);
22681 int actual_name_len
= strlen (actual_name
.get ());
22682 const char *ptr
= actual_name
.get ();
22684 /* Test for '::' as a sanity check. */
22685 if (actual_name_len
> die_name_len
+ 2
22686 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22687 name
= obstack_strndup (
22688 &objfile
->per_bfd
->storage_obstack
,
22689 ptr
, actual_name_len
- die_name_len
- 2);
22700 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22701 prefix part in such case. See
22702 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22704 static const char *
22705 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22707 struct attribute
*attr
;
22710 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22711 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22714 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22717 attr
= dw2_linkage_name_attr (die
, cu
);
22718 const char *attr_name
= attr
->as_string ();
22719 if (attr
== NULL
|| attr_name
== NULL
)
22722 /* dwarf2_name had to be already called. */
22723 gdb_assert (attr
->canonical_string_p ());
22725 /* Strip the base name, keep any leading namespaces/classes. */
22726 base
= strrchr (attr_name
, ':');
22727 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22730 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22731 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22733 &base
[-1] - attr_name
);
22736 /* Return the name of the namespace/class that DIE is defined within,
22737 or "" if we can't tell. The caller should not xfree the result.
22739 For example, if we're within the method foo() in the following
22749 then determine_prefix on foo's die will return "N::C". */
22751 static const char *
22752 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22754 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22755 struct die_info
*parent
, *spec_die
;
22756 struct dwarf2_cu
*spec_cu
;
22757 struct type
*parent_type
;
22758 const char *retval
;
22760 if (cu
->language
!= language_cplus
22761 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22762 && cu
->language
!= language_rust
)
22765 retval
= anonymous_struct_prefix (die
, cu
);
22769 /* We have to be careful in the presence of DW_AT_specification.
22770 For example, with GCC 3.4, given the code
22774 // Definition of N::foo.
22778 then we'll have a tree of DIEs like this:
22780 1: DW_TAG_compile_unit
22781 2: DW_TAG_namespace // N
22782 3: DW_TAG_subprogram // declaration of N::foo
22783 4: DW_TAG_subprogram // definition of N::foo
22784 DW_AT_specification // refers to die #3
22786 Thus, when processing die #4, we have to pretend that we're in
22787 the context of its DW_AT_specification, namely the contex of die
22790 spec_die
= die_specification (die
, &spec_cu
);
22791 if (spec_die
== NULL
)
22792 parent
= die
->parent
;
22795 parent
= spec_die
->parent
;
22799 if (parent
== NULL
)
22801 else if (parent
->building_fullname
)
22804 const char *parent_name
;
22806 /* It has been seen on RealView 2.2 built binaries,
22807 DW_TAG_template_type_param types actually _defined_ as
22808 children of the parent class:
22811 template class <class Enum> Class{};
22812 Class<enum E> class_e;
22814 1: DW_TAG_class_type (Class)
22815 2: DW_TAG_enumeration_type (E)
22816 3: DW_TAG_enumerator (enum1:0)
22817 3: DW_TAG_enumerator (enum2:1)
22819 2: DW_TAG_template_type_param
22820 DW_AT_type DW_FORM_ref_udata (E)
22822 Besides being broken debug info, it can put GDB into an
22823 infinite loop. Consider:
22825 When we're building the full name for Class<E>, we'll start
22826 at Class, and go look over its template type parameters,
22827 finding E. We'll then try to build the full name of E, and
22828 reach here. We're now trying to build the full name of E,
22829 and look over the parent DIE for containing scope. In the
22830 broken case, if we followed the parent DIE of E, we'd again
22831 find Class, and once again go look at its template type
22832 arguments, etc., etc. Simply don't consider such parent die
22833 as source-level parent of this die (it can't be, the language
22834 doesn't allow it), and break the loop here. */
22835 name
= dwarf2_name (die
, cu
);
22836 parent_name
= dwarf2_name (parent
, cu
);
22837 complaint (_("template param type '%s' defined within parent '%s'"),
22838 name
? name
: "<unknown>",
22839 parent_name
? parent_name
: "<unknown>");
22843 switch (parent
->tag
)
22845 case DW_TAG_namespace
:
22846 parent_type
= read_type_die (parent
, cu
);
22847 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22848 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22849 Work around this problem here. */
22850 if (cu
->language
== language_cplus
22851 && strcmp (parent_type
->name (), "::") == 0)
22853 /* We give a name to even anonymous namespaces. */
22854 return parent_type
->name ();
22855 case DW_TAG_class_type
:
22856 case DW_TAG_interface_type
:
22857 case DW_TAG_structure_type
:
22858 case DW_TAG_union_type
:
22859 case DW_TAG_module
:
22860 parent_type
= read_type_die (parent
, cu
);
22861 if (parent_type
->name () != NULL
)
22862 return parent_type
->name ();
22864 /* An anonymous structure is only allowed non-static data
22865 members; no typedefs, no member functions, et cetera.
22866 So it does not need a prefix. */
22868 case DW_TAG_compile_unit
:
22869 case DW_TAG_partial_unit
:
22870 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22871 if (cu
->language
== language_cplus
22872 && !per_objfile
->per_bfd
->types
.empty ()
22873 && die
->child
!= NULL
22874 && (die
->tag
== DW_TAG_class_type
22875 || die
->tag
== DW_TAG_structure_type
22876 || die
->tag
== DW_TAG_union_type
))
22878 const char *name
= guess_full_die_structure_name (die
, cu
);
22883 case DW_TAG_subprogram
:
22884 /* Nested subroutines in Fortran get a prefix with the name
22885 of the parent's subroutine. */
22886 if (cu
->language
== language_fortran
)
22888 if ((die
->tag
== DW_TAG_subprogram
)
22889 && (dwarf2_name (parent
, cu
) != NULL
))
22890 return dwarf2_name (parent
, cu
);
22892 return determine_prefix (parent
, cu
);
22893 case DW_TAG_enumeration_type
:
22894 parent_type
= read_type_die (parent
, cu
);
22895 if (parent_type
->is_declared_class ())
22897 if (parent_type
->name () != NULL
)
22898 return parent_type
->name ();
22901 /* Fall through. */
22903 return determine_prefix (parent
, cu
);
22907 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22908 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22909 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22910 an obconcat, otherwise allocate storage for the result. The CU argument is
22911 used to determine the language and hence, the appropriate separator. */
22913 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22916 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22917 int physname
, struct dwarf2_cu
*cu
)
22919 const char *lead
= "";
22922 if (suffix
== NULL
|| suffix
[0] == '\0'
22923 || prefix
== NULL
|| prefix
[0] == '\0')
22925 else if (cu
->language
== language_d
)
22927 /* For D, the 'main' function could be defined in any module, but it
22928 should never be prefixed. */
22929 if (strcmp (suffix
, "D main") == 0)
22937 else if (cu
->language
== language_fortran
&& physname
)
22939 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22940 DW_AT_MIPS_linkage_name is preferred and used instead. */
22948 if (prefix
== NULL
)
22950 if (suffix
== NULL
)
22957 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22959 strcpy (retval
, lead
);
22960 strcat (retval
, prefix
);
22961 strcat (retval
, sep
);
22962 strcat (retval
, suffix
);
22967 /* We have an obstack. */
22968 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22972 /* Get name of a die, return NULL if not found. */
22974 static const char *
22975 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22976 struct objfile
*objfile
)
22978 if (name
&& cu
->language
== language_cplus
)
22980 gdb::unique_xmalloc_ptr
<char> canon_name
22981 = cp_canonicalize_string (name
);
22983 if (canon_name
!= nullptr)
22984 name
= objfile
->intern (canon_name
.get ());
22990 /* Get name of a die, return NULL if not found.
22991 Anonymous namespaces are converted to their magic string. */
22993 static const char *
22994 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22996 struct attribute
*attr
;
22997 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22999 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23000 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23001 if (attr_name
== nullptr
23002 && die
->tag
!= DW_TAG_namespace
23003 && die
->tag
!= DW_TAG_class_type
23004 && die
->tag
!= DW_TAG_interface_type
23005 && die
->tag
!= DW_TAG_structure_type
23006 && die
->tag
!= DW_TAG_union_type
)
23011 case DW_TAG_compile_unit
:
23012 case DW_TAG_partial_unit
:
23013 /* Compilation units have a DW_AT_name that is a filename, not
23014 a source language identifier. */
23015 case DW_TAG_enumeration_type
:
23016 case DW_TAG_enumerator
:
23017 /* These tags always have simple identifiers already; no need
23018 to canonicalize them. */
23021 case DW_TAG_namespace
:
23022 if (attr_name
!= nullptr)
23024 return CP_ANONYMOUS_NAMESPACE_STR
;
23026 case DW_TAG_class_type
:
23027 case DW_TAG_interface_type
:
23028 case DW_TAG_structure_type
:
23029 case DW_TAG_union_type
:
23030 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23031 structures or unions. These were of the form "._%d" in GCC 4.1,
23032 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23033 and GCC 4.4. We work around this problem by ignoring these. */
23034 if (attr_name
!= nullptr
23035 && (startswith (attr_name
, "._")
23036 || startswith (attr_name
, "<anonymous")))
23039 /* GCC might emit a nameless typedef that has a linkage name. See
23040 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23041 if (!attr
|| attr_name
== NULL
)
23043 attr
= dw2_linkage_name_attr (die
, cu
);
23044 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23045 if (attr
== NULL
|| attr_name
== NULL
)
23048 /* Avoid demangling attr_name the second time on a second
23049 call for the same DIE. */
23050 if (!attr
->canonical_string_p ())
23052 gdb::unique_xmalloc_ptr
<char> demangled
23053 (gdb_demangle (attr_name
, DMGL_TYPES
));
23054 if (demangled
== nullptr)
23057 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
23058 attr_name
= attr
->as_string ();
23061 /* Strip any leading namespaces/classes, keep only the
23062 base name. DW_AT_name for named DIEs does not
23063 contain the prefixes. */
23064 const char *base
= strrchr (attr_name
, ':');
23065 if (base
&& base
> attr_name
&& base
[-1] == ':')
23076 if (!attr
->canonical_string_p ())
23077 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
23079 return attr
->as_string ();
23082 /* Return the die that this die in an extension of, or NULL if there
23083 is none. *EXT_CU is the CU containing DIE on input, and the CU
23084 containing the return value on output. */
23086 static struct die_info
*
23087 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23089 struct attribute
*attr
;
23091 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23095 return follow_die_ref (die
, attr
, ext_cu
);
23099 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23103 print_spaces (indent
, f
);
23104 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23105 dwarf_tag_name (die
->tag
), die
->abbrev
,
23106 sect_offset_str (die
->sect_off
));
23108 if (die
->parent
!= NULL
)
23110 print_spaces (indent
, f
);
23111 fprintf_unfiltered (f
, " parent at offset: %s\n",
23112 sect_offset_str (die
->parent
->sect_off
));
23115 print_spaces (indent
, f
);
23116 fprintf_unfiltered (f
, " has children: %s\n",
23117 dwarf_bool_name (die
->child
!= NULL
));
23119 print_spaces (indent
, f
);
23120 fprintf_unfiltered (f
, " attributes:\n");
23122 for (i
= 0; i
< die
->num_attrs
; ++i
)
23124 print_spaces (indent
, f
);
23125 fprintf_unfiltered (f
, " %s (%s) ",
23126 dwarf_attr_name (die
->attrs
[i
].name
),
23127 dwarf_form_name (die
->attrs
[i
].form
));
23129 switch (die
->attrs
[i
].form
)
23132 case DW_FORM_addrx
:
23133 case DW_FORM_GNU_addr_index
:
23134 fprintf_unfiltered (f
, "address: ");
23135 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
23137 case DW_FORM_block2
:
23138 case DW_FORM_block4
:
23139 case DW_FORM_block
:
23140 case DW_FORM_block1
:
23141 fprintf_unfiltered (f
, "block: size %s",
23142 pulongest (die
->attrs
[i
].as_block ()->size
));
23144 case DW_FORM_exprloc
:
23145 fprintf_unfiltered (f
, "expression: size %s",
23146 pulongest (die
->attrs
[i
].as_block ()->size
));
23148 case DW_FORM_data16
:
23149 fprintf_unfiltered (f
, "constant of 16 bytes");
23151 case DW_FORM_ref_addr
:
23152 fprintf_unfiltered (f
, "ref address: ");
23153 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23155 case DW_FORM_GNU_ref_alt
:
23156 fprintf_unfiltered (f
, "alt ref address: ");
23157 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23163 case DW_FORM_ref_udata
:
23164 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23165 (long) (die
->attrs
[i
].as_unsigned ()));
23167 case DW_FORM_data1
:
23168 case DW_FORM_data2
:
23169 case DW_FORM_data4
:
23170 case DW_FORM_data8
:
23171 case DW_FORM_udata
:
23172 fprintf_unfiltered (f
, "constant: %s",
23173 pulongest (die
->attrs
[i
].as_unsigned ()));
23175 case DW_FORM_sec_offset
:
23176 fprintf_unfiltered (f
, "section offset: %s",
23177 pulongest (die
->attrs
[i
].as_unsigned ()));
23179 case DW_FORM_ref_sig8
:
23180 fprintf_unfiltered (f
, "signature: %s",
23181 hex_string (die
->attrs
[i
].as_signature ()));
23183 case DW_FORM_string
:
23185 case DW_FORM_line_strp
:
23187 case DW_FORM_GNU_str_index
:
23188 case DW_FORM_GNU_strp_alt
:
23189 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23190 die
->attrs
[i
].as_string ()
23191 ? die
->attrs
[i
].as_string () : "",
23192 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23195 if (die
->attrs
[i
].as_boolean ())
23196 fprintf_unfiltered (f
, "flag: TRUE");
23198 fprintf_unfiltered (f
, "flag: FALSE");
23200 case DW_FORM_flag_present
:
23201 fprintf_unfiltered (f
, "flag: TRUE");
23203 case DW_FORM_indirect
:
23204 /* The reader will have reduced the indirect form to
23205 the "base form" so this form should not occur. */
23206 fprintf_unfiltered (f
,
23207 "unexpected attribute form: DW_FORM_indirect");
23209 case DW_FORM_sdata
:
23210 case DW_FORM_implicit_const
:
23211 fprintf_unfiltered (f
, "constant: %s",
23212 plongest (die
->attrs
[i
].as_signed ()));
23215 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23216 die
->attrs
[i
].form
);
23219 fprintf_unfiltered (f
, "\n");
23224 dump_die_for_error (struct die_info
*die
)
23226 dump_die_shallow (gdb_stderr
, 0, die
);
23230 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23232 int indent
= level
* 4;
23234 gdb_assert (die
!= NULL
);
23236 if (level
>= max_level
)
23239 dump_die_shallow (f
, indent
, die
);
23241 if (die
->child
!= NULL
)
23243 print_spaces (indent
, f
);
23244 fprintf_unfiltered (f
, " Children:");
23245 if (level
+ 1 < max_level
)
23247 fprintf_unfiltered (f
, "\n");
23248 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23252 fprintf_unfiltered (f
,
23253 " [not printed, max nesting level reached]\n");
23257 if (die
->sibling
!= NULL
&& level
> 0)
23259 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23263 /* This is called from the pdie macro in gdbinit.in.
23264 It's not static so gcc will keep a copy callable from gdb. */
23267 dump_die (struct die_info
*die
, int max_level
)
23269 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23273 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23277 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23278 to_underlying (die
->sect_off
),
23284 /* Follow reference or signature attribute ATTR of SRC_DIE.
23285 On entry *REF_CU is the CU of SRC_DIE.
23286 On exit *REF_CU is the CU of the result. */
23288 static struct die_info
*
23289 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23290 struct dwarf2_cu
**ref_cu
)
23292 struct die_info
*die
;
23294 if (attr
->form_is_ref ())
23295 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23296 else if (attr
->form
== DW_FORM_ref_sig8
)
23297 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23300 dump_die_for_error (src_die
);
23301 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23302 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23308 /* Follow reference OFFSET.
23309 On entry *REF_CU is the CU of the source die referencing OFFSET.
23310 On exit *REF_CU is the CU of the result.
23311 Returns NULL if OFFSET is invalid. */
23313 static struct die_info
*
23314 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23315 struct dwarf2_cu
**ref_cu
)
23317 struct die_info temp_die
;
23318 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23319 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23321 gdb_assert (cu
->per_cu
!= NULL
);
23325 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23326 "source CU contains target offset: %d",
23327 sect_offset_str (cu
->per_cu
->sect_off
),
23328 sect_offset_str (sect_off
),
23329 cu
->header
.offset_in_cu_p (sect_off
));
23331 if (cu
->per_cu
->is_debug_types
)
23333 /* .debug_types CUs cannot reference anything outside their CU.
23334 If they need to, they have to reference a signatured type via
23335 DW_FORM_ref_sig8. */
23336 if (!cu
->header
.offset_in_cu_p (sect_off
))
23339 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23340 || !cu
->header
.offset_in_cu_p (sect_off
))
23342 struct dwarf2_per_cu_data
*per_cu
;
23344 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23347 dwarf_read_debug_printf_v ("target CU offset: %s, "
23348 "target CU DIEs loaded: %d",
23349 sect_offset_str (per_cu
->sect_off
),
23350 per_objfile
->get_cu (per_cu
) != nullptr);
23352 /* If necessary, add it to the queue and load its DIEs.
23354 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23355 it doesn't mean they are currently loaded. Since we require them
23356 to be loaded, we must check for ourselves. */
23357 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
)
23358 || per_objfile
->get_cu (per_cu
) == nullptr)
23359 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23360 false, cu
->language
);
23362 target_cu
= per_objfile
->get_cu (per_cu
);
23363 gdb_assert (target_cu
!= nullptr);
23365 else if (cu
->dies
== NULL
)
23367 /* We're loading full DIEs during partial symbol reading. */
23368 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23369 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23373 *ref_cu
= target_cu
;
23374 temp_die
.sect_off
= sect_off
;
23376 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23378 to_underlying (sect_off
));
23381 /* Follow reference attribute ATTR of SRC_DIE.
23382 On entry *REF_CU is the CU of SRC_DIE.
23383 On exit *REF_CU is the CU of the result. */
23385 static struct die_info
*
23386 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23387 struct dwarf2_cu
**ref_cu
)
23389 sect_offset sect_off
= attr
->get_ref_die_offset ();
23390 struct dwarf2_cu
*cu
= *ref_cu
;
23391 struct die_info
*die
;
23393 die
= follow_die_offset (sect_off
,
23394 (attr
->form
== DW_FORM_GNU_ref_alt
23395 || cu
->per_cu
->is_dwz
),
23398 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23399 "at %s [in module %s]"),
23400 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23401 objfile_name (cu
->per_objfile
->objfile
));
23408 struct dwarf2_locexpr_baton
23409 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23410 dwarf2_per_cu_data
*per_cu
,
23411 dwarf2_per_objfile
*per_objfile
,
23412 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23413 bool resolve_abstract_p
)
23415 struct die_info
*die
;
23416 struct attribute
*attr
;
23417 struct dwarf2_locexpr_baton retval
;
23418 struct objfile
*objfile
= per_objfile
->objfile
;
23420 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23422 cu
= load_cu (per_cu
, per_objfile
, false);
23426 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23427 Instead just throw an error, not much else we can do. */
23428 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23429 sect_offset_str (sect_off
), objfile_name (objfile
));
23432 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23434 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23435 sect_offset_str (sect_off
), objfile_name (objfile
));
23437 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23438 if (!attr
&& resolve_abstract_p
23439 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23440 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23442 CORE_ADDR pc
= get_frame_pc ();
23443 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23444 struct gdbarch
*gdbarch
= objfile
->arch ();
23446 for (const auto &cand_off
23447 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23449 struct dwarf2_cu
*cand_cu
= cu
;
23450 struct die_info
*cand
23451 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23454 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23457 CORE_ADDR pc_low
, pc_high
;
23458 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23459 if (pc_low
== ((CORE_ADDR
) -1))
23461 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23462 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23463 if (!(pc_low
<= pc
&& pc
< pc_high
))
23467 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23474 /* DWARF: "If there is no such attribute, then there is no effect.".
23475 DATA is ignored if SIZE is 0. */
23477 retval
.data
= NULL
;
23480 else if (attr
->form_is_section_offset ())
23482 struct dwarf2_loclist_baton loclist_baton
;
23483 CORE_ADDR pc
= get_frame_pc ();
23486 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23488 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23490 retval
.size
= size
;
23494 if (!attr
->form_is_block ())
23495 error (_("Dwarf Error: DIE at %s referenced in module %s "
23496 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23497 sect_offset_str (sect_off
), objfile_name (objfile
));
23499 struct dwarf_block
*block
= attr
->as_block ();
23500 retval
.data
= block
->data
;
23501 retval
.size
= block
->size
;
23503 retval
.per_objfile
= per_objfile
;
23504 retval
.per_cu
= cu
->per_cu
;
23506 per_objfile
->age_comp_units ();
23513 struct dwarf2_locexpr_baton
23514 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23515 dwarf2_per_cu_data
*per_cu
,
23516 dwarf2_per_objfile
*per_objfile
,
23517 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23519 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23521 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23525 /* Write a constant of a given type as target-ordered bytes into
23528 static const gdb_byte
*
23529 write_constant_as_bytes (struct obstack
*obstack
,
23530 enum bfd_endian byte_order
,
23537 *len
= TYPE_LENGTH (type
);
23538 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23539 store_unsigned_integer (result
, *len
, byte_order
, value
);
23547 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23548 dwarf2_per_cu_data
*per_cu
,
23549 dwarf2_per_objfile
*per_objfile
,
23553 struct die_info
*die
;
23554 struct attribute
*attr
;
23555 const gdb_byte
*result
= NULL
;
23558 enum bfd_endian byte_order
;
23559 struct objfile
*objfile
= per_objfile
->objfile
;
23561 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23563 cu
= load_cu (per_cu
, per_objfile
, false);
23567 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23568 Instead just throw an error, not much else we can do. */
23569 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23570 sect_offset_str (sect_off
), objfile_name (objfile
));
23573 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23575 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23576 sect_offset_str (sect_off
), objfile_name (objfile
));
23578 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23582 byte_order
= (bfd_big_endian (objfile
->obfd
)
23583 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23585 switch (attr
->form
)
23588 case DW_FORM_addrx
:
23589 case DW_FORM_GNU_addr_index
:
23593 *len
= cu
->header
.addr_size
;
23594 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23595 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23599 case DW_FORM_string
:
23602 case DW_FORM_GNU_str_index
:
23603 case DW_FORM_GNU_strp_alt
:
23604 /* The string is already allocated on the objfile obstack, point
23607 const char *attr_name
= attr
->as_string ();
23608 result
= (const gdb_byte
*) attr_name
;
23609 *len
= strlen (attr_name
);
23612 case DW_FORM_block1
:
23613 case DW_FORM_block2
:
23614 case DW_FORM_block4
:
23615 case DW_FORM_block
:
23616 case DW_FORM_exprloc
:
23617 case DW_FORM_data16
:
23619 struct dwarf_block
*block
= attr
->as_block ();
23620 result
= block
->data
;
23621 *len
= block
->size
;
23625 /* The DW_AT_const_value attributes are supposed to carry the
23626 symbol's value "represented as it would be on the target
23627 architecture." By the time we get here, it's already been
23628 converted to host endianness, so we just need to sign- or
23629 zero-extend it as appropriate. */
23630 case DW_FORM_data1
:
23631 type
= die_type (die
, cu
);
23632 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23633 if (result
== NULL
)
23634 result
= write_constant_as_bytes (obstack
, byte_order
,
23637 case DW_FORM_data2
:
23638 type
= die_type (die
, cu
);
23639 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23640 if (result
== NULL
)
23641 result
= write_constant_as_bytes (obstack
, byte_order
,
23644 case DW_FORM_data4
:
23645 type
= die_type (die
, cu
);
23646 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23647 if (result
== NULL
)
23648 result
= write_constant_as_bytes (obstack
, byte_order
,
23651 case DW_FORM_data8
:
23652 type
= die_type (die
, cu
);
23653 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23654 if (result
== NULL
)
23655 result
= write_constant_as_bytes (obstack
, byte_order
,
23659 case DW_FORM_sdata
:
23660 case DW_FORM_implicit_const
:
23661 type
= die_type (die
, cu
);
23662 result
= write_constant_as_bytes (obstack
, byte_order
,
23663 type
, attr
->as_signed (), len
);
23666 case DW_FORM_udata
:
23667 type
= die_type (die
, cu
);
23668 result
= write_constant_as_bytes (obstack
, byte_order
,
23669 type
, attr
->as_unsigned (), len
);
23673 complaint (_("unsupported const value attribute form: '%s'"),
23674 dwarf_form_name (attr
->form
));
23684 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23685 dwarf2_per_cu_data
*per_cu
,
23686 dwarf2_per_objfile
*per_objfile
)
23688 struct die_info
*die
;
23690 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23692 cu
= load_cu (per_cu
, per_objfile
, false);
23697 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23701 return die_type (die
, cu
);
23707 dwarf2_get_die_type (cu_offset die_offset
,
23708 dwarf2_per_cu_data
*per_cu
,
23709 dwarf2_per_objfile
*per_objfile
)
23711 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23712 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23715 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23716 On entry *REF_CU is the CU of SRC_DIE.
23717 On exit *REF_CU is the CU of the result.
23718 Returns NULL if the referenced DIE isn't found. */
23720 static struct die_info
*
23721 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23722 struct dwarf2_cu
**ref_cu
)
23724 struct die_info temp_die
;
23725 struct dwarf2_cu
*sig_cu
;
23726 struct die_info
*die
;
23727 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23730 /* While it might be nice to assert sig_type->type == NULL here,
23731 we can get here for DW_AT_imported_declaration where we need
23732 the DIE not the type. */
23734 /* If necessary, add it to the queue and load its DIEs.
23736 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23737 it doesn't mean they are currently loaded. Since we require them
23738 to be loaded, we must check for ourselves. */
23739 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
23741 || per_objfile
->get_cu (sig_type
) == nullptr)
23742 read_signatured_type (sig_type
, per_objfile
);
23744 sig_cu
= per_objfile
->get_cu (sig_type
);
23745 gdb_assert (sig_cu
!= NULL
);
23746 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23747 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23748 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23749 to_underlying (temp_die
.sect_off
));
23752 /* For .gdb_index version 7 keep track of included TUs.
23753 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23754 if (per_objfile
->per_bfd
->index_table
!= NULL
23755 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23757 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23768 /* Follow signatured type referenced by ATTR in SRC_DIE.
23769 On entry *REF_CU is the CU of SRC_DIE.
23770 On exit *REF_CU is the CU of the result.
23771 The result is the DIE of the type.
23772 If the referenced type cannot be found an error is thrown. */
23774 static struct die_info
*
23775 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23776 struct dwarf2_cu
**ref_cu
)
23778 ULONGEST signature
= attr
->as_signature ();
23779 struct signatured_type
*sig_type
;
23780 struct die_info
*die
;
23782 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23784 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23785 /* sig_type will be NULL if the signatured type is missing from
23787 if (sig_type
== NULL
)
23789 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23790 " from DIE at %s [in module %s]"),
23791 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23792 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23795 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23798 dump_die_for_error (src_die
);
23799 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23800 " from DIE at %s [in module %s]"),
23801 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23802 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23808 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23809 reading in and processing the type unit if necessary. */
23811 static struct type
*
23812 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23813 struct dwarf2_cu
*cu
)
23815 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23816 struct signatured_type
*sig_type
;
23817 struct dwarf2_cu
*type_cu
;
23818 struct die_info
*type_die
;
23821 sig_type
= lookup_signatured_type (cu
, signature
);
23822 /* sig_type will be NULL if the signatured type is missing from
23824 if (sig_type
== NULL
)
23826 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23827 " from DIE at %s [in module %s]"),
23828 hex_string (signature
), sect_offset_str (die
->sect_off
),
23829 objfile_name (per_objfile
->objfile
));
23830 return build_error_marker_type (cu
, die
);
23833 /* If we already know the type we're done. */
23834 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23835 if (type
!= nullptr)
23839 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23840 if (type_die
!= NULL
)
23842 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23843 is created. This is important, for example, because for c++ classes
23844 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23845 type
= read_type_die (type_die
, type_cu
);
23848 complaint (_("Dwarf Error: Cannot build signatured type %s"
23849 " referenced from DIE at %s [in module %s]"),
23850 hex_string (signature
), sect_offset_str (die
->sect_off
),
23851 objfile_name (per_objfile
->objfile
));
23852 type
= build_error_marker_type (cu
, die
);
23857 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23858 " from DIE at %s [in module %s]"),
23859 hex_string (signature
), sect_offset_str (die
->sect_off
),
23860 objfile_name (per_objfile
->objfile
));
23861 type
= build_error_marker_type (cu
, die
);
23864 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23869 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23870 reading in and processing the type unit if necessary. */
23872 static struct type
*
23873 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23874 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23876 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23877 if (attr
->form_is_ref ())
23879 struct dwarf2_cu
*type_cu
= cu
;
23880 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23882 return read_type_die (type_die
, type_cu
);
23884 else if (attr
->form
== DW_FORM_ref_sig8
)
23886 return get_signatured_type (die
, attr
->as_signature (), cu
);
23890 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23892 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23893 " at %s [in module %s]"),
23894 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23895 objfile_name (per_objfile
->objfile
));
23896 return build_error_marker_type (cu
, die
);
23900 /* Load the DIEs associated with type unit PER_CU into memory. */
23903 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23904 dwarf2_per_objfile
*per_objfile
)
23906 struct signatured_type
*sig_type
;
23908 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23909 gdb_assert (! per_cu
->type_unit_group_p ());
23911 /* We have the per_cu, but we need the signatured_type.
23912 Fortunately this is an easy translation. */
23913 gdb_assert (per_cu
->is_debug_types
);
23914 sig_type
= (struct signatured_type
*) per_cu
;
23916 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23918 read_signatured_type (sig_type
, per_objfile
);
23920 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23923 /* Read in a signatured type and build its CU and DIEs.
23924 If the type is a stub for the real type in a DWO file,
23925 read in the real type from the DWO file as well. */
23928 read_signatured_type (signatured_type
*sig_type
,
23929 dwarf2_per_objfile
*per_objfile
)
23931 gdb_assert (sig_type
->is_debug_types
);
23932 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
23934 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
23936 if (!reader
.dummy_p
)
23938 struct dwarf2_cu
*cu
= reader
.cu
;
23939 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23941 gdb_assert (cu
->die_hash
== NULL
);
23943 htab_create_alloc_ex (cu
->header
.length
/ 12,
23947 &cu
->comp_unit_obstack
,
23948 hashtab_obstack_allocate
,
23949 dummy_obstack_deallocate
);
23951 if (reader
.comp_unit_die
->has_children
)
23952 reader
.comp_unit_die
->child
23953 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23954 reader
.comp_unit_die
);
23955 cu
->dies
= reader
.comp_unit_die
;
23956 /* comp_unit_die is not stored in die_hash, no need. */
23958 /* We try not to read any attributes in this function, because
23959 not all CUs needed for references have been loaded yet, and
23960 symbol table processing isn't initialized. But we have to
23961 set the CU language, or we won't be able to build types
23962 correctly. Similarly, if we do not read the producer, we can
23963 not apply producer-specific interpretation. */
23964 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23969 sig_type
->tu_read
= 1;
23972 /* Decode simple location descriptions.
23973 Given a pointer to a dwarf block that defines a location, compute
23974 the location and return the value. If COMPUTED is non-null, it is
23975 set to true to indicate that decoding was successful, and false
23976 otherwise. If COMPUTED is null, then this function may emit a
23980 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
23982 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23984 size_t size
= blk
->size
;
23985 const gdb_byte
*data
= blk
->data
;
23986 CORE_ADDR stack
[64];
23988 unsigned int bytes_read
, unsnd
;
23991 if (computed
!= nullptr)
23997 stack
[++stacki
] = 0;
24036 stack
[++stacki
] = op
- DW_OP_lit0
;
24071 stack
[++stacki
] = op
- DW_OP_reg0
;
24074 if (computed
== nullptr)
24075 dwarf2_complex_location_expr_complaint ();
24082 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24084 stack
[++stacki
] = unsnd
;
24087 if (computed
== nullptr)
24088 dwarf2_complex_location_expr_complaint ();
24095 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
24100 case DW_OP_const1u
:
24101 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24105 case DW_OP_const1s
:
24106 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24110 case DW_OP_const2u
:
24111 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24115 case DW_OP_const2s
:
24116 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24120 case DW_OP_const4u
:
24121 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24125 case DW_OP_const4s
:
24126 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24130 case DW_OP_const8u
:
24131 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24136 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24142 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24147 stack
[stacki
+ 1] = stack
[stacki
];
24152 stack
[stacki
- 1] += stack
[stacki
];
24156 case DW_OP_plus_uconst
:
24157 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24163 stack
[stacki
- 1] -= stack
[stacki
];
24168 /* If we're not the last op, then we definitely can't encode
24169 this using GDB's address_class enum. This is valid for partial
24170 global symbols, although the variable's address will be bogus
24174 if (computed
== nullptr)
24175 dwarf2_complex_location_expr_complaint ();
24181 case DW_OP_GNU_push_tls_address
:
24182 case DW_OP_form_tls_address
:
24183 /* The top of the stack has the offset from the beginning
24184 of the thread control block at which the variable is located. */
24185 /* Nothing should follow this operator, so the top of stack would
24187 /* This is valid for partial global symbols, but the variable's
24188 address will be bogus in the psymtab. Make it always at least
24189 non-zero to not look as a variable garbage collected by linker
24190 which have DW_OP_addr 0. */
24193 if (computed
== nullptr)
24194 dwarf2_complex_location_expr_complaint ();
24201 case DW_OP_GNU_uninit
:
24202 if (computed
!= nullptr)
24207 case DW_OP_GNU_addr_index
:
24208 case DW_OP_GNU_const_index
:
24209 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24215 if (computed
== nullptr)
24217 const char *name
= get_DW_OP_name (op
);
24220 complaint (_("unsupported stack op: '%s'"),
24223 complaint (_("unsupported stack op: '%02x'"),
24227 return (stack
[stacki
]);
24230 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24231 outside of the allocated space. Also enforce minimum>0. */
24232 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24234 if (computed
== nullptr)
24235 complaint (_("location description stack overflow"));
24241 if (computed
== nullptr)
24242 complaint (_("location description stack underflow"));
24247 if (computed
!= nullptr)
24249 return (stack
[stacki
]);
24252 /* memory allocation interface */
24254 static struct dwarf_block
*
24255 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24257 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24260 static struct die_info
*
24261 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24263 struct die_info
*die
;
24264 size_t size
= sizeof (struct die_info
);
24267 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24269 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24270 memset (die
, 0, sizeof (struct die_info
));
24276 /* Macro support. */
24278 /* An overload of dwarf_decode_macros that finds the correct section
24279 and ensures it is read in before calling the other overload. */
24282 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24283 int section_is_gnu
)
24285 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24286 struct objfile
*objfile
= per_objfile
->objfile
;
24287 const struct line_header
*lh
= cu
->line_header
;
24288 unsigned int offset_size
= cu
->header
.offset_size
;
24289 struct dwarf2_section_info
*section
;
24290 const char *section_name
;
24292 if (cu
->dwo_unit
!= nullptr)
24294 if (section_is_gnu
)
24296 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24297 section_name
= ".debug_macro.dwo";
24301 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24302 section_name
= ".debug_macinfo.dwo";
24307 if (section_is_gnu
)
24309 section
= &per_objfile
->per_bfd
->macro
;
24310 section_name
= ".debug_macro";
24314 section
= &per_objfile
->per_bfd
->macinfo
;
24315 section_name
= ".debug_macinfo";
24319 section
->read (objfile
);
24320 if (section
->buffer
== nullptr)
24322 complaint (_("missing %s section"), section_name
);
24326 buildsym_compunit
*builder
= cu
->get_builder ();
24328 struct dwarf2_section_info
*str_offsets_section
;
24329 struct dwarf2_section_info
*str_section
;
24330 ULONGEST str_offsets_base
;
24332 if (cu
->dwo_unit
!= nullptr)
24334 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24335 ->sections
.str_offsets
;
24336 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24337 str_offsets_base
= cu
->header
.addr_size
;
24341 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24342 str_section
= &per_objfile
->per_bfd
->str
;
24343 str_offsets_base
= *cu
->str_offsets_base
;
24346 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24347 offset_size
, offset
, str_section
, str_offsets_section
,
24348 str_offsets_base
, section_is_gnu
);
24351 /* Return the .debug_loc section to use for CU.
24352 For DWO files use .debug_loc.dwo. */
24354 static struct dwarf2_section_info
*
24355 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24357 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24361 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24363 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24365 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24366 : &per_objfile
->per_bfd
->loc
);
24369 /* Return the .debug_rnglists section to use for CU. */
24370 static struct dwarf2_section_info
*
24371 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24373 if (cu
->header
.version
< 5)
24374 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24375 cu
->header
.version
);
24376 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24378 /* Make sure we read the .debug_rnglists section from the file that
24379 contains the DW_AT_ranges attribute we are reading. Normally that
24380 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24381 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24383 if (cu
->dwo_unit
!= nullptr
24384 && tag
!= DW_TAG_compile_unit
24385 && tag
!= DW_TAG_skeleton_unit
)
24387 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24389 if (sections
->rnglists
.size
> 0)
24390 return §ions
->rnglists
;
24392 error (_(".debug_rnglists section is missing from .dwo file."));
24394 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24397 /* A helper function that fills in a dwarf2_loclist_baton. */
24400 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24401 struct dwarf2_loclist_baton
*baton
,
24402 const struct attribute
*attr
)
24404 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24405 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24407 section
->read (per_objfile
->objfile
);
24409 baton
->per_objfile
= per_objfile
;
24410 baton
->per_cu
= cu
->per_cu
;
24411 gdb_assert (baton
->per_cu
);
24412 /* We don't know how long the location list is, but make sure we
24413 don't run off the edge of the section. */
24414 baton
->size
= section
->size
- attr
->as_unsigned ();
24415 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24416 if (cu
->base_address
.has_value ())
24417 baton
->base_address
= *cu
->base_address
;
24419 baton
->base_address
= 0;
24420 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24424 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24425 struct dwarf2_cu
*cu
, int is_block
)
24427 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24428 struct objfile
*objfile
= per_objfile
->objfile
;
24429 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24431 if (attr
->form_is_section_offset ()
24432 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24433 the section. If so, fall through to the complaint in the
24435 && attr
->as_unsigned () < section
->get_size (objfile
))
24437 struct dwarf2_loclist_baton
*baton
;
24439 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24441 fill_in_loclist_baton (cu
, baton
, attr
);
24443 if (!cu
->base_address
.has_value ())
24444 complaint (_("Location list used without "
24445 "specifying the CU base address."));
24447 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24448 ? dwarf2_loclist_block_index
24449 : dwarf2_loclist_index
);
24450 SYMBOL_LOCATION_BATON (sym
) = baton
;
24454 struct dwarf2_locexpr_baton
*baton
;
24456 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24457 baton
->per_objfile
= per_objfile
;
24458 baton
->per_cu
= cu
->per_cu
;
24459 gdb_assert (baton
->per_cu
);
24461 if (attr
->form_is_block ())
24463 /* Note that we're just copying the block's data pointer
24464 here, not the actual data. We're still pointing into the
24465 info_buffer for SYM's objfile; right now we never release
24466 that buffer, but when we do clean up properly this may
24468 struct dwarf_block
*block
= attr
->as_block ();
24469 baton
->size
= block
->size
;
24470 baton
->data
= block
->data
;
24474 dwarf2_invalid_attrib_class_complaint ("location description",
24475 sym
->natural_name ());
24479 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24480 ? dwarf2_locexpr_block_index
24481 : dwarf2_locexpr_index
);
24482 SYMBOL_LOCATION_BATON (sym
) = baton
;
24488 const comp_unit_head
*
24489 dwarf2_per_cu_data::get_header () const
24491 if (!m_header_read_in
)
24493 const gdb_byte
*info_ptr
24494 = this->section
->buffer
+ to_underlying (this->sect_off
);
24496 memset (&m_header
, 0, sizeof (m_header
));
24498 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24499 rcuh_kind::COMPILE
);
24501 m_header_read_in
= true;
24510 dwarf2_per_cu_data::addr_size () const
24512 return this->get_header ()->addr_size
;
24518 dwarf2_per_cu_data::offset_size () const
24520 return this->get_header ()->offset_size
;
24526 dwarf2_per_cu_data::ref_addr_size () const
24528 const comp_unit_head
*header
= this->get_header ();
24530 if (header
->version
== 2)
24531 return header
->addr_size
;
24533 return header
->offset_size
;
24539 dwarf2_cu::addr_type () const
24541 struct objfile
*objfile
= this->per_objfile
->objfile
;
24542 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24543 struct type
*addr_type
= lookup_pointer_type (void_type
);
24544 int addr_size
= this->per_cu
->addr_size ();
24546 if (TYPE_LENGTH (addr_type
) == addr_size
)
24549 addr_type
= addr_sized_int_type (addr_type
->is_unsigned ());
24553 /* A helper function for dwarf2_find_containing_comp_unit that returns
24554 the index of the result, and that searches a vector. It will
24555 return a result even if the offset in question does not actually
24556 occur in any CU. This is separate so that it can be unit
24560 dwarf2_find_containing_comp_unit
24561 (sect_offset sect_off
,
24562 unsigned int offset_in_dwz
,
24563 const std::vector
<std::unique_ptr
<dwarf2_per_cu_data
>> &all_comp_units
)
24568 high
= all_comp_units
.size () - 1;
24571 struct dwarf2_per_cu_data
*mid_cu
;
24572 int mid
= low
+ (high
- low
) / 2;
24574 mid_cu
= all_comp_units
[mid
].get ();
24575 if (mid_cu
->is_dwz
> offset_in_dwz
24576 || (mid_cu
->is_dwz
== offset_in_dwz
24577 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24582 gdb_assert (low
== high
);
24586 /* Locate the .debug_info compilation unit from CU's objfile which contains
24587 the DIE at OFFSET. Raises an error on failure. */
24589 static struct dwarf2_per_cu_data
*
24590 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24591 unsigned int offset_in_dwz
,
24592 dwarf2_per_objfile
*per_objfile
)
24594 int low
= dwarf2_find_containing_comp_unit
24595 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24596 dwarf2_per_cu_data
*this_cu
24597 = per_objfile
->per_bfd
->all_comp_units
[low
].get ();
24599 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24601 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24602 error (_("Dwarf Error: could not find partial DIE containing "
24603 "offset %s [in module %s]"),
24604 sect_offset_str (sect_off
),
24605 bfd_get_filename (per_objfile
->objfile
->obfd
));
24607 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24609 return per_objfile
->per_bfd
->all_comp_units
[low
- 1].get ();
24613 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24614 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24615 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24616 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24623 namespace selftests
{
24624 namespace find_containing_comp_unit
{
24629 std::unique_ptr
<dwarf2_per_cu_data
> one (new dwarf2_per_cu_data
);
24630 dwarf2_per_cu_data
*one_ptr
= one
.get ();
24631 std::unique_ptr
<dwarf2_per_cu_data
> two (new dwarf2_per_cu_data
);
24632 dwarf2_per_cu_data
*two_ptr
= two
.get ();
24633 std::unique_ptr
<dwarf2_per_cu_data
> three (new dwarf2_per_cu_data
);
24634 dwarf2_per_cu_data
*three_ptr
= three
.get ();
24635 std::unique_ptr
<dwarf2_per_cu_data
> four (new dwarf2_per_cu_data
);
24636 dwarf2_per_cu_data
*four_ptr
= four
.get ();
24639 two
->sect_off
= sect_offset (one
->length
);
24644 four
->sect_off
= sect_offset (three
->length
);
24648 std::vector
<std::unique_ptr
<dwarf2_per_cu_data
>> units
;
24649 units
.push_back (std::move (one
));
24650 units
.push_back (std::move (two
));
24651 units
.push_back (std::move (three
));
24652 units
.push_back (std::move (four
));
24656 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24657 SELF_CHECK (units
[result
].get () == one_ptr
);
24658 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24659 SELF_CHECK (units
[result
].get () == one_ptr
);
24660 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24661 SELF_CHECK (units
[result
].get () == two_ptr
);
24663 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24664 SELF_CHECK (units
[result
].get () == three_ptr
);
24665 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24666 SELF_CHECK (units
[result
].get () == three_ptr
);
24667 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24668 SELF_CHECK (units
[result
].get () == four_ptr
);
24674 #endif /* GDB_SELF_TEST */
24676 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
24678 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
24679 dwarf2_per_objfile
*per_objfile
)
24681 per_objfile (per_objfile
),
24683 has_loclist (false),
24684 checked_producer (false),
24685 producer_is_gxx_lt_4_6 (false),
24686 producer_is_gcc_lt_4_3 (false),
24687 producer_is_icc (false),
24688 producer_is_icc_lt_14 (false),
24689 producer_is_codewarrior (false),
24690 processing_has_namespace_info (false)
24694 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24697 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24698 enum language pretend_language
)
24700 struct attribute
*attr
;
24702 /* Set the language we're debugging. */
24703 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24704 if (attr
!= nullptr)
24705 set_cu_language (attr
->constant_value (0), cu
);
24708 cu
->language
= pretend_language
;
24709 cu
->language_defn
= language_def (cu
->language
);
24712 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24718 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24720 auto it
= m_dwarf2_cus
.find (per_cu
);
24721 if (it
== m_dwarf2_cus
.end ())
24730 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24732 gdb_assert (this->get_cu (per_cu
) == nullptr);
24734 m_dwarf2_cus
[per_cu
] = cu
;
24740 dwarf2_per_objfile::age_comp_units ()
24742 dwarf_read_debug_printf_v ("running");
24744 /* This is not expected to be called in the middle of CU expansion. There is
24745 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
24746 loaded in memory. Calling age_comp_units while the queue is in use could
24747 make us free the DIEs for a CU that is in the queue and therefore break
24749 gdb_assert (!this->per_bfd
->queue
.has_value ());
24751 /* Start by clearing all marks. */
24752 for (auto pair
: m_dwarf2_cus
)
24753 pair
.second
->mark
= false;
24755 /* Traverse all CUs, mark them and their dependencies if used recently
24757 for (auto pair
: m_dwarf2_cus
)
24759 dwarf2_cu
*cu
= pair
.second
;
24762 if (cu
->last_used
<= dwarf_max_cache_age
)
24766 /* Delete all CUs still not marked. */
24767 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24769 dwarf2_cu
*cu
= it
->second
;
24773 dwarf_read_debug_printf_v ("deleting old CU %s",
24774 sect_offset_str (cu
->per_cu
->sect_off
));
24776 it
= m_dwarf2_cus
.erase (it
);
24786 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24788 auto it
= m_dwarf2_cus
.find (per_cu
);
24789 if (it
== m_dwarf2_cus
.end ())
24794 m_dwarf2_cus
.erase (it
);
24797 dwarf2_per_objfile::~dwarf2_per_objfile ()
24802 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24803 We store these in a hash table separate from the DIEs, and preserve them
24804 when the DIEs are flushed out of cache.
24806 The CU "per_cu" pointer is needed because offset alone is not enough to
24807 uniquely identify the type. A file may have multiple .debug_types sections,
24808 or the type may come from a DWO file. Furthermore, while it's more logical
24809 to use per_cu->section+offset, with Fission the section with the data is in
24810 the DWO file but we don't know that section at the point we need it.
24811 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24812 because we can enter the lookup routine, get_die_type_at_offset, from
24813 outside this file, and thus won't necessarily have PER_CU->cu.
24814 Fortunately, PER_CU is stable for the life of the objfile. */
24816 struct dwarf2_per_cu_offset_and_type
24818 const struct dwarf2_per_cu_data
*per_cu
;
24819 sect_offset sect_off
;
24823 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24826 per_cu_offset_and_type_hash (const void *item
)
24828 const struct dwarf2_per_cu_offset_and_type
*ofs
24829 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24831 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24834 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24837 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24839 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24840 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24841 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24842 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24844 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24845 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24848 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24849 table if necessary. For convenience, return TYPE.
24851 The DIEs reading must have careful ordering to:
24852 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24853 reading current DIE.
24854 * Not trying to dereference contents of still incompletely read in types
24855 while reading in other DIEs.
24856 * Enable referencing still incompletely read in types just by a pointer to
24857 the type without accessing its fields.
24859 Therefore caller should follow these rules:
24860 * Try to fetch any prerequisite types we may need to build this DIE type
24861 before building the type and calling set_die_type.
24862 * After building type call set_die_type for current DIE as soon as
24863 possible before fetching more types to complete the current type.
24864 * Make the type as complete as possible before fetching more types. */
24866 static struct type
*
24867 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
24868 bool skip_data_location
)
24870 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24871 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24872 struct objfile
*objfile
= per_objfile
->objfile
;
24873 struct attribute
*attr
;
24874 struct dynamic_prop prop
;
24876 /* For Ada types, make sure that the gnat-specific data is always
24877 initialized (if not already set). There are a few types where
24878 we should not be doing so, because the type-specific area is
24879 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24880 where the type-specific area is used to store the floatformat).
24881 But this is not a problem, because the gnat-specific information
24882 is actually not needed for these types. */
24883 if (need_gnat_info (cu
)
24884 && type
->code () != TYPE_CODE_FUNC
24885 && type
->code () != TYPE_CODE_FLT
24886 && type
->code () != TYPE_CODE_METHODPTR
24887 && type
->code () != TYPE_CODE_MEMBERPTR
24888 && type
->code () != TYPE_CODE_METHOD
24889 && type
->code () != TYPE_CODE_FIXED_POINT
24890 && !HAVE_GNAT_AUX_INFO (type
))
24891 INIT_GNAT_SPECIFIC (type
);
24893 /* Read DW_AT_allocated and set in type. */
24894 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24897 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24898 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24899 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24902 /* Read DW_AT_associated and set in type. */
24903 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24906 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24907 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24908 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24911 /* Read DW_AT_data_location and set in type. */
24912 if (!skip_data_location
)
24914 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24915 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24916 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24919 if (per_objfile
->die_type_hash
== NULL
)
24920 per_objfile
->die_type_hash
24921 = htab_up (htab_create_alloc (127,
24922 per_cu_offset_and_type_hash
,
24923 per_cu_offset_and_type_eq
,
24924 NULL
, xcalloc
, xfree
));
24926 ofs
.per_cu
= cu
->per_cu
;
24927 ofs
.sect_off
= die
->sect_off
;
24929 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24930 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24932 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24933 sect_offset_str (die
->sect_off
));
24934 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24935 struct dwarf2_per_cu_offset_and_type
);
24940 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24941 or return NULL if the die does not have a saved type. */
24943 static struct type
*
24944 get_die_type_at_offset (sect_offset sect_off
,
24945 dwarf2_per_cu_data
*per_cu
,
24946 dwarf2_per_objfile
*per_objfile
)
24948 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24950 if (per_objfile
->die_type_hash
== NULL
)
24953 ofs
.per_cu
= per_cu
;
24954 ofs
.sect_off
= sect_off
;
24955 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24956 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24963 /* Look up the type for DIE in CU in die_type_hash,
24964 or return NULL if DIE does not have a saved type. */
24966 static struct type
*
24967 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24969 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24972 /* Add a dependence relationship from CU to REF_PER_CU. */
24975 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
24976 struct dwarf2_per_cu_data
*ref_per_cu
)
24980 if (cu
->dependencies
== NULL
)
24982 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
24983 NULL
, &cu
->comp_unit_obstack
,
24984 hashtab_obstack_allocate
,
24985 dummy_obstack_deallocate
);
24987 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
24989 *slot
= ref_per_cu
;
24992 /* Subroutine of dwarf2_mark to pass to htab_traverse.
24993 Set the mark field in every compilation unit in the
24994 cache that we must keep because we are keeping CU.
24996 DATA is the dwarf2_per_objfile object in which to look up CUs. */
24999 dwarf2_mark_helper (void **slot
, void *data
)
25001 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
25002 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
25003 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
25005 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25006 reading of the chain. As such dependencies remain valid it is not much
25007 useful to track and undo them during QUIT cleanups. */
25016 if (cu
->dependencies
!= nullptr)
25017 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
25022 /* Set the mark field in CU and in every other compilation unit in the
25023 cache that we must keep because we are keeping CU. */
25026 dwarf2_mark (struct dwarf2_cu
*cu
)
25033 if (cu
->dependencies
!= nullptr)
25034 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
25037 /* Trivial hash function for partial_die_info: the hash value of a DIE
25038 is its offset in .debug_info for this objfile. */
25041 partial_die_hash (const void *item
)
25043 const struct partial_die_info
*part_die
25044 = (const struct partial_die_info
*) item
;
25046 return to_underlying (part_die
->sect_off
);
25049 /* Trivial comparison function for partial_die_info structures: two DIEs
25050 are equal if they have the same offset. */
25053 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25055 const struct partial_die_info
*part_die_lhs
25056 = (const struct partial_die_info
*) item_lhs
;
25057 const struct partial_die_info
*part_die_rhs
25058 = (const struct partial_die_info
*) item_rhs
;
25060 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25063 struct cmd_list_element
*set_dwarf_cmdlist
;
25064 struct cmd_list_element
*show_dwarf_cmdlist
;
25067 show_check_physname (struct ui_file
*file
, int from_tty
,
25068 struct cmd_list_element
*c
, const char *value
)
25070 fprintf_filtered (file
,
25071 _("Whether to check \"physname\" is %s.\n"),
25075 void _initialize_dwarf2_read ();
25077 _initialize_dwarf2_read ()
25079 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
25080 Set DWARF specific variables.\n\
25081 Configure DWARF variables such as the cache size."),
25082 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25083 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25085 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
25086 Show DWARF specific variables.\n\
25087 Show DWARF variables such as the cache size."),
25088 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25089 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25091 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25092 &dwarf_max_cache_age
, _("\
25093 Set the upper bound on the age of cached DWARF compilation units."), _("\
25094 Show the upper bound on the age of cached DWARF compilation units."), _("\
25095 A higher limit means that cached compilation units will be stored\n\
25096 in memory longer, and more total memory will be used. Zero disables\n\
25097 caching, which can slow down startup."),
25099 show_dwarf_max_cache_age
,
25100 &set_dwarf_cmdlist
,
25101 &show_dwarf_cmdlist
);
25103 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25104 Set debugging of the DWARF reader."), _("\
25105 Show debugging of the DWARF reader."), _("\
25106 When enabled (non-zero), debugging messages are printed during DWARF\n\
25107 reading and symtab expansion. A value of 1 (one) provides basic\n\
25108 information. A value greater than 1 provides more verbose information."),
25111 &setdebuglist
, &showdebuglist
);
25113 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25114 Set debugging of the DWARF DIE reader."), _("\
25115 Show debugging of the DWARF DIE reader."), _("\
25116 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25117 The value is the maximum depth to print."),
25120 &setdebuglist
, &showdebuglist
);
25122 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25123 Set debugging of the dwarf line reader."), _("\
25124 Show debugging of the dwarf line reader."), _("\
25125 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25126 A value of 1 (one) provides basic information.\n\
25127 A value greater than 1 provides more verbose information."),
25130 &setdebuglist
, &showdebuglist
);
25132 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25133 Set cross-checking of \"physname\" code against demangler."), _("\
25134 Show cross-checking of \"physname\" code against demangler."), _("\
25135 When enabled, GDB's internal \"physname\" code is checked against\n\
25137 NULL
, show_check_physname
,
25138 &setdebuglist
, &showdebuglist
);
25140 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25141 no_class
, &use_deprecated_index_sections
, _("\
25142 Set whether to use deprecated gdb_index sections."), _("\
25143 Show whether to use deprecated gdb_index sections."), _("\
25144 When enabled, deprecated .gdb_index sections are used anyway.\n\
25145 Normally they are ignored either because of a missing feature or\n\
25146 performance issue.\n\
25147 Warning: This option must be enabled before gdb reads the file."),
25150 &setlist
, &showlist
);
25152 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25153 &dwarf2_locexpr_funcs
);
25154 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25155 &dwarf2_loclist_funcs
);
25157 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25158 &dwarf2_block_frame_base_locexpr_funcs
);
25159 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25160 &dwarf2_block_frame_base_loclist_funcs
);
25163 selftests::register_test ("dw2_expand_symtabs_matching",
25164 selftests::dw2_expand_symtabs_matching::run_test
);
25165 selftests::register_test ("dwarf2_find_containing_comp_unit",
25166 selftests::find_containing_comp_unit::run_test
);