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 /* If this CU was inherited by another CU (via specification,
688 abstract_origin, etc), this is the ancestor CU. */
691 /* Get the buildsym_compunit for this CU. */
692 buildsym_compunit
*get_builder ()
694 /* If this CU has a builder associated with it, use that. */
695 if (m_builder
!= nullptr)
696 return m_builder
.get ();
698 /* Otherwise, search ancestors for a valid builder. */
699 if (ancestor
!= nullptr)
700 return ancestor
->get_builder ();
706 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
707 This includes type_unit_group and quick_file_names. */
709 struct stmt_list_hash
711 /* The DWO unit this table is from or NULL if there is none. */
712 struct dwo_unit
*dwo_unit
;
714 /* Offset in .debug_line or .debug_line.dwo. */
715 sect_offset line_sect_off
;
718 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
719 an object of this type. This contains elements of type unit groups
720 that can be shared across objfiles. The non-shareable parts are in
721 type_unit_group_unshareable. */
723 struct type_unit_group
: public dwarf2_per_cu_data
725 /* The TUs that share this DW_AT_stmt_list entry.
726 This is added to while parsing type units to build partial symtabs,
727 and is deleted afterwards and not used again. */
728 std::vector
<signatured_type
*> *tus
= nullptr;
730 /* The data used to construct the hash key. */
731 struct stmt_list_hash hash
{};
734 /* These sections are what may appear in a (real or virtual) DWO file. */
738 struct dwarf2_section_info abbrev
;
739 struct dwarf2_section_info line
;
740 struct dwarf2_section_info loc
;
741 struct dwarf2_section_info loclists
;
742 struct dwarf2_section_info macinfo
;
743 struct dwarf2_section_info macro
;
744 struct dwarf2_section_info rnglists
;
745 struct dwarf2_section_info str
;
746 struct dwarf2_section_info str_offsets
;
747 /* In the case of a virtual DWO file, these two are unused. */
748 struct dwarf2_section_info info
;
749 std::vector
<dwarf2_section_info
> types
;
752 /* CUs/TUs in DWP/DWO files. */
756 /* Backlink to the containing struct dwo_file. */
757 struct dwo_file
*dwo_file
;
759 /* The "id" that distinguishes this CU/TU.
760 .debug_info calls this "dwo_id", .debug_types calls this "signature".
761 Since signatures came first, we stick with it for consistency. */
764 /* The section this CU/TU lives in, in the DWO file. */
765 struct dwarf2_section_info
*section
;
767 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
768 sect_offset sect_off
;
771 /* For types, offset in the type's DIE of the type defined by this TU. */
772 cu_offset type_offset_in_tu
;
775 /* include/dwarf2.h defines the DWP section codes.
776 It defines a max value but it doesn't define a min value, which we
777 use for error checking, so provide one. */
779 enum dwp_v2_section_ids
784 /* Data for one DWO file.
786 This includes virtual DWO files (a virtual DWO file is a DWO file as it
787 appears in a DWP file). DWP files don't really have DWO files per se -
788 comdat folding of types "loses" the DWO file they came from, and from
789 a high level view DWP files appear to contain a mass of random types.
790 However, to maintain consistency with the non-DWP case we pretend DWP
791 files contain virtual DWO files, and we assign each TU with one virtual
792 DWO file (generally based on the line and abbrev section offsets -
793 a heuristic that seems to work in practice). */
797 dwo_file () = default;
798 DISABLE_COPY_AND_ASSIGN (dwo_file
);
800 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
801 For virtual DWO files the name is constructed from the section offsets
802 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
803 from related CU+TUs. */
804 const char *dwo_name
= nullptr;
806 /* The DW_AT_comp_dir attribute. */
807 const char *comp_dir
= nullptr;
809 /* The bfd, when the file is open. Otherwise this is NULL.
810 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
811 gdb_bfd_ref_ptr dbfd
;
813 /* The sections that make up this DWO file.
814 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
815 sections (for lack of a better name). */
816 struct dwo_sections sections
{};
818 /* The CUs in the file.
819 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
820 an extension to handle LLVM's Link Time Optimization output (where
821 multiple source files may be compiled into a single object/dwo pair). */
824 /* Table of TUs in the file.
825 Each element is a struct dwo_unit. */
829 /* These sections are what may appear in a DWP file. */
833 /* These are used by all DWP versions (1, 2 and 5). */
834 struct dwarf2_section_info str
;
835 struct dwarf2_section_info cu_index
;
836 struct dwarf2_section_info tu_index
;
838 /* These are only used by DWP version 2 and version 5 files.
839 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
840 sections are referenced by section number, and are not recorded here.
841 In DWP version 2 or 5 there is at most one copy of all these sections,
842 each section being (effectively) comprised of the concatenation of all of
843 the individual sections that exist in the version 1 format.
844 To keep the code simple we treat each of these concatenated pieces as a
845 section itself (a virtual section?). */
846 struct dwarf2_section_info abbrev
;
847 struct dwarf2_section_info info
;
848 struct dwarf2_section_info line
;
849 struct dwarf2_section_info loc
;
850 struct dwarf2_section_info loclists
;
851 struct dwarf2_section_info macinfo
;
852 struct dwarf2_section_info macro
;
853 struct dwarf2_section_info rnglists
;
854 struct dwarf2_section_info str_offsets
;
855 struct dwarf2_section_info types
;
858 /* These sections are what may appear in a virtual DWO file in DWP version 1.
859 A virtual DWO file is a DWO file as it appears in a DWP file. */
861 struct virtual_v1_dwo_sections
863 struct dwarf2_section_info abbrev
;
864 struct dwarf2_section_info line
;
865 struct dwarf2_section_info loc
;
866 struct dwarf2_section_info macinfo
;
867 struct dwarf2_section_info macro
;
868 struct dwarf2_section_info str_offsets
;
869 /* Each DWP hash table entry records one CU or one TU.
870 That is recorded here, and copied to dwo_unit.section. */
871 struct dwarf2_section_info info_or_types
;
874 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
875 In version 2, the sections of the DWO files are concatenated together
876 and stored in one section of that name. Thus each ELF section contains
877 several "virtual" sections. */
879 struct virtual_v2_or_v5_dwo_sections
881 bfd_size_type abbrev_offset
;
882 bfd_size_type abbrev_size
;
884 bfd_size_type line_offset
;
885 bfd_size_type line_size
;
887 bfd_size_type loc_offset
;
888 bfd_size_type loc_size
;
890 bfd_size_type loclists_offset
;
891 bfd_size_type loclists_size
;
893 bfd_size_type macinfo_offset
;
894 bfd_size_type macinfo_size
;
896 bfd_size_type macro_offset
;
897 bfd_size_type macro_size
;
899 bfd_size_type rnglists_offset
;
900 bfd_size_type rnglists_size
;
902 bfd_size_type str_offsets_offset
;
903 bfd_size_type str_offsets_size
;
905 /* Each DWP hash table entry records one CU or one TU.
906 That is recorded here, and copied to dwo_unit.section. */
907 bfd_size_type info_or_types_offset
;
908 bfd_size_type info_or_types_size
;
911 /* Contents of DWP hash tables. */
913 struct dwp_hash_table
915 uint32_t version
, nr_columns
;
916 uint32_t nr_units
, nr_slots
;
917 const gdb_byte
*hash_table
, *unit_table
;
922 const gdb_byte
*indices
;
926 /* This is indexed by column number and gives the id of the section
928 #define MAX_NR_V2_DWO_SECTIONS \
929 (1 /* .debug_info or .debug_types */ \
930 + 1 /* .debug_abbrev */ \
931 + 1 /* .debug_line */ \
932 + 1 /* .debug_loc */ \
933 + 1 /* .debug_str_offsets */ \
934 + 1 /* .debug_macro or .debug_macinfo */)
935 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
936 const gdb_byte
*offsets
;
937 const gdb_byte
*sizes
;
941 /* This is indexed by column number and gives the id of the section
943 #define MAX_NR_V5_DWO_SECTIONS \
944 (1 /* .debug_info */ \
945 + 1 /* .debug_abbrev */ \
946 + 1 /* .debug_line */ \
947 + 1 /* .debug_loclists */ \
948 + 1 /* .debug_str_offsets */ \
949 + 1 /* .debug_macro */ \
950 + 1 /* .debug_rnglists */)
951 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
952 const gdb_byte
*offsets
;
953 const gdb_byte
*sizes
;
958 /* Data for one DWP file. */
962 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
964 dbfd (std::move (abfd
))
968 /* Name of the file. */
971 /* File format version. */
975 gdb_bfd_ref_ptr dbfd
;
977 /* Section info for this file. */
978 struct dwp_sections sections
{};
980 /* Table of CUs in the file. */
981 const struct dwp_hash_table
*cus
= nullptr;
983 /* Table of TUs in the file. */
984 const struct dwp_hash_table
*tus
= nullptr;
986 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
990 /* Table to map ELF section numbers to their sections.
991 This is only needed for the DWP V1 file format. */
992 unsigned int num_sections
= 0;
993 asection
**elf_sections
= nullptr;
996 /* Struct used to pass misc. parameters to read_die_and_children, et
997 al. which are used for both .debug_info and .debug_types dies.
998 All parameters here are unchanging for the life of the call. This
999 struct exists to abstract away the constant parameters of die reading. */
1001 struct die_reader_specs
1003 /* The bfd of die_section. */
1006 /* The CU of the DIE we are parsing. */
1007 struct dwarf2_cu
*cu
;
1009 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1010 struct dwo_file
*dwo_file
;
1012 /* The section the die comes from.
1013 This is either .debug_info or .debug_types, or the .dwo variants. */
1014 struct dwarf2_section_info
*die_section
;
1016 /* die_section->buffer. */
1017 const gdb_byte
*buffer
;
1019 /* The end of the buffer. */
1020 const gdb_byte
*buffer_end
;
1022 /* The abbreviation table to use when reading the DIEs. */
1023 struct abbrev_table
*abbrev_table
;
1026 /* A subclass of die_reader_specs that holds storage and has complex
1027 constructor and destructor behavior. */
1029 class cutu_reader
: public die_reader_specs
1033 cutu_reader (dwarf2_per_cu_data
*this_cu
,
1034 dwarf2_per_objfile
*per_objfile
,
1035 struct abbrev_table
*abbrev_table
,
1036 dwarf2_cu
*existing_cu
,
1039 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
1040 dwarf2_per_objfile
*per_objfile
,
1041 struct dwarf2_cu
*parent_cu
= nullptr,
1042 struct dwo_file
*dwo_file
= nullptr);
1044 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
1046 const gdb_byte
*info_ptr
= nullptr;
1047 struct die_info
*comp_unit_die
= nullptr;
1048 bool dummy_p
= false;
1050 /* Release the new CU, putting it on the chain. This cannot be done
1055 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
1056 dwarf2_per_objfile
*per_objfile
,
1057 dwarf2_cu
*existing_cu
);
1059 struct dwarf2_per_cu_data
*m_this_cu
;
1060 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
1062 /* The ordinary abbreviation table. */
1063 abbrev_table_up m_abbrev_table_holder
;
1065 /* The DWO abbreviation table. */
1066 abbrev_table_up m_dwo_abbrev_table
;
1069 /* When we construct a partial symbol table entry we only
1070 need this much information. */
1071 struct partial_die_info
: public allocate_on_obstack
1073 partial_die_info (sect_offset sect_off
, const struct abbrev_info
*abbrev
);
1075 /* Disable assign but still keep copy ctor, which is needed
1076 load_partial_dies. */
1077 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1079 /* Adjust the partial die before generating a symbol for it. This
1080 function may set the is_external flag or change the DIE's
1082 void fixup (struct dwarf2_cu
*cu
);
1084 /* Read a minimal amount of information into the minimal die
1086 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1087 const struct abbrev_info
&abbrev
,
1088 const gdb_byte
*info_ptr
);
1090 /* Compute the name of this partial DIE. This memoizes the
1091 result, so it is safe to call multiple times. */
1092 const char *name (dwarf2_cu
*cu
);
1094 /* Offset of this DIE. */
1095 const sect_offset sect_off
;
1097 /* DWARF-2 tag for this DIE. */
1098 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1100 /* Assorted flags describing the data found in this DIE. */
1101 const unsigned int has_children
: 1;
1103 unsigned int is_external
: 1;
1104 unsigned int is_declaration
: 1;
1105 unsigned int has_type
: 1;
1106 unsigned int has_specification
: 1;
1107 unsigned int has_pc_info
: 1;
1108 unsigned int may_be_inlined
: 1;
1110 /* This DIE has been marked DW_AT_main_subprogram. */
1111 unsigned int main_subprogram
: 1;
1113 /* Flag set if the SCOPE field of this structure has been
1115 unsigned int scope_set
: 1;
1117 /* Flag set if the DIE has a byte_size attribute. */
1118 unsigned int has_byte_size
: 1;
1120 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1121 unsigned int has_const_value
: 1;
1123 /* Flag set if any of the DIE's children are template arguments. */
1124 unsigned int has_template_arguments
: 1;
1126 /* Flag set if fixup has been called on this die. */
1127 unsigned int fixup_called
: 1;
1129 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1130 unsigned int is_dwz
: 1;
1132 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1133 unsigned int spec_is_dwz
: 1;
1135 unsigned int canonical_name
: 1;
1137 /* The name of this DIE. Normally the value of DW_AT_name, but
1138 sometimes a default name for unnamed DIEs. */
1139 const char *raw_name
= nullptr;
1141 /* The linkage name, if present. */
1142 const char *linkage_name
= nullptr;
1144 /* The scope to prepend to our children. This is generally
1145 allocated on the comp_unit_obstack, so will disappear
1146 when this compilation unit leaves the cache. */
1147 const char *scope
= nullptr;
1149 /* Some data associated with the partial DIE. The tag determines
1150 which field is live. */
1153 /* The location description associated with this DIE, if any. */
1154 struct dwarf_block
*locdesc
;
1155 /* The offset of an import, for DW_TAG_imported_unit. */
1156 sect_offset sect_off
;
1159 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1160 CORE_ADDR lowpc
= 0;
1161 CORE_ADDR highpc
= 0;
1163 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1164 DW_AT_sibling, if any. */
1165 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1166 could return DW_AT_sibling values to its caller load_partial_dies. */
1167 const gdb_byte
*sibling
= nullptr;
1169 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1170 DW_AT_specification (or DW_AT_abstract_origin or
1171 DW_AT_extension). */
1172 sect_offset spec_offset
{};
1174 /* Pointers to this DIE's parent, first child, and next sibling,
1176 struct partial_die_info
*die_parent
= nullptr;
1177 struct partial_die_info
*die_child
= nullptr;
1178 struct partial_die_info
*die_sibling
= nullptr;
1180 friend struct partial_die_info
*
1181 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1184 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1185 partial_die_info (sect_offset sect_off
)
1186 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1190 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1192 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1197 has_specification
= 0;
1200 main_subprogram
= 0;
1203 has_const_value
= 0;
1204 has_template_arguments
= 0;
1212 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1213 but this would require a corresponding change in unpack_field_as_long
1215 static int bits_per_byte
= 8;
1217 struct variant_part_builder
;
1219 /* When reading a variant, we track a bit more information about the
1220 field, and store it in an object of this type. */
1222 struct variant_field
1224 int first_field
= -1;
1225 int last_field
= -1;
1227 /* A variant can contain other variant parts. */
1228 std::vector
<variant_part_builder
> variant_parts
;
1230 /* If we see a DW_TAG_variant, then this will be set if this is the
1232 bool default_branch
= false;
1233 /* If we see a DW_AT_discr_value, then this will be the discriminant
1235 ULONGEST discriminant_value
= 0;
1236 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1238 struct dwarf_block
*discr_list_data
= nullptr;
1241 /* This represents a DW_TAG_variant_part. */
1243 struct variant_part_builder
1245 /* The offset of the discriminant field. */
1246 sect_offset discriminant_offset
{};
1248 /* Variants that are direct children of this variant part. */
1249 std::vector
<variant_field
> variants
;
1251 /* True if we're currently reading a variant. */
1252 bool processing_variant
= false;
1257 int accessibility
= 0;
1259 /* Variant parts need to find the discriminant, which is a DIE
1260 reference. We track the section offset of each field to make
1263 struct field field
{};
1268 const char *name
= nullptr;
1269 std::vector
<struct fn_field
> fnfields
;
1272 /* The routines that read and process dies for a C struct or C++ class
1273 pass lists of data member fields and lists of member function fields
1274 in an instance of a field_info structure, as defined below. */
1277 /* List of data member and baseclasses fields. */
1278 std::vector
<struct nextfield
> fields
;
1279 std::vector
<struct nextfield
> baseclasses
;
1281 /* Set if the accessibility of one of the fields is not public. */
1282 bool non_public_fields
= false;
1284 /* Member function fieldlist array, contains name of possibly overloaded
1285 member function, number of overloaded member functions and a pointer
1286 to the head of the member function field chain. */
1287 std::vector
<struct fnfieldlist
> fnfieldlists
;
1289 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1290 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1291 std::vector
<struct decl_field
> typedef_field_list
;
1293 /* Nested types defined by this class and the number of elements in this
1295 std::vector
<struct decl_field
> nested_types_list
;
1297 /* If non-null, this is the variant part we are currently
1299 variant_part_builder
*current_variant_part
= nullptr;
1300 /* This holds all the top-level variant parts attached to the type
1302 std::vector
<variant_part_builder
> variant_parts
;
1304 /* Return the total number of fields (including baseclasses). */
1305 int nfields () const
1307 return fields
.size () + baseclasses
.size ();
1311 /* Loaded secondary compilation units are kept in memory until they
1312 have not been referenced for the processing of this many
1313 compilation units. Set this to zero to disable caching. Cache
1314 sizes of up to at least twenty will improve startup time for
1315 typical inter-CU-reference binaries, at an obvious memory cost. */
1316 static int dwarf_max_cache_age
= 5;
1318 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1319 struct cmd_list_element
*c
, const char *value
)
1321 fprintf_filtered (file
, _("The upper bound on the age of cached "
1322 "DWARF compilation units is %s.\n"),
1326 /* local function prototypes */
1328 static void dwarf2_find_base_address (struct die_info
*die
,
1329 struct dwarf2_cu
*cu
);
1331 static dwarf2_psymtab
*create_partial_symtab
1332 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1335 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1336 const gdb_byte
*info_ptr
,
1337 struct die_info
*type_unit_die
);
1339 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1341 static void scan_partial_symbols (struct partial_die_info
*,
1342 CORE_ADDR
*, CORE_ADDR
*,
1343 int, struct dwarf2_cu
*);
1345 static void add_partial_symbol (struct partial_die_info
*,
1346 struct dwarf2_cu
*);
1348 static void add_partial_namespace (struct partial_die_info
*pdi
,
1349 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1350 int set_addrmap
, struct dwarf2_cu
*cu
);
1352 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1353 CORE_ADDR
*highpc
, int set_addrmap
,
1354 struct dwarf2_cu
*cu
);
1356 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1357 struct dwarf2_cu
*cu
);
1359 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1360 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1361 int need_pc
, struct dwarf2_cu
*cu
);
1363 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1365 static struct partial_die_info
*load_partial_dies
1366 (const struct die_reader_specs
*, const gdb_byte
*, int);
1368 /* A pair of partial_die_info and compilation unit. */
1369 struct cu_partial_die_info
1371 /* The compilation unit of the partial_die_info. */
1372 struct dwarf2_cu
*cu
;
1373 /* A partial_die_info. */
1374 struct partial_die_info
*pdi
;
1376 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1382 cu_partial_die_info () = delete;
1385 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1386 struct dwarf2_cu
*);
1388 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1390 const struct attr_abbrev
*,
1393 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1394 struct attribute
*attr
, dwarf_tag tag
);
1396 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1398 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1399 dwarf2_section_info
*, sect_offset
);
1401 static const char *read_indirect_string
1402 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1403 const struct comp_unit_head
*, unsigned int *);
1405 static const char *read_indirect_string_at_offset
1406 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1408 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1412 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1413 ULONGEST str_index
);
1415 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1416 ULONGEST str_index
);
1418 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1420 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1421 struct dwarf2_cu
*);
1423 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1424 struct dwarf2_cu
*cu
);
1426 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1428 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1429 struct dwarf2_cu
*cu
);
1431 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1433 static struct die_info
*die_specification (struct die_info
*die
,
1434 struct dwarf2_cu
**);
1436 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1437 struct dwarf2_cu
*cu
);
1439 static void dwarf_decode_lines (struct line_header
*, const char *,
1440 struct dwarf2_cu
*, dwarf2_psymtab
*,
1441 CORE_ADDR
, int decode_mapping
);
1443 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1446 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1447 struct dwarf2_cu
*, struct symbol
* = NULL
);
1449 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1450 struct dwarf2_cu
*);
1452 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1455 struct obstack
*obstack
,
1456 struct dwarf2_cu
*cu
, LONGEST
*value
,
1457 const gdb_byte
**bytes
,
1458 struct dwarf2_locexpr_baton
**baton
);
1460 static struct type
*read_subrange_index_type (struct die_info
*die
,
1461 struct dwarf2_cu
*cu
);
1463 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1465 static int need_gnat_info (struct dwarf2_cu
*);
1467 static struct type
*die_descriptive_type (struct die_info
*,
1468 struct dwarf2_cu
*);
1470 static void set_descriptive_type (struct type
*, struct die_info
*,
1471 struct dwarf2_cu
*);
1473 static struct type
*die_containing_type (struct die_info
*,
1474 struct dwarf2_cu
*);
1476 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1477 struct dwarf2_cu
*);
1479 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1481 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1483 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1485 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1486 const char *suffix
, int physname
,
1487 struct dwarf2_cu
*cu
);
1489 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1491 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1493 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1495 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1497 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1499 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1501 /* Return the .debug_loclists section to use for cu. */
1502 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1504 /* Return the .debug_rnglists section to use for cu. */
1505 static struct dwarf2_section_info
*cu_debug_rnglists_section
1506 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1508 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1509 values. Keep the items ordered with increasing constraints compliance. */
1512 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1513 PC_BOUNDS_NOT_PRESENT
,
1515 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1516 were present but they do not form a valid range of PC addresses. */
1519 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1522 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1526 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1527 CORE_ADDR
*, CORE_ADDR
*,
1531 static void get_scope_pc_bounds (struct die_info
*,
1532 CORE_ADDR
*, CORE_ADDR
*,
1533 struct dwarf2_cu
*);
1535 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1536 CORE_ADDR
, struct dwarf2_cu
*);
1538 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1539 struct dwarf2_cu
*);
1541 static void dwarf2_attach_fields_to_type (struct field_info
*,
1542 struct type
*, struct dwarf2_cu
*);
1544 static void dwarf2_add_member_fn (struct field_info
*,
1545 struct die_info
*, struct type
*,
1546 struct dwarf2_cu
*);
1548 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1550 struct dwarf2_cu
*);
1552 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1554 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1556 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1558 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1560 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1562 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1564 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1566 static struct type
*read_module_type (struct die_info
*die
,
1567 struct dwarf2_cu
*cu
);
1569 static const char *namespace_name (struct die_info
*die
,
1570 int *is_anonymous
, struct dwarf2_cu
*);
1572 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1574 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1577 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1578 struct dwarf2_cu
*);
1580 static struct die_info
*read_die_and_siblings_1
1581 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1584 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1585 const gdb_byte
*info_ptr
,
1586 const gdb_byte
**new_info_ptr
,
1587 struct die_info
*parent
);
1589 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1590 struct die_info
**, const gdb_byte
*,
1593 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1594 struct die_info
**, const gdb_byte
*);
1596 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1598 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1601 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1603 static const char *dwarf2_full_name (const char *name
,
1604 struct die_info
*die
,
1605 struct dwarf2_cu
*cu
);
1607 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1608 struct dwarf2_cu
*cu
);
1610 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1611 struct dwarf2_cu
**);
1613 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1615 static void dump_die_for_error (struct die_info
*);
1617 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1620 /*static*/ void dump_die (struct die_info
*, int max_level
);
1622 static void store_in_ref_table (struct die_info
*,
1623 struct dwarf2_cu
*);
1625 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1626 const struct attribute
*,
1627 struct dwarf2_cu
**);
1629 static struct die_info
*follow_die_ref (struct die_info
*,
1630 const struct attribute
*,
1631 struct dwarf2_cu
**);
1633 static struct die_info
*follow_die_sig (struct die_info
*,
1634 const struct attribute
*,
1635 struct dwarf2_cu
**);
1637 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1638 struct dwarf2_cu
*);
1640 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1641 const struct attribute
*,
1642 struct dwarf2_cu
*);
1644 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1645 dwarf2_per_objfile
*per_objfile
);
1647 static void read_signatured_type (signatured_type
*sig_type
,
1648 dwarf2_per_objfile
*per_objfile
);
1650 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1651 struct die_info
*die
, struct dwarf2_cu
*cu
,
1652 struct dynamic_prop
*prop
, struct type
*type
);
1654 /* memory allocation interface */
1656 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1658 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1660 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1662 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1663 struct dwarf2_loclist_baton
*baton
,
1664 const struct attribute
*attr
);
1666 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1668 struct dwarf2_cu
*cu
,
1671 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1672 const gdb_byte
*info_ptr
,
1673 const struct abbrev_info
*abbrev
);
1675 static hashval_t
partial_die_hash (const void *item
);
1677 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1679 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1680 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1681 dwarf2_per_objfile
*per_objfile
);
1683 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1684 struct die_info
*comp_unit_die
,
1685 enum language pretend_language
);
1687 static struct type
*set_die_type (struct die_info
*, struct type
*,
1688 struct dwarf2_cu
*, bool = false);
1690 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1692 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1693 dwarf2_per_objfile
*per_objfile
,
1694 dwarf2_cu
*existing_cu
,
1696 enum language pretend_language
);
1698 static void process_full_comp_unit (dwarf2_cu
*cu
,
1699 enum language pretend_language
);
1701 static void process_full_type_unit (dwarf2_cu
*cu
,
1702 enum language pretend_language
);
1704 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1705 struct dwarf2_per_cu_data
*);
1707 static void dwarf2_mark (struct dwarf2_cu
*);
1709 static struct type
*get_die_type_at_offset (sect_offset
,
1710 dwarf2_per_cu_data
*per_cu
,
1711 dwarf2_per_objfile
*per_objfile
);
1713 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1715 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1716 dwarf2_per_objfile
*per_objfile
,
1717 enum language pretend_language
);
1719 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1721 /* Class, the destructor of which frees all allocated queue entries. This
1722 will only have work to do if an error was thrown while processing the
1723 dwarf. If no error was thrown then the queue entries should have all
1724 been processed, and freed, as we went along. */
1726 class dwarf2_queue_guard
1729 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1730 : m_per_objfile (per_objfile
)
1732 gdb_assert (!m_per_objfile
->per_bfd
->queue
.has_value ());
1734 m_per_objfile
->per_bfd
->queue
.emplace ();
1737 /* Free any entries remaining on the queue. There should only be
1738 entries left if we hit an error while processing the dwarf. */
1739 ~dwarf2_queue_guard ()
1741 gdb_assert (m_per_objfile
->per_bfd
->queue
.has_value ());
1743 m_per_objfile
->per_bfd
->queue
.reset ();
1746 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1749 dwarf2_per_objfile
*m_per_objfile
;
1752 dwarf2_queue_item::~dwarf2_queue_item ()
1754 /* Anything still marked queued is likely to be in an
1755 inconsistent state, so discard it. */
1758 per_objfile
->remove_cu (per_cu
);
1763 /* The return type of find_file_and_directory. Note, the enclosed
1764 string pointers are only valid while this object is valid. */
1766 struct file_and_directory
1768 /* The filename. This is never NULL. */
1771 /* The compilation directory. NULL if not known. If we needed to
1772 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1773 points directly to the DW_AT_comp_dir string attribute owned by
1774 the obstack that owns the DIE. */
1775 const char *comp_dir
;
1777 /* If we needed to build a new string for comp_dir, this is what
1778 owns the storage. */
1779 std::string comp_dir_storage
;
1782 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1783 struct dwarf2_cu
*cu
);
1785 static htab_up
allocate_signatured_type_table ();
1787 static htab_up
allocate_dwo_unit_table ();
1789 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1790 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1791 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1793 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1795 static struct dwo_unit
*lookup_dwo_comp_unit
1796 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1797 ULONGEST signature
);
1799 static struct dwo_unit
*lookup_dwo_type_unit
1800 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1802 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1804 /* A unique pointer to a dwo_file. */
1806 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1808 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1810 static void check_producer (struct dwarf2_cu
*cu
);
1812 static void free_line_header_voidp (void *arg
);
1814 /* Various complaints about symbol reading that don't abort the process. */
1817 dwarf2_debug_line_missing_file_complaint (void)
1819 complaint (_(".debug_line section has line data without a file"));
1823 dwarf2_debug_line_missing_end_sequence_complaint (void)
1825 complaint (_(".debug_line section has line "
1826 "program sequence without an end"));
1830 dwarf2_complex_location_expr_complaint (void)
1832 complaint (_("location expression too complex"));
1836 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1839 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1844 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1846 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1850 /* Hash function for line_header_hash. */
1853 line_header_hash (const struct line_header
*ofs
)
1855 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1858 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1861 line_header_hash_voidp (const void *item
)
1863 const struct line_header
*ofs
= (const struct line_header
*) item
;
1865 return line_header_hash (ofs
);
1868 /* Equality function for line_header_hash. */
1871 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1873 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1874 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1876 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1877 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1882 /* See declaration. */
1884 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1887 can_copy (can_copy_
)
1890 names
= &dwarf2_elf_names
;
1892 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1893 locate_sections (obfd
, sec
, *names
);
1896 dwarf2_per_bfd::~dwarf2_per_bfd ()
1898 for (auto &per_cu
: all_comp_units
)
1899 per_cu
->imported_symtabs_free ();
1901 /* Everything else should be on this->obstack. */
1907 dwarf2_per_objfile::remove_all_cus ()
1909 gdb_assert (!this->per_bfd
->queue
.has_value ());
1911 for (auto pair
: m_dwarf2_cus
)
1914 m_dwarf2_cus
.clear ();
1917 /* A helper class that calls free_cached_comp_units on
1920 class free_cached_comp_units
1924 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1925 : m_per_objfile (per_objfile
)
1929 ~free_cached_comp_units ()
1931 m_per_objfile
->remove_all_cus ();
1934 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1938 dwarf2_per_objfile
*m_per_objfile
;
1944 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1946 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1948 return this->m_symtabs
[per_cu
->index
] != nullptr;
1954 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1956 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1958 return this->m_symtabs
[per_cu
->index
];
1964 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1965 compunit_symtab
*symtab
)
1967 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1968 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1970 this->m_symtabs
[per_cu
->index
] = symtab
;
1973 /* Try to locate the sections we need for DWARF 2 debugging
1974 information and return true if we have enough to do something.
1975 NAMES points to the dwarf2 section names, or is NULL if the standard
1976 ELF names are used. CAN_COPY is true for formats where symbol
1977 interposition is possible and so symbol values must follow copy
1978 relocation rules. */
1981 dwarf2_has_info (struct objfile
*objfile
,
1982 const struct dwarf2_debug_sections
*names
,
1985 if (objfile
->flags
& OBJF_READNEVER
)
1988 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1990 if (per_objfile
== NULL
)
1992 dwarf2_per_bfd
*per_bfd
;
1994 /* We can share a "dwarf2_per_bfd" with other objfiles if the
1995 BFD doesn't require relocations.
1997 We don't share with objfiles for which -readnow was requested,
1998 because it would complicate things when loading the same BFD with
1999 -readnow and then without -readnow. */
2000 if (!gdb_bfd_requires_relocations (objfile
->obfd
)
2001 && (objfile
->flags
& OBJF_READNOW
) == 0)
2003 /* See if one has been created for this BFD yet. */
2004 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
2006 if (per_bfd
== nullptr)
2008 /* No, create it now. */
2009 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
2010 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
2015 /* No sharing possible, create one specifically for this objfile. */
2016 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
2017 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
2020 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
2023 return (!per_objfile
->per_bfd
->info
.is_virtual
2024 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
2025 && !per_objfile
->per_bfd
->abbrev
.is_virtual
2026 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
2029 /* See declaration. */
2032 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
2033 const dwarf2_debug_sections
&names
)
2035 flagword aflag
= bfd_section_flags (sectp
);
2037 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2040 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2041 > bfd_get_file_size (abfd
))
2043 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2044 warning (_("Discarding section %s which has a section size (%s"
2045 ") larger than the file size [in module %s]"),
2046 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2047 bfd_get_filename (abfd
));
2049 else if (names
.info
.matches (sectp
->name
))
2051 this->info
.s
.section
= sectp
;
2052 this->info
.size
= bfd_section_size (sectp
);
2054 else if (names
.abbrev
.matches (sectp
->name
))
2056 this->abbrev
.s
.section
= sectp
;
2057 this->abbrev
.size
= bfd_section_size (sectp
);
2059 else if (names
.line
.matches (sectp
->name
))
2061 this->line
.s
.section
= sectp
;
2062 this->line
.size
= bfd_section_size (sectp
);
2064 else if (names
.loc
.matches (sectp
->name
))
2066 this->loc
.s
.section
= sectp
;
2067 this->loc
.size
= bfd_section_size (sectp
);
2069 else if (names
.loclists
.matches (sectp
->name
))
2071 this->loclists
.s
.section
= sectp
;
2072 this->loclists
.size
= bfd_section_size (sectp
);
2074 else if (names
.macinfo
.matches (sectp
->name
))
2076 this->macinfo
.s
.section
= sectp
;
2077 this->macinfo
.size
= bfd_section_size (sectp
);
2079 else if (names
.macro
.matches (sectp
->name
))
2081 this->macro
.s
.section
= sectp
;
2082 this->macro
.size
= bfd_section_size (sectp
);
2084 else if (names
.str
.matches (sectp
->name
))
2086 this->str
.s
.section
= sectp
;
2087 this->str
.size
= bfd_section_size (sectp
);
2089 else if (names
.str_offsets
.matches (sectp
->name
))
2091 this->str_offsets
.s
.section
= sectp
;
2092 this->str_offsets
.size
= bfd_section_size (sectp
);
2094 else if (names
.line_str
.matches (sectp
->name
))
2096 this->line_str
.s
.section
= sectp
;
2097 this->line_str
.size
= bfd_section_size (sectp
);
2099 else if (names
.addr
.matches (sectp
->name
))
2101 this->addr
.s
.section
= sectp
;
2102 this->addr
.size
= bfd_section_size (sectp
);
2104 else if (names
.frame
.matches (sectp
->name
))
2106 this->frame
.s
.section
= sectp
;
2107 this->frame
.size
= bfd_section_size (sectp
);
2109 else if (names
.eh_frame
.matches (sectp
->name
))
2111 this->eh_frame
.s
.section
= sectp
;
2112 this->eh_frame
.size
= bfd_section_size (sectp
);
2114 else if (names
.ranges
.matches (sectp
->name
))
2116 this->ranges
.s
.section
= sectp
;
2117 this->ranges
.size
= bfd_section_size (sectp
);
2119 else if (names
.rnglists
.matches (sectp
->name
))
2121 this->rnglists
.s
.section
= sectp
;
2122 this->rnglists
.size
= bfd_section_size (sectp
);
2124 else if (names
.types
.matches (sectp
->name
))
2126 struct dwarf2_section_info type_section
;
2128 memset (&type_section
, 0, sizeof (type_section
));
2129 type_section
.s
.section
= sectp
;
2130 type_section
.size
= bfd_section_size (sectp
);
2132 this->types
.push_back (type_section
);
2134 else if (names
.gdb_index
.matches (sectp
->name
))
2136 this->gdb_index
.s
.section
= sectp
;
2137 this->gdb_index
.size
= bfd_section_size (sectp
);
2139 else if (names
.debug_names
.matches (sectp
->name
))
2141 this->debug_names
.s
.section
= sectp
;
2142 this->debug_names
.size
= bfd_section_size (sectp
);
2144 else if (names
.debug_aranges
.matches (sectp
->name
))
2146 this->debug_aranges
.s
.section
= sectp
;
2147 this->debug_aranges
.size
= bfd_section_size (sectp
);
2150 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2151 && bfd_section_vma (sectp
) == 0)
2152 this->has_section_at_zero
= true;
2155 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2159 dwarf2_get_section_info (struct objfile
*objfile
,
2160 enum dwarf2_section_enum sect
,
2161 asection
**sectp
, const gdb_byte
**bufp
,
2162 bfd_size_type
*sizep
)
2164 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2165 struct dwarf2_section_info
*info
;
2167 /* We may see an objfile without any DWARF, in which case we just
2169 if (per_objfile
== NULL
)
2178 case DWARF2_DEBUG_FRAME
:
2179 info
= &per_objfile
->per_bfd
->frame
;
2181 case DWARF2_EH_FRAME
:
2182 info
= &per_objfile
->per_bfd
->eh_frame
;
2185 gdb_assert_not_reached ("unexpected section");
2188 info
->read (objfile
);
2190 *sectp
= info
->get_bfd_section ();
2191 *bufp
= info
->buffer
;
2192 *sizep
= info
->size
;
2196 /* DWARF quick_symbol_functions support. */
2198 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2199 unique line tables, so we maintain a separate table of all .debug_line
2200 derived entries to support the sharing.
2201 All the quick functions need is the list of file names. We discard the
2202 line_header when we're done and don't need to record it here. */
2203 struct quick_file_names
2205 /* The data used to construct the hash key. */
2206 struct stmt_list_hash hash
;
2208 /* The number of entries in file_names, real_names. */
2209 unsigned int num_file_names
;
2211 /* The file names from the line table, after being run through
2213 const char **file_names
;
2215 /* The file names from the line table after being run through
2216 gdb_realpath. These are computed lazily. */
2217 const char **real_names
;
2220 /* When using the index (and thus not using psymtabs), each CU has an
2221 object of this type. This is used to hold information needed by
2222 the various "quick" methods. */
2223 struct dwarf2_per_cu_quick_data
2225 /* The file table. This can be NULL if there was no file table
2226 or it's currently not read in.
2227 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2228 struct quick_file_names
*file_names
;
2230 /* A temporary mark bit used when iterating over all CUs in
2231 expand_symtabs_matching. */
2232 unsigned int mark
: 1;
2234 /* True if we've tried to read the file table and found there isn't one.
2235 There will be no point in trying to read it again next time. */
2236 unsigned int no_file_data
: 1;
2239 /* A subclass of psymbol_functions that arranges to read the DWARF
2240 partial symbols when needed. */
2241 struct lazy_dwarf_reader
: public psymbol_functions
2243 using psymbol_functions::psymbol_functions
;
2245 bool can_lazily_read_symbols () override
2250 void read_partial_symbols (struct objfile
*objfile
) override
2252 if (dwarf2_has_info (objfile
, nullptr))
2253 dwarf2_build_psymtabs (objfile
, this);
2257 static quick_symbol_functions_up
2258 make_lazy_dwarf_reader ()
2260 return quick_symbol_functions_up (new lazy_dwarf_reader
);
2263 struct dwarf2_base_index_functions
: public quick_symbol_functions
2265 bool has_symbols (struct objfile
*objfile
) override
;
2267 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
2269 void forget_cached_source_info (struct objfile
*objfile
) override
;
2271 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
2274 bool *symbol_found_p
) override
2276 *symbol_found_p
= false;
2277 return language_unknown
;
2280 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
2282 void expand_all_symtabs (struct objfile
*objfile
) override
;
2284 struct compunit_symtab
*find_pc_sect_compunit_symtab
2285 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
2286 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
2288 struct compunit_symtab
*find_compunit_symtab_by_address
2289 (struct objfile
*objfile
, CORE_ADDR address
) override
2294 void map_symbol_filenames (struct objfile
*objfile
,
2295 gdb::function_view
<symbol_filename_ftype
> fun
,
2296 bool need_fullname
) override
;
2299 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
2301 void dump (struct objfile
*objfile
) override
;
2303 void expand_matching_symbols
2305 const lookup_name_info
&lookup_name
,
2308 symbol_compare_ftype
*ordered_compare
) override
;
2310 bool expand_symtabs_matching
2311 (struct objfile
*objfile
,
2312 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2313 const lookup_name_info
*lookup_name
,
2314 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2315 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2316 block_search_flags search_flags
,
2318 enum search_domain kind
) override
;
2321 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
2323 void dump (struct objfile
*objfile
) override
;
2325 void expand_matching_symbols
2327 const lookup_name_info
&lookup_name
,
2330 symbol_compare_ftype
*ordered_compare
) override
;
2332 bool expand_symtabs_matching
2333 (struct objfile
*objfile
,
2334 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2335 const lookup_name_info
*lookup_name
,
2336 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2337 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2338 block_search_flags search_flags
,
2340 enum search_domain kind
) override
;
2343 static quick_symbol_functions_up
2344 make_dwarf_gdb_index ()
2346 return quick_symbol_functions_up (new dwarf2_gdb_index
);
2349 static quick_symbol_functions_up
2350 make_dwarf_debug_names ()
2352 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
2355 /* Utility hash function for a stmt_list_hash. */
2358 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2362 if (stmt_list_hash
->dwo_unit
!= NULL
)
2363 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2364 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2368 /* Utility equality function for a stmt_list_hash. */
2371 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2372 const struct stmt_list_hash
*rhs
)
2374 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2376 if (lhs
->dwo_unit
!= NULL
2377 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2380 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2383 /* Hash function for a quick_file_names. */
2386 hash_file_name_entry (const void *e
)
2388 const struct quick_file_names
*file_data
2389 = (const struct quick_file_names
*) e
;
2391 return hash_stmt_list_entry (&file_data
->hash
);
2394 /* Equality function for a quick_file_names. */
2397 eq_file_name_entry (const void *a
, const void *b
)
2399 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2400 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2402 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2405 /* Delete function for a quick_file_names. */
2408 delete_file_name_entry (void *e
)
2410 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2413 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2415 xfree ((void*) file_data
->file_names
[i
]);
2416 if (file_data
->real_names
)
2417 xfree ((void*) file_data
->real_names
[i
]);
2420 /* The space for the struct itself lives on the obstack, so we don't
2424 /* Create a quick_file_names hash table. */
2427 create_quick_file_names_table (unsigned int nr_initial_entries
)
2429 return htab_up (htab_create_alloc (nr_initial_entries
,
2430 hash_file_name_entry
, eq_file_name_entry
,
2431 delete_file_name_entry
, xcalloc
, xfree
));
2434 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2435 function is unrelated to symtabs, symtab would have to be created afterwards.
2436 You should call age_cached_comp_units after processing the CU. */
2439 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2442 if (per_cu
->is_debug_types
)
2443 load_full_type_unit (per_cu
, per_objfile
);
2445 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2446 skip_partial
, language_minimal
);
2448 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2450 return nullptr; /* Dummy CU. */
2452 dwarf2_find_base_address (cu
->dies
, cu
);
2457 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2460 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2461 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2463 /* Skip type_unit_groups, reading the type units they contain
2464 is handled elsewhere. */
2465 if (per_cu
->type_unit_group_p ())
2469 /* The destructor of dwarf2_queue_guard frees any entries left on
2470 the queue. After this point we're guaranteed to leave this function
2471 with the dwarf queue empty. */
2472 dwarf2_queue_guard
q_guard (per_objfile
);
2474 if (!per_objfile
->symtab_set_p (per_cu
))
2476 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2477 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2479 /* If we just loaded a CU from a DWO, and we're working with an index
2480 that may badly handle TUs, load all the TUs in that DWO as well.
2481 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2482 if (!per_cu
->is_debug_types
2484 && cu
->dwo_unit
!= NULL
2485 && per_objfile
->per_bfd
->index_table
!= NULL
2486 && per_objfile
->per_bfd
->index_table
->version
<= 7
2487 /* DWP files aren't supported yet. */
2488 && get_dwp_file (per_objfile
) == NULL
)
2489 queue_and_load_all_dwo_tus (cu
);
2492 process_queue (per_objfile
);
2495 /* Age the cache, releasing compilation units that have not
2496 been used recently. */
2497 per_objfile
->age_comp_units ();
2500 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2501 the per-objfile for which this symtab is instantiated.
2503 Returns the resulting symbol table. */
2505 static struct compunit_symtab
*
2506 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2507 dwarf2_per_objfile
*per_objfile
,
2510 gdb_assert (per_objfile
->per_bfd
->using_index
);
2512 if (!per_objfile
->symtab_set_p (per_cu
))
2514 free_cached_comp_units
freer (per_objfile
);
2515 scoped_restore decrementer
= increment_reading_symtab ();
2516 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2517 process_cu_includes (per_objfile
);
2520 return per_objfile
->get_symtab (per_cu
);
2525 std::unique_ptr
<dwarf2_per_cu_data
>
2526 dwarf2_per_bfd::allocate_per_cu ()
2528 std::unique_ptr
<dwarf2_per_cu_data
> result (new dwarf2_per_cu_data
);
2529 result
->per_bfd
= this;
2530 result
->index
= m_num_psymtabs
++;
2536 std::unique_ptr
<signatured_type
>
2537 dwarf2_per_bfd::allocate_signatured_type ()
2539 std::unique_ptr
<signatured_type
> result (new signatured_type
);
2540 result
->per_bfd
= this;
2541 result
->index
= m_num_psymtabs
++;
2546 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2547 obstack, and constructed with the specified field values. */
2549 static std::unique_ptr
<dwarf2_per_cu_data
>
2550 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2551 struct dwarf2_section_info
*section
,
2553 sect_offset sect_off
, ULONGEST length
)
2555 std::unique_ptr
<dwarf2_per_cu_data
> the_cu
= per_bfd
->allocate_per_cu ();
2556 the_cu
->sect_off
= sect_off
;
2557 the_cu
->length
= length
;
2558 the_cu
->section
= section
;
2559 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2560 struct dwarf2_per_cu_quick_data
);
2561 the_cu
->is_dwz
= is_dwz
;
2565 /* A helper for create_cus_from_index that handles a given list of
2569 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2570 const gdb_byte
*cu_list
, offset_type n_elements
,
2571 struct dwarf2_section_info
*section
,
2574 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2576 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2578 sect_offset sect_off
2579 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2580 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2583 std::unique_ptr
<dwarf2_per_cu_data
> per_cu
2584 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2586 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
2590 /* Read the CU list from the mapped index, and use it to create all
2591 the CU objects for PER_BFD. */
2594 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2595 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2596 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2598 gdb_assert (per_bfd
->all_comp_units
.empty ());
2599 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2601 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2604 if (dwz_elements
== 0)
2607 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2608 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2612 /* Create the signatured type hash table from the index. */
2615 create_signatured_type_table_from_index
2616 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2617 const gdb_byte
*bytes
, offset_type elements
)
2619 htab_up sig_types_hash
= allocate_signatured_type_table ();
2621 for (offset_type i
= 0; i
< elements
; i
+= 3)
2623 std::unique_ptr
<signatured_type
> sig_type
;
2626 cu_offset type_offset_in_tu
;
2628 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2629 sect_offset sect_off
2630 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2632 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2634 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2637 sig_type
= per_bfd
->allocate_signatured_type ();
2638 sig_type
->signature
= signature
;
2639 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2640 sig_type
->is_debug_types
= 1;
2641 sig_type
->section
= section
;
2642 sig_type
->sect_off
= sect_off
;
2644 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2645 struct dwarf2_per_cu_quick_data
);
2647 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2648 *slot
= sig_type
.get ();
2650 per_bfd
->all_comp_units
.push_back (std::move (sig_type
));
2653 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2656 /* Create the signatured type hash table from .debug_names. */
2659 create_signatured_type_table_from_debug_names
2660 (dwarf2_per_objfile
*per_objfile
,
2661 const mapped_debug_names
&map
,
2662 struct dwarf2_section_info
*section
,
2663 struct dwarf2_section_info
*abbrev_section
)
2665 struct objfile
*objfile
= per_objfile
->objfile
;
2667 section
->read (objfile
);
2668 abbrev_section
->read (objfile
);
2670 htab_up sig_types_hash
= allocate_signatured_type_table ();
2672 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2674 std::unique_ptr
<signatured_type
> sig_type
;
2677 sect_offset sect_off
2678 = (sect_offset
) (extract_unsigned_integer
2679 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2681 map
.dwarf5_byte_order
));
2683 comp_unit_head cu_header
;
2684 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2686 section
->buffer
+ to_underlying (sect_off
),
2689 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2690 sig_type
->signature
= cu_header
.signature
;
2691 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2692 sig_type
->is_debug_types
= 1;
2693 sig_type
->section
= section
;
2694 sig_type
->sect_off
= sect_off
;
2696 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2697 struct dwarf2_per_cu_quick_data
);
2699 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
2700 *slot
= sig_type
.get ();
2702 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (sig_type
));
2705 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2708 /* Read the address map data from the mapped index, and use it to
2709 populate the psymtabs_addrmap. */
2712 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2713 struct mapped_index
*index
)
2715 struct objfile
*objfile
= per_objfile
->objfile
;
2716 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2717 struct gdbarch
*gdbarch
= objfile
->arch ();
2718 const gdb_byte
*iter
, *end
;
2719 struct addrmap
*mutable_map
;
2722 auto_obstack temp_obstack
;
2724 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2726 iter
= index
->address_table
.data ();
2727 end
= iter
+ index
->address_table
.size ();
2729 baseaddr
= objfile
->text_section_offset ();
2733 ULONGEST hi
, lo
, cu_index
;
2734 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2736 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2738 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2743 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2744 hex_string (lo
), hex_string (hi
));
2748 if (cu_index
>= per_bfd
->all_comp_units
.size ())
2750 complaint (_(".gdb_index address table has invalid CU number %u"),
2751 (unsigned) cu_index
);
2755 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2756 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2757 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2758 per_bfd
->get_cu (cu_index
));
2761 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2765 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2766 populate the psymtabs_addrmap. */
2769 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2770 struct dwarf2_section_info
*section
)
2772 struct objfile
*objfile
= per_objfile
->objfile
;
2773 bfd
*abfd
= objfile
->obfd
;
2774 struct gdbarch
*gdbarch
= objfile
->arch ();
2775 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2776 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2778 auto_obstack temp_obstack
;
2779 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2781 std::unordered_map
<sect_offset
,
2782 dwarf2_per_cu_data
*,
2783 gdb::hash_enum
<sect_offset
>>
2784 debug_info_offset_to_per_cu
;
2785 for (const auto &per_cu
: per_bfd
->all_comp_units
)
2787 const auto insertpair
2788 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
,
2790 if (!insertpair
.second
)
2792 warning (_("Section .debug_aranges in %s has duplicate "
2793 "debug_info_offset %s, ignoring .debug_aranges."),
2794 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2799 section
->read (objfile
);
2801 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2803 const gdb_byte
*addr
= section
->buffer
;
2805 while (addr
< section
->buffer
+ section
->size
)
2807 const gdb_byte
*const entry_addr
= addr
;
2808 unsigned int bytes_read
;
2810 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2814 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2815 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2816 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2817 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2819 warning (_("Section .debug_aranges in %s entry at offset %s "
2820 "length %s exceeds section length %s, "
2821 "ignoring .debug_aranges."),
2822 objfile_name (objfile
),
2823 plongest (entry_addr
- section
->buffer
),
2824 plongest (bytes_read
+ entry_length
),
2825 pulongest (section
->size
));
2829 /* The version number. */
2830 const uint16_t version
= read_2_bytes (abfd
, addr
);
2834 warning (_("Section .debug_aranges in %s entry at offset %s "
2835 "has unsupported version %d, ignoring .debug_aranges."),
2836 objfile_name (objfile
),
2837 plongest (entry_addr
- section
->buffer
), version
);
2841 const uint64_t debug_info_offset
2842 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2843 addr
+= offset_size
;
2844 const auto per_cu_it
2845 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2846 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2848 warning (_("Section .debug_aranges in %s entry at offset %s "
2849 "debug_info_offset %s does not exists, "
2850 "ignoring .debug_aranges."),
2851 objfile_name (objfile
),
2852 plongest (entry_addr
- section
->buffer
),
2853 pulongest (debug_info_offset
));
2856 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2858 const uint8_t address_size
= *addr
++;
2859 if (address_size
< 1 || address_size
> 8)
2861 warning (_("Section .debug_aranges in %s entry at offset %s "
2862 "address_size %u is invalid, ignoring .debug_aranges."),
2863 objfile_name (objfile
),
2864 plongest (entry_addr
- section
->buffer
), address_size
);
2868 const uint8_t segment_selector_size
= *addr
++;
2869 if (segment_selector_size
!= 0)
2871 warning (_("Section .debug_aranges in %s entry at offset %s "
2872 "segment_selector_size %u is not supported, "
2873 "ignoring .debug_aranges."),
2874 objfile_name (objfile
),
2875 plongest (entry_addr
- section
->buffer
),
2876 segment_selector_size
);
2880 /* Must pad to an alignment boundary that is twice the address
2881 size. It is undocumented by the DWARF standard but GCC does
2883 for (size_t padding
= ((-(addr
- section
->buffer
))
2884 & (2 * address_size
- 1));
2885 padding
> 0; padding
--)
2888 warning (_("Section .debug_aranges in %s entry at offset %s "
2889 "padding is not zero, ignoring .debug_aranges."),
2890 objfile_name (objfile
),
2891 plongest (entry_addr
- section
->buffer
));
2897 if (addr
+ 2 * address_size
> entry_end
)
2899 warning (_("Section .debug_aranges in %s entry at offset %s "
2900 "address list is not properly terminated, "
2901 "ignoring .debug_aranges."),
2902 objfile_name (objfile
),
2903 plongest (entry_addr
- section
->buffer
));
2906 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2908 addr
+= address_size
;
2909 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2911 addr
+= address_size
;
2912 if (start
== 0 && length
== 0)
2914 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2916 /* Symbol was eliminated due to a COMDAT group. */
2919 ULONGEST end
= start
+ length
;
2920 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2922 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2924 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2928 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2932 /* A helper function that reads the .gdb_index from BUFFER and fills
2933 in MAP. FILENAME is the name of the file containing the data;
2934 it is used for error reporting. DEPRECATED_OK is true if it is
2935 ok to use deprecated sections.
2937 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2938 out parameters that are filled in with information about the CU and
2939 TU lists in the section.
2941 Returns true if all went well, false otherwise. */
2944 read_gdb_index_from_buffer (const char *filename
,
2946 gdb::array_view
<const gdb_byte
> buffer
,
2947 struct mapped_index
*map
,
2948 const gdb_byte
**cu_list
,
2949 offset_type
*cu_list_elements
,
2950 const gdb_byte
**types_list
,
2951 offset_type
*types_list_elements
)
2953 const gdb_byte
*addr
= &buffer
[0];
2954 offset_view
metadata (buffer
);
2956 /* Version check. */
2957 offset_type version
= metadata
[0];
2958 /* Versions earlier than 3 emitted every copy of a psymbol. This
2959 causes the index to behave very poorly for certain requests. Version 3
2960 contained incomplete addrmap. So, it seems better to just ignore such
2964 static int warning_printed
= 0;
2965 if (!warning_printed
)
2967 warning (_("Skipping obsolete .gdb_index section in %s."),
2969 warning_printed
= 1;
2973 /* Index version 4 uses a different hash function than index version
2976 Versions earlier than 6 did not emit psymbols for inlined
2977 functions. Using these files will cause GDB not to be able to
2978 set breakpoints on inlined functions by name, so we ignore these
2979 indices unless the user has done
2980 "set use-deprecated-index-sections on". */
2981 if (version
< 6 && !deprecated_ok
)
2983 static int warning_printed
= 0;
2984 if (!warning_printed
)
2987 Skipping deprecated .gdb_index section in %s.\n\
2988 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2989 to use the section anyway."),
2991 warning_printed
= 1;
2995 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2996 of the TU (for symbols coming from TUs),
2997 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2998 Plus gold-generated indices can have duplicate entries for global symbols,
2999 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3000 These are just performance bugs, and we can't distinguish gdb-generated
3001 indices from gold-generated ones, so issue no warning here. */
3003 /* Indexes with higher version than the one supported by GDB may be no
3004 longer backward compatible. */
3008 map
->version
= version
;
3011 *cu_list
= addr
+ metadata
[i
];
3012 *cu_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
3015 *types_list
= addr
+ metadata
[i
];
3016 *types_list_elements
= (metadata
[i
+ 1] - metadata
[i
]) / 8;
3019 const gdb_byte
*address_table
= addr
+ metadata
[i
];
3020 const gdb_byte
*address_table_end
= addr
+ metadata
[i
+ 1];
3022 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3025 const gdb_byte
*symbol_table
= addr
+ metadata
[i
];
3026 const gdb_byte
*symbol_table_end
= addr
+ metadata
[i
+ 1];
3028 = offset_view (gdb::array_view
<const gdb_byte
> (symbol_table
,
3032 map
->constant_pool
= buffer
.slice (metadata
[i
]);
3037 /* Callback types for dwarf2_read_gdb_index. */
3039 typedef gdb::function_view
3040 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3041 get_gdb_index_contents_ftype
;
3042 typedef gdb::function_view
3043 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3044 get_gdb_index_contents_dwz_ftype
;
3046 /* Read .gdb_index. If everything went ok, initialize the "quick"
3047 elements of all the CUs and return 1. Otherwise, return 0. */
3050 dwarf2_read_gdb_index
3051 (dwarf2_per_objfile
*per_objfile
,
3052 get_gdb_index_contents_ftype get_gdb_index_contents
,
3053 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3055 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3056 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3057 struct dwz_file
*dwz
;
3058 struct objfile
*objfile
= per_objfile
->objfile
;
3059 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3061 gdb::array_view
<const gdb_byte
> main_index_contents
3062 = get_gdb_index_contents (objfile
, per_bfd
);
3064 if (main_index_contents
.empty ())
3067 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3068 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3069 use_deprecated_index_sections
,
3070 main_index_contents
, map
.get (), &cu_list
,
3071 &cu_list_elements
, &types_list
,
3072 &types_list_elements
))
3075 /* Don't use the index if it's empty. */
3076 if (map
->symbol_table
.empty ())
3079 /* If there is a .dwz file, read it so we can get its CU list as
3081 dwz
= dwarf2_get_dwz_file (per_bfd
);
3084 struct mapped_index dwz_map
;
3085 const gdb_byte
*dwz_types_ignore
;
3086 offset_type dwz_types_elements_ignore
;
3088 gdb::array_view
<const gdb_byte
> dwz_index_content
3089 = get_gdb_index_contents_dwz (objfile
, dwz
);
3091 if (dwz_index_content
.empty ())
3094 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3095 1, dwz_index_content
, &dwz_map
,
3096 &dwz_list
, &dwz_list_elements
,
3098 &dwz_types_elements_ignore
))
3100 warning (_("could not read '.gdb_index' section from %s; skipping"),
3101 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3106 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
3109 if (types_list_elements
)
3111 /* We can only handle a single .debug_types when we have an
3113 if (per_bfd
->types
.size () != 1)
3116 dwarf2_section_info
*section
= &per_bfd
->types
[0];
3118 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
3119 types_list_elements
);
3122 create_addrmap_from_index (per_objfile
, map
.get ());
3124 per_bfd
->index_table
= std::move (map
);
3125 per_bfd
->using_index
= 1;
3126 per_bfd
->quick_file_names_table
=
3127 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
3132 /* die_reader_func for dw2_get_file_names. */
3135 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3136 struct die_info
*comp_unit_die
)
3138 struct dwarf2_cu
*cu
= reader
->cu
;
3139 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3140 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3141 struct dwarf2_per_cu_data
*lh_cu
;
3142 struct attribute
*attr
;
3144 struct quick_file_names
*qfn
;
3146 gdb_assert (! this_cu
->is_debug_types
);
3148 /* Our callers never want to match partial units -- instead they
3149 will match the enclosing full CU. */
3150 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3152 this_cu
->v
.quick
->no_file_data
= 1;
3160 sect_offset line_offset
{};
3162 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3163 if (attr
!= nullptr && attr
->form_is_unsigned ())
3165 struct quick_file_names find_entry
;
3167 line_offset
= (sect_offset
) attr
->as_unsigned ();
3169 /* We may have already read in this line header (TU line header sharing).
3170 If we have we're done. */
3171 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3172 find_entry
.hash
.line_sect_off
= line_offset
;
3173 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3174 &find_entry
, INSERT
);
3177 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3181 lh
= dwarf_decode_line_header (line_offset
, cu
);
3185 lh_cu
->v
.quick
->no_file_data
= 1;
3189 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3190 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3191 qfn
->hash
.line_sect_off
= line_offset
;
3192 gdb_assert (slot
!= NULL
);
3195 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3198 if (strcmp (fnd
.name
, "<unknown>") != 0)
3201 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3203 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3204 qfn
->num_file_names
);
3206 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3207 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3208 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3209 fnd
.comp_dir
).release ();
3210 qfn
->real_names
= NULL
;
3212 lh_cu
->v
.quick
->file_names
= qfn
;
3215 /* A helper for the "quick" functions which attempts to read the line
3216 table for THIS_CU. */
3218 static struct quick_file_names
*
3219 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3220 dwarf2_per_objfile
*per_objfile
)
3222 /* This should never be called for TUs. */
3223 gdb_assert (! this_cu
->is_debug_types
);
3224 /* Nor type unit groups. */
3225 gdb_assert (! this_cu
->type_unit_group_p ());
3227 if (this_cu
->v
.quick
->file_names
!= NULL
)
3228 return this_cu
->v
.quick
->file_names
;
3229 /* If we know there is no line data, no point in looking again. */
3230 if (this_cu
->v
.quick
->no_file_data
)
3233 cutu_reader
reader (this_cu
, per_objfile
);
3234 if (!reader
.dummy_p
)
3235 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
3237 if (this_cu
->v
.quick
->no_file_data
)
3239 return this_cu
->v
.quick
->file_names
;
3242 /* A helper for the "quick" functions which computes and caches the
3243 real path for a given file name from the line table. */
3246 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3247 struct quick_file_names
*qfn
, int index
)
3249 if (qfn
->real_names
== NULL
)
3250 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3251 qfn
->num_file_names
, const char *);
3253 if (qfn
->real_names
[index
] == NULL
)
3254 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3256 return qfn
->real_names
[index
];
3260 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3262 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3263 dwarf2_per_cu_data
*dwarf_cu
3264 = per_objfile
->per_bfd
->all_comp_units
.back ().get ();
3265 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3270 return compunit_primary_filetab (cust
);
3273 /* Traversal function for dw2_forget_cached_source_info. */
3276 dw2_free_cached_file_names (void **slot
, void *info
)
3278 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3280 if (file_data
->real_names
)
3284 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3286 xfree ((void*) file_data
->real_names
[i
]);
3287 file_data
->real_names
[i
] = NULL
;
3295 dwarf2_base_index_functions::forget_cached_source_info
3296 (struct objfile
*objfile
)
3298 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3300 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3301 dw2_free_cached_file_names
, NULL
);
3304 /* Struct used to manage iterating over all CUs looking for a symbol. */
3306 struct dw2_symtab_iterator
3308 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3309 dwarf2_per_objfile
*per_objfile
;
3310 /* If set, only look for symbols that match that block. Valid values are
3311 GLOBAL_BLOCK and STATIC_BLOCK. */
3312 gdb::optional
<block_enum
> block_index
;
3313 /* The kind of symbol we're looking for. */
3315 /* The list of CUs from the index entry of the symbol,
3316 or NULL if not found. */
3318 /* The next element in VEC to look at. */
3320 /* The number of elements in VEC, or zero if there is no match. */
3322 /* Have we seen a global version of the symbol?
3323 If so we can ignore all further global instances.
3324 This is to work around gold/15646, inefficient gold-generated
3329 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3332 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3333 dwarf2_per_objfile
*per_objfile
,
3334 gdb::optional
<block_enum
> block_index
,
3335 domain_enum domain
, offset_type namei
)
3337 iter
->per_objfile
= per_objfile
;
3338 iter
->block_index
= block_index
;
3339 iter
->domain
= domain
;
3341 iter
->global_seen
= 0;
3345 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3346 /* index is NULL if OBJF_READNOW. */
3350 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3351 offset_type vec_idx
= index
->symbol_vec_index (namei
);
3353 iter
->vec
= offset_view (index
->constant_pool
.slice (vec_idx
));
3354 iter
->length
= iter
->vec
[0];
3357 /* Return the next matching CU or NULL if there are no more. */
3359 static struct dwarf2_per_cu_data
*
3360 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3362 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3364 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3366 offset_type cu_index_and_attrs
= iter
->vec
[iter
->next
+ 1];
3367 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3368 gdb_index_symbol_kind symbol_kind
=
3369 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3370 /* Only check the symbol attributes if they're present.
3371 Indices prior to version 7 don't record them,
3372 and indices >= 7 may elide them for certain symbols
3373 (gold does this). */
3375 (per_objfile
->per_bfd
->index_table
->version
>= 7
3376 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3378 /* Don't crash on bad data. */
3379 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
3381 complaint (_(".gdb_index entry has bad CU index"
3382 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3386 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
3388 /* Skip if already read in. */
3389 if (per_objfile
->symtab_set_p (per_cu
))
3392 /* Check static vs global. */
3395 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3397 if (iter
->block_index
.has_value ())
3399 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3401 if (is_static
!= want_static
)
3405 /* Work around gold/15646. */
3407 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3409 if (iter
->global_seen
)
3412 iter
->global_seen
= 1;
3416 /* Only check the symbol's kind if it has one. */
3419 switch (iter
->domain
)
3422 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3423 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3424 /* Some types are also in VAR_DOMAIN. */
3425 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3429 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3433 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3437 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3453 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
3459 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3460 int total
= per_objfile
->per_bfd
->all_comp_units
.size ();
3463 for (int i
= 0; i
< total
; ++i
)
3465 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3467 if (!per_objfile
->symtab_set_p (per_cu
))
3470 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3471 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3474 /* This dumps minimal information about the index.
3475 It is called via "mt print objfiles".
3476 One use is to verify .gdb_index has been loaded by the
3477 gdb.dwarf2/gdb-index.exp testcase. */
3480 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3482 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3484 gdb_assert (per_objfile
->per_bfd
->using_index
);
3485 printf_filtered (".gdb_index:");
3486 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3488 printf_filtered (" version %d\n",
3489 per_objfile
->per_bfd
->index_table
->version
);
3492 printf_filtered (" faked for \"readnow\"\n");
3493 printf_filtered ("\n");
3497 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3499 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3500 int total_units
= per_objfile
->per_bfd
->all_comp_units
.size ();
3502 for (int i
= 0; i
< total_units
; ++i
)
3504 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (i
);
3506 /* We don't want to directly expand a partial CU, because if we
3507 read it with the wrong language, then assertion failures can
3508 be triggered later on. See PR symtab/23010. So, tell
3509 dw2_instantiate_symtab to skip partial CUs -- any important
3510 partial CU will be read via DW_TAG_imported_unit anyway. */
3511 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3516 dw2_expand_symtabs_matching_symbol
3517 (mapped_index_base
&index
,
3518 const lookup_name_info
&lookup_name_in
,
3519 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3520 gdb::function_view
<bool (offset_type
)> match_callback
,
3521 dwarf2_per_objfile
*per_objfile
);
3524 dw2_expand_symtabs_matching_one
3525 (dwarf2_per_cu_data
*per_cu
,
3526 dwarf2_per_objfile
*per_objfile
,
3527 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3528 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3531 dwarf2_gdb_index::expand_matching_symbols
3532 (struct objfile
*objfile
,
3533 const lookup_name_info
&name
, domain_enum domain
,
3535 symbol_compare_ftype
*ordered_compare
)
3538 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3540 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3542 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3544 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3546 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3547 auto matcher
= [&] (const char *symname
)
3549 if (ordered_compare
== nullptr)
3551 return ordered_compare (symname
, match_name
) == 0;
3554 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
,
3555 [&] (offset_type namei
)
3557 struct dw2_symtab_iterator iter
;
3558 struct dwarf2_per_cu_data
*per_cu
;
3560 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3562 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3563 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3570 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3571 proceed assuming all symtabs have been read in. */
3575 /* Starting from a search name, return the string that finds the upper
3576 bound of all strings that start with SEARCH_NAME in a sorted name
3577 list. Returns the empty string to indicate that the upper bound is
3578 the end of the list. */
3581 make_sort_after_prefix_name (const char *search_name
)
3583 /* When looking to complete "func", we find the upper bound of all
3584 symbols that start with "func" by looking for where we'd insert
3585 the closest string that would follow "func" in lexicographical
3586 order. Usually, that's "func"-with-last-character-incremented,
3587 i.e. "fund". Mind non-ASCII characters, though. Usually those
3588 will be UTF-8 multi-byte sequences, but we can't be certain.
3589 Especially mind the 0xff character, which is a valid character in
3590 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3591 rule out compilers allowing it in identifiers. Note that
3592 conveniently, strcmp/strcasecmp are specified to compare
3593 characters interpreted as unsigned char. So what we do is treat
3594 the whole string as a base 256 number composed of a sequence of
3595 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3596 to 0, and carries 1 to the following more-significant position.
3597 If the very first character in SEARCH_NAME ends up incremented
3598 and carries/overflows, then the upper bound is the end of the
3599 list. The string after the empty string is also the empty
3602 Some examples of this operation:
3604 SEARCH_NAME => "+1" RESULT
3608 "\xff" "a" "\xff" => "\xff" "b"
3613 Then, with these symbols for example:
3619 completing "func" looks for symbols between "func" and
3620 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3621 which finds "func" and "func1", but not "fund".
3625 funcÿ (Latin1 'ÿ' [0xff])
3629 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3630 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3634 ÿÿ (Latin1 'ÿ' [0xff])
3637 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3638 the end of the list.
3640 std::string after
= search_name
;
3641 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3643 if (!after
.empty ())
3644 after
.back () = (unsigned char) after
.back () + 1;
3648 /* See declaration. */
3650 std::pair
<std::vector
<name_component
>::const_iterator
,
3651 std::vector
<name_component
>::const_iterator
>
3652 mapped_index_base::find_name_components_bounds
3653 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3654 dwarf2_per_objfile
*per_objfile
) const
3657 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3659 const char *lang_name
3660 = lookup_name_without_params
.language_lookup_name (lang
);
3662 /* Comparison function object for lower_bound that matches against a
3663 given symbol name. */
3664 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3667 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3668 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3669 return name_cmp (elem_name
, name
) < 0;
3672 /* Comparison function object for upper_bound that matches against a
3673 given symbol name. */
3674 auto lookup_compare_upper
= [&] (const char *name
,
3675 const name_component
&elem
)
3677 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3678 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3679 return name_cmp (name
, elem_name
) < 0;
3682 auto begin
= this->name_components
.begin ();
3683 auto end
= this->name_components
.end ();
3685 /* Find the lower bound. */
3688 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3691 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3694 /* Find the upper bound. */
3697 if (lookup_name_without_params
.completion_mode ())
3699 /* In completion mode, we want UPPER to point past all
3700 symbols names that have the same prefix. I.e., with
3701 these symbols, and completing "func":
3703 function << lower bound
3705 other_function << upper bound
3707 We find the upper bound by looking for the insertion
3708 point of "func"-with-last-character-incremented,
3710 std::string after
= make_sort_after_prefix_name (lang_name
);
3713 return std::lower_bound (lower
, end
, after
.c_str (),
3714 lookup_compare_lower
);
3717 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3720 return {lower
, upper
};
3723 /* See declaration. */
3726 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
3728 if (!this->name_components
.empty ())
3731 this->name_components_casing
= case_sensitivity
;
3733 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3735 /* The code below only knows how to break apart components of C++
3736 symbol names (and other languages that use '::' as
3737 namespace/module separator) and Ada symbol names. */
3738 auto count
= this->symbol_name_count ();
3739 for (offset_type idx
= 0; idx
< count
; idx
++)
3741 if (this->symbol_name_slot_invalid (idx
))
3744 const char *name
= this->symbol_name_at (idx
, per_objfile
);
3746 /* Add each name component to the name component table. */
3747 unsigned int previous_len
= 0;
3749 if (strstr (name
, "::") != nullptr)
3751 for (unsigned int current_len
= cp_find_first_component (name
);
3752 name
[current_len
] != '\0';
3753 current_len
+= cp_find_first_component (name
+ current_len
))
3755 gdb_assert (name
[current_len
] == ':');
3756 this->name_components
.push_back ({previous_len
, idx
});
3757 /* Skip the '::'. */
3759 previous_len
= current_len
;
3764 /* Handle the Ada encoded (aka mangled) form here. */
3765 for (const char *iter
= strstr (name
, "__");
3767 iter
= strstr (iter
, "__"))
3769 this->name_components
.push_back ({previous_len
, idx
});
3771 previous_len
= iter
- name
;
3775 this->name_components
.push_back ({previous_len
, idx
});
3778 /* Sort name_components elements by name. */
3779 auto name_comp_compare
= [&] (const name_component
&left
,
3780 const name_component
&right
)
3782 const char *left_qualified
3783 = this->symbol_name_at (left
.idx
, per_objfile
);
3784 const char *right_qualified
3785 = this->symbol_name_at (right
.idx
, per_objfile
);
3787 const char *left_name
= left_qualified
+ left
.name_offset
;
3788 const char *right_name
= right_qualified
+ right
.name_offset
;
3790 return name_cmp (left_name
, right_name
) < 0;
3793 std::sort (this->name_components
.begin (),
3794 this->name_components
.end (),
3798 /* Helper for dw2_expand_symtabs_matching that works with a
3799 mapped_index_base instead of the containing objfile. This is split
3800 to a separate function in order to be able to unit test the
3801 name_components matching using a mock mapped_index_base. For each
3802 symbol name that matches, calls MATCH_CALLBACK, passing it the
3803 symbol's index in the mapped_index_base symbol table. */
3806 dw2_expand_symtabs_matching_symbol
3807 (mapped_index_base
&index
,
3808 const lookup_name_info
&lookup_name_in
,
3809 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3810 gdb::function_view
<bool (offset_type
)> match_callback
,
3811 dwarf2_per_objfile
*per_objfile
)
3813 lookup_name_info lookup_name_without_params
3814 = lookup_name_in
.make_ignore_params ();
3816 /* Build the symbol name component sorted vector, if we haven't
3818 index
.build_name_components (per_objfile
);
3820 /* The same symbol may appear more than once in the range though.
3821 E.g., if we're looking for symbols that complete "w", and we have
3822 a symbol named "w1::w2", we'll find the two name components for
3823 that same symbol in the range. To be sure we only call the
3824 callback once per symbol, we first collect the symbol name
3825 indexes that matched in a temporary vector and ignore
3827 std::vector
<offset_type
> matches
;
3829 struct name_and_matcher
3831 symbol_name_matcher_ftype
*matcher
;
3834 bool operator== (const name_and_matcher
&other
) const
3836 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
3840 /* A vector holding all the different symbol name matchers, for all
3842 std::vector
<name_and_matcher
> matchers
;
3844 for (int i
= 0; i
< nr_languages
; i
++)
3846 enum language lang_e
= (enum language
) i
;
3848 const language_defn
*lang
= language_def (lang_e
);
3849 symbol_name_matcher_ftype
*name_matcher
3850 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
3852 name_and_matcher key
{
3854 lookup_name_without_params
.language_lookup_name (lang_e
)
3857 /* Don't insert the same comparison routine more than once.
3858 Note that we do this linear walk. This is not a problem in
3859 practice because the number of supported languages is
3861 if (std::find (matchers
.begin (), matchers
.end (), key
)
3864 matchers
.push_back (std::move (key
));
3867 = index
.find_name_components_bounds (lookup_name_without_params
,
3868 lang_e
, per_objfile
);
3870 /* Now for each symbol name in range, check to see if we have a name
3871 match, and if so, call the MATCH_CALLBACK callback. */
3873 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3875 const char *qualified
3876 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
3878 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3879 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3882 matches
.push_back (bounds
.first
->idx
);
3886 std::sort (matches
.begin (), matches
.end ());
3888 /* Finally call the callback, once per match. */
3891 for (offset_type idx
: matches
)
3895 if (!match_callback (idx
))
3904 /* Above we use a type wider than idx's for 'prev', since 0 and
3905 (offset_type)-1 are both possible values. */
3906 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3913 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3915 /* A mock .gdb_index/.debug_names-like name index table, enough to
3916 exercise dw2_expand_symtabs_matching_symbol, which works with the
3917 mapped_index_base interface. Builds an index from the symbol list
3918 passed as parameter to the constructor. */
3919 class mock_mapped_index
: public mapped_index_base
3922 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3923 : m_symbol_table (symbols
)
3926 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3928 /* Return the number of names in the symbol table. */
3929 size_t symbol_name_count () const override
3931 return m_symbol_table
.size ();
3934 /* Get the name of the symbol at IDX in the symbol table. */
3935 const char *symbol_name_at
3936 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
3938 return m_symbol_table
[idx
];
3942 gdb::array_view
<const char *> m_symbol_table
;
3945 /* Convenience function that converts a NULL pointer to a "<null>"
3946 string, to pass to print routines. */
3949 string_or_null (const char *str
)
3951 return str
!= NULL
? str
: "<null>";
3954 /* Check if a lookup_name_info built from
3955 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3956 index. EXPECTED_LIST is the list of expected matches, in expected
3957 matching order. If no match expected, then an empty list is
3958 specified. Returns true on success. On failure prints a warning
3959 indicating the file:line that failed, and returns false. */
3962 check_match (const char *file
, int line
,
3963 mock_mapped_index
&mock_index
,
3964 const char *name
, symbol_name_match_type match_type
,
3965 bool completion_mode
,
3966 std::initializer_list
<const char *> expected_list
,
3967 dwarf2_per_objfile
*per_objfile
)
3969 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3971 bool matched
= true;
3973 auto mismatch
= [&] (const char *expected_str
,
3976 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3977 "expected=\"%s\", got=\"%s\"\n"),
3979 (match_type
== symbol_name_match_type::FULL
3981 name
, string_or_null (expected_str
), string_or_null (got
));
3985 auto expected_it
= expected_list
.begin ();
3986 auto expected_end
= expected_list
.end ();
3988 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
3990 [&] (offset_type idx
)
3992 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
3993 const char *expected_str
3994 = expected_it
== expected_end
? NULL
: *expected_it
++;
3996 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
3997 mismatch (expected_str
, matched_name
);
4001 const char *expected_str
4002 = expected_it
== expected_end
? NULL
: *expected_it
++;
4003 if (expected_str
!= NULL
)
4004 mismatch (expected_str
, NULL
);
4009 /* The symbols added to the mock mapped_index for testing (in
4011 static const char *test_symbols
[] = {
4020 "ns2::tmpl<int>::foo2",
4021 "(anonymous namespace)::A::B::C",
4023 /* These are used to check that the increment-last-char in the
4024 matching algorithm for completion doesn't match "t1_fund" when
4025 completing "t1_func". */
4031 /* A UTF-8 name with multi-byte sequences to make sure that
4032 cp-name-parser understands this as a single identifier ("função"
4033 is "function" in PT). */
4036 /* \377 (0xff) is Latin1 'ÿ'. */
4039 /* \377 (0xff) is Latin1 'ÿ'. */
4043 /* A name with all sorts of complications. Starts with "z" to make
4044 it easier for the completion tests below. */
4045 #define Z_SYM_NAME \
4046 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4047 "::tuple<(anonymous namespace)::ui*, " \
4048 "std::default_delete<(anonymous namespace)::ui>, void>"
4053 /* Returns true if the mapped_index_base::find_name_component_bounds
4054 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4055 in completion mode. */
4058 check_find_bounds_finds (mapped_index_base
&index
,
4059 const char *search_name
,
4060 gdb::array_view
<const char *> expected_syms
,
4061 dwarf2_per_objfile
*per_objfile
)
4063 lookup_name_info
lookup_name (search_name
,
4064 symbol_name_match_type::FULL
, true);
4066 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4070 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4071 if (distance
!= expected_syms
.size ())
4074 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4076 auto nc_elem
= bounds
.first
+ exp_elem
;
4077 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4078 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4085 /* Test the lower-level mapped_index::find_name_component_bounds
4089 test_mapped_index_find_name_component_bounds ()
4091 mock_mapped_index
mock_index (test_symbols
);
4093 mock_index
.build_name_components (NULL
/* per_objfile */);
4095 /* Test the lower-level mapped_index::find_name_component_bounds
4096 method in completion mode. */
4098 static const char *expected_syms
[] = {
4103 SELF_CHECK (check_find_bounds_finds
4104 (mock_index
, "t1_func", expected_syms
,
4105 NULL
/* per_objfile */));
4108 /* Check that the increment-last-char in the name matching algorithm
4109 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4111 static const char *expected_syms1
[] = {
4115 SELF_CHECK (check_find_bounds_finds
4116 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4118 static const char *expected_syms2
[] = {
4121 SELF_CHECK (check_find_bounds_finds
4122 (mock_index
, "\377\377", expected_syms2
,
4123 NULL
/* per_objfile */));
4127 /* Test dw2_expand_symtabs_matching_symbol. */
4130 test_dw2_expand_symtabs_matching_symbol ()
4132 mock_mapped_index
mock_index (test_symbols
);
4134 /* We let all tests run until the end even if some fails, for debug
4136 bool any_mismatch
= false;
4138 /* Create the expected symbols list (an initializer_list). Needed
4139 because lists have commas, and we need to pass them to CHECK,
4140 which is a macro. */
4141 #define EXPECT(...) { __VA_ARGS__ }
4143 /* Wrapper for check_match that passes down the current
4144 __FILE__/__LINE__. */
4145 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4146 any_mismatch |= !check_match (__FILE__, __LINE__, \
4148 NAME, MATCH_TYPE, COMPLETION_MODE, \
4149 EXPECTED_LIST, NULL)
4151 /* Identity checks. */
4152 for (const char *sym
: test_symbols
)
4154 /* Should be able to match all existing symbols. */
4155 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4158 /* Should be able to match all existing symbols with
4160 std::string with_params
= std::string (sym
) + "(int)";
4161 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4164 /* Should be able to match all existing symbols with
4165 parameters and qualifiers. */
4166 with_params
= std::string (sym
) + " ( int ) const";
4167 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4170 /* This should really find sym, but cp-name-parser.y doesn't
4171 know about lvalue/rvalue qualifiers yet. */
4172 with_params
= std::string (sym
) + " ( int ) &&";
4173 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4177 /* Check that the name matching algorithm for completion doesn't get
4178 confused with Latin1 'ÿ' / 0xff. */
4180 static const char str
[] = "\377";
4181 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4182 EXPECT ("\377", "\377\377123"));
4185 /* Check that the increment-last-char in the matching algorithm for
4186 completion doesn't match "t1_fund" when completing "t1_func". */
4188 static const char str
[] = "t1_func";
4189 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4190 EXPECT ("t1_func", "t1_func1"));
4193 /* Check that completion mode works at each prefix of the expected
4196 static const char str
[] = "function(int)";
4197 size_t len
= strlen (str
);
4200 for (size_t i
= 1; i
< len
; i
++)
4202 lookup
.assign (str
, i
);
4203 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4204 EXPECT ("function"));
4208 /* While "w" is a prefix of both components, the match function
4209 should still only be called once. */
4211 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4213 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4217 /* Same, with a "complicated" symbol. */
4219 static const char str
[] = Z_SYM_NAME
;
4220 size_t len
= strlen (str
);
4223 for (size_t i
= 1; i
< len
; i
++)
4225 lookup
.assign (str
, i
);
4226 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4227 EXPECT (Z_SYM_NAME
));
4231 /* In FULL mode, an incomplete symbol doesn't match. */
4233 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4237 /* A complete symbol with parameters matches any overload, since the
4238 index has no overload info. */
4240 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4241 EXPECT ("std::zfunction", "std::zfunction2"));
4242 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4243 EXPECT ("std::zfunction", "std::zfunction2"));
4244 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4245 EXPECT ("std::zfunction", "std::zfunction2"));
4248 /* Check that whitespace is ignored appropriately. A symbol with a
4249 template argument list. */
4251 static const char expected
[] = "ns::foo<int>";
4252 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4254 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4258 /* Check that whitespace is ignored appropriately. A symbol with a
4259 template argument list that includes a pointer. */
4261 static const char expected
[] = "ns::foo<char*>";
4262 /* Try both completion and non-completion modes. */
4263 static const bool completion_mode
[2] = {false, true};
4264 for (size_t i
= 0; i
< 2; i
++)
4266 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4267 completion_mode
[i
], EXPECT (expected
));
4268 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4269 completion_mode
[i
], EXPECT (expected
));
4271 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4272 completion_mode
[i
], EXPECT (expected
));
4273 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4274 completion_mode
[i
], EXPECT (expected
));
4279 /* Check method qualifiers are ignored. */
4280 static const char expected
[] = "ns::foo<char*>";
4281 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4282 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4283 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4284 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4285 CHECK_MATCH ("foo < char * > ( int ) const",
4286 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4287 CHECK_MATCH ("foo < char * > ( int ) &&",
4288 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4291 /* Test lookup names that don't match anything. */
4293 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4296 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4300 /* Some wild matching tests, exercising "(anonymous namespace)",
4301 which should not be confused with a parameter list. */
4303 static const char *syms
[] = {
4307 "A :: B :: C ( int )",
4312 for (const char *s
: syms
)
4314 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4315 EXPECT ("(anonymous namespace)::A::B::C"));
4320 static const char expected
[] = "ns2::tmpl<int>::foo2";
4321 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4323 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4327 SELF_CHECK (!any_mismatch
);
4336 test_mapped_index_find_name_component_bounds ();
4337 test_dw2_expand_symtabs_matching_symbol ();
4340 }} // namespace selftests::dw2_expand_symtabs_matching
4342 #endif /* GDB_SELF_TEST */
4344 /* If FILE_MATCHER is NULL or if PER_CU has
4345 dwarf2_per_cu_quick_data::MARK set (see
4346 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4347 EXPANSION_NOTIFY on it. */
4350 dw2_expand_symtabs_matching_one
4351 (dwarf2_per_cu_data
*per_cu
,
4352 dwarf2_per_objfile
*per_objfile
,
4353 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4354 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4356 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4358 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4360 compunit_symtab
*symtab
4361 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4362 gdb_assert (symtab
!= nullptr);
4364 if (expansion_notify
!= NULL
&& symtab_was_null
)
4365 return expansion_notify (symtab
);
4370 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4371 matched, to expand corresponding CUs that were marked. IDX is the
4372 index of the symbol name that matched. */
4375 dw2_expand_marked_cus
4376 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4377 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4378 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4379 block_search_flags search_flags
,
4382 offset_type vec_len
, vec_idx
;
4383 bool global_seen
= false;
4384 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4386 offset_view
vec (index
.constant_pool
.slice (index
.symbol_vec_index (idx
)));
4388 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4390 offset_type cu_index_and_attrs
= vec
[vec_idx
+ 1];
4391 /* This value is only valid for index versions >= 7. */
4392 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4393 gdb_index_symbol_kind symbol_kind
=
4394 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4395 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4396 /* Only check the symbol attributes if they're present.
4397 Indices prior to version 7 don't record them,
4398 and indices >= 7 may elide them for certain symbols
4399 (gold does this). */
4402 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4404 /* Work around gold/15646. */
4407 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4415 /* Only check the symbol's kind if it has one. */
4420 if ((search_flags
& SEARCH_STATIC_BLOCK
) == 0)
4425 if ((search_flags
& SEARCH_GLOBAL_BLOCK
) == 0)
4431 case VARIABLES_DOMAIN
:
4432 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4435 case FUNCTIONS_DOMAIN
:
4436 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4440 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4443 case MODULES_DOMAIN
:
4444 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4452 /* Don't crash on bad data. */
4453 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
4455 complaint (_(".gdb_index entry has bad CU index"
4456 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4460 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cu (cu_index
);
4461 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4469 /* If FILE_MATCHER is non-NULL, set all the
4470 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4471 that match FILE_MATCHER. */
4474 dw_expand_symtabs_matching_file_matcher
4475 (dwarf2_per_objfile
*per_objfile
,
4476 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4478 if (file_matcher
== NULL
)
4481 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4483 NULL
, xcalloc
, xfree
));
4484 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4486 NULL
, xcalloc
, xfree
));
4488 /* The rule is CUs specify all the files, including those used by
4489 any TU, so there's no need to scan TUs here. */
4491 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4495 if (per_cu
->is_debug_types
)
4497 per_cu
->v
.quick
->mark
= 0;
4499 /* We only need to look at symtabs not already expanded. */
4500 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4503 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4505 if (file_data
== NULL
)
4508 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4510 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4512 per_cu
->v
.quick
->mark
= 1;
4516 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4518 const char *this_real_name
;
4520 if (file_matcher (file_data
->file_names
[j
], false))
4522 per_cu
->v
.quick
->mark
= 1;
4526 /* Before we invoke realpath, which can get expensive when many
4527 files are involved, do a quick comparison of the basenames. */
4528 if (!basenames_may_differ
4529 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4533 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4534 if (file_matcher (this_real_name
, false))
4536 per_cu
->v
.quick
->mark
= 1;
4541 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4542 ? visited_found
.get ()
4543 : visited_not_found
.get (),
4550 dwarf2_gdb_index::expand_symtabs_matching
4551 (struct objfile
*objfile
,
4552 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4553 const lookup_name_info
*lookup_name
,
4554 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4555 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4556 block_search_flags search_flags
,
4558 enum search_domain kind
)
4560 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4562 /* index_table is NULL if OBJF_READNOW. */
4563 if (!per_objfile
->per_bfd
->index_table
)
4566 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4568 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4570 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4574 if (!dw2_expand_symtabs_matching_one (per_cu
.get (), per_objfile
,
4582 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4585 = dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4587 [&] (offset_type idx
)
4589 if (!dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
,
4590 expansion_notify
, search_flags
, kind
))
4598 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4601 static struct compunit_symtab
*
4602 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4607 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4608 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4611 if (cust
->includes
== NULL
)
4614 for (i
= 0; cust
->includes
[i
]; ++i
)
4616 struct compunit_symtab
*s
= cust
->includes
[i
];
4618 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4626 struct compunit_symtab
*
4627 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4628 (struct objfile
*objfile
,
4629 struct bound_minimal_symbol msymbol
,
4631 struct obj_section
*section
,
4634 struct dwarf2_per_cu_data
*data
;
4635 struct compunit_symtab
*result
;
4637 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4638 if (per_objfile
->per_bfd
->index_addrmap
== nullptr)
4641 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4642 data
= ((struct dwarf2_per_cu_data
*)
4643 addrmap_find (per_objfile
->per_bfd
->index_addrmap
,
4648 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4649 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4650 paddress (objfile
->arch (), pc
));
4652 result
= recursively_find_pc_sect_compunit_symtab
4653 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4655 gdb_assert (result
!= NULL
);
4660 dwarf2_base_index_functions::map_symbol_filenames
4661 (struct objfile
*objfile
,
4662 gdb::function_view
<symbol_filename_ftype
> fun
,
4665 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4667 /* Use caches to ensure we only call FUN once for each filename. */
4668 filename_seen_cache filenames_cache
;
4669 std::unordered_set
<quick_file_names
*> qfn_cache
;
4671 /* The rule is CUs specify all the files, including those used by any TU,
4672 so there's no need to scan TUs here. We can ignore file names coming
4673 from already-expanded CUs. It is possible that an expanded CU might
4674 reuse the file names data from a currently unexpanded CU, in this
4675 case we don't want to report the files from the unexpanded CU. */
4677 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4679 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4681 if (per_cu
->v
.quick
->file_names
!= nullptr)
4682 qfn_cache
.insert (per_cu
->v
.quick
->file_names
);
4686 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4688 /* We only need to look at symtabs not already expanded. */
4689 if (per_objfile
->symtab_set_p (per_cu
.get ()))
4692 quick_file_names
*file_data
= dw2_get_file_names (per_cu
.get (),
4694 if (file_data
== nullptr
4695 || qfn_cache
.find (file_data
) != qfn_cache
.end ())
4698 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4700 const char *filename
= file_data
->file_names
[j
];
4701 filenames_cache
.seen (filename
);
4705 filenames_cache
.traverse ([&] (const char *filename
)
4707 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4710 this_real_name
= gdb_realpath (filename
);
4711 fun (filename
, this_real_name
.get ());
4716 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
4721 /* DWARF-5 debug_names reader. */
4723 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4724 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4726 /* A helper function that reads the .debug_names section in SECTION
4727 and fills in MAP. FILENAME is the name of the file containing the
4728 section; it is used for error reporting.
4730 Returns true if all went well, false otherwise. */
4733 read_debug_names_from_section (struct objfile
*objfile
,
4734 const char *filename
,
4735 struct dwarf2_section_info
*section
,
4736 mapped_debug_names
&map
)
4738 if (section
->empty ())
4741 /* Older elfutils strip versions could keep the section in the main
4742 executable while splitting it for the separate debug info file. */
4743 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4746 section
->read (objfile
);
4748 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
4750 const gdb_byte
*addr
= section
->buffer
;
4752 bfd
*const abfd
= section
->get_bfd_owner ();
4754 unsigned int bytes_read
;
4755 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4758 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4759 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4760 if (bytes_read
+ length
!= section
->size
)
4762 /* There may be multiple per-CU indices. */
4763 warning (_("Section .debug_names in %s length %s does not match "
4764 "section length %s, ignoring .debug_names."),
4765 filename
, plongest (bytes_read
+ length
),
4766 pulongest (section
->size
));
4770 /* The version number. */
4771 uint16_t version
= read_2_bytes (abfd
, addr
);
4775 warning (_("Section .debug_names in %s has unsupported version %d, "
4776 "ignoring .debug_names."),
4782 uint16_t padding
= read_2_bytes (abfd
, addr
);
4786 warning (_("Section .debug_names in %s has unsupported padding %d, "
4787 "ignoring .debug_names."),
4792 /* comp_unit_count - The number of CUs in the CU list. */
4793 map
.cu_count
= read_4_bytes (abfd
, addr
);
4796 /* local_type_unit_count - The number of TUs in the local TU
4798 map
.tu_count
= read_4_bytes (abfd
, addr
);
4801 /* foreign_type_unit_count - The number of TUs in the foreign TU
4803 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4805 if (foreign_tu_count
!= 0)
4807 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4808 "ignoring .debug_names."),
4809 filename
, static_cast<unsigned long> (foreign_tu_count
));
4813 /* bucket_count - The number of hash buckets in the hash lookup
4815 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4818 /* name_count - The number of unique names in the index. */
4819 map
.name_count
= read_4_bytes (abfd
, addr
);
4822 /* abbrev_table_size - The size in bytes of the abbreviations
4824 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4827 /* augmentation_string_size - The size in bytes of the augmentation
4828 string. This value is rounded up to a multiple of 4. */
4829 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4831 map
.augmentation_is_gdb
= ((augmentation_string_size
4832 == sizeof (dwarf5_augmentation
))
4833 && memcmp (addr
, dwarf5_augmentation
,
4834 sizeof (dwarf5_augmentation
)) == 0);
4835 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4836 addr
+= augmentation_string_size
;
4839 map
.cu_table_reordered
= addr
;
4840 addr
+= map
.cu_count
* map
.offset_size
;
4842 /* List of Local TUs */
4843 map
.tu_table_reordered
= addr
;
4844 addr
+= map
.tu_count
* map
.offset_size
;
4846 /* Hash Lookup Table */
4847 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4848 addr
+= map
.bucket_count
* 4;
4849 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4850 addr
+= map
.name_count
* 4;
4853 map
.name_table_string_offs_reordered
= addr
;
4854 addr
+= map
.name_count
* map
.offset_size
;
4855 map
.name_table_entry_offs_reordered
= addr
;
4856 addr
+= map
.name_count
* map
.offset_size
;
4858 const gdb_byte
*abbrev_table_start
= addr
;
4861 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4866 const auto insertpair
4867 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4868 if (!insertpair
.second
)
4870 warning (_("Section .debug_names in %s has duplicate index %s, "
4871 "ignoring .debug_names."),
4872 filename
, pulongest (index_num
));
4875 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4876 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4881 mapped_debug_names::index_val::attr attr
;
4882 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4884 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4886 if (attr
.form
== DW_FORM_implicit_const
)
4888 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4892 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4894 indexval
.attr_vec
.push_back (std::move (attr
));
4897 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4899 warning (_("Section .debug_names in %s has abbreviation_table "
4900 "of size %s vs. written as %u, ignoring .debug_names."),
4901 filename
, plongest (addr
- abbrev_table_start
),
4905 map
.entry_pool
= addr
;
4910 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4914 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
4915 const mapped_debug_names
&map
,
4916 dwarf2_section_info
§ion
,
4919 if (!map
.augmentation_is_gdb
)
4921 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
4923 sect_offset sect_off
4924 = (sect_offset
) (extract_unsigned_integer
4925 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4927 map
.dwarf5_byte_order
));
4928 /* We don't know the length of the CU, because the CU list in a
4929 .debug_names index can be incomplete, so we can't use the start
4930 of the next CU as end of this CU. We create the CUs here with
4931 length 0, and in cutu_reader::cutu_reader we'll fill in the
4933 std::unique_ptr
<dwarf2_per_cu_data
> per_cu
4934 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4936 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4941 sect_offset sect_off_prev
;
4942 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4944 sect_offset sect_off_next
;
4945 if (i
< map
.cu_count
)
4948 = (sect_offset
) (extract_unsigned_integer
4949 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4951 map
.dwarf5_byte_order
));
4954 sect_off_next
= (sect_offset
) section
.size
;
4957 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4958 std::unique_ptr
<dwarf2_per_cu_data
> per_cu
4959 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
4960 sect_off_prev
, length
);
4961 per_bfd
->all_comp_units
.push_back (std::move (per_cu
));
4963 sect_off_prev
= sect_off_next
;
4967 /* Read the CU list from the mapped index, and use it to create all
4968 the CU objects for this dwarf2_per_objfile. */
4971 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
4972 const mapped_debug_names
&map
,
4973 const mapped_debug_names
&dwz_map
)
4975 gdb_assert (per_bfd
->all_comp_units
.empty ());
4976 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4978 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
4979 false /* is_dwz */);
4981 if (dwz_map
.cu_count
== 0)
4984 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
4985 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
4989 /* Read .debug_names. If everything went ok, initialize the "quick"
4990 elements of all the CUs and return true. Otherwise, return false. */
4993 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
4995 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
4996 mapped_debug_names dwz_map
;
4997 struct objfile
*objfile
= per_objfile
->objfile
;
4998 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5000 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5001 &per_bfd
->debug_names
, *map
))
5004 /* Don't use the index if it's empty. */
5005 if (map
->name_count
== 0)
5008 /* If there is a .dwz file, read it so we can get its CU list as
5010 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5013 if (!read_debug_names_from_section (objfile
,
5014 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5015 &dwz
->debug_names
, dwz_map
))
5017 warning (_("could not read '.debug_names' section from %s; skipping"),
5018 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5023 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
5025 if (map
->tu_count
!= 0)
5027 /* We can only handle a single .debug_types when we have an
5029 if (per_bfd
->types
.size () != 1)
5032 dwarf2_section_info
*section
= &per_bfd
->types
[0];
5034 create_signatured_type_table_from_debug_names
5035 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
5038 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
5040 per_bfd
->debug_names_table
= std::move (map
);
5041 per_bfd
->using_index
= 1;
5042 per_bfd
->quick_file_names_table
=
5043 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5048 /* Type used to manage iterating over all CUs looking for a symbol for
5051 class dw2_debug_names_iterator
5054 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5055 block_search_flags block_index
,
5057 const char *name
, dwarf2_per_objfile
*per_objfile
)
5058 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5059 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5060 m_per_objfile (per_objfile
)
5063 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5064 search_domain search
, uint32_t namei
,
5065 dwarf2_per_objfile
*per_objfile
,
5066 domain_enum domain
= UNDEF_DOMAIN
)
5070 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5071 m_per_objfile (per_objfile
)
5074 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5075 block_search_flags block_index
, domain_enum domain
,
5076 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5077 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5078 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5079 m_per_objfile (per_objfile
)
5082 /* Return the next matching CU or NULL if there are no more. */
5083 dwarf2_per_cu_data
*next ();
5086 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5088 dwarf2_per_objfile
*per_objfile
);
5089 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5091 dwarf2_per_objfile
*per_objfile
);
5093 /* The internalized form of .debug_names. */
5094 const mapped_debug_names
&m_map
;
5096 /* Restrict the search to these blocks. */
5097 block_search_flags m_block_index
= (SEARCH_GLOBAL_BLOCK
5098 | SEARCH_STATIC_BLOCK
);
5100 /* The kind of symbol we're looking for. */
5101 const domain_enum m_domain
= UNDEF_DOMAIN
;
5102 const search_domain m_search
= ALL_DOMAIN
;
5104 /* The list of CUs from the index entry of the symbol, or NULL if
5106 const gdb_byte
*m_addr
;
5108 dwarf2_per_objfile
*m_per_objfile
;
5112 mapped_debug_names::namei_to_name
5113 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5115 const ULONGEST namei_string_offs
5116 = extract_unsigned_integer ((name_table_string_offs_reordered
5117 + namei
* offset_size
),
5120 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5123 /* Find a slot in .debug_names for the object named NAME. If NAME is
5124 found, return pointer to its pool data. If NAME cannot be found,
5128 dw2_debug_names_iterator::find_vec_in_debug_names
5129 (const mapped_debug_names
&map
, const char *name
,
5130 dwarf2_per_objfile
*per_objfile
)
5132 int (*cmp
) (const char *, const char *);
5134 gdb::unique_xmalloc_ptr
<char> without_params
;
5135 if (current_language
->la_language
== language_cplus
5136 || current_language
->la_language
== language_fortran
5137 || current_language
->la_language
== language_d
)
5139 /* NAME is already canonical. Drop any qualifiers as
5140 .debug_names does not contain any. */
5142 if (strchr (name
, '(') != NULL
)
5144 without_params
= cp_remove_params (name
);
5145 if (without_params
!= NULL
)
5146 name
= without_params
.get ();
5150 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5152 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5154 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5155 (map
.bucket_table_reordered
5156 + (full_hash
% map
.bucket_count
)), 4,
5157 map
.dwarf5_byte_order
);
5161 if (namei
>= map
.name_count
)
5163 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5165 namei
, map
.name_count
,
5166 objfile_name (per_objfile
->objfile
));
5172 const uint32_t namei_full_hash
5173 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5174 (map
.hash_table_reordered
+ namei
), 4,
5175 map
.dwarf5_byte_order
);
5176 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5179 if (full_hash
== namei_full_hash
)
5181 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5183 #if 0 /* An expensive sanity check. */
5184 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5186 complaint (_("Wrong .debug_names hash for string at index %u "
5188 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5193 if (cmp (namei_string
, name
) == 0)
5195 const ULONGEST namei_entry_offs
5196 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5197 + namei
* map
.offset_size
),
5198 map
.offset_size
, map
.dwarf5_byte_order
);
5199 return map
.entry_pool
+ namei_entry_offs
;
5204 if (namei
>= map
.name_count
)
5210 dw2_debug_names_iterator::find_vec_in_debug_names
5211 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5213 if (namei
>= map
.name_count
)
5215 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5217 namei
, map
.name_count
,
5218 objfile_name (per_objfile
->objfile
));
5222 const ULONGEST namei_entry_offs
5223 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5224 + namei
* map
.offset_size
),
5225 map
.offset_size
, map
.dwarf5_byte_order
);
5226 return map
.entry_pool
+ namei_entry_offs
;
5229 /* See dw2_debug_names_iterator. */
5231 dwarf2_per_cu_data
*
5232 dw2_debug_names_iterator::next ()
5237 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5238 struct objfile
*objfile
= m_per_objfile
->objfile
;
5239 bfd
*const abfd
= objfile
->obfd
;
5243 unsigned int bytes_read
;
5244 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5245 m_addr
+= bytes_read
;
5249 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5250 if (indexval_it
== m_map
.abbrev_map
.cend ())
5252 complaint (_("Wrong .debug_names undefined abbrev code %s "
5254 pulongest (abbrev
), objfile_name (objfile
));
5257 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5258 enum class symbol_linkage
{
5262 } symbol_linkage_
= symbol_linkage::unknown
;
5263 dwarf2_per_cu_data
*per_cu
= NULL
;
5264 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5269 case DW_FORM_implicit_const
:
5270 ull
= attr
.implicit_const
;
5272 case DW_FORM_flag_present
:
5276 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5277 m_addr
+= bytes_read
;
5280 ull
= read_4_bytes (abfd
, m_addr
);
5284 ull
= read_8_bytes (abfd
, m_addr
);
5287 case DW_FORM_ref_sig8
:
5288 ull
= read_8_bytes (abfd
, m_addr
);
5292 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5293 dwarf_form_name (attr
.form
),
5294 objfile_name (objfile
));
5297 switch (attr
.dw_idx
)
5299 case DW_IDX_compile_unit
:
5300 /* Don't crash on bad data. */
5301 if (ull
>= per_bfd
->all_comp_units
.size ())
5303 complaint (_(".debug_names entry has bad CU index %s"
5306 objfile_name (objfile
));
5309 per_cu
= per_bfd
->get_cu (ull
);
5311 case DW_IDX_type_unit
:
5312 /* Don't crash on bad data. */
5313 if (ull
>= per_bfd
->tu_stats
.nr_tus
)
5315 complaint (_(".debug_names entry has bad TU index %s"
5318 objfile_name (objfile
));
5321 per_cu
= per_bfd
->get_cu (ull
+ per_bfd
->tu_stats
.nr_tus
);
5323 case DW_IDX_die_offset
:
5324 /* In a per-CU index (as opposed to a per-module index), index
5325 entries without CU attribute implicitly refer to the single CU. */
5327 per_cu
= per_bfd
->get_cu (0);
5329 case DW_IDX_GNU_internal
:
5330 if (!m_map
.augmentation_is_gdb
)
5332 symbol_linkage_
= symbol_linkage::static_
;
5334 case DW_IDX_GNU_external
:
5335 if (!m_map
.augmentation_is_gdb
)
5337 symbol_linkage_
= symbol_linkage::extern_
;
5342 /* Skip if already read in. */
5343 if (m_per_objfile
->symtab_set_p (per_cu
))
5346 /* Check static vs global. */
5347 if (symbol_linkage_
!= symbol_linkage::unknown
)
5349 if (symbol_linkage_
== symbol_linkage::static_
)
5351 if ((m_block_index
& SEARCH_STATIC_BLOCK
) == 0)
5356 if ((m_block_index
& SEARCH_GLOBAL_BLOCK
) == 0)
5361 /* Match dw2_symtab_iter_next, symbol_kind
5362 and debug_names::psymbol_tag. */
5366 switch (indexval
.dwarf_tag
)
5368 case DW_TAG_variable
:
5369 case DW_TAG_subprogram
:
5370 /* Some types are also in VAR_DOMAIN. */
5371 case DW_TAG_typedef
:
5372 case DW_TAG_structure_type
:
5379 switch (indexval
.dwarf_tag
)
5381 case DW_TAG_typedef
:
5382 case DW_TAG_structure_type
:
5389 switch (indexval
.dwarf_tag
)
5392 case DW_TAG_variable
:
5399 switch (indexval
.dwarf_tag
)
5411 /* Match dw2_expand_symtabs_matching, symbol_kind and
5412 debug_names::psymbol_tag. */
5415 case VARIABLES_DOMAIN
:
5416 switch (indexval
.dwarf_tag
)
5418 case DW_TAG_variable
:
5424 case FUNCTIONS_DOMAIN
:
5425 switch (indexval
.dwarf_tag
)
5427 case DW_TAG_subprogram
:
5434 switch (indexval
.dwarf_tag
)
5436 case DW_TAG_typedef
:
5437 case DW_TAG_structure_type
:
5443 case MODULES_DOMAIN
:
5444 switch (indexval
.dwarf_tag
)
5458 /* This dumps minimal information about .debug_names. It is called
5459 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5460 uses this to verify that .debug_names has been loaded. */
5463 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5465 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5467 gdb_assert (per_objfile
->per_bfd
->using_index
);
5468 printf_filtered (".debug_names:");
5469 if (per_objfile
->per_bfd
->debug_names_table
)
5470 printf_filtered (" exists\n");
5472 printf_filtered (" faked for \"readnow\"\n");
5473 printf_filtered ("\n");
5477 dwarf2_debug_names_index::expand_matching_symbols
5478 (struct objfile
*objfile
,
5479 const lookup_name_info
&name
, domain_enum domain
,
5481 symbol_compare_ftype
*ordered_compare
)
5483 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5485 /* debug_names_table is NULL if OBJF_READNOW. */
5486 if (!per_objfile
->per_bfd
->debug_names_table
)
5489 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5490 const block_search_flags block_flags
5491 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
5493 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5494 auto matcher
= [&] (const char *symname
)
5496 if (ordered_compare
== nullptr)
5498 return ordered_compare (symname
, match_name
) == 0;
5501 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
5502 [&] (offset_type namei
)
5504 /* The name was matched, now expand corresponding CUs that were
5506 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
5509 struct dwarf2_per_cu_data
*per_cu
;
5510 while ((per_cu
= iter
.next ()) != NULL
)
5511 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5518 dwarf2_debug_names_index::expand_symtabs_matching
5519 (struct objfile
*objfile
,
5520 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5521 const lookup_name_info
*lookup_name
,
5522 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5523 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5524 block_search_flags search_flags
,
5526 enum search_domain kind
)
5528 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5530 /* debug_names_table is NULL if OBJF_READNOW. */
5531 if (!per_objfile
->per_bfd
->debug_names_table
)
5534 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5536 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5538 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5542 if (!dw2_expand_symtabs_matching_one (per_cu
.get (), per_objfile
,
5550 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5553 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5555 [&] (offset_type namei
)
5557 /* The name was matched, now expand corresponding CUs that were
5559 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
5561 struct dwarf2_per_cu_data
*per_cu
;
5562 while ((per_cu
= iter
.next ()) != NULL
)
5563 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
5573 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5574 to either a dwarf2_per_bfd or dwz_file object. */
5576 template <typename T
>
5577 static gdb::array_view
<const gdb_byte
>
5578 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5580 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5582 if (section
->empty ())
5585 /* Older elfutils strip versions could keep the section in the main
5586 executable while splitting it for the separate debug info file. */
5587 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5590 section
->read (obj
);
5592 /* dwarf2_section_info::size is a bfd_size_type, while
5593 gdb::array_view works with size_t. On 32-bit hosts, with
5594 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5595 is 32-bit. So we need an explicit narrowing conversion here.
5596 This is fine, because it's impossible to allocate or mmap an
5597 array/buffer larger than what size_t can represent. */
5598 return gdb::make_array_view (section
->buffer
, section
->size
);
5601 /* Lookup the index cache for the contents of the index associated to
5604 static gdb::array_view
<const gdb_byte
>
5605 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5607 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5608 if (build_id
== nullptr)
5611 return global_index_cache
.lookup_gdb_index (build_id
,
5612 &dwarf2_per_bfd
->index_cache_res
);
5615 /* Same as the above, but for DWZ. */
5617 static gdb::array_view
<const gdb_byte
>
5618 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5620 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5621 if (build_id
== nullptr)
5624 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5627 /* See dwarf2/public.h. */
5630 dwarf2_initialize_objfile (struct objfile
*objfile
)
5632 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5633 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5635 dwarf_read_debug_printf ("called");
5637 /* If we're about to read full symbols, don't bother with the
5638 indices. In this case we also don't care if some other debug
5639 format is making psymtabs, because they are all about to be
5641 if ((objfile
->flags
& OBJF_READNOW
))
5643 dwarf_read_debug_printf ("readnow requested");
5645 /* When using READNOW, the using_index flag (set below) indicates that
5646 PER_BFD was already initialized, when we loaded some other objfile. */
5647 if (per_bfd
->using_index
)
5649 dwarf_read_debug_printf ("using_index already set");
5650 per_objfile
->resize_symtabs ();
5651 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5655 per_bfd
->using_index
= 1;
5656 create_all_comp_units (per_objfile
);
5657 per_bfd
->quick_file_names_table
5658 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
5659 per_objfile
->resize_symtabs ();
5661 for (int i
= 0; i
< per_bfd
->all_comp_units
.size (); ++i
)
5663 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cu (i
);
5665 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
5666 struct dwarf2_per_cu_quick_data
);
5669 /* Arrange for gdb to see the "quick" functions. However, these
5670 functions will be no-ops because we will have expanded all
5672 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5676 /* Was a debug names index already read when we processed an objfile sharing
5678 if (per_bfd
->debug_names_table
!= nullptr)
5680 dwarf_read_debug_printf ("re-using shared debug names table");
5681 per_objfile
->resize_symtabs ();
5682 objfile
->qf
.push_front (make_dwarf_debug_names ());
5686 /* Was a GDB index already read when we processed an objfile sharing
5688 if (per_bfd
->index_table
!= nullptr)
5690 dwarf_read_debug_printf ("re-using shared index table");
5691 per_objfile
->resize_symtabs ();
5692 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5696 /* There might already be partial symtabs built for this BFD. This happens
5697 when loading the same binary twice with the index-cache enabled. If so,
5698 don't try to read an index. The objfile / per_objfile initialization will
5699 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
5701 if (per_bfd
->partial_symtabs
!= nullptr)
5703 dwarf_read_debug_printf ("re-using shared partial symtabs");
5704 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5708 if (dwarf2_read_debug_names (per_objfile
))
5710 dwarf_read_debug_printf ("found debug names");
5711 per_objfile
->resize_symtabs ();
5712 objfile
->qf
.push_front (make_dwarf_debug_names ());
5716 if (dwarf2_read_gdb_index (per_objfile
,
5717 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
5718 get_gdb_index_contents_from_section
<dwz_file
>))
5720 dwarf_read_debug_printf ("found gdb index from file");
5721 per_objfile
->resize_symtabs ();
5722 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5726 /* ... otherwise, try to find the index in the index cache. */
5727 if (dwarf2_read_gdb_index (per_objfile
,
5728 get_gdb_index_contents_from_cache
,
5729 get_gdb_index_contents_from_cache_dwz
))
5731 dwarf_read_debug_printf ("found gdb index from cache");
5732 global_index_cache
.hit ();
5733 per_objfile
->resize_symtabs ();
5734 objfile
->qf
.push_front (make_dwarf_gdb_index ());
5738 global_index_cache
.miss ();
5739 objfile
->qf
.push_front (make_lazy_dwarf_reader ());
5744 /* Build a partial symbol table. */
5747 dwarf2_build_psymtabs (struct objfile
*objfile
, psymbol_functions
*psf
)
5749 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5750 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5752 if (per_bfd
->partial_symtabs
!= nullptr)
5754 /* Partial symbols were already read, so now we can simply
5758 psf
= new psymbol_functions (per_bfd
->partial_symtabs
);
5759 objfile
->qf
.emplace_front (psf
);
5762 psf
->set_partial_symtabs (per_bfd
->partial_symtabs
);
5763 per_objfile
->resize_symtabs ();
5769 psf
= new psymbol_functions
;
5770 objfile
->qf
.emplace_front (psf
);
5772 const std::shared_ptr
<psymtab_storage
> &partial_symtabs
5773 = psf
->get_partial_symtabs ();
5775 /* Set the local reference to partial symtabs, so that we don't try
5776 to read them again if reading another objfile with the same BFD.
5777 If we can't in fact share, this won't make a difference anyway as
5778 the dwarf2_per_bfd object won't be shared. */
5779 per_bfd
->partial_symtabs
= partial_symtabs
;
5783 /* This isn't really ideal: all the data we allocate on the
5784 objfile's obstack is still uselessly kept around. However,
5785 freeing it seems unsafe. */
5786 psymtab_discarder
psymtabs (partial_symtabs
.get ());
5787 dwarf2_build_psymtabs_hard (per_objfile
);
5790 per_objfile
->resize_symtabs ();
5792 /* (maybe) store an index in the cache. */
5793 global_index_cache
.store (per_objfile
);
5795 catch (const gdb_exception_error
&except
)
5797 exception_print (gdb_stderr
, except
);
5801 /* Find the base address of the compilation unit for range lists and
5802 location lists. It will normally be specified by DW_AT_low_pc.
5803 In DWARF-3 draft 4, the base address could be overridden by
5804 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5805 compilation units with discontinuous ranges. */
5808 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5810 struct attribute
*attr
;
5812 cu
->base_address
.reset ();
5814 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5815 if (attr
!= nullptr)
5816 cu
->base_address
= attr
->as_address ();
5819 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5820 if (attr
!= nullptr)
5821 cu
->base_address
= attr
->as_address ();
5825 /* Helper function that returns the proper abbrev section for
5828 static struct dwarf2_section_info
*
5829 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5831 struct dwarf2_section_info
*abbrev
;
5832 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
5834 if (this_cu
->is_dwz
)
5835 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
5837 abbrev
= &per_bfd
->abbrev
;
5842 /* Fetch the abbreviation table offset from a comp or type unit header. */
5845 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
5846 struct dwarf2_section_info
*section
,
5847 sect_offset sect_off
)
5849 bfd
*abfd
= section
->get_bfd_owner ();
5850 const gdb_byte
*info_ptr
;
5851 unsigned int initial_length_size
, offset_size
;
5854 section
->read (per_objfile
->objfile
);
5855 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5856 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5857 offset_size
= initial_length_size
== 4 ? 4 : 8;
5858 info_ptr
+= initial_length_size
;
5860 version
= read_2_bytes (abfd
, info_ptr
);
5864 /* Skip unit type and address size. */
5868 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5871 /* A partial symtab that is used only for include files. */
5872 struct dwarf2_include_psymtab
: public partial_symtab
5874 dwarf2_include_psymtab (const char *filename
,
5875 psymtab_storage
*partial_symtabs
,
5876 objfile_per_bfd_storage
*objfile_per_bfd
)
5877 : partial_symtab (filename
, partial_symtabs
, objfile_per_bfd
)
5881 void read_symtab (struct objfile
*objfile
) override
5883 /* It's an include file, no symbols to read for it.
5884 Everything is in the includer symtab. */
5886 /* The expansion of a dwarf2_include_psymtab is just a trigger for
5887 expansion of the includer psymtab. We use the dependencies[0] field to
5888 model the includer. But if we go the regular route of calling
5889 expand_psymtab here, and having expand_psymtab call expand_dependencies
5890 to expand the includer, we'll only use expand_psymtab on the includer
5891 (making it a non-toplevel psymtab), while if we expand the includer via
5892 another path, we'll use read_symtab (making it a toplevel psymtab).
5893 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
5894 psymtab, and trigger read_symtab on the includer here directly. */
5895 includer ()->read_symtab (objfile
);
5898 void expand_psymtab (struct objfile
*objfile
) override
5900 /* This is not called by read_symtab, and should not be called by any
5901 expand_dependencies. */
5905 bool readin_p (struct objfile
*objfile
) const override
5907 return includer ()->readin_p (objfile
);
5910 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
5916 partial_symtab
*includer () const
5918 /* An include psymtab has exactly one dependency: the psymtab that
5920 gdb_assert (this->number_of_dependencies
== 1);
5921 return this->dependencies
[0];
5925 /* Allocate a new partial symtab for file named NAME and mark this new
5926 partial symtab as being an include of PST. */
5929 dwarf2_create_include_psymtab (dwarf2_per_bfd
*per_bfd
,
5931 dwarf2_psymtab
*pst
,
5932 psymtab_storage
*partial_symtabs
,
5933 objfile_per_bfd_storage
*objfile_per_bfd
)
5935 dwarf2_include_psymtab
*subpst
5936 = new dwarf2_include_psymtab (name
, partial_symtabs
, objfile_per_bfd
);
5938 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5939 subpst
->dirname
= pst
->dirname
;
5941 subpst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (1);
5942 subpst
->dependencies
[0] = pst
;
5943 subpst
->number_of_dependencies
= 1;
5946 /* Read the Line Number Program data and extract the list of files
5947 included by the source file represented by PST. Build an include
5948 partial symtab for each of these included files. */
5951 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5952 struct die_info
*die
,
5953 dwarf2_psymtab
*pst
)
5956 struct attribute
*attr
;
5958 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5959 if (attr
!= nullptr && attr
->form_is_unsigned ())
5960 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
5962 return; /* No linetable, so no includes. */
5964 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5965 that we pass in the raw text_low here; that is ok because we're
5966 only decoding the line table to make include partial symtabs, and
5967 so the addresses aren't really used. */
5968 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5969 pst
->raw_text_low (), 1);
5973 hash_signatured_type (const void *item
)
5975 const struct signatured_type
*sig_type
5976 = (const struct signatured_type
*) item
;
5978 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5979 return sig_type
->signature
;
5983 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5985 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5986 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5988 return lhs
->signature
== rhs
->signature
;
5991 /* Allocate a hash table for signatured types. */
5994 allocate_signatured_type_table ()
5996 return htab_up (htab_create_alloc (41,
5997 hash_signatured_type
,
5999 NULL
, xcalloc
, xfree
));
6002 /* A helper for create_debug_types_hash_table. Read types from SECTION
6003 and fill them into TYPES_HTAB. It will process only type units,
6004 therefore DW_UT_type. */
6007 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6008 struct dwo_file
*dwo_file
,
6009 dwarf2_section_info
*section
, htab_up
&types_htab
,
6010 rcuh_kind section_kind
)
6012 struct objfile
*objfile
= per_objfile
->objfile
;
6013 struct dwarf2_section_info
*abbrev_section
;
6015 const gdb_byte
*info_ptr
, *end_ptr
;
6017 abbrev_section
= &dwo_file
->sections
.abbrev
;
6019 dwarf_read_debug_printf ("Reading %s for %s",
6020 section
->get_name (),
6021 abbrev_section
->get_file_name ());
6023 section
->read (objfile
);
6024 info_ptr
= section
->buffer
;
6026 if (info_ptr
== NULL
)
6029 /* We can't set abfd until now because the section may be empty or
6030 not present, in which case the bfd is unknown. */
6031 abfd
= section
->get_bfd_owner ();
6033 /* We don't use cutu_reader here because we don't need to read
6034 any dies: the signature is in the header. */
6036 end_ptr
= info_ptr
+ section
->size
;
6037 while (info_ptr
< end_ptr
)
6039 std::unique_ptr
<signatured_type
> sig_type
;
6040 struct dwo_unit
*dwo_tu
;
6042 const gdb_byte
*ptr
= info_ptr
;
6043 struct comp_unit_head header
;
6044 unsigned int length
;
6046 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6048 /* Initialize it due to a false compiler warning. */
6049 header
.signature
= -1;
6050 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6052 /* We need to read the type's signature in order to build the hash
6053 table, but we don't need anything else just yet. */
6055 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6056 abbrev_section
, ptr
, section_kind
);
6058 length
= header
.get_length ();
6060 /* Skip dummy type units. */
6061 if (ptr
>= info_ptr
+ length
6062 || peek_abbrev_code (abfd
, ptr
) == 0
6063 || (header
.unit_type
!= DW_UT_type
6064 && header
.unit_type
!= DW_UT_split_type
))
6070 if (types_htab
== NULL
)
6071 types_htab
= allocate_dwo_unit_table ();
6073 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6074 dwo_tu
->dwo_file
= dwo_file
;
6075 dwo_tu
->signature
= header
.signature
;
6076 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6077 dwo_tu
->section
= section
;
6078 dwo_tu
->sect_off
= sect_off
;
6079 dwo_tu
->length
= length
;
6081 slot
= htab_find_slot (types_htab
.get (), dwo_tu
, INSERT
);
6082 gdb_assert (slot
!= NULL
);
6084 complaint (_("debug type entry at offset %s is duplicate to"
6085 " the entry at offset %s, signature %s"),
6086 sect_offset_str (sect_off
),
6087 sect_offset_str (dwo_tu
->sect_off
),
6088 hex_string (header
.signature
));
6091 dwarf_read_debug_printf_v (" offset %s, signature %s",
6092 sect_offset_str (sect_off
),
6093 hex_string (header
.signature
));
6099 /* Create the hash table of all entries in the .debug_types
6100 (or .debug_types.dwo) section(s).
6101 DWO_FILE is a pointer to the DWO file object.
6103 The result is a pointer to the hash table or NULL if there are no types.
6105 Note: This function processes DWO files only, not DWP files. */
6108 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6109 struct dwo_file
*dwo_file
,
6110 gdb::array_view
<dwarf2_section_info
> type_sections
,
6111 htab_up
&types_htab
)
6113 for (dwarf2_section_info
§ion
: type_sections
)
6114 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6118 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6119 If SLOT is non-NULL, it is the entry to use in the hash table.
6120 Otherwise we find one. */
6122 static struct signatured_type
*
6123 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6125 if (per_objfile
->per_bfd
->all_comp_units
.size ()
6126 == per_objfile
->per_bfd
->all_comp_units
.capacity ())
6127 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6129 std::unique_ptr
<signatured_type
> sig_type_holder
6130 = per_objfile
->per_bfd
->allocate_signatured_type ();
6131 signatured_type
*sig_type
= sig_type_holder
.get ();
6133 per_objfile
->resize_symtabs ();
6135 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (sig_type_holder
));
6136 sig_type
->signature
= sig
;
6137 sig_type
->is_debug_types
= 1;
6138 if (per_objfile
->per_bfd
->using_index
)
6141 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6142 struct dwarf2_per_cu_quick_data
);
6147 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6150 gdb_assert (*slot
== NULL
);
6152 /* The rest of sig_type must be filled in by the caller. */
6156 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6157 Fill in SIG_ENTRY with DWO_ENTRY. */
6160 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6161 struct signatured_type
*sig_entry
,
6162 struct dwo_unit
*dwo_entry
)
6164 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6166 /* Make sure we're not clobbering something we don't expect to. */
6167 gdb_assert (! sig_entry
->queued
);
6168 gdb_assert (per_objfile
->get_cu (sig_entry
) == NULL
);
6169 if (per_bfd
->using_index
)
6171 gdb_assert (sig_entry
->v
.quick
!= NULL
);
6172 gdb_assert (!per_objfile
->symtab_set_p (sig_entry
));
6175 gdb_assert (sig_entry
->v
.psymtab
== NULL
);
6176 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6177 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6178 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6179 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6181 sig_entry
->section
= dwo_entry
->section
;
6182 sig_entry
->sect_off
= dwo_entry
->sect_off
;
6183 sig_entry
->length
= dwo_entry
->length
;
6184 sig_entry
->reading_dwo_directly
= 1;
6185 sig_entry
->per_bfd
= per_bfd
;
6186 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6187 sig_entry
->dwo_unit
= dwo_entry
;
6190 /* Subroutine of lookup_signatured_type.
6191 If we haven't read the TU yet, create the signatured_type data structure
6192 for a TU to be read in directly from a DWO file, bypassing the stub.
6193 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6194 using .gdb_index, then when reading a CU we want to stay in the DWO file
6195 containing that CU. Otherwise we could end up reading several other DWO
6196 files (due to comdat folding) to process the transitive closure of all the
6197 mentioned TUs, and that can be slow. The current DWO file will have every
6198 type signature that it needs.
6199 We only do this for .gdb_index because in the psymtab case we already have
6200 to read all the DWOs to build the type unit groups. */
6202 static struct signatured_type
*
6203 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6205 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6206 struct dwo_file
*dwo_file
;
6207 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6208 struct signatured_type find_sig_entry
, *sig_entry
;
6211 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6213 /* If TU skeletons have been removed then we may not have read in any
6215 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6216 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6218 /* We only ever need to read in one copy of a signatured type.
6219 Use the global signatured_types array to do our own comdat-folding
6220 of types. If this is the first time we're reading this TU, and
6221 the TU has an entry in .gdb_index, replace the recorded data from
6222 .gdb_index with this TU. */
6224 find_sig_entry
.signature
= sig
;
6225 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6226 &find_sig_entry
, INSERT
);
6227 sig_entry
= (struct signatured_type
*) *slot
;
6229 /* We can get here with the TU already read, *or* in the process of being
6230 read. Don't reassign the global entry to point to this DWO if that's
6231 the case. Also note that if the TU is already being read, it may not
6232 have come from a DWO, the program may be a mix of Fission-compiled
6233 code and non-Fission-compiled code. */
6235 /* Have we already tried to read this TU?
6236 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6237 needn't exist in the global table yet). */
6238 if (sig_entry
!= NULL
&& sig_entry
->tu_read
)
6241 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6242 dwo_unit of the TU itself. */
6243 dwo_file
= cu
->dwo_unit
->dwo_file
;
6245 /* Ok, this is the first time we're reading this TU. */
6246 if (dwo_file
->tus
== NULL
)
6248 find_dwo_entry
.signature
= sig
;
6249 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6251 if (dwo_entry
== NULL
)
6254 /* If the global table doesn't have an entry for this TU, add one. */
6255 if (sig_entry
== NULL
)
6256 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6258 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6259 sig_entry
->tu_read
= 1;
6263 /* Subroutine of lookup_signatured_type.
6264 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6265 then try the DWP file. If the TU stub (skeleton) has been removed then
6266 it won't be in .gdb_index. */
6268 static struct signatured_type
*
6269 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6271 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6272 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6273 struct dwo_unit
*dwo_entry
;
6274 struct signatured_type find_sig_entry
, *sig_entry
;
6277 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6278 gdb_assert (dwp_file
!= NULL
);
6280 /* If TU skeletons have been removed then we may not have read in any
6282 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6283 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6285 find_sig_entry
.signature
= sig
;
6286 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6287 &find_sig_entry
, INSERT
);
6288 sig_entry
= (struct signatured_type
*) *slot
;
6290 /* Have we already tried to read this TU?
6291 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6292 needn't exist in the global table yet). */
6293 if (sig_entry
!= NULL
)
6296 if (dwp_file
->tus
== NULL
)
6298 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6299 1 /* is_debug_types */);
6300 if (dwo_entry
== NULL
)
6303 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6304 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6309 /* Lookup a signature based type for DW_FORM_ref_sig8.
6310 Returns NULL if signature SIG is not present in the table.
6311 It is up to the caller to complain about this. */
6313 static struct signatured_type
*
6314 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6316 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6318 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6320 /* We're in a DWO/DWP file, and we're using .gdb_index.
6321 These cases require special processing. */
6322 if (get_dwp_file (per_objfile
) == NULL
)
6323 return lookup_dwo_signatured_type (cu
, sig
);
6325 return lookup_dwp_signatured_type (cu
, sig
);
6329 struct signatured_type find_entry
, *entry
;
6331 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6333 find_entry
.signature
= sig
;
6334 entry
= ((struct signatured_type
*)
6335 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6341 /* Low level DIE reading support. */
6343 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6346 init_cu_die_reader (struct die_reader_specs
*reader
,
6347 struct dwarf2_cu
*cu
,
6348 struct dwarf2_section_info
*section
,
6349 struct dwo_file
*dwo_file
,
6350 struct abbrev_table
*abbrev_table
)
6352 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6353 reader
->abfd
= section
->get_bfd_owner ();
6355 reader
->dwo_file
= dwo_file
;
6356 reader
->die_section
= section
;
6357 reader
->buffer
= section
->buffer
;
6358 reader
->buffer_end
= section
->buffer
+ section
->size
;
6359 reader
->abbrev_table
= abbrev_table
;
6362 /* Subroutine of cutu_reader to simplify it.
6363 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6364 There's just a lot of work to do, and cutu_reader is big enough
6367 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6368 from it to the DIE in the DWO. If NULL we are skipping the stub.
6369 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6370 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6371 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6372 STUB_COMP_DIR may be non-NULL.
6373 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6374 are filled in with the info of the DIE from the DWO file.
6375 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6376 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6377 kept around for at least as long as *RESULT_READER.
6379 The result is non-zero if a valid (non-dummy) DIE was found. */
6382 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6383 struct dwo_unit
*dwo_unit
,
6384 struct die_info
*stub_comp_unit_die
,
6385 const char *stub_comp_dir
,
6386 struct die_reader_specs
*result_reader
,
6387 const gdb_byte
**result_info_ptr
,
6388 struct die_info
**result_comp_unit_die
,
6389 abbrev_table_up
*result_dwo_abbrev_table
)
6391 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6392 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6393 struct objfile
*objfile
= per_objfile
->objfile
;
6395 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6396 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6397 int i
,num_extra_attrs
;
6398 struct dwarf2_section_info
*dwo_abbrev_section
;
6399 struct die_info
*comp_unit_die
;
6401 /* At most one of these may be provided. */
6402 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6404 /* These attributes aren't processed until later:
6405 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6406 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6407 referenced later. However, these attributes are found in the stub
6408 which we won't have later. In order to not impose this complication
6409 on the rest of the code, we read them here and copy them to the
6418 if (stub_comp_unit_die
!= NULL
)
6420 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6422 if (!per_cu
->is_debug_types
)
6423 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6424 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6425 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6426 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6427 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6429 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6431 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6432 We need the value before we can process DW_AT_ranges values from the
6434 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6436 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6437 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6438 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6439 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6441 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6443 else if (stub_comp_dir
!= NULL
)
6445 /* Reconstruct the comp_dir attribute to simplify the code below. */
6446 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6447 comp_dir
->name
= DW_AT_comp_dir
;
6448 comp_dir
->form
= DW_FORM_string
;
6449 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6452 /* Set up for reading the DWO CU/TU. */
6453 cu
->dwo_unit
= dwo_unit
;
6454 dwarf2_section_info
*section
= dwo_unit
->section
;
6455 section
->read (objfile
);
6456 abfd
= section
->get_bfd_owner ();
6457 begin_info_ptr
= info_ptr
= (section
->buffer
6458 + to_underlying (dwo_unit
->sect_off
));
6459 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6461 if (per_cu
->is_debug_types
)
6463 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6465 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6466 section
, dwo_abbrev_section
,
6467 info_ptr
, rcuh_kind::TYPE
);
6468 /* This is not an assert because it can be caused by bad debug info. */
6469 if (sig_type
->signature
!= cu
->header
.signature
)
6471 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6472 " TU at offset %s [in module %s]"),
6473 hex_string (sig_type
->signature
),
6474 hex_string (cu
->header
.signature
),
6475 sect_offset_str (dwo_unit
->sect_off
),
6476 bfd_get_filename (abfd
));
6478 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6479 /* For DWOs coming from DWP files, we don't know the CU length
6480 nor the type's offset in the TU until now. */
6481 dwo_unit
->length
= cu
->header
.get_length ();
6482 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6484 /* Establish the type offset that can be used to lookup the type.
6485 For DWO files, we don't know it until now. */
6486 sig_type
->type_offset_in_section
6487 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6491 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6492 section
, dwo_abbrev_section
,
6493 info_ptr
, rcuh_kind::COMPILE
);
6494 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6495 /* For DWOs coming from DWP files, we don't know the CU length
6497 dwo_unit
->length
= cu
->header
.get_length ();
6500 dwo_abbrev_section
->read (objfile
);
6501 *result_dwo_abbrev_table
6502 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6503 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6504 result_dwo_abbrev_table
->get ());
6506 /* Read in the die, but leave space to copy over the attributes
6507 from the stub. This has the benefit of simplifying the rest of
6508 the code - all the work to maintain the illusion of a single
6509 DW_TAG_{compile,type}_unit DIE is done here. */
6510 num_extra_attrs
= ((stmt_list
!= NULL
)
6514 + (comp_dir
!= NULL
));
6515 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6518 /* Copy over the attributes from the stub to the DIE we just read in. */
6519 comp_unit_die
= *result_comp_unit_die
;
6520 i
= comp_unit_die
->num_attrs
;
6521 if (stmt_list
!= NULL
)
6522 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6524 comp_unit_die
->attrs
[i
++] = *low_pc
;
6525 if (high_pc
!= NULL
)
6526 comp_unit_die
->attrs
[i
++] = *high_pc
;
6528 comp_unit_die
->attrs
[i
++] = *ranges
;
6529 if (comp_dir
!= NULL
)
6530 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6531 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6533 if (dwarf_die_debug
)
6535 fprintf_unfiltered (gdb_stdlog
,
6536 "Read die from %s@0x%x of %s:\n",
6537 section
->get_name (),
6538 (unsigned) (begin_info_ptr
- section
->buffer
),
6539 bfd_get_filename (abfd
));
6540 dump_die (comp_unit_die
, dwarf_die_debug
);
6543 /* Skip dummy compilation units. */
6544 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6545 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6548 *result_info_ptr
= info_ptr
;
6552 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6553 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6554 signature is part of the header. */
6555 static gdb::optional
<ULONGEST
>
6556 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6558 if (cu
->header
.version
>= 5)
6559 return cu
->header
.signature
;
6560 struct attribute
*attr
;
6561 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6562 if (attr
== nullptr || !attr
->form_is_unsigned ())
6563 return gdb::optional
<ULONGEST
> ();
6564 return attr
->as_unsigned ();
6567 /* Subroutine of cutu_reader to simplify it.
6568 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6569 Returns NULL if the specified DWO unit cannot be found. */
6571 static struct dwo_unit
*
6572 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
6574 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6575 struct dwo_unit
*dwo_unit
;
6576 const char *comp_dir
;
6578 gdb_assert (cu
!= NULL
);
6580 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6581 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6582 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6584 if (per_cu
->is_debug_types
)
6585 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
6588 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6590 if (!signature
.has_value ())
6591 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6593 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
6595 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
6601 /* Subroutine of cutu_reader to simplify it.
6602 See it for a description of the parameters.
6603 Read a TU directly from a DWO file, bypassing the stub. */
6606 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
6607 dwarf2_per_objfile
*per_objfile
,
6608 dwarf2_cu
*existing_cu
)
6610 struct signatured_type
*sig_type
;
6612 /* Verify we can do the following downcast, and that we have the
6614 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6615 sig_type
= (struct signatured_type
*) this_cu
;
6616 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6620 if (existing_cu
!= nullptr)
6623 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
6624 /* There's no need to do the rereading_dwo_cu handling that
6625 cutu_reader does since we don't read the stub. */
6629 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6630 in per_objfile yet. */
6631 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6632 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6633 cu
= m_new_cu
.get ();
6636 /* A future optimization, if needed, would be to use an existing
6637 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6638 could share abbrev tables. */
6640 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
6641 NULL
/* stub_comp_unit_die */,
6642 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6645 &m_dwo_abbrev_table
) == 0)
6652 /* Initialize a CU (or TU) and read its DIEs.
6653 If the CU defers to a DWO file, read the DWO file as well.
6655 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6656 Otherwise the table specified in the comp unit header is read in and used.
6657 This is an optimization for when we already have the abbrev table.
6659 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
6662 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6663 dwarf2_per_objfile
*per_objfile
,
6664 struct abbrev_table
*abbrev_table
,
6665 dwarf2_cu
*existing_cu
,
6667 : die_reader_specs
{},
6670 struct objfile
*objfile
= per_objfile
->objfile
;
6671 struct dwarf2_section_info
*section
= this_cu
->section
;
6672 bfd
*abfd
= section
->get_bfd_owner ();
6673 const gdb_byte
*begin_info_ptr
;
6674 struct signatured_type
*sig_type
= NULL
;
6675 struct dwarf2_section_info
*abbrev_section
;
6676 /* Non-zero if CU currently points to a DWO file and we need to
6677 reread it. When this happens we need to reread the skeleton die
6678 before we can reread the DWO file (this only applies to CUs, not TUs). */
6679 int rereading_dwo_cu
= 0;
6681 if (dwarf_die_debug
)
6682 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6683 this_cu
->is_debug_types
? "type" : "comp",
6684 sect_offset_str (this_cu
->sect_off
));
6686 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6687 file (instead of going through the stub), short-circuit all of this. */
6688 if (this_cu
->reading_dwo_directly
)
6690 /* Narrow down the scope of possibilities to have to understand. */
6691 gdb_assert (this_cu
->is_debug_types
);
6692 gdb_assert (abbrev_table
== NULL
);
6693 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
6697 /* This is cheap if the section is already read in. */
6698 section
->read (objfile
);
6700 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6702 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6706 if (existing_cu
!= nullptr)
6709 /* If this CU is from a DWO file we need to start over, we need to
6710 refetch the attributes from the skeleton CU.
6711 This could be optimized by retrieving those attributes from when we
6712 were here the first time: the previous comp_unit_die was stored in
6713 comp_unit_obstack. But there's no data yet that we need this
6715 if (cu
->dwo_unit
!= NULL
)
6716 rereading_dwo_cu
= 1;
6720 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
6721 in per_objfile yet. */
6722 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6723 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6724 cu
= m_new_cu
.get ();
6727 /* Get the header. */
6728 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6730 /* We already have the header, there's no need to read it in again. */
6731 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6735 if (this_cu
->is_debug_types
)
6737 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6738 section
, abbrev_section
,
6739 info_ptr
, rcuh_kind::TYPE
);
6741 /* Since per_cu is the first member of struct signatured_type,
6742 we can go from a pointer to one to a pointer to the other. */
6743 sig_type
= (struct signatured_type
*) this_cu
;
6744 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6745 gdb_assert (sig_type
->type_offset_in_tu
6746 == cu
->header
.type_cu_offset_in_tu
);
6747 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6749 /* LENGTH has not been set yet for type units if we're
6750 using .gdb_index. */
6751 this_cu
->length
= cu
->header
.get_length ();
6753 /* Establish the type offset that can be used to lookup the type. */
6754 sig_type
->type_offset_in_section
=
6755 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6757 this_cu
->dwarf_version
= cu
->header
.version
;
6761 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6762 section
, abbrev_section
,
6764 rcuh_kind::COMPILE
);
6766 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6767 if (this_cu
->length
== 0)
6768 this_cu
->length
= cu
->header
.get_length ();
6770 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6771 this_cu
->dwarf_version
= cu
->header
.version
;
6775 /* Skip dummy compilation units. */
6776 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6777 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6783 /* If we don't have them yet, read the abbrevs for this compilation unit.
6784 And if we need to read them now, make sure they're freed when we're
6786 if (abbrev_table
!= NULL
)
6787 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6790 abbrev_section
->read (objfile
);
6791 m_abbrev_table_holder
6792 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
6793 abbrev_table
= m_abbrev_table_holder
.get ();
6796 /* Read the top level CU/TU die. */
6797 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6798 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6800 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6806 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6807 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6808 table from the DWO file and pass the ownership over to us. It will be
6809 referenced from READER, so we must make sure to free it after we're done
6812 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6813 DWO CU, that this test will fail (the attribute will not be present). */
6814 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6815 if (dwo_name
!= nullptr)
6817 struct dwo_unit
*dwo_unit
;
6818 struct die_info
*dwo_comp_unit_die
;
6820 if (comp_unit_die
->has_children
)
6822 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6823 " has children (offset %s) [in module %s]"),
6824 sect_offset_str (this_cu
->sect_off
),
6825 bfd_get_filename (abfd
));
6827 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
6828 if (dwo_unit
!= NULL
)
6830 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
6831 comp_unit_die
, NULL
,
6834 &m_dwo_abbrev_table
) == 0)
6840 comp_unit_die
= dwo_comp_unit_die
;
6844 /* Yikes, we couldn't find the rest of the DIE, we only have
6845 the stub. A complaint has already been logged. There's
6846 not much more we can do except pass on the stub DIE to
6847 die_reader_func. We don't want to throw an error on bad
6854 cutu_reader::keep ()
6856 /* Done, clean up. */
6857 gdb_assert (!dummy_p
);
6858 if (m_new_cu
!= NULL
)
6860 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
6862 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
6863 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
6867 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6868 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6869 assumed to have already done the lookup to find the DWO file).
6871 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6872 THIS_CU->is_debug_types, but nothing else.
6874 We fill in THIS_CU->length.
6876 THIS_CU->cu is always freed when done.
6877 This is done in order to not leave THIS_CU->cu in a state where we have
6878 to care whether it refers to the "main" CU or the DWO CU.
6880 When parent_cu is passed, it is used to provide a default value for
6881 str_offsets_base and addr_base from the parent. */
6883 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
6884 dwarf2_per_objfile
*per_objfile
,
6885 struct dwarf2_cu
*parent_cu
,
6886 struct dwo_file
*dwo_file
)
6887 : die_reader_specs
{},
6890 struct objfile
*objfile
= per_objfile
->objfile
;
6891 struct dwarf2_section_info
*section
= this_cu
->section
;
6892 bfd
*abfd
= section
->get_bfd_owner ();
6893 struct dwarf2_section_info
*abbrev_section
;
6894 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6896 if (dwarf_die_debug
)
6897 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6898 this_cu
->is_debug_types
? "type" : "comp",
6899 sect_offset_str (this_cu
->sect_off
));
6901 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
6903 abbrev_section
= (dwo_file
!= NULL
6904 ? &dwo_file
->sections
.abbrev
6905 : get_abbrev_section_for_cu (this_cu
));
6907 /* This is cheap if the section is already read in. */
6908 section
->read (objfile
);
6910 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
6912 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6913 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
6914 section
, abbrev_section
, info_ptr
,
6915 (this_cu
->is_debug_types
6917 : rcuh_kind::COMPILE
));
6919 if (parent_cu
!= nullptr)
6921 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6922 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6924 this_cu
->length
= m_new_cu
->header
.get_length ();
6926 /* Skip dummy compilation units. */
6927 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6928 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6934 abbrev_section
->read (objfile
);
6935 m_abbrev_table_holder
6936 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
6938 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6939 m_abbrev_table_holder
.get ());
6940 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6944 /* Type Unit Groups.
6946 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6947 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6948 so that all types coming from the same compilation (.o file) are grouped
6949 together. A future step could be to put the types in the same symtab as
6950 the CU the types ultimately came from. */
6953 hash_type_unit_group (const void *item
)
6955 const struct type_unit_group
*tu_group
6956 = (const struct type_unit_group
*) item
;
6958 return hash_stmt_list_entry (&tu_group
->hash
);
6962 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6964 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6965 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
6967 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
6970 /* Allocate a hash table for type unit groups. */
6973 allocate_type_unit_groups_table ()
6975 return htab_up (htab_create_alloc (3,
6976 hash_type_unit_group
,
6980 type_unit_group
*grp
6981 = (type_unit_group
*) arg
;
6987 /* Type units that don't have DW_AT_stmt_list are grouped into their own
6988 partial symtabs. We combine several TUs per psymtab to not let the size
6989 of any one psymtab grow too big. */
6990 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
6991 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
6993 /* Helper routine for get_type_unit_group.
6994 Create the type_unit_group object used to hold one or more TUs. */
6996 static std::unique_ptr
<type_unit_group
>
6997 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
6999 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7000 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7002 std::unique_ptr
<type_unit_group
> tu_group (new type_unit_group
);
7003 tu_group
->per_bfd
= per_bfd
;
7005 if (per_bfd
->using_index
)
7007 tu_group
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7008 struct dwarf2_per_cu_quick_data
);
7012 unsigned int line_offset
= to_underlying (line_offset_struct
);
7013 dwarf2_psymtab
*pst
;
7016 /* Give the symtab a useful name for debug purposes. */
7017 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7018 name
= string_printf ("<type_units_%d>",
7019 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7021 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7023 pst
= create_partial_symtab (tu_group
.get (), per_objfile
,
7025 pst
->anonymous
= true;
7028 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7029 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7034 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7035 STMT_LIST is a DW_AT_stmt_list attribute. */
7037 static struct type_unit_group
*
7038 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7040 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7041 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7042 struct type_unit_group
*tu_group
;
7044 unsigned int line_offset
;
7045 struct type_unit_group type_unit_group_for_lookup
;
7047 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7048 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7050 /* Do we need to create a new group, or can we use an existing one? */
7052 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
7054 line_offset
= stmt_list
->as_unsigned ();
7055 ++tu_stats
->nr_symtab_sharers
;
7059 /* Ugh, no stmt_list. Rare, but we have to handle it.
7060 We can do various things here like create one group per TU or
7061 spread them over multiple groups to split up the expansion work.
7062 To avoid worst case scenarios (too many groups or too large groups)
7063 we, umm, group them in bunches. */
7064 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7065 | (tu_stats
->nr_stmt_less_type_units
7066 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7067 ++tu_stats
->nr_stmt_less_type_units
;
7070 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7071 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7072 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7073 &type_unit_group_for_lookup
, INSERT
);
7074 if (*slot
== nullptr)
7076 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7077 std::unique_ptr
<type_unit_group
> grp
7078 = create_type_unit_group (cu
, line_offset_struct
);
7079 *slot
= grp
.release ();
7080 ++tu_stats
->nr_symtabs
;
7083 tu_group
= (struct type_unit_group
*) *slot
;
7084 gdb_assert (tu_group
!= nullptr);
7088 /* Partial symbol tables. */
7090 /* Create a psymtab named NAME and assign it to PER_CU.
7092 The caller must fill in the following details:
7093 dirname, textlow, texthigh. */
7095 static dwarf2_psymtab
*
7096 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7097 dwarf2_per_objfile
*per_objfile
,
7101 = new dwarf2_psymtab (name
, per_objfile
->per_bfd
->partial_symtabs
.get (),
7102 per_objfile
->objfile
->per_bfd
, per_cu
);
7104 pst
->psymtabs_addrmap_supported
= true;
7106 /* This is the glue that links PST into GDB's symbol API. */
7107 per_cu
->v
.psymtab
= pst
;
7112 /* DIE reader function for process_psymtab_comp_unit. */
7115 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7116 const gdb_byte
*info_ptr
,
7117 struct die_info
*comp_unit_die
,
7118 enum language pretend_language
)
7120 struct dwarf2_cu
*cu
= reader
->cu
;
7121 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7122 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7123 struct objfile
*objfile
= per_objfile
->objfile
;
7124 struct gdbarch
*gdbarch
= objfile
->arch ();
7125 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7127 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7128 dwarf2_psymtab
*pst
;
7129 enum pc_bounds_kind cu_bounds_kind
;
7130 const char *filename
;
7132 gdb_assert (! per_cu
->is_debug_types
);
7134 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7136 /* Allocate a new partial symbol table structure. */
7137 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7138 static const char artificial
[] = "<artificial>";
7139 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7140 if (filename
== NULL
)
7142 else if (strcmp (filename
, artificial
) == 0)
7144 debug_filename
.reset (concat (artificial
, "@",
7145 sect_offset_str (per_cu
->sect_off
),
7147 filename
= debug_filename
.get ();
7150 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7152 /* This must be done before calling dwarf2_build_include_psymtabs. */
7153 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7155 baseaddr
= objfile
->text_section_offset ();
7157 dwarf2_find_base_address (comp_unit_die
, cu
);
7159 /* Possibly set the default values of LOWPC and HIGHPC from
7161 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7162 &best_highpc
, cu
, pst
);
7163 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7166 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7169 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7171 /* Store the contiguous range if it is not empty; it can be
7172 empty for CUs with no code. */
7173 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7177 /* Check if comp unit has_children.
7178 If so, read the rest of the partial symbols from this comp unit.
7179 If not, there's no more debug_info for this comp unit. */
7180 if (comp_unit_die
->has_children
)
7182 struct partial_die_info
*first_die
;
7183 CORE_ADDR lowpc
, highpc
;
7185 lowpc
= ((CORE_ADDR
) -1);
7186 highpc
= ((CORE_ADDR
) 0);
7188 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7190 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7191 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7193 /* If we didn't find a lowpc, set it to highpc to avoid
7194 complaints from `maint check'. */
7195 if (lowpc
== ((CORE_ADDR
) -1))
7198 /* If the compilation unit didn't have an explicit address range,
7199 then use the information extracted from its child dies. */
7200 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7203 best_highpc
= highpc
;
7206 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7207 best_lowpc
+ baseaddr
)
7209 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7210 best_highpc
+ baseaddr
)
7215 if (!cu
->per_cu
->imported_symtabs_empty ())
7218 int len
= cu
->per_cu
->imported_symtabs_size ();
7220 /* Fill in 'dependencies' here; we fill in 'users' in a
7222 pst
->number_of_dependencies
= len
;
7224 = per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7225 for (i
= 0; i
< len
; ++i
)
7227 pst
->dependencies
[i
]
7228 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7231 cu
->per_cu
->imported_symtabs_free ();
7234 /* Get the list of files included in the current compilation unit,
7235 and build a psymtab for each of them. */
7236 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7238 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7239 ", %d global, %d static syms",
7240 per_cu
->is_debug_types
? "type" : "comp",
7241 sect_offset_str (per_cu
->sect_off
),
7242 paddress (gdbarch
, pst
->text_low (objfile
)),
7243 paddress (gdbarch
, pst
->text_high (objfile
)),
7244 (int) pst
->global_psymbols
.size (),
7245 (int) pst
->static_psymbols
.size ());
7248 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7249 Process compilation unit THIS_CU for a psymtab. */
7252 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7253 dwarf2_per_objfile
*per_objfile
,
7254 bool want_partial_unit
,
7255 enum language pretend_language
)
7257 /* If this compilation unit was already read in, free the
7258 cached copy in order to read it in again. This is
7259 necessary because we skipped some symbols when we first
7260 read in the compilation unit (see load_partial_dies).
7261 This problem could be avoided, but the benefit is unclear. */
7262 per_objfile
->remove_cu (this_cu
);
7264 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7266 switch (reader
.comp_unit_die
->tag
)
7268 case DW_TAG_compile_unit
:
7269 this_cu
->unit_type
= DW_UT_compile
;
7271 case DW_TAG_partial_unit
:
7272 this_cu
->unit_type
= DW_UT_partial
;
7274 case DW_TAG_type_unit
:
7275 this_cu
->unit_type
= DW_UT_type
;
7278 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
7279 dwarf_tag_name (reader
.comp_unit_die
->tag
),
7280 sect_offset_str (reader
.cu
->per_cu
->sect_off
),
7281 objfile_name (per_objfile
->objfile
));
7288 else if (this_cu
->is_debug_types
)
7289 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7290 reader
.comp_unit_die
);
7291 else if (want_partial_unit
7292 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7293 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7294 reader
.comp_unit_die
,
7297 this_cu
->lang
= reader
.cu
->language
;
7299 /* Age out any secondary CUs. */
7300 per_objfile
->age_comp_units ();
7303 /* Reader function for build_type_psymtabs. */
7306 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7307 const gdb_byte
*info_ptr
,
7308 struct die_info
*type_unit_die
)
7310 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7311 struct dwarf2_cu
*cu
= reader
->cu
;
7312 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7313 struct signatured_type
*sig_type
;
7314 struct type_unit_group
*tu_group
;
7315 struct attribute
*attr
;
7316 struct partial_die_info
*first_die
;
7317 CORE_ADDR lowpc
, highpc
;
7318 dwarf2_psymtab
*pst
;
7320 gdb_assert (per_cu
->is_debug_types
);
7321 sig_type
= (struct signatured_type
*) per_cu
;
7323 if (! type_unit_die
->has_children
)
7326 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7327 tu_group
= get_type_unit_group (cu
, attr
);
7329 if (tu_group
->tus
== nullptr)
7330 tu_group
->tus
= new std::vector
<signatured_type
*>;
7331 tu_group
->tus
->push_back (sig_type
);
7333 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7334 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7335 pst
->anonymous
= true;
7337 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7339 lowpc
= (CORE_ADDR
) -1;
7340 highpc
= (CORE_ADDR
) 0;
7341 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7346 /* Struct used to sort TUs by their abbreviation table offset. */
7348 struct tu_abbrev_offset
7350 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7351 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7354 signatured_type
*sig_type
;
7355 sect_offset abbrev_offset
;
7358 /* Helper routine for build_type_psymtabs, passed to std::sort. */
7361 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7362 const struct tu_abbrev_offset
&b
)
7364 return a
.abbrev_offset
< b
.abbrev_offset
;
7367 /* Efficiently read all the type units.
7369 The efficiency is because we sort TUs by the abbrev table they use and
7370 only read each abbrev table once. In one program there are 200K TUs
7371 sharing 8K abbrev tables.
7373 The main purpose of this function is to support building the
7374 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7375 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7376 can collapse the search space by grouping them by stmt_list.
7377 The savings can be significant, in the same program from above the 200K TUs
7378 share 8K stmt_list tables.
7380 FUNC is expected to call get_type_unit_group, which will create the
7381 struct type_unit_group if necessary and add it to
7382 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7385 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7387 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7388 abbrev_table_up abbrev_table
;
7389 sect_offset abbrev_offset
;
7391 /* It's up to the caller to not call us multiple times. */
7392 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7394 if (per_objfile
->per_bfd
->tu_stats
.nr_tus
== 0)
7397 /* TUs typically share abbrev tables, and there can be way more TUs than
7398 abbrev tables. Sort by abbrev table to reduce the number of times we
7399 read each abbrev table in.
7400 Alternatives are to punt or to maintain a cache of abbrev tables.
7401 This is simpler and efficient enough for now.
7403 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7404 symtab to use). Typically TUs with the same abbrev offset have the same
7405 stmt_list value too so in practice this should work well.
7407 The basic algorithm here is:
7409 sort TUs by abbrev table
7410 for each TU with same abbrev table:
7411 read abbrev table if first user
7412 read TU top level DIE
7413 [IWBN if DWO skeletons had DW_AT_stmt_list]
7416 dwarf_read_debug_printf ("Building type unit groups ...");
7418 /* Sort in a separate table to maintain the order of all_comp_units
7419 for .gdb_index: TU indices directly index all_type_units. */
7420 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7421 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->tu_stats
.nr_tus
);
7423 for (const auto &cu
: per_objfile
->per_bfd
->all_comp_units
)
7425 if (cu
->is_debug_types
)
7427 auto sig_type
= static_cast<signatured_type
*> (cu
.get ());
7428 sorted_by_abbrev
.emplace_back
7429 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->section
,
7430 sig_type
->sect_off
));
7434 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7435 sort_tu_by_abbrev_offset
);
7437 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7439 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7441 /* Switch to the next abbrev table if necessary. */
7442 if (abbrev_table
== NULL
7443 || tu
.abbrev_offset
!= abbrev_offset
)
7445 abbrev_offset
= tu
.abbrev_offset
;
7446 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7448 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7449 ++tu_stats
->nr_uniq_abbrev_tables
;
7452 cutu_reader
reader (tu
.sig_type
, per_objfile
,
7453 abbrev_table
.get (), nullptr, false);
7454 if (!reader
.dummy_p
)
7455 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7456 reader
.comp_unit_die
);
7460 /* Print collected type unit statistics. */
7463 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7465 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7467 dwarf_read_debug_printf ("Type unit statistics:");
7468 dwarf_read_debug_printf (" %d TUs", tu_stats
->nr_tus
);
7469 dwarf_read_debug_printf (" %d uniq abbrev tables",
7470 tu_stats
->nr_uniq_abbrev_tables
);
7471 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7472 tu_stats
->nr_symtabs
);
7473 dwarf_read_debug_printf (" %d symtab sharers",
7474 tu_stats
->nr_symtab_sharers
);
7475 dwarf_read_debug_printf (" %d type units without a stmt_list",
7476 tu_stats
->nr_stmt_less_type_units
);
7477 dwarf_read_debug_printf (" %d all_type_units reallocs",
7478 tu_stats
->nr_all_type_units_reallocs
);
7481 /* Traversal function for build_type_psymtabs. */
7484 build_type_psymtab_dependencies (void **slot
, void *info
)
7486 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7487 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7488 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7489 dwarf2_psymtab
*pst
= tu_group
->v
.psymtab
;
7490 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7493 gdb_assert (len
> 0);
7494 gdb_assert (tu_group
->type_unit_group_p ());
7496 pst
->number_of_dependencies
= len
;
7497 pst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7498 for (i
= 0; i
< len
; ++i
)
7500 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7501 gdb_assert (iter
->is_debug_types
);
7502 pst
->dependencies
[i
] = iter
->v
.psymtab
;
7503 iter
->type_unit_group
= tu_group
;
7506 delete tu_group
->tus
;
7507 tu_group
->tus
= nullptr;
7512 /* Traversal function for process_skeletonless_type_unit.
7513 Read a TU in a DWO file and build partial symbols for it. */
7516 process_skeletonless_type_unit (void **slot
, void *info
)
7518 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7519 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7520 struct signatured_type find_entry
, *entry
;
7522 /* If this TU doesn't exist in the global table, add it and read it in. */
7524 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7525 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7527 find_entry
.signature
= dwo_unit
->signature
;
7528 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7529 &find_entry
, INSERT
);
7530 /* If we've already seen this type there's nothing to do. What's happening
7531 is we're doing our own version of comdat-folding here. */
7535 /* This does the job that create_all_comp_units would have done for
7537 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7538 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7541 /* This does the job that build_type_psymtabs would have done. */
7542 cutu_reader
reader (entry
, per_objfile
, nullptr, nullptr, false);
7543 if (!reader
.dummy_p
)
7544 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7545 reader
.comp_unit_die
);
7550 /* Traversal function for process_skeletonless_type_units. */
7553 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7555 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7557 if (dwo_file
->tus
!= NULL
)
7558 htab_traverse_noresize (dwo_file
->tus
.get (),
7559 process_skeletonless_type_unit
, info
);
7564 /* Scan all TUs of DWO files, verifying we've processed them.
7565 This is needed in case a TU was emitted without its skeleton.
7566 Note: This can't be done until we know what all the DWO files are. */
7569 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
7571 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7572 if (get_dwp_file (per_objfile
) == NULL
7573 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
7575 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
7576 process_dwo_file_for_skeletonless_type_units
,
7581 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7584 set_partial_user (dwarf2_per_objfile
*per_objfile
)
7586 for (const auto &per_cu
: per_objfile
->per_bfd
->all_comp_units
)
7588 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7593 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7595 /* Set the 'user' field only if it is not already set. */
7596 if (pst
->dependencies
[j
]->user
== NULL
)
7597 pst
->dependencies
[j
]->user
= pst
;
7602 /* Build the partial symbol table by doing a quick pass through the
7603 .debug_info and .debug_abbrev sections. */
7606 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
7608 struct objfile
*objfile
= per_objfile
->objfile
;
7609 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7611 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
7612 objfile_name (objfile
));
7614 scoped_restore restore_reading_psyms
7615 = make_scoped_restore (&per_bfd
->reading_partial_symbols
, true);
7617 per_bfd
->info
.read (objfile
);
7619 /* Any cached compilation units will be linked by the per-objfile
7620 read_in_chain. Make sure to free them when we're done. */
7621 free_cached_comp_units
freer (per_objfile
);
7623 create_all_comp_units (per_objfile
);
7624 build_type_psymtabs (per_objfile
);
7626 /* Create a temporary address map on a temporary obstack. We later
7627 copy this to the final obstack. */
7628 auto_obstack temp_obstack
;
7630 scoped_restore save_psymtabs_addrmap
7631 = make_scoped_restore (&per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7632 addrmap_create_mutable (&temp_obstack
));
7634 for (const auto &per_cu
: per_bfd
->all_comp_units
)
7636 if (per_cu
->v
.psymtab
!= NULL
)
7637 /* In case a forward DW_TAG_imported_unit has read the CU already. */
7639 process_psymtab_comp_unit (per_cu
.get (), per_objfile
, false,
7643 /* This has to wait until we read the CUs, we need the list of DWOs. */
7644 process_skeletonless_type_units (per_objfile
);
7646 /* Now that all TUs have been processed we can fill in the dependencies. */
7647 if (per_bfd
->type_unit_groups
!= NULL
)
7649 htab_traverse_noresize (per_bfd
->type_unit_groups
.get (),
7650 build_type_psymtab_dependencies
, per_objfile
);
7653 if (dwarf_read_debug
> 0)
7654 print_tu_stats (per_objfile
);
7656 set_partial_user (per_objfile
);
7658 per_bfd
->partial_symtabs
->psymtabs_addrmap
7659 = addrmap_create_fixed (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7660 per_bfd
->partial_symtabs
->obstack ());
7661 /* At this point we want to keep the address map. */
7662 save_psymtabs_addrmap
.release ();
7664 dwarf_read_debug_printf ("Done building psymtabs of %s",
7665 objfile_name (objfile
));
7668 /* Load the partial DIEs for a secondary CU into memory.
7669 This is also used when rereading a primary CU with load_all_dies. */
7672 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
7673 dwarf2_per_objfile
*per_objfile
,
7674 dwarf2_cu
*existing_cu
)
7676 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
7678 if (!reader
.dummy_p
)
7680 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7683 /* Check if comp unit has_children.
7684 If so, read the rest of the partial symbols from this comp unit.
7685 If not, there's no more debug_info for this comp unit. */
7686 if (reader
.comp_unit_die
->has_children
)
7687 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7694 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
7695 struct dwarf2_section_info
*section
,
7696 struct dwarf2_section_info
*abbrev_section
,
7697 unsigned int is_dwz
,
7698 htab_up
&types_htab
,
7699 rcuh_kind section_kind
)
7701 const gdb_byte
*info_ptr
;
7702 struct objfile
*objfile
= per_objfile
->objfile
;
7704 dwarf_read_debug_printf ("Reading %s for %s",
7705 section
->get_name (),
7706 section
->get_file_name ());
7708 section
->read (objfile
);
7710 info_ptr
= section
->buffer
;
7712 while (info_ptr
< section
->buffer
+ section
->size
)
7714 std::unique_ptr
<dwarf2_per_cu_data
> this_cu
;
7716 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7718 comp_unit_head cu_header
;
7719 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
7720 abbrev_section
, info_ptr
,
7723 /* Save the compilation unit for later lookup. */
7724 if (cu_header
.unit_type
!= DW_UT_type
)
7725 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
7728 if (types_htab
== nullptr)
7729 types_htab
= allocate_signatured_type_table ();
7731 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
7732 signatured_type
*sig_ptr
= sig_type
.get ();
7733 sig_type
->signature
= cu_header
.signature
;
7734 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7735 this_cu
= std::move (sig_type
);
7737 void **slot
= htab_find_slot (types_htab
.get (), sig_ptr
, INSERT
);
7738 gdb_assert (slot
!= nullptr);
7739 if (*slot
!= nullptr)
7740 complaint (_("debug type entry at offset %s is duplicate to"
7741 " the entry at offset %s, signature %s"),
7742 sect_offset_str (sect_off
),
7743 sect_offset_str (sig_ptr
->sect_off
),
7744 hex_string (sig_ptr
->signature
));
7747 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7748 this_cu
->sect_off
= sect_off
;
7749 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7750 this_cu
->is_dwz
= is_dwz
;
7751 this_cu
->section
= section
;
7753 info_ptr
= info_ptr
+ this_cu
->length
;
7754 per_objfile
->per_bfd
->all_comp_units
.push_back (std::move (this_cu
));
7758 /* Create a list of all compilation units in OBJFILE.
7759 This is only done for -readnow and building partial symtabs. */
7762 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
7766 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
7767 &per_objfile
->per_bfd
->abbrev
, 0,
7768 types_htab
, rcuh_kind::COMPILE
);
7769 for (dwarf2_section_info
§ion
: per_objfile
->per_bfd
->types
)
7770 read_comp_units_from_section (per_objfile
, §ion
,
7771 &per_objfile
->per_bfd
->abbrev
, 0,
7772 types_htab
, rcuh_kind::TYPE
);
7774 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
7776 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1,
7777 types_htab
, rcuh_kind::COMPILE
);
7779 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
7782 /* Process all loaded DIEs for compilation unit CU, starting at
7783 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7784 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7785 DW_AT_ranges). See the comments of add_partial_subprogram on how
7786 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7789 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7790 CORE_ADDR
*highpc
, int set_addrmap
,
7791 struct dwarf2_cu
*cu
)
7793 struct partial_die_info
*pdi
;
7795 /* Now, march along the PDI's, descending into ones which have
7796 interesting children but skipping the children of the other ones,
7797 until we reach the end of the compilation unit. */
7805 /* Anonymous namespaces or modules have no name but have interesting
7806 children, so we need to look at them. Ditto for anonymous
7809 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7810 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7811 || pdi
->tag
== DW_TAG_imported_unit
7812 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7816 case DW_TAG_subprogram
:
7817 case DW_TAG_inlined_subroutine
:
7818 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7819 if (cu
->language
== language_cplus
)
7820 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7823 case DW_TAG_constant
:
7824 case DW_TAG_variable
:
7825 case DW_TAG_typedef
:
7826 case DW_TAG_union_type
:
7827 if (!pdi
->is_declaration
7828 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
7830 add_partial_symbol (pdi
, cu
);
7833 case DW_TAG_class_type
:
7834 case DW_TAG_interface_type
:
7835 case DW_TAG_structure_type
:
7836 if (!pdi
->is_declaration
)
7838 add_partial_symbol (pdi
, cu
);
7840 if ((cu
->language
== language_rust
7841 || cu
->language
== language_cplus
) && pdi
->has_children
)
7842 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7845 case DW_TAG_enumeration_type
:
7846 if (!pdi
->is_declaration
)
7847 add_partial_enumeration (pdi
, cu
);
7849 case DW_TAG_base_type
:
7850 case DW_TAG_subrange_type
:
7851 /* File scope base type definitions are added to the partial
7853 add_partial_symbol (pdi
, cu
);
7855 case DW_TAG_namespace
:
7856 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7859 if (!pdi
->is_declaration
)
7860 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7862 case DW_TAG_imported_unit
:
7864 struct dwarf2_per_cu_data
*per_cu
;
7866 /* For now we don't handle imported units in type units. */
7867 if (cu
->per_cu
->is_debug_types
)
7869 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7870 " supported in type units [in module %s]"),
7871 objfile_name (cu
->per_objfile
->objfile
));
7874 per_cu
= dwarf2_find_containing_comp_unit
7875 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
7877 /* Go read the partial unit, if needed. */
7878 if (per_cu
->v
.psymtab
== NULL
)
7879 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
7882 cu
->per_cu
->imported_symtabs_push (per_cu
);
7885 case DW_TAG_imported_declaration
:
7886 add_partial_symbol (pdi
, cu
);
7893 /* If the die has a sibling, skip to the sibling. */
7895 pdi
= pdi
->die_sibling
;
7899 /* Functions used to compute the fully scoped name of a partial DIE.
7901 Normally, this is simple. For C++, the parent DIE's fully scoped
7902 name is concatenated with "::" and the partial DIE's name.
7903 Enumerators are an exception; they use the scope of their parent
7904 enumeration type, i.e. the name of the enumeration type is not
7905 prepended to the enumerator.
7907 There are two complexities. One is DW_AT_specification; in this
7908 case "parent" means the parent of the target of the specification,
7909 instead of the direct parent of the DIE. The other is compilers
7910 which do not emit DW_TAG_namespace; in this case we try to guess
7911 the fully qualified name of structure types from their members'
7912 linkage names. This must be done using the DIE's children rather
7913 than the children of any DW_AT_specification target. We only need
7914 to do this for structures at the top level, i.e. if the target of
7915 any DW_AT_specification (if any; otherwise the DIE itself) does not
7918 /* Compute the scope prefix associated with PDI's parent, in
7919 compilation unit CU. The result will be allocated on CU's
7920 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7921 field. NULL is returned if no prefix is necessary. */
7923 partial_die_parent_scope (struct partial_die_info
*pdi
,
7924 struct dwarf2_cu
*cu
)
7926 const char *grandparent_scope
;
7927 struct partial_die_info
*parent
, *real_pdi
;
7929 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7930 then this means the parent of the specification DIE. */
7933 while (real_pdi
->has_specification
)
7935 auto res
= find_partial_die (real_pdi
->spec_offset
,
7936 real_pdi
->spec_is_dwz
, cu
);
7941 parent
= real_pdi
->die_parent
;
7945 if (parent
->scope_set
)
7946 return parent
->scope
;
7950 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7952 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7953 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7954 Work around this problem here. */
7955 if (cu
->language
== language_cplus
7956 && parent
->tag
== DW_TAG_namespace
7957 && strcmp (parent
->name (cu
), "::") == 0
7958 && grandparent_scope
== NULL
)
7960 parent
->scope
= NULL
;
7961 parent
->scope_set
= 1;
7965 /* Nested subroutines in Fortran get a prefix. */
7966 if (pdi
->tag
== DW_TAG_enumerator
)
7967 /* Enumerators should not get the name of the enumeration as a prefix. */
7968 parent
->scope
= grandparent_scope
;
7969 else if (parent
->tag
== DW_TAG_namespace
7970 || parent
->tag
== DW_TAG_module
7971 || parent
->tag
== DW_TAG_structure_type
7972 || parent
->tag
== DW_TAG_class_type
7973 || parent
->tag
== DW_TAG_interface_type
7974 || parent
->tag
== DW_TAG_union_type
7975 || parent
->tag
== DW_TAG_enumeration_type
7976 || (cu
->language
== language_fortran
7977 && parent
->tag
== DW_TAG_subprogram
7978 && pdi
->tag
== DW_TAG_subprogram
))
7980 if (grandparent_scope
== NULL
)
7981 parent
->scope
= parent
->name (cu
);
7983 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
7985 parent
->name (cu
), 0, cu
);
7989 /* FIXME drow/2004-04-01: What should we be doing with
7990 function-local names? For partial symbols, we should probably be
7992 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
7993 dwarf_tag_name (parent
->tag
),
7994 sect_offset_str (pdi
->sect_off
));
7995 parent
->scope
= grandparent_scope
;
7998 parent
->scope_set
= 1;
7999 return parent
->scope
;
8002 /* Return the fully scoped name associated with PDI, from compilation unit
8003 CU. The result will be allocated with malloc. */
8005 static gdb::unique_xmalloc_ptr
<char>
8006 partial_die_full_name (struct partial_die_info
*pdi
,
8007 struct dwarf2_cu
*cu
)
8009 const char *parent_scope
;
8011 /* If this is a template instantiation, we can not work out the
8012 template arguments from partial DIEs. So, unfortunately, we have
8013 to go through the full DIEs. At least any work we do building
8014 types here will be reused if full symbols are loaded later. */
8015 if (pdi
->has_template_arguments
)
8019 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8021 struct die_info
*die
;
8022 struct attribute attr
;
8023 struct dwarf2_cu
*ref_cu
= cu
;
8025 /* DW_FORM_ref_addr is using section offset. */
8026 attr
.name
= (enum dwarf_attribute
) 0;
8027 attr
.form
= DW_FORM_ref_addr
;
8028 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8029 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8031 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8035 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8036 if (parent_scope
== NULL
)
8039 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8045 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8047 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8048 struct objfile
*objfile
= per_objfile
->objfile
;
8049 struct gdbarch
*gdbarch
= objfile
->arch ();
8051 const char *actual_name
= NULL
;
8054 baseaddr
= objfile
->text_section_offset ();
8056 gdb::unique_xmalloc_ptr
<char> built_actual_name
8057 = partial_die_full_name (pdi
, cu
);
8058 if (built_actual_name
!= NULL
)
8059 actual_name
= built_actual_name
.get ();
8061 if (actual_name
== NULL
)
8062 actual_name
= pdi
->name (cu
);
8064 partial_symbol psymbol
;
8065 memset (&psymbol
, 0, sizeof (psymbol
));
8066 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8067 psymbol
.ginfo
.set_section_index (-1);
8069 /* The code below indicates that the psymbol should be installed by
8071 gdb::optional
<psymbol_placement
> where
;
8075 case DW_TAG_inlined_subroutine
:
8076 case DW_TAG_subprogram
:
8077 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8079 if (pdi
->is_external
8080 || cu
->language
== language_ada
8081 || (cu
->language
== language_fortran
8082 && pdi
->die_parent
!= NULL
8083 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8085 /* Normally, only "external" DIEs are part of the global scope.
8086 But in Ada and Fortran, we want to be able to access nested
8087 procedures globally. So all Ada and Fortran subprograms are
8088 stored in the global scope. */
8089 where
= psymbol_placement::GLOBAL
;
8092 where
= psymbol_placement::STATIC
;
8094 psymbol
.domain
= VAR_DOMAIN
;
8095 psymbol
.aclass
= LOC_BLOCK
;
8096 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8097 psymbol
.ginfo
.value
.address
= addr
;
8099 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8100 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8102 case DW_TAG_constant
:
8103 psymbol
.domain
= VAR_DOMAIN
;
8104 psymbol
.aclass
= LOC_STATIC
;
8105 where
= (pdi
->is_external
8106 ? psymbol_placement::GLOBAL
8107 : psymbol_placement::STATIC
);
8109 case DW_TAG_variable
:
8111 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8115 && !per_objfile
->per_bfd
->has_section_at_zero
)
8117 /* A global or static variable may also have been stripped
8118 out by the linker if unused, in which case its address
8119 will be nullified; do not add such variables into partial
8120 symbol table then. */
8122 else if (pdi
->is_external
)
8125 Don't enter into the minimal symbol tables as there is
8126 a minimal symbol table entry from the ELF symbols already.
8127 Enter into partial symbol table if it has a location
8128 descriptor or a type.
8129 If the location descriptor is missing, new_symbol will create
8130 a LOC_UNRESOLVED symbol, the address of the variable will then
8131 be determined from the minimal symbol table whenever the variable
8133 The address for the partial symbol table entry is not
8134 used by GDB, but it comes in handy for debugging partial symbol
8137 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8139 psymbol
.domain
= VAR_DOMAIN
;
8140 psymbol
.aclass
= LOC_STATIC
;
8141 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8142 psymbol
.ginfo
.value
.address
= addr
;
8143 where
= psymbol_placement::GLOBAL
;
8148 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8150 /* Static Variable. Skip symbols whose value we cannot know (those
8151 without location descriptors or constant values). */
8152 if (!has_loc
&& !pdi
->has_const_value
)
8155 psymbol
.domain
= VAR_DOMAIN
;
8156 psymbol
.aclass
= LOC_STATIC
;
8157 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8159 psymbol
.ginfo
.value
.address
= addr
;
8160 where
= psymbol_placement::STATIC
;
8163 case DW_TAG_array_type
:
8164 case DW_TAG_typedef
:
8165 case DW_TAG_base_type
:
8166 case DW_TAG_subrange_type
:
8167 psymbol
.domain
= VAR_DOMAIN
;
8168 psymbol
.aclass
= LOC_TYPEDEF
;
8169 where
= psymbol_placement::STATIC
;
8171 case DW_TAG_imported_declaration
:
8172 case DW_TAG_namespace
:
8173 psymbol
.domain
= VAR_DOMAIN
;
8174 psymbol
.aclass
= LOC_TYPEDEF
;
8175 where
= psymbol_placement::GLOBAL
;
8178 /* With Fortran 77 there might be a "BLOCK DATA" module
8179 available without any name. If so, we skip the module as it
8180 doesn't bring any value. */
8181 if (actual_name
!= nullptr)
8183 psymbol
.domain
= MODULE_DOMAIN
;
8184 psymbol
.aclass
= LOC_TYPEDEF
;
8185 where
= psymbol_placement::GLOBAL
;
8188 case DW_TAG_class_type
:
8189 case DW_TAG_interface_type
:
8190 case DW_TAG_structure_type
:
8191 case DW_TAG_union_type
:
8192 case DW_TAG_enumeration_type
:
8193 /* Skip external references. The DWARF standard says in the section
8194 about "Structure, Union, and Class Type Entries": "An incomplete
8195 structure, union or class type is represented by a structure,
8196 union or class entry that does not have a byte size attribute
8197 and that has a DW_AT_declaration attribute." */
8198 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8201 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8202 static vs. global. */
8203 psymbol
.domain
= STRUCT_DOMAIN
;
8204 psymbol
.aclass
= LOC_TYPEDEF
;
8205 where
= (cu
->language
== language_cplus
8206 ? psymbol_placement::GLOBAL
8207 : psymbol_placement::STATIC
);
8209 case DW_TAG_enumerator
:
8210 psymbol
.domain
= VAR_DOMAIN
;
8211 psymbol
.aclass
= LOC_CONST
;
8212 where
= (cu
->language
== language_cplus
8213 ? psymbol_placement::GLOBAL
8214 : psymbol_placement::STATIC
);
8220 if (where
.has_value ())
8222 if (built_actual_name
!= nullptr)
8223 actual_name
= objfile
->intern (actual_name
);
8224 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8225 psymbol
.ginfo
.set_linkage_name (actual_name
);
8228 psymbol
.ginfo
.set_demangled_name (actual_name
,
8229 &objfile
->objfile_obstack
);
8230 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8232 cu
->per_cu
->v
.psymtab
->add_psymbol
8233 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
8238 /* Read a partial die corresponding to a namespace; also, add a symbol
8239 corresponding to that namespace to the symbol table. NAMESPACE is
8240 the name of the enclosing namespace. */
8243 add_partial_namespace (struct partial_die_info
*pdi
,
8244 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8245 int set_addrmap
, struct dwarf2_cu
*cu
)
8247 /* Add a symbol for the namespace. */
8249 add_partial_symbol (pdi
, cu
);
8251 /* Now scan partial symbols in that namespace. */
8253 if (pdi
->has_children
)
8254 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8257 /* Read a partial die corresponding to a Fortran module. */
8260 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8261 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8263 /* Add a symbol for the namespace. */
8265 add_partial_symbol (pdi
, cu
);
8267 /* Now scan partial symbols in that module. */
8269 if (pdi
->has_children
)
8270 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8273 /* Read a partial die corresponding to a subprogram or an inlined
8274 subprogram and create a partial symbol for that subprogram.
8275 When the CU language allows it, this routine also defines a partial
8276 symbol for each nested subprogram that this subprogram contains.
8277 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8278 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8280 PDI may also be a lexical block, in which case we simply search
8281 recursively for subprograms defined inside that lexical block.
8282 Again, this is only performed when the CU language allows this
8283 type of definitions. */
8286 add_partial_subprogram (struct partial_die_info
*pdi
,
8287 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8288 int set_addrmap
, struct dwarf2_cu
*cu
)
8290 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8292 if (pdi
->has_pc_info
)
8294 if (pdi
->lowpc
< *lowpc
)
8295 *lowpc
= pdi
->lowpc
;
8296 if (pdi
->highpc
> *highpc
)
8297 *highpc
= pdi
->highpc
;
8300 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8301 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8302 struct gdbarch
*gdbarch
= objfile
->arch ();
8304 CORE_ADDR this_highpc
;
8305 CORE_ADDR this_lowpc
;
8307 baseaddr
= objfile
->text_section_offset ();
8309 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8310 pdi
->lowpc
+ baseaddr
)
8313 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8314 pdi
->highpc
+ baseaddr
)
8316 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8317 this_lowpc
, this_highpc
- 1,
8318 cu
->per_cu
->v
.psymtab
);
8322 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8324 if (!pdi
->is_declaration
)
8325 /* Ignore subprogram DIEs that do not have a name, they are
8326 illegal. Do not emit a complaint at this point, we will
8327 do so when we convert this psymtab into a symtab. */
8329 add_partial_symbol (pdi
, cu
);
8333 if (! pdi
->has_children
)
8336 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8338 pdi
= pdi
->die_child
;
8342 if (pdi
->tag
== DW_TAG_subprogram
8343 || pdi
->tag
== DW_TAG_inlined_subroutine
8344 || pdi
->tag
== DW_TAG_lexical_block
)
8345 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8346 pdi
= pdi
->die_sibling
;
8351 /* Read a partial die corresponding to an enumeration type. */
8354 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8355 struct dwarf2_cu
*cu
)
8357 struct partial_die_info
*pdi
;
8359 if (enum_pdi
->name (cu
) != NULL
)
8360 add_partial_symbol (enum_pdi
, cu
);
8362 pdi
= enum_pdi
->die_child
;
8365 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8366 complaint (_("malformed enumerator DIE ignored"));
8368 add_partial_symbol (pdi
, cu
);
8369 pdi
= pdi
->die_sibling
;
8373 /* Return the initial uleb128 in the die at INFO_PTR. */
8376 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8378 unsigned int bytes_read
;
8380 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8383 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8384 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8386 Return the corresponding abbrev, or NULL if the number is zero (indicating
8387 an empty DIE). In either case *BYTES_READ will be set to the length of
8388 the initial number. */
8390 static const struct abbrev_info
*
8391 peek_die_abbrev (const die_reader_specs
&reader
,
8392 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8394 dwarf2_cu
*cu
= reader
.cu
;
8395 bfd
*abfd
= reader
.abfd
;
8396 unsigned int abbrev_number
8397 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8399 if (abbrev_number
== 0)
8402 const abbrev_info
*abbrev
8403 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8406 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8407 " at offset %s [in module %s]"),
8408 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8409 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8415 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8416 Returns a pointer to the end of a series of DIEs, terminated by an empty
8417 DIE. Any children of the skipped DIEs will also be skipped. */
8419 static const gdb_byte
*
8420 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8424 unsigned int bytes_read
;
8425 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8429 return info_ptr
+ bytes_read
;
8431 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8435 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8436 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8437 abbrev corresponding to that skipped uleb128 should be passed in
8438 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8441 static const gdb_byte
*
8442 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8443 const struct abbrev_info
*abbrev
)
8445 unsigned int bytes_read
;
8446 struct attribute attr
;
8447 bfd
*abfd
= reader
->abfd
;
8448 struct dwarf2_cu
*cu
= reader
->cu
;
8449 const gdb_byte
*buffer
= reader
->buffer
;
8450 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8451 unsigned int form
, i
;
8453 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8455 /* The only abbrev we care about is DW_AT_sibling. */
8456 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8458 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8459 if (attr
.form
== DW_FORM_ref_addr
)
8460 complaint (_("ignoring absolute DW_AT_sibling"));
8463 sect_offset off
= attr
.get_ref_die_offset ();
8464 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8466 if (sibling_ptr
< info_ptr
)
8467 complaint (_("DW_AT_sibling points backwards"));
8468 else if (sibling_ptr
> reader
->buffer_end
)
8469 reader
->die_section
->overflow_complaint ();
8475 /* If it isn't DW_AT_sibling, skip this attribute. */
8476 form
= abbrev
->attrs
[i
].form
;
8480 case DW_FORM_ref_addr
:
8481 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8482 and later it is offset sized. */
8483 if (cu
->header
.version
== 2)
8484 info_ptr
+= cu
->header
.addr_size
;
8486 info_ptr
+= cu
->header
.offset_size
;
8488 case DW_FORM_GNU_ref_alt
:
8489 info_ptr
+= cu
->header
.offset_size
;
8492 info_ptr
+= cu
->header
.addr_size
;
8500 case DW_FORM_flag_present
:
8501 case DW_FORM_implicit_const
:
8518 case DW_FORM_ref_sig8
:
8521 case DW_FORM_data16
:
8524 case DW_FORM_string
:
8525 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8526 info_ptr
+= bytes_read
;
8528 case DW_FORM_sec_offset
:
8530 case DW_FORM_GNU_strp_alt
:
8531 info_ptr
+= cu
->header
.offset_size
;
8533 case DW_FORM_exprloc
:
8535 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8536 info_ptr
+= bytes_read
;
8538 case DW_FORM_block1
:
8539 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8541 case DW_FORM_block2
:
8542 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8544 case DW_FORM_block4
:
8545 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8551 case DW_FORM_ref_udata
:
8552 case DW_FORM_GNU_addr_index
:
8553 case DW_FORM_GNU_str_index
:
8554 case DW_FORM_rnglistx
:
8555 case DW_FORM_loclistx
:
8556 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8558 case DW_FORM_indirect
:
8559 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8560 info_ptr
+= bytes_read
;
8561 /* We need to continue parsing from here, so just go back to
8563 goto skip_attribute
;
8566 error (_("Dwarf Error: Cannot handle %s "
8567 "in DWARF reader [in module %s]"),
8568 dwarf_form_name (form
),
8569 bfd_get_filename (abfd
));
8573 if (abbrev
->has_children
)
8574 return skip_children (reader
, info_ptr
);
8579 /* Locate ORIG_PDI's sibling.
8580 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8582 static const gdb_byte
*
8583 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8584 struct partial_die_info
*orig_pdi
,
8585 const gdb_byte
*info_ptr
)
8587 /* Do we know the sibling already? */
8589 if (orig_pdi
->sibling
)
8590 return orig_pdi
->sibling
;
8592 /* Are there any children to deal with? */
8594 if (!orig_pdi
->has_children
)
8597 /* Skip the children the long way. */
8599 return skip_children (reader
, info_ptr
);
8602 /* Expand this partial symbol table into a full symbol table. SELF is
8606 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8608 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8610 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
8612 /* If this psymtab is constructed from a debug-only objfile, the
8613 has_section_at_zero flag will not necessarily be correct. We
8614 can get the correct value for this flag by looking at the data
8615 associated with the (presumably stripped) associated objfile. */
8616 if (objfile
->separate_debug_objfile_backlink
)
8618 dwarf2_per_objfile
*per_objfile_backlink
8619 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8621 per_objfile
->per_bfd
->has_section_at_zero
8622 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
8625 expand_psymtab (objfile
);
8627 process_cu_includes (per_objfile
);
8630 /* Reading in full CUs. */
8632 /* Add PER_CU to the queue. */
8635 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
8636 dwarf2_per_objfile
*per_objfile
,
8637 enum language pretend_language
)
8641 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
8642 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
8645 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
8647 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8650 Return true if maybe_queue_comp_unit requires the caller to load the CU's
8651 DIEs, false otherwise.
8653 Explanation: there is an invariant that if a CU is queued for expansion
8654 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
8655 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
8656 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
8657 are not yet loaded, the the caller must load the CU's DIEs to ensure the
8658 invariant is respected.
8660 The caller is therefore not required to load the CU's DIEs (we return false)
8663 - the CU is already expanded, and therefore does not get enqueued
8664 - the CU gets enqueued for expansion, but its DIEs are already loaded
8666 Note that the caller should not use this function's return value as an
8667 indicator of whether the CU's DIEs are loaded right now, it should check
8668 that by calling `dwarf2_per_objfile::get_cu` instead. */
8671 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8672 dwarf2_per_cu_data
*per_cu
,
8673 dwarf2_per_objfile
*per_objfile
,
8674 enum language pretend_language
)
8676 /* We may arrive here during partial symbol reading, if we need full
8677 DIEs to process an unusual case (e.g. template arguments). Do
8678 not queue PER_CU, just tell our caller to load its DIEs. */
8679 if (per_cu
->per_bfd
->reading_partial_symbols
)
8681 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8683 if (cu
== NULL
|| cu
->dies
== NULL
)
8688 /* Mark the dependence relation so that we don't flush PER_CU
8690 if (dependent_cu
!= NULL
)
8691 dwarf2_add_dependence (dependent_cu
, per_cu
);
8693 /* If it's already on the queue, we have nothing to do. */
8696 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
8698 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
8700 /* If the CU is queued for expansion, it should not already be
8702 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
8704 /* The DIEs are already loaded, the caller doesn't need to do it. */
8708 bool queued
= false;
8709 if (!per_objfile
->symtab_set_p (per_cu
))
8711 /* Add it to the queue. */
8712 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
8716 /* If the compilation unit is already loaded, just mark it as
8718 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8722 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
8723 and the DIEs are not already loaded. */
8724 return queued
&& cu
== nullptr;
8727 /* Process the queue. */
8730 process_queue (dwarf2_per_objfile
*per_objfile
)
8732 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
8733 objfile_name (per_objfile
->objfile
));
8735 /* The queue starts out with one item, but following a DIE reference
8736 may load a new CU, adding it to the end of the queue. */
8737 while (!per_objfile
->per_bfd
->queue
->empty ())
8739 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
8740 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8742 if (!per_objfile
->symtab_set_p (per_cu
))
8744 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
8746 /* Skip dummy CUs. */
8749 unsigned int debug_print_threshold
;
8752 if (per_cu
->is_debug_types
)
8754 struct signatured_type
*sig_type
=
8755 (struct signatured_type
*) per_cu
;
8757 sprintf (buf
, "TU %s at offset %s",
8758 hex_string (sig_type
->signature
),
8759 sect_offset_str (per_cu
->sect_off
));
8760 /* There can be 100s of TUs.
8761 Only print them in verbose mode. */
8762 debug_print_threshold
= 2;
8766 sprintf (buf
, "CU at offset %s",
8767 sect_offset_str (per_cu
->sect_off
));
8768 debug_print_threshold
= 1;
8771 if (dwarf_read_debug
>= debug_print_threshold
)
8772 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
8774 if (per_cu
->is_debug_types
)
8775 process_full_type_unit (cu
, item
.pretend_language
);
8777 process_full_comp_unit (cu
, item
.pretend_language
);
8779 if (dwarf_read_debug
>= debug_print_threshold
)
8780 dwarf_read_debug_printf ("Done expanding %s", buf
);
8785 per_objfile
->per_bfd
->queue
->pop ();
8788 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
8789 objfile_name (per_objfile
->objfile
));
8792 /* Read in full symbols for PST, and anything it depends on. */
8795 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8797 gdb_assert (!readin_p (objfile
));
8799 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8800 free_cached_comp_units
freer (per_objfile
);
8801 expand_dependencies (objfile
);
8803 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
8804 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
8807 /* See psympriv.h. */
8810 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
8812 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8813 return per_objfile
->symtab_set_p (per_cu_data
);
8816 /* See psympriv.h. */
8819 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
8821 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
8822 return per_objfile
->get_symtab (per_cu_data
);
8825 /* Trivial hash function for die_info: the hash value of a DIE
8826 is its offset in .debug_info for this objfile. */
8829 die_hash (const void *item
)
8831 const struct die_info
*die
= (const struct die_info
*) item
;
8833 return to_underlying (die
->sect_off
);
8836 /* Trivial comparison function for die_info structures: two DIEs
8837 are equal if they have the same offset. */
8840 die_eq (const void *item_lhs
, const void *item_rhs
)
8842 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8843 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8845 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8848 /* Load the DIEs associated with PER_CU into memory.
8850 In some cases, the caller, while reading partial symbols, will need to load
8851 the full symbols for the CU for some reason. It will already have a
8852 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
8853 rather than creating a new one. */
8856 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
8857 dwarf2_per_objfile
*per_objfile
,
8858 dwarf2_cu
*existing_cu
,
8860 enum language pretend_language
)
8862 gdb_assert (! this_cu
->is_debug_types
);
8864 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
8868 struct dwarf2_cu
*cu
= reader
.cu
;
8869 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8871 gdb_assert (cu
->die_hash
== NULL
);
8873 htab_create_alloc_ex (cu
->header
.length
/ 12,
8877 &cu
->comp_unit_obstack
,
8878 hashtab_obstack_allocate
,
8879 dummy_obstack_deallocate
);
8881 if (reader
.comp_unit_die
->has_children
)
8882 reader
.comp_unit_die
->child
8883 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8884 &info_ptr
, reader
.comp_unit_die
);
8885 cu
->dies
= reader
.comp_unit_die
;
8886 /* comp_unit_die is not stored in die_hash, no need. */
8888 /* We try not to read any attributes in this function, because not
8889 all CUs needed for references have been loaded yet, and symbol
8890 table processing isn't initialized. But we have to set the CU language,
8891 or we won't be able to build types correctly.
8892 Similarly, if we do not read the producer, we can not apply
8893 producer-specific interpretation. */
8894 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8899 /* Add a DIE to the delayed physname list. */
8902 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8903 const char *name
, struct die_info
*die
,
8904 struct dwarf2_cu
*cu
)
8906 struct delayed_method_info mi
;
8908 mi
.fnfield_index
= fnfield_index
;
8912 cu
->method_list
.push_back (mi
);
8915 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8916 "const" / "volatile". If so, decrements LEN by the length of the
8917 modifier and return true. Otherwise return false. */
8921 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8923 size_t mod_len
= sizeof (mod
) - 1;
8924 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8932 /* Compute the physnames of any methods on the CU's method list.
8934 The computation of method physnames is delayed in order to avoid the
8935 (bad) condition that one of the method's formal parameters is of an as yet
8939 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8941 /* Only C++ delays computing physnames. */
8942 if (cu
->method_list
.empty ())
8944 gdb_assert (cu
->language
== language_cplus
);
8946 for (const delayed_method_info
&mi
: cu
->method_list
)
8948 const char *physname
;
8949 struct fn_fieldlist
*fn_flp
8950 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8951 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8952 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8953 = physname
? physname
: "";
8955 /* Since there's no tag to indicate whether a method is a
8956 const/volatile overload, extract that information out of the
8958 if (physname
!= NULL
)
8960 size_t len
= strlen (physname
);
8964 if (physname
[len
] == ')') /* shortcut */
8966 else if (check_modifier (physname
, len
, " const"))
8967 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8968 else if (check_modifier (physname
, len
, " volatile"))
8969 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8976 /* The list is no longer needed. */
8977 cu
->method_list
.clear ();
8980 /* Go objects should be embedded in a DW_TAG_module DIE,
8981 and it's not clear if/how imported objects will appear.
8982 To keep Go support simple until that's worked out,
8983 go back through what we've read and create something usable.
8984 We could do this while processing each DIE, and feels kinda cleaner,
8985 but that way is more invasive.
8986 This is to, for example, allow the user to type "p var" or "b main"
8987 without having to specify the package name, and allow lookups
8988 of module.object to work in contexts that use the expression
8992 fixup_go_packaging (struct dwarf2_cu
*cu
)
8994 gdb::unique_xmalloc_ptr
<char> package_name
;
8995 struct pending
*list
;
8998 for (list
= *cu
->get_builder ()->get_global_symbols ();
9002 for (i
= 0; i
< list
->nsyms
; ++i
)
9004 struct symbol
*sym
= list
->symbol
[i
];
9006 if (sym
->language () == language_go
9007 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9009 gdb::unique_xmalloc_ptr
<char> this_package_name
9010 (go_symbol_package_name (sym
));
9012 if (this_package_name
== NULL
)
9014 if (package_name
== NULL
)
9015 package_name
= std::move (this_package_name
);
9018 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9019 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9020 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9021 (symbol_symtab (sym
) != NULL
9022 ? symtab_to_filename_for_display
9023 (symbol_symtab (sym
))
9024 : objfile_name (objfile
)),
9025 this_package_name
.get (), package_name
.get ());
9031 if (package_name
!= NULL
)
9033 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9034 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9035 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9036 saved_package_name
);
9039 sym
= new (&objfile
->objfile_obstack
) symbol
;
9040 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9041 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9042 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9043 e.g., "main" finds the "main" module and not C's main(). */
9044 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9045 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9046 SYMBOL_TYPE (sym
) = type
;
9048 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9052 /* Allocate a fully-qualified name consisting of the two parts on the
9056 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9058 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9061 /* A helper that allocates a variant part to attach to a Rust enum
9062 type. OBSTACK is where the results should be allocated. TYPE is
9063 the type we're processing. DISCRIMINANT_INDEX is the index of the
9064 discriminant. It must be the index of one of the fields of TYPE,
9065 or -1 to mean there is no discriminant (univariant enum).
9066 DEFAULT_INDEX is the index of the default field; or -1 if there is
9067 no default. RANGES is indexed by "effective" field number (the
9068 field index, but omitting the discriminant and default fields) and
9069 must hold the discriminant values used by the variants. Note that
9070 RANGES must have a lifetime at least as long as OBSTACK -- either
9071 already allocated on it, or static. */
9074 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9075 int discriminant_index
, int default_index
,
9076 gdb::array_view
<discriminant_range
> ranges
)
9078 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
9079 gdb_assert (discriminant_index
== -1
9080 || (discriminant_index
>= 0
9081 && discriminant_index
< type
->num_fields ()));
9082 gdb_assert (default_index
== -1
9083 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9085 /* We have one variant for each non-discriminant field. */
9086 int n_variants
= type
->num_fields ();
9087 if (discriminant_index
!= -1)
9090 variant
*variants
= new (obstack
) variant
[n_variants
];
9093 for (int i
= 0; i
< type
->num_fields (); ++i
)
9095 if (i
== discriminant_index
)
9098 variants
[var_idx
].first_field
= i
;
9099 variants
[var_idx
].last_field
= i
+ 1;
9101 /* The default field does not need a range, but other fields do.
9102 We skipped the discriminant above. */
9103 if (i
!= default_index
)
9105 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9112 gdb_assert (range_idx
== ranges
.size ());
9113 gdb_assert (var_idx
== n_variants
);
9115 variant_part
*part
= new (obstack
) variant_part
;
9116 part
->discriminant_index
= discriminant_index
;
9117 /* If there is no discriminant, then whether it is signed is of no
9120 = (discriminant_index
== -1
9122 : type
->field (discriminant_index
).type ()->is_unsigned ());
9123 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9125 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9126 gdb::array_view
<variant_part
> *prop_value
9127 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9129 struct dynamic_prop prop
;
9130 prop
.set_variant_parts (prop_value
);
9132 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9135 /* Some versions of rustc emitted enums in an unusual way.
9137 Ordinary enums were emitted as unions. The first element of each
9138 structure in the union was named "RUST$ENUM$DISR". This element
9139 held the discriminant.
9141 These versions of Rust also implemented the "non-zero"
9142 optimization. When the enum had two values, and one is empty and
9143 the other holds a pointer that cannot be zero, the pointer is used
9144 as the discriminant, with a zero value meaning the empty variant.
9145 Here, the union's first member is of the form
9146 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9147 where the fieldnos are the indices of the fields that should be
9148 traversed in order to find the field (which may be several fields deep)
9149 and the variantname is the name of the variant of the case when the
9152 This function recognizes whether TYPE is of one of these forms,
9153 and, if so, smashes it to be a variant type. */
9156 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9158 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9160 /* We don't need to deal with empty enums. */
9161 if (type
->num_fields () == 0)
9164 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9165 if (type
->num_fields () == 1
9166 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9168 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9170 /* Decode the field name to find the offset of the
9172 ULONGEST bit_offset
= 0;
9173 struct type
*field_type
= type
->field (0).type ();
9174 while (name
[0] >= '0' && name
[0] <= '9')
9177 unsigned long index
= strtoul (name
, &tail
, 10);
9180 || index
>= field_type
->num_fields ()
9181 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9182 != FIELD_LOC_KIND_BITPOS
))
9184 complaint (_("Could not parse Rust enum encoding string \"%s\""
9186 TYPE_FIELD_NAME (type
, 0),
9187 objfile_name (objfile
));
9192 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9193 field_type
= field_type
->field (index
).type ();
9196 /* Smash this type to be a structure type. We have to do this
9197 because the type has already been recorded. */
9198 type
->set_code (TYPE_CODE_STRUCT
);
9199 type
->set_num_fields (3);
9200 /* Save the field we care about. */
9201 struct field saved_field
= type
->field (0);
9203 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9205 /* Put the discriminant at index 0. */
9206 type
->field (0).set_type (field_type
);
9207 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9208 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9209 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9211 /* The order of fields doesn't really matter, so put the real
9212 field at index 1 and the data-less field at index 2. */
9213 type
->field (1) = saved_field
;
9214 TYPE_FIELD_NAME (type
, 1)
9215 = rust_last_path_segment (type
->field (1).type ()->name ());
9216 type
->field (1).type ()->set_name
9217 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9218 TYPE_FIELD_NAME (type
, 1)));
9220 const char *dataless_name
9221 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9223 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9225 type
->field (2).set_type (dataless_type
);
9226 /* NAME points into the original discriminant name, which
9227 already has the correct lifetime. */
9228 TYPE_FIELD_NAME (type
, 2) = name
;
9229 SET_FIELD_BITPOS (type
->field (2), 0);
9231 /* Indicate that this is a variant type. */
9232 static discriminant_range ranges
[1] = { { 0, 0 } };
9233 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9235 /* A union with a single anonymous field is probably an old-style
9237 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9239 /* Smash this type to be a structure type. We have to do this
9240 because the type has already been recorded. */
9241 type
->set_code (TYPE_CODE_STRUCT
);
9243 struct type
*field_type
= type
->field (0).type ();
9244 const char *variant_name
9245 = rust_last_path_segment (field_type
->name ());
9246 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9247 field_type
->set_name
9248 (rust_fully_qualify (&objfile
->objfile_obstack
,
9249 type
->name (), variant_name
));
9251 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9255 struct type
*disr_type
= nullptr;
9256 for (int i
= 0; i
< type
->num_fields (); ++i
)
9258 disr_type
= type
->field (i
).type ();
9260 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9262 /* All fields of a true enum will be structs. */
9265 else if (disr_type
->num_fields () == 0)
9267 /* Could be data-less variant, so keep going. */
9268 disr_type
= nullptr;
9270 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9271 "RUST$ENUM$DISR") != 0)
9273 /* Not a Rust enum. */
9283 /* If we got here without a discriminant, then it's probably
9285 if (disr_type
== nullptr)
9288 /* Smash this type to be a structure type. We have to do this
9289 because the type has already been recorded. */
9290 type
->set_code (TYPE_CODE_STRUCT
);
9292 /* Make space for the discriminant field. */
9293 struct field
*disr_field
= &disr_type
->field (0);
9295 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9296 * sizeof (struct field
)));
9297 memcpy (new_fields
+ 1, type
->fields (),
9298 type
->num_fields () * sizeof (struct field
));
9299 type
->set_fields (new_fields
);
9300 type
->set_num_fields (type
->num_fields () + 1);
9302 /* Install the discriminant at index 0 in the union. */
9303 type
->field (0) = *disr_field
;
9304 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9305 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9307 /* We need a way to find the correct discriminant given a
9308 variant name. For convenience we build a map here. */
9309 struct type
*enum_type
= disr_field
->type ();
9310 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9311 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9313 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9316 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9317 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9321 int n_fields
= type
->num_fields ();
9322 /* We don't need a range entry for the discriminant, but we do
9323 need one for every other field, as there is no default
9325 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9328 /* Skip the discriminant here. */
9329 for (int i
= 1; i
< n_fields
; ++i
)
9331 /* Find the final word in the name of this variant's type.
9332 That name can be used to look up the correct
9334 const char *variant_name
9335 = rust_last_path_segment (type
->field (i
).type ()->name ());
9337 auto iter
= discriminant_map
.find (variant_name
);
9338 if (iter
!= discriminant_map
.end ())
9340 ranges
[i
- 1].low
= iter
->second
;
9341 ranges
[i
- 1].high
= iter
->second
;
9344 /* In Rust, each element should have the size of the
9346 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9348 /* Remove the discriminant field, if it exists. */
9349 struct type
*sub_type
= type
->field (i
).type ();
9350 if (sub_type
->num_fields () > 0)
9352 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9353 sub_type
->set_fields (sub_type
->fields () + 1);
9355 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9357 (rust_fully_qualify (&objfile
->objfile_obstack
,
9358 type
->name (), variant_name
));
9361 /* Indicate that this is a variant type. */
9362 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9363 gdb::array_view
<discriminant_range
> (ranges
,
9368 /* Rewrite some Rust unions to be structures with variants parts. */
9371 rust_union_quirks (struct dwarf2_cu
*cu
)
9373 gdb_assert (cu
->language
== language_rust
);
9374 for (type
*type_
: cu
->rust_unions
)
9375 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9376 /* We don't need this any more. */
9377 cu
->rust_unions
.clear ();
9382 type_unit_group_unshareable
*
9383 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9385 auto iter
= this->m_type_units
.find (tu_group
);
9386 if (iter
!= this->m_type_units
.end ())
9387 return iter
->second
.get ();
9389 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9390 type_unit_group_unshareable
*result
= uniq
.get ();
9391 this->m_type_units
[tu_group
] = std::move (uniq
);
9396 dwarf2_per_objfile::get_type_for_signatured_type
9397 (signatured_type
*sig_type
) const
9399 auto iter
= this->m_type_map
.find (sig_type
);
9400 if (iter
== this->m_type_map
.end ())
9403 return iter
->second
;
9406 void dwarf2_per_objfile::set_type_for_signatured_type
9407 (signatured_type
*sig_type
, struct type
*type
)
9409 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9411 this->m_type_map
[sig_type
] = type
;
9414 /* A helper function for computing the list of all symbol tables
9415 included by PER_CU. */
9418 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9419 htab_t all_children
, htab_t all_type_symtabs
,
9420 dwarf2_per_cu_data
*per_cu
,
9421 dwarf2_per_objfile
*per_objfile
,
9422 struct compunit_symtab
*immediate_parent
)
9424 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9427 /* This inclusion and its children have been processed. */
9433 /* Only add a CU if it has a symbol table. */
9434 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9437 /* If this is a type unit only add its symbol table if we haven't
9438 seen it yet (type unit per_cu's can share symtabs). */
9439 if (per_cu
->is_debug_types
)
9441 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9445 result
->push_back (cust
);
9446 if (cust
->user
== NULL
)
9447 cust
->user
= immediate_parent
;
9452 result
->push_back (cust
);
9453 if (cust
->user
== NULL
)
9454 cust
->user
= immediate_parent
;
9458 if (!per_cu
->imported_symtabs_empty ())
9459 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9461 recursively_compute_inclusions (result
, all_children
,
9462 all_type_symtabs
, ptr
, per_objfile
,
9467 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9471 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9472 dwarf2_per_objfile
*per_objfile
)
9474 gdb_assert (! per_cu
->is_debug_types
);
9476 if (!per_cu
->imported_symtabs_empty ())
9479 std::vector
<compunit_symtab
*> result_symtabs
;
9480 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9482 /* If we don't have a symtab, we can just skip this case. */
9486 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9488 NULL
, xcalloc
, xfree
));
9489 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9491 NULL
, xcalloc
, xfree
));
9493 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9495 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9496 all_type_symtabs
.get (), ptr
,
9500 /* Now we have a transitive closure of all the included symtabs. */
9501 len
= result_symtabs
.size ();
9503 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9504 struct compunit_symtab
*, len
+ 1);
9505 memcpy (cust
->includes
, result_symtabs
.data (),
9506 len
* sizeof (compunit_symtab
*));
9507 cust
->includes
[len
] = NULL
;
9511 /* Compute the 'includes' field for the symtabs of all the CUs we just
9515 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9517 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9519 if (! iter
->is_debug_types
)
9520 compute_compunit_symtab_includes (iter
, per_objfile
);
9523 per_objfile
->per_bfd
->just_read_cus
.clear ();
9526 /* Generate full symbol information for CU, whose DIEs have
9527 already been loaded into memory. */
9530 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9532 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9533 struct objfile
*objfile
= per_objfile
->objfile
;
9534 struct gdbarch
*gdbarch
= objfile
->arch ();
9535 CORE_ADDR lowpc
, highpc
;
9536 struct compunit_symtab
*cust
;
9538 struct block
*static_block
;
9541 baseaddr
= objfile
->text_section_offset ();
9543 /* Clear the list here in case something was left over. */
9544 cu
->method_list
.clear ();
9546 cu
->language
= pretend_language
;
9547 cu
->language_defn
= language_def (cu
->language
);
9549 dwarf2_find_base_address (cu
->dies
, cu
);
9551 /* Before we start reading the top-level DIE, ensure it has a valid tag
9553 switch (cu
->dies
->tag
)
9555 case DW_TAG_compile_unit
:
9556 case DW_TAG_partial_unit
:
9557 case DW_TAG_type_unit
:
9560 error (_("Dwarf Error: unexpected tag '%s' at offset %s [in module %s]"),
9561 dwarf_tag_name (cu
->dies
->tag
),
9562 sect_offset_str (cu
->per_cu
->sect_off
),
9563 objfile_name (per_objfile
->objfile
));
9566 /* Do line number decoding in read_file_scope () */
9567 process_die (cu
->dies
, cu
);
9569 /* For now fudge the Go package. */
9570 if (cu
->language
== language_go
)
9571 fixup_go_packaging (cu
);
9573 /* Now that we have processed all the DIEs in the CU, all the types
9574 should be complete, and it should now be safe to compute all of the
9576 compute_delayed_physnames (cu
);
9578 if (cu
->language
== language_rust
)
9579 rust_union_quirks (cu
);
9581 /* Some compilers don't define a DW_AT_high_pc attribute for the
9582 compilation unit. If the DW_AT_high_pc is missing, synthesize
9583 it, by scanning the DIE's below the compilation unit. */
9584 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9586 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9587 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9589 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9590 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9591 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9592 addrmap to help ensure it has an accurate map of pc values belonging to
9594 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9596 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9597 SECT_OFF_TEXT (objfile
),
9602 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9604 /* Set symtab language to language from DW_AT_language. If the
9605 compilation is from a C file generated by language preprocessors, do
9606 not set the language if it was already deduced by start_subfile. */
9607 if (!(cu
->language
== language_c
9608 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9609 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9611 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9612 produce DW_AT_location with location lists but it can be possibly
9613 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9614 there were bugs in prologue debug info, fixed later in GCC-4.5
9615 by "unwind info for epilogues" patch (which is not directly related).
9617 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9618 needed, it would be wrong due to missing DW_AT_producer there.
9620 Still one can confuse GDB by using non-standard GCC compilation
9621 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9623 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9624 cust
->locations_valid
= 1;
9626 if (gcc_4_minor
>= 5)
9627 cust
->epilogue_unwind_valid
= 1;
9629 cust
->call_site_htab
= cu
->call_site_htab
;
9632 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9634 /* Push it for inclusion processing later. */
9635 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
9637 /* Not needed any more. */
9638 cu
->reset_builder ();
9641 /* Generate full symbol information for type unit CU, whose DIEs have
9642 already been loaded into memory. */
9645 process_full_type_unit (dwarf2_cu
*cu
,
9646 enum language pretend_language
)
9648 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9649 struct objfile
*objfile
= per_objfile
->objfile
;
9650 struct compunit_symtab
*cust
;
9651 struct signatured_type
*sig_type
;
9653 gdb_assert (cu
->per_cu
->is_debug_types
);
9654 sig_type
= (struct signatured_type
*) cu
->per_cu
;
9656 /* Clear the list here in case something was left over. */
9657 cu
->method_list
.clear ();
9659 cu
->language
= pretend_language
;
9660 cu
->language_defn
= language_def (cu
->language
);
9662 /* The symbol tables are set up in read_type_unit_scope. */
9663 process_die (cu
->dies
, cu
);
9665 /* For now fudge the Go package. */
9666 if (cu
->language
== language_go
)
9667 fixup_go_packaging (cu
);
9669 /* Now that we have processed all the DIEs in the CU, all the types
9670 should be complete, and it should now be safe to compute all of the
9672 compute_delayed_physnames (cu
);
9674 if (cu
->language
== language_rust
)
9675 rust_union_quirks (cu
);
9677 /* TUs share symbol tables.
9678 If this is the first TU to use this symtab, complete the construction
9679 of it with end_expandable_symtab. Otherwise, complete the addition of
9680 this TU's symbols to the existing symtab. */
9681 type_unit_group_unshareable
*tug_unshare
=
9682 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
9683 if (tug_unshare
->compunit_symtab
== NULL
)
9685 buildsym_compunit
*builder
= cu
->get_builder ();
9686 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9687 tug_unshare
->compunit_symtab
= cust
;
9691 /* Set symtab language to language from DW_AT_language. If the
9692 compilation is from a C file generated by language preprocessors,
9693 do not set the language if it was already deduced by
9695 if (!(cu
->language
== language_c
9696 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9697 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9702 cu
->get_builder ()->augment_type_symtab ();
9703 cust
= tug_unshare
->compunit_symtab
;
9706 per_objfile
->set_symtab (cu
->per_cu
, cust
);
9708 /* Not needed any more. */
9709 cu
->reset_builder ();
9712 /* Process an imported unit DIE. */
9715 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9717 struct attribute
*attr
;
9719 /* For now we don't handle imported units in type units. */
9720 if (cu
->per_cu
->is_debug_types
)
9722 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9723 " supported in type units [in module %s]"),
9724 objfile_name (cu
->per_objfile
->objfile
));
9727 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9730 sect_offset sect_off
= attr
->get_ref_die_offset ();
9731 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9732 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9733 dwarf2_per_cu_data
*per_cu
9734 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
9736 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9737 into another compilation unit, at root level. Regard this as a hint,
9739 if (die
->parent
&& die
->parent
->parent
== NULL
9740 && per_cu
->unit_type
== DW_UT_compile
9741 && per_cu
->lang
== language_cplus
)
9744 /* If necessary, add it to the queue and load its DIEs. */
9745 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
9746 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
9747 false, cu
->language
);
9749 cu
->per_cu
->imported_symtabs_push (per_cu
);
9753 /* RAII object that represents a process_die scope: i.e.,
9754 starts/finishes processing a DIE. */
9755 class process_die_scope
9758 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9759 : m_die (die
), m_cu (cu
)
9761 /* We should only be processing DIEs not already in process. */
9762 gdb_assert (!m_die
->in_process
);
9763 m_die
->in_process
= true;
9766 ~process_die_scope ()
9768 m_die
->in_process
= false;
9770 /* If we're done processing the DIE for the CU that owns the line
9771 header, we don't need the line header anymore. */
9772 if (m_cu
->line_header_die_owner
== m_die
)
9774 delete m_cu
->line_header
;
9775 m_cu
->line_header
= NULL
;
9776 m_cu
->line_header_die_owner
= NULL
;
9785 /* Process a die and its children. */
9788 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9790 process_die_scope
scope (die
, cu
);
9794 case DW_TAG_padding
:
9796 case DW_TAG_compile_unit
:
9797 case DW_TAG_partial_unit
:
9798 read_file_scope (die
, cu
);
9800 case DW_TAG_type_unit
:
9801 read_type_unit_scope (die
, cu
);
9803 case DW_TAG_subprogram
:
9804 /* Nested subprograms in Fortran get a prefix. */
9805 if (cu
->language
== language_fortran
9806 && die
->parent
!= NULL
9807 && die
->parent
->tag
== DW_TAG_subprogram
)
9808 cu
->processing_has_namespace_info
= true;
9810 case DW_TAG_inlined_subroutine
:
9811 read_func_scope (die
, cu
);
9813 case DW_TAG_lexical_block
:
9814 case DW_TAG_try_block
:
9815 case DW_TAG_catch_block
:
9816 read_lexical_block_scope (die
, cu
);
9818 case DW_TAG_call_site
:
9819 case DW_TAG_GNU_call_site
:
9820 read_call_site_scope (die
, cu
);
9822 case DW_TAG_class_type
:
9823 case DW_TAG_interface_type
:
9824 case DW_TAG_structure_type
:
9825 case DW_TAG_union_type
:
9826 process_structure_scope (die
, cu
);
9828 case DW_TAG_enumeration_type
:
9829 process_enumeration_scope (die
, cu
);
9832 /* These dies have a type, but processing them does not create
9833 a symbol or recurse to process the children. Therefore we can
9834 read them on-demand through read_type_die. */
9835 case DW_TAG_subroutine_type
:
9836 case DW_TAG_set_type
:
9837 case DW_TAG_pointer_type
:
9838 case DW_TAG_ptr_to_member_type
:
9839 case DW_TAG_reference_type
:
9840 case DW_TAG_rvalue_reference_type
:
9841 case DW_TAG_string_type
:
9844 case DW_TAG_array_type
:
9845 /* We only need to handle this case for Ada -- in other
9846 languages, it's normal for the compiler to emit a typedef
9848 if (cu
->language
!= language_ada
)
9851 case DW_TAG_base_type
:
9852 case DW_TAG_subrange_type
:
9853 case DW_TAG_typedef
:
9854 /* Add a typedef symbol for the type definition, if it has a
9856 new_symbol (die
, read_type_die (die
, cu
), cu
);
9858 case DW_TAG_common_block
:
9859 read_common_block (die
, cu
);
9861 case DW_TAG_common_inclusion
:
9863 case DW_TAG_namespace
:
9864 cu
->processing_has_namespace_info
= true;
9865 read_namespace (die
, cu
);
9868 cu
->processing_has_namespace_info
= true;
9869 read_module (die
, cu
);
9871 case DW_TAG_imported_declaration
:
9872 cu
->processing_has_namespace_info
= true;
9873 if (read_namespace_alias (die
, cu
))
9875 /* The declaration is not a global namespace alias. */
9877 case DW_TAG_imported_module
:
9878 cu
->processing_has_namespace_info
= true;
9879 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9880 || cu
->language
!= language_fortran
))
9881 complaint (_("Tag '%s' has unexpected children"),
9882 dwarf_tag_name (die
->tag
));
9883 read_import_statement (die
, cu
);
9886 case DW_TAG_imported_unit
:
9887 process_imported_unit_die (die
, cu
);
9890 case DW_TAG_variable
:
9891 read_variable (die
, cu
);
9895 new_symbol (die
, NULL
, cu
);
9900 /* DWARF name computation. */
9902 /* A helper function for dwarf2_compute_name which determines whether DIE
9903 needs to have the name of the scope prepended to the name listed in the
9907 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9909 struct attribute
*attr
;
9913 case DW_TAG_namespace
:
9914 case DW_TAG_typedef
:
9915 case DW_TAG_class_type
:
9916 case DW_TAG_interface_type
:
9917 case DW_TAG_structure_type
:
9918 case DW_TAG_union_type
:
9919 case DW_TAG_enumeration_type
:
9920 case DW_TAG_enumerator
:
9921 case DW_TAG_subprogram
:
9922 case DW_TAG_inlined_subroutine
:
9924 case DW_TAG_imported_declaration
:
9927 case DW_TAG_variable
:
9928 case DW_TAG_constant
:
9929 /* We only need to prefix "globally" visible variables. These include
9930 any variable marked with DW_AT_external or any variable that
9931 lives in a namespace. [Variables in anonymous namespaces
9932 require prefixing, but they are not DW_AT_external.] */
9934 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9936 struct dwarf2_cu
*spec_cu
= cu
;
9938 return die_needs_namespace (die_specification (die
, &spec_cu
),
9942 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9943 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9944 && die
->parent
->tag
!= DW_TAG_module
)
9946 /* A variable in a lexical block of some kind does not need a
9947 namespace, even though in C++ such variables may be external
9948 and have a mangled name. */
9949 if (die
->parent
->tag
== DW_TAG_lexical_block
9950 || die
->parent
->tag
== DW_TAG_try_block
9951 || die
->parent
->tag
== DW_TAG_catch_block
9952 || die
->parent
->tag
== DW_TAG_subprogram
)
9961 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9962 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9963 defined for the given DIE. */
9965 static struct attribute
*
9966 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9968 struct attribute
*attr
;
9970 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9972 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9977 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9978 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9979 defined for the given DIE. */
9982 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9984 const char *linkage_name
;
9986 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9987 if (linkage_name
== NULL
)
9988 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9990 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
9991 See https://github.com/rust-lang/rust/issues/32925. */
9992 if (cu
->language
== language_rust
&& linkage_name
!= NULL
9993 && strchr (linkage_name
, '{') != NULL
)
9994 linkage_name
= NULL
;
9996 return linkage_name
;
9999 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10000 compute the physname for the object, which include a method's:
10001 - formal parameters (C++),
10002 - receiver type (Go),
10004 The term "physname" is a bit confusing.
10005 For C++, for example, it is the demangled name.
10006 For Go, for example, it's the mangled name.
10008 For Ada, return the DIE's linkage name rather than the fully qualified
10009 name. PHYSNAME is ignored..
10011 The result is allocated on the objfile->per_bfd's obstack and
10014 static const char *
10015 dwarf2_compute_name (const char *name
,
10016 struct die_info
*die
, struct dwarf2_cu
*cu
,
10019 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10022 name
= dwarf2_name (die
, cu
);
10024 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10025 but otherwise compute it by typename_concat inside GDB.
10026 FIXME: Actually this is not really true, or at least not always true.
10027 It's all very confusing. compute_and_set_names doesn't try to demangle
10028 Fortran names because there is no mangling standard. So new_symbol
10029 will set the demangled name to the result of dwarf2_full_name, and it is
10030 the demangled name that GDB uses if it exists. */
10031 if (cu
->language
== language_ada
10032 || (cu
->language
== language_fortran
&& physname
))
10034 /* For Ada unit, we prefer the linkage name over the name, as
10035 the former contains the exported name, which the user expects
10036 to be able to reference. Ideally, we want the user to be able
10037 to reference this entity using either natural or linkage name,
10038 but we haven't started looking at this enhancement yet. */
10039 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10041 if (linkage_name
!= NULL
)
10042 return linkage_name
;
10045 /* These are the only languages we know how to qualify names in. */
10047 && (cu
->language
== language_cplus
10048 || cu
->language
== language_fortran
|| cu
->language
== language_d
10049 || cu
->language
== language_rust
))
10051 if (die_needs_namespace (die
, cu
))
10053 const char *prefix
;
10054 const char *canonical_name
= NULL
;
10058 prefix
= determine_prefix (die
, cu
);
10059 if (*prefix
!= '\0')
10061 gdb::unique_xmalloc_ptr
<char> prefixed_name
10062 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10064 buf
.puts (prefixed_name
.get ());
10069 /* Template parameters may be specified in the DIE's DW_AT_name, or
10070 as children with DW_TAG_template_type_param or
10071 DW_TAG_value_type_param. If the latter, add them to the name
10072 here. If the name already has template parameters, then
10073 skip this step; some versions of GCC emit both, and
10074 it is more efficient to use the pre-computed name.
10076 Something to keep in mind about this process: it is very
10077 unlikely, or in some cases downright impossible, to produce
10078 something that will match the mangled name of a function.
10079 If the definition of the function has the same debug info,
10080 we should be able to match up with it anyway. But fallbacks
10081 using the minimal symbol, for instance to find a method
10082 implemented in a stripped copy of libstdc++, will not work.
10083 If we do not have debug info for the definition, we will have to
10084 match them up some other way.
10086 When we do name matching there is a related problem with function
10087 templates; two instantiated function templates are allowed to
10088 differ only by their return types, which we do not add here. */
10090 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10092 struct attribute
*attr
;
10093 struct die_info
*child
;
10095 const language_defn
*cplus_lang
= language_def (cu
->language
);
10097 die
->building_fullname
= 1;
10099 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10103 const gdb_byte
*bytes
;
10104 struct dwarf2_locexpr_baton
*baton
;
10107 if (child
->tag
!= DW_TAG_template_type_param
10108 && child
->tag
!= DW_TAG_template_value_param
)
10119 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10122 complaint (_("template parameter missing DW_AT_type"));
10123 buf
.puts ("UNKNOWN_TYPE");
10126 type
= die_type (child
, cu
);
10128 if (child
->tag
== DW_TAG_template_type_param
)
10130 cplus_lang
->print_type (type
, "", &buf
, -1, 0,
10131 &type_print_raw_options
);
10135 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10138 complaint (_("template parameter missing "
10139 "DW_AT_const_value"));
10140 buf
.puts ("UNKNOWN_VALUE");
10144 dwarf2_const_value_attr (attr
, type
, name
,
10145 &cu
->comp_unit_obstack
, cu
,
10146 &value
, &bytes
, &baton
);
10148 if (type
->has_no_signedness ())
10149 /* GDB prints characters as NUMBER 'CHAR'. If that's
10150 changed, this can use value_print instead. */
10151 cplus_lang
->printchar (value
, type
, &buf
);
10154 struct value_print_options opts
;
10157 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10161 baton
->per_objfile
);
10162 else if (bytes
!= NULL
)
10164 v
= allocate_value (type
);
10165 memcpy (value_contents_writeable (v
), bytes
,
10166 TYPE_LENGTH (type
));
10169 v
= value_from_longest (type
, value
);
10171 /* Specify decimal so that we do not depend on
10173 get_formatted_print_options (&opts
, 'd');
10175 value_print (v
, &buf
, &opts
);
10180 die
->building_fullname
= 0;
10184 /* Close the argument list, with a space if necessary
10185 (nested templates). */
10186 if (!buf
.empty () && buf
.string ().back () == '>')
10193 /* For C++ methods, append formal parameter type
10194 information, if PHYSNAME. */
10196 if (physname
&& die
->tag
== DW_TAG_subprogram
10197 && cu
->language
== language_cplus
)
10199 struct type
*type
= read_type_die (die
, cu
);
10201 c_type_print_args (type
, &buf
, 1, cu
->language
,
10202 &type_print_raw_options
);
10204 if (cu
->language
== language_cplus
)
10206 /* Assume that an artificial first parameter is
10207 "this", but do not crash if it is not. RealView
10208 marks unnamed (and thus unused) parameters as
10209 artificial; there is no way to differentiate
10211 if (type
->num_fields () > 0
10212 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10213 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10214 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10215 buf
.puts (" const");
10219 const std::string
&intermediate_name
= buf
.string ();
10221 if (cu
->language
== language_cplus
)
10223 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10226 /* If we only computed INTERMEDIATE_NAME, or if
10227 INTERMEDIATE_NAME is already canonical, then we need to
10229 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10230 name
= objfile
->intern (intermediate_name
);
10232 name
= canonical_name
;
10239 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10240 If scope qualifiers are appropriate they will be added. The result
10241 will be allocated on the storage_obstack, or NULL if the DIE does
10242 not have a name. NAME may either be from a previous call to
10243 dwarf2_name or NULL.
10245 The output string will be canonicalized (if C++). */
10247 static const char *
10248 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10250 return dwarf2_compute_name (name
, die
, cu
, 0);
10253 /* Construct a physname for the given DIE in CU. NAME may either be
10254 from a previous call to dwarf2_name or NULL. The result will be
10255 allocated on the objfile_objstack or NULL if the DIE does not have a
10258 The output string will be canonicalized (if C++). */
10260 static const char *
10261 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10263 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10264 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10267 /* In this case dwarf2_compute_name is just a shortcut not building anything
10269 if (!die_needs_namespace (die
, cu
))
10270 return dwarf2_compute_name (name
, die
, cu
, 1);
10272 if (cu
->language
!= language_rust
)
10273 mangled
= dw2_linkage_name (die
, cu
);
10275 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10277 gdb::unique_xmalloc_ptr
<char> demangled
;
10278 if (mangled
!= NULL
)
10281 if (language_def (cu
->language
)->store_sym_names_in_linkage_form_p ())
10283 /* Do nothing (do not demangle the symbol name). */
10287 /* Use DMGL_RET_DROP for C++ template functions to suppress
10288 their return type. It is easier for GDB users to search
10289 for such functions as `name(params)' than `long name(params)'.
10290 In such case the minimal symbol names do not match the full
10291 symbol names but for template functions there is never a need
10292 to look up their definition from their declaration so
10293 the only disadvantage remains the minimal symbol variant
10294 `long name(params)' does not have the proper inferior type. */
10295 demangled
.reset (gdb_demangle (mangled
,
10296 (DMGL_PARAMS
| DMGL_ANSI
10297 | DMGL_RET_DROP
)));
10300 canon
= demangled
.get ();
10308 if (canon
== NULL
|| check_physname
)
10310 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10312 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10314 /* It may not mean a bug in GDB. The compiler could also
10315 compute DW_AT_linkage_name incorrectly. But in such case
10316 GDB would need to be bug-to-bug compatible. */
10318 complaint (_("Computed physname <%s> does not match demangled <%s> "
10319 "(from linkage <%s>) - DIE at %s [in module %s]"),
10320 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10321 objfile_name (objfile
));
10323 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10324 is available here - over computed PHYSNAME. It is safer
10325 against both buggy GDB and buggy compilers. */
10339 retval
= objfile
->intern (retval
);
10344 /* Inspect DIE in CU for a namespace alias. If one exists, record
10345 a new symbol for it.
10347 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10350 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10352 struct attribute
*attr
;
10354 /* If the die does not have a name, this is not a namespace
10356 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10360 struct die_info
*d
= die
;
10361 struct dwarf2_cu
*imported_cu
= cu
;
10363 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10364 keep inspecting DIEs until we hit the underlying import. */
10365 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10366 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10368 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10372 d
= follow_die_ref (d
, attr
, &imported_cu
);
10373 if (d
->tag
!= DW_TAG_imported_declaration
)
10377 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10379 complaint (_("DIE at %s has too many recursively imported "
10380 "declarations"), sect_offset_str (d
->sect_off
));
10387 sect_offset sect_off
= attr
->get_ref_die_offset ();
10389 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10390 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10392 /* This declaration is a global namespace alias. Add
10393 a symbol for it whose type is the aliased namespace. */
10394 new_symbol (die
, type
, cu
);
10403 /* Return the using directives repository (global or local?) to use in the
10404 current context for CU.
10406 For Ada, imported declarations can materialize renamings, which *may* be
10407 global. However it is impossible (for now?) in DWARF to distinguish
10408 "external" imported declarations and "static" ones. As all imported
10409 declarations seem to be static in all other languages, make them all CU-wide
10410 global only in Ada. */
10412 static struct using_direct
**
10413 using_directives (struct dwarf2_cu
*cu
)
10415 if (cu
->language
== language_ada
10416 && cu
->get_builder ()->outermost_context_p ())
10417 return cu
->get_builder ()->get_global_using_directives ();
10419 return cu
->get_builder ()->get_local_using_directives ();
10422 /* Read the import statement specified by the given die and record it. */
10425 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10427 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10428 struct attribute
*import_attr
;
10429 struct die_info
*imported_die
, *child_die
;
10430 struct dwarf2_cu
*imported_cu
;
10431 const char *imported_name
;
10432 const char *imported_name_prefix
;
10433 const char *canonical_name
;
10434 const char *import_alias
;
10435 const char *imported_declaration
= NULL
;
10436 const char *import_prefix
;
10437 std::vector
<const char *> excludes
;
10439 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10440 if (import_attr
== NULL
)
10442 complaint (_("Tag '%s' has no DW_AT_import"),
10443 dwarf_tag_name (die
->tag
));
10448 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10449 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10450 if (imported_name
== NULL
)
10452 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10454 The import in the following code:
10468 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10469 <52> DW_AT_decl_file : 1
10470 <53> DW_AT_decl_line : 6
10471 <54> DW_AT_import : <0x75>
10472 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10473 <59> DW_AT_name : B
10474 <5b> DW_AT_decl_file : 1
10475 <5c> DW_AT_decl_line : 2
10476 <5d> DW_AT_type : <0x6e>
10478 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10479 <76> DW_AT_byte_size : 4
10480 <77> DW_AT_encoding : 5 (signed)
10482 imports the wrong die ( 0x75 instead of 0x58 ).
10483 This case will be ignored until the gcc bug is fixed. */
10487 /* Figure out the local name after import. */
10488 import_alias
= dwarf2_name (die
, cu
);
10490 /* Figure out where the statement is being imported to. */
10491 import_prefix
= determine_prefix (die
, cu
);
10493 /* Figure out what the scope of the imported die is and prepend it
10494 to the name of the imported die. */
10495 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10497 if (imported_die
->tag
!= DW_TAG_namespace
10498 && imported_die
->tag
!= DW_TAG_module
)
10500 imported_declaration
= imported_name
;
10501 canonical_name
= imported_name_prefix
;
10503 else if (strlen (imported_name_prefix
) > 0)
10504 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10505 imported_name_prefix
,
10506 (cu
->language
== language_d
? "." : "::"),
10507 imported_name
, (char *) NULL
);
10509 canonical_name
= imported_name
;
10511 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10512 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10513 child_die
= child_die
->sibling
)
10515 /* DWARF-4: A Fortran use statement with a “rename list” may be
10516 represented by an imported module entry with an import attribute
10517 referring to the module and owned entries corresponding to those
10518 entities that are renamed as part of being imported. */
10520 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10522 complaint (_("child DW_TAG_imported_declaration expected "
10523 "- DIE at %s [in module %s]"),
10524 sect_offset_str (child_die
->sect_off
),
10525 objfile_name (objfile
));
10529 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10530 if (import_attr
== NULL
)
10532 complaint (_("Tag '%s' has no DW_AT_import"),
10533 dwarf_tag_name (child_die
->tag
));
10538 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10540 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10541 if (imported_name
== NULL
)
10543 complaint (_("child DW_TAG_imported_declaration has unknown "
10544 "imported name - DIE at %s [in module %s]"),
10545 sect_offset_str (child_die
->sect_off
),
10546 objfile_name (objfile
));
10550 excludes
.push_back (imported_name
);
10552 process_die (child_die
, cu
);
10555 add_using_directive (using_directives (cu
),
10559 imported_declaration
,
10562 &objfile
->objfile_obstack
);
10565 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10566 types, but gives them a size of zero. Starting with version 14,
10567 ICC is compatible with GCC. */
10570 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10572 if (!cu
->checked_producer
)
10573 check_producer (cu
);
10575 return cu
->producer_is_icc_lt_14
;
10578 /* ICC generates a DW_AT_type for C void functions. This was observed on
10579 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10580 which says that void functions should not have a DW_AT_type. */
10583 producer_is_icc (struct dwarf2_cu
*cu
)
10585 if (!cu
->checked_producer
)
10586 check_producer (cu
);
10588 return cu
->producer_is_icc
;
10591 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10592 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10593 this, it was first present in GCC release 4.3.0. */
10596 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10598 if (!cu
->checked_producer
)
10599 check_producer (cu
);
10601 return cu
->producer_is_gcc_lt_4_3
;
10604 static file_and_directory
10605 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10607 file_and_directory res
;
10609 /* Find the filename. Do not use dwarf2_name here, since the filename
10610 is not a source language identifier. */
10611 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10612 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10614 if (res
.comp_dir
== NULL
10615 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10616 && IS_ABSOLUTE_PATH (res
.name
))
10618 res
.comp_dir_storage
= ldirname (res
.name
);
10619 if (!res
.comp_dir_storage
.empty ())
10620 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10622 if (res
.comp_dir
!= NULL
)
10624 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10625 directory, get rid of it. */
10626 const char *cp
= strchr (res
.comp_dir
, ':');
10628 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10629 res
.comp_dir
= cp
+ 1;
10632 if (res
.name
== NULL
)
10633 res
.name
= "<unknown>";
10638 /* Handle DW_AT_stmt_list for a compilation unit.
10639 DIE is the DW_TAG_compile_unit die for CU.
10640 COMP_DIR is the compilation directory. LOWPC is passed to
10641 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10644 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10645 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10647 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10648 struct attribute
*attr
;
10649 struct line_header line_header_local
;
10650 hashval_t line_header_local_hash
;
10652 int decode_mapping
;
10654 gdb_assert (! cu
->per_cu
->is_debug_types
);
10656 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10657 if (attr
== NULL
|| !attr
->form_is_unsigned ())
10660 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10662 /* The line header hash table is only created if needed (it exists to
10663 prevent redundant reading of the line table for partial_units).
10664 If we're given a partial_unit, we'll need it. If we're given a
10665 compile_unit, then use the line header hash table if it's already
10666 created, but don't create one just yet. */
10668 if (per_objfile
->line_header_hash
== NULL
10669 && die
->tag
== DW_TAG_partial_unit
)
10671 per_objfile
->line_header_hash
10672 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10673 line_header_eq_voidp
,
10674 free_line_header_voidp
,
10678 line_header_local
.sect_off
= line_offset
;
10679 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10680 line_header_local_hash
= line_header_hash (&line_header_local
);
10681 if (per_objfile
->line_header_hash
!= NULL
)
10683 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10684 &line_header_local
,
10685 line_header_local_hash
, NO_INSERT
);
10687 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10688 is not present in *SLOT (since if there is something in *SLOT then
10689 it will be for a partial_unit). */
10690 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10692 gdb_assert (*slot
!= NULL
);
10693 cu
->line_header
= (struct line_header
*) *slot
;
10698 /* dwarf_decode_line_header does not yet provide sufficient information.
10699 We always have to call also dwarf_decode_lines for it. */
10700 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10704 cu
->line_header
= lh
.release ();
10705 cu
->line_header_die_owner
= die
;
10707 if (per_objfile
->line_header_hash
== NULL
)
10711 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
10712 &line_header_local
,
10713 line_header_local_hash
, INSERT
);
10714 gdb_assert (slot
!= NULL
);
10716 if (slot
!= NULL
&& *slot
== NULL
)
10718 /* This newly decoded line number information unit will be owned
10719 by line_header_hash hash table. */
10720 *slot
= cu
->line_header
;
10721 cu
->line_header_die_owner
= NULL
;
10725 /* We cannot free any current entry in (*slot) as that struct line_header
10726 may be already used by multiple CUs. Create only temporary decoded
10727 line_header for this CU - it may happen at most once for each line
10728 number information unit. And if we're not using line_header_hash
10729 then this is what we want as well. */
10730 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10732 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10733 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10738 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10741 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10743 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10744 struct objfile
*objfile
= per_objfile
->objfile
;
10745 struct gdbarch
*gdbarch
= objfile
->arch ();
10746 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10747 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10748 struct attribute
*attr
;
10749 struct die_info
*child_die
;
10750 CORE_ADDR baseaddr
;
10752 prepare_one_comp_unit (cu
, die
, cu
->language
);
10753 baseaddr
= objfile
->text_section_offset ();
10755 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10757 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10758 from finish_block. */
10759 if (lowpc
== ((CORE_ADDR
) -1))
10761 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10763 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10765 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10766 standardised yet. As a workaround for the language detection we fall
10767 back to the DW_AT_producer string. */
10768 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10769 cu
->language
= language_opencl
;
10771 /* Similar hack for Go. */
10772 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10773 set_cu_language (DW_LANG_Go
, cu
);
10775 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10777 /* Decode line number information if present. We do this before
10778 processing child DIEs, so that the line header table is available
10779 for DW_AT_decl_file. */
10780 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10782 /* Process all dies in compilation unit. */
10783 if (die
->child
!= NULL
)
10785 child_die
= die
->child
;
10786 while (child_die
&& child_die
->tag
)
10788 process_die (child_die
, cu
);
10789 child_die
= child_die
->sibling
;
10793 /* Decode macro information, if present. Dwarf 2 macro information
10794 refers to information in the line number info statement program
10795 header, so we can only read it if we've read the header
10797 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10799 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10800 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10802 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10803 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10805 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
10809 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10810 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
10812 unsigned int macro_offset
= attr
->as_unsigned ();
10814 dwarf_decode_macros (cu
, macro_offset
, 0);
10820 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10822 struct type_unit_group
*tu_group
;
10824 struct attribute
*attr
;
10826 struct signatured_type
*sig_type
;
10828 gdb_assert (per_cu
->is_debug_types
);
10829 sig_type
= (struct signatured_type
*) per_cu
;
10831 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10833 /* If we're using .gdb_index (includes -readnow) then
10834 per_cu->type_unit_group may not have been set up yet. */
10835 if (sig_type
->type_unit_group
== NULL
)
10836 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10837 tu_group
= sig_type
->type_unit_group
;
10839 /* If we've already processed this stmt_list there's no real need to
10840 do it again, we could fake it and just recreate the part we need
10841 (file name,index -> symtab mapping). If data shows this optimization
10842 is useful we can do it then. */
10843 type_unit_group_unshareable
*tug_unshare
10844 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
10845 first_time
= tug_unshare
->compunit_symtab
== NULL
;
10847 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10850 if (attr
!= NULL
&& attr
->form_is_unsigned ())
10852 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
10853 lh
= dwarf_decode_line_header (line_offset
, this);
10858 start_symtab ("", NULL
, 0);
10861 gdb_assert (tug_unshare
->symtabs
== NULL
);
10862 gdb_assert (m_builder
== nullptr);
10863 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10864 m_builder
.reset (new struct buildsym_compunit
10865 (COMPUNIT_OBJFILE (cust
), "",
10866 COMPUNIT_DIRNAME (cust
),
10867 compunit_language (cust
),
10869 list_in_scope
= get_builder ()->get_file_symbols ();
10874 line_header
= lh
.release ();
10875 line_header_die_owner
= die
;
10879 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10881 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10882 still initializing it, and our caller (a few levels up)
10883 process_full_type_unit still needs to know if this is the first
10886 tug_unshare
->symtabs
10887 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10888 struct symtab
*, line_header
->file_names_size ());
10890 auto &file_names
= line_header
->file_names ();
10891 for (i
= 0; i
< file_names
.size (); ++i
)
10893 file_entry
&fe
= file_names
[i
];
10894 dwarf2_start_subfile (this, fe
.name
,
10895 fe
.include_dir (line_header
));
10896 buildsym_compunit
*b
= get_builder ();
10897 if (b
->get_current_subfile ()->symtab
== NULL
)
10899 /* NOTE: start_subfile will recognize when it's been
10900 passed a file it has already seen. So we can't
10901 assume there's a simple mapping from
10902 cu->line_header->file_names to subfiles, plus
10903 cu->line_header->file_names may contain dups. */
10904 b
->get_current_subfile ()->symtab
10905 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10908 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10909 tug_unshare
->symtabs
[i
] = fe
.symtab
;
10914 gdb_assert (m_builder
== nullptr);
10915 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
10916 m_builder
.reset (new struct buildsym_compunit
10917 (COMPUNIT_OBJFILE (cust
), "",
10918 COMPUNIT_DIRNAME (cust
),
10919 compunit_language (cust
),
10921 list_in_scope
= get_builder ()->get_file_symbols ();
10923 auto &file_names
= line_header
->file_names ();
10924 for (i
= 0; i
< file_names
.size (); ++i
)
10926 file_entry
&fe
= file_names
[i
];
10927 fe
.symtab
= tug_unshare
->symtabs
[i
];
10931 /* The main symtab is allocated last. Type units don't have DW_AT_name
10932 so they don't have a "real" (so to speak) symtab anyway.
10933 There is later code that will assign the main symtab to all symbols
10934 that don't have one. We need to handle the case of a symbol with a
10935 missing symtab (DW_AT_decl_file) anyway. */
10938 /* Process DW_TAG_type_unit.
10939 For TUs we want to skip the first top level sibling if it's not the
10940 actual type being defined by this TU. In this case the first top
10941 level sibling is there to provide context only. */
10944 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10946 struct die_info
*child_die
;
10948 prepare_one_comp_unit (cu
, die
, language_minimal
);
10950 /* Initialize (or reinitialize) the machinery for building symtabs.
10951 We do this before processing child DIEs, so that the line header table
10952 is available for DW_AT_decl_file. */
10953 cu
->setup_type_unit_groups (die
);
10955 if (die
->child
!= NULL
)
10957 child_die
= die
->child
;
10958 while (child_die
&& child_die
->tag
)
10960 process_die (child_die
, cu
);
10961 child_die
= child_die
->sibling
;
10968 http://gcc.gnu.org/wiki/DebugFission
10969 http://gcc.gnu.org/wiki/DebugFissionDWP
10971 To simplify handling of both DWO files ("object" files with the DWARF info)
10972 and DWP files (a file with the DWOs packaged up into one file), we treat
10973 DWP files as having a collection of virtual DWO files. */
10976 hash_dwo_file (const void *item
)
10978 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10981 hash
= htab_hash_string (dwo_file
->dwo_name
);
10982 if (dwo_file
->comp_dir
!= NULL
)
10983 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10988 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10990 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10991 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10993 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10995 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10996 return lhs
->comp_dir
== rhs
->comp_dir
;
10997 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11000 /* Allocate a hash table for DWO files. */
11003 allocate_dwo_file_hash_table ()
11005 auto delete_dwo_file
= [] (void *item
)
11007 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11012 return htab_up (htab_create_alloc (41,
11019 /* Lookup DWO file DWO_NAME. */
11022 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11023 const char *dwo_name
,
11024 const char *comp_dir
)
11026 struct dwo_file find_entry
;
11029 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11030 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11032 find_entry
.dwo_name
= dwo_name
;
11033 find_entry
.comp_dir
= comp_dir
;
11034 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11041 hash_dwo_unit (const void *item
)
11043 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11045 /* This drops the top 32 bits of the id, but is ok for a hash. */
11046 return dwo_unit
->signature
;
11050 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11052 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11053 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11055 /* The signature is assumed to be unique within the DWO file.
11056 So while object file CU dwo_id's always have the value zero,
11057 that's OK, assuming each object file DWO file has only one CU,
11058 and that's the rule for now. */
11059 return lhs
->signature
== rhs
->signature
;
11062 /* Allocate a hash table for DWO CUs,TUs.
11063 There is one of these tables for each of CUs,TUs for each DWO file. */
11066 allocate_dwo_unit_table ()
11068 /* Start out with a pretty small number.
11069 Generally DWO files contain only one CU and maybe some TUs. */
11070 return htab_up (htab_create_alloc (3,
11073 NULL
, xcalloc
, xfree
));
11076 /* die_reader_func for create_dwo_cu. */
11079 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11080 const gdb_byte
*info_ptr
,
11081 struct die_info
*comp_unit_die
,
11082 struct dwo_file
*dwo_file
,
11083 struct dwo_unit
*dwo_unit
)
11085 struct dwarf2_cu
*cu
= reader
->cu
;
11086 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11087 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11089 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11090 if (!signature
.has_value ())
11092 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11093 " its dwo_id [in module %s]"),
11094 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11098 dwo_unit
->dwo_file
= dwo_file
;
11099 dwo_unit
->signature
= *signature
;
11100 dwo_unit
->section
= section
;
11101 dwo_unit
->sect_off
= sect_off
;
11102 dwo_unit
->length
= cu
->per_cu
->length
;
11104 dwarf_read_debug_printf (" offset %s, dwo_id %s",
11105 sect_offset_str (sect_off
),
11106 hex_string (dwo_unit
->signature
));
11109 /* Create the dwo_units for the CUs in a DWO_FILE.
11110 Note: This function processes DWO files only, not DWP files. */
11113 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11114 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11115 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11117 struct objfile
*objfile
= per_objfile
->objfile
;
11118 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11119 const gdb_byte
*info_ptr
, *end_ptr
;
11121 section
.read (objfile
);
11122 info_ptr
= section
.buffer
;
11124 if (info_ptr
== NULL
)
11127 dwarf_read_debug_printf ("Reading %s for %s:",
11128 section
.get_name (),
11129 section
.get_file_name ());
11131 end_ptr
= info_ptr
+ section
.size
;
11132 while (info_ptr
< end_ptr
)
11134 struct dwarf2_per_cu_data per_cu
;
11135 struct dwo_unit read_unit
{};
11136 struct dwo_unit
*dwo_unit
;
11138 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11140 per_cu
.per_bfd
= per_bfd
;
11141 per_cu
.is_debug_types
= 0;
11142 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11143 per_cu
.section
= §ion
;
11145 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11146 if (!reader
.dummy_p
)
11147 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11148 &dwo_file
, &read_unit
);
11149 info_ptr
+= per_cu
.length
;
11151 // If the unit could not be parsed, skip it.
11152 if (read_unit
.dwo_file
== NULL
)
11155 if (cus_htab
== NULL
)
11156 cus_htab
= allocate_dwo_unit_table ();
11158 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11160 *dwo_unit
= read_unit
;
11161 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11162 gdb_assert (slot
!= NULL
);
11165 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11166 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11168 complaint (_("debug cu entry at offset %s is duplicate to"
11169 " the entry at offset %s, signature %s"),
11170 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11171 hex_string (dwo_unit
->signature
));
11173 *slot
= (void *)dwo_unit
;
11177 /* DWP file .debug_{cu,tu}_index section format:
11178 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11179 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11181 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11182 officially standard DWP format was published with DWARF v5 and is called
11183 Version 5. There are no versions 3 or 4.
11187 Both index sections have the same format, and serve to map a 64-bit
11188 signature to a set of section numbers. Each section begins with a header,
11189 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11190 indexes, and a pool of 32-bit section numbers. The index sections will be
11191 aligned at 8-byte boundaries in the file.
11193 The index section header consists of:
11195 V, 32 bit version number
11197 N, 32 bit number of compilation units or type units in the index
11198 M, 32 bit number of slots in the hash table
11200 Numbers are recorded using the byte order of the application binary.
11202 The hash table begins at offset 16 in the section, and consists of an array
11203 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11204 order of the application binary). Unused slots in the hash table are 0.
11205 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11207 The parallel table begins immediately after the hash table
11208 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11209 array of 32-bit indexes (using the byte order of the application binary),
11210 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11211 table contains a 32-bit index into the pool of section numbers. For unused
11212 hash table slots, the corresponding entry in the parallel table will be 0.
11214 The pool of section numbers begins immediately following the hash table
11215 (at offset 16 + 12 * M from the beginning of the section). The pool of
11216 section numbers consists of an array of 32-bit words (using the byte order
11217 of the application binary). Each item in the array is indexed starting
11218 from 0. The hash table entry provides the index of the first section
11219 number in the set. Additional section numbers in the set follow, and the
11220 set is terminated by a 0 entry (section number 0 is not used in ELF).
11222 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11223 section must be the first entry in the set, and the .debug_abbrev.dwo must
11224 be the second entry. Other members of the set may follow in any order.
11228 DWP Versions 2 and 5:
11230 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11231 and the entries in the index tables are now offsets into these sections.
11232 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11235 Index Section Contents:
11237 Hash Table of Signatures dwp_hash_table.hash_table
11238 Parallel Table of Indices dwp_hash_table.unit_table
11239 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11240 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11242 The index section header consists of:
11244 V, 32 bit version number
11245 L, 32 bit number of columns in the table of section offsets
11246 N, 32 bit number of compilation units or type units in the index
11247 M, 32 bit number of slots in the hash table
11249 Numbers are recorded using the byte order of the application binary.
11251 The hash table has the same format as version 1.
11252 The parallel table of indices has the same format as version 1,
11253 except that the entries are origin-1 indices into the table of sections
11254 offsets and the table of section sizes.
11256 The table of offsets begins immediately following the parallel table
11257 (at offset 16 + 12 * M from the beginning of the section). The table is
11258 a two-dimensional array of 32-bit words (using the byte order of the
11259 application binary), with L columns and N+1 rows, in row-major order.
11260 Each row in the array is indexed starting from 0. The first row provides
11261 a key to the remaining rows: each column in this row provides an identifier
11262 for a debug section, and the offsets in the same column of subsequent rows
11263 refer to that section. The section identifiers for Version 2 are:
11265 DW_SECT_INFO 1 .debug_info.dwo
11266 DW_SECT_TYPES 2 .debug_types.dwo
11267 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11268 DW_SECT_LINE 4 .debug_line.dwo
11269 DW_SECT_LOC 5 .debug_loc.dwo
11270 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11271 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11272 DW_SECT_MACRO 8 .debug_macro.dwo
11274 The section identifiers for Version 5 are:
11276 DW_SECT_INFO_V5 1 .debug_info.dwo
11277 DW_SECT_RESERVED_V5 2 --
11278 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11279 DW_SECT_LINE_V5 4 .debug_line.dwo
11280 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11281 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11282 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11283 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11285 The offsets provided by the CU and TU index sections are the base offsets
11286 for the contributions made by each CU or TU to the corresponding section
11287 in the package file. Each CU and TU header contains an abbrev_offset
11288 field, used to find the abbreviations table for that CU or TU within the
11289 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11290 be interpreted as relative to the base offset given in the index section.
11291 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11292 should be interpreted as relative to the base offset for .debug_line.dwo,
11293 and offsets into other debug sections obtained from DWARF attributes should
11294 also be interpreted as relative to the corresponding base offset.
11296 The table of sizes begins immediately following the table of offsets.
11297 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11298 with L columns and N rows, in row-major order. Each row in the array is
11299 indexed starting from 1 (row 0 is shared by the two tables).
11303 Hash table lookup is handled the same in version 1 and 2:
11305 We assume that N and M will not exceed 2^32 - 1.
11306 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11308 Given a 64-bit compilation unit signature or a type signature S, an entry
11309 in the hash table is located as follows:
11311 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11312 the low-order k bits all set to 1.
11314 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11316 3) If the hash table entry at index H matches the signature, use that
11317 entry. If the hash table entry at index H is unused (all zeroes),
11318 terminate the search: the signature is not present in the table.
11320 4) Let H = (H + H') modulo M. Repeat at Step 3.
11322 Because M > N and H' and M are relatively prime, the search is guaranteed
11323 to stop at an unused slot or find the match. */
11325 /* Create a hash table to map DWO IDs to their CU/TU entry in
11326 .debug_{info,types}.dwo in DWP_FILE.
11327 Returns NULL if there isn't one.
11328 Note: This function processes DWP files only, not DWO files. */
11330 static struct dwp_hash_table
*
11331 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11332 struct dwp_file
*dwp_file
, int is_debug_types
)
11334 struct objfile
*objfile
= per_objfile
->objfile
;
11335 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11336 const gdb_byte
*index_ptr
, *index_end
;
11337 struct dwarf2_section_info
*index
;
11338 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11339 struct dwp_hash_table
*htab
;
11341 if (is_debug_types
)
11342 index
= &dwp_file
->sections
.tu_index
;
11344 index
= &dwp_file
->sections
.cu_index
;
11346 if (index
->empty ())
11348 index
->read (objfile
);
11350 index_ptr
= index
->buffer
;
11351 index_end
= index_ptr
+ index
->size
;
11353 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11354 For now it's safe to just read 4 bytes (particularly as it's difficult to
11355 tell if you're dealing with Version 5 before you've read the version). */
11356 version
= read_4_bytes (dbfd
, index_ptr
);
11358 if (version
== 2 || version
== 5)
11359 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11363 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11365 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11368 if (version
!= 1 && version
!= 2 && version
!= 5)
11370 error (_("Dwarf Error: unsupported DWP file version (%s)"
11371 " [in module %s]"),
11372 pulongest (version
), dwp_file
->name
);
11374 if (nr_slots
!= (nr_slots
& -nr_slots
))
11376 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11377 " is not power of 2 [in module %s]"),
11378 pulongest (nr_slots
), dwp_file
->name
);
11381 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11382 htab
->version
= version
;
11383 htab
->nr_columns
= nr_columns
;
11384 htab
->nr_units
= nr_units
;
11385 htab
->nr_slots
= nr_slots
;
11386 htab
->hash_table
= index_ptr
;
11387 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11389 /* Exit early if the table is empty. */
11390 if (nr_slots
== 0 || nr_units
== 0
11391 || (version
== 2 && nr_columns
== 0)
11392 || (version
== 5 && nr_columns
== 0))
11394 /* All must be zero. */
11395 if (nr_slots
!= 0 || nr_units
!= 0
11396 || (version
== 2 && nr_columns
!= 0)
11397 || (version
== 5 && nr_columns
!= 0))
11399 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11400 " all zero [in modules %s]"),
11408 htab
->section_pool
.v1
.indices
=
11409 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11410 /* It's harder to decide whether the section is too small in v1.
11411 V1 is deprecated anyway so we punt. */
11413 else if (version
== 2)
11415 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11416 int *ids
= htab
->section_pool
.v2
.section_ids
;
11417 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11418 /* Reverse map for error checking. */
11419 int ids_seen
[DW_SECT_MAX
+ 1];
11422 if (nr_columns
< 2)
11424 error (_("Dwarf Error: bad DWP hash table, too few columns"
11425 " in section table [in module %s]"),
11428 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11430 error (_("Dwarf Error: bad DWP hash table, too many columns"
11431 " in section table [in module %s]"),
11434 memset (ids
, 255, sizeof_ids
);
11435 memset (ids_seen
, 255, sizeof (ids_seen
));
11436 for (i
= 0; i
< nr_columns
; ++i
)
11438 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11440 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11442 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11443 " in section table [in module %s]"),
11444 id
, dwp_file
->name
);
11446 if (ids_seen
[id
] != -1)
11448 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11449 " id %d in section table [in module %s]"),
11450 id
, dwp_file
->name
);
11455 /* Must have exactly one info or types section. */
11456 if (((ids_seen
[DW_SECT_INFO
] != -1)
11457 + (ids_seen
[DW_SECT_TYPES
] != -1))
11460 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11461 " DWO info/types section [in module %s]"),
11464 /* Must have an abbrev section. */
11465 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11467 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11468 " section [in module %s]"),
11471 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11472 htab
->section_pool
.v2
.sizes
=
11473 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11474 * nr_units
* nr_columns
);
11475 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11476 * nr_units
* nr_columns
))
11479 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11480 " [in module %s]"),
11484 else /* version == 5 */
11486 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11487 int *ids
= htab
->section_pool
.v5
.section_ids
;
11488 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11489 /* Reverse map for error checking. */
11490 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11492 if (nr_columns
< 2)
11494 error (_("Dwarf Error: bad DWP hash table, too few columns"
11495 " in section table [in module %s]"),
11498 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11500 error (_("Dwarf Error: bad DWP hash table, too many columns"
11501 " in section table [in module %s]"),
11504 memset (ids
, 255, sizeof_ids
);
11505 memset (ids_seen
, 255, sizeof (ids_seen
));
11506 for (int i
= 0; i
< nr_columns
; ++i
)
11508 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11510 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11512 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11513 " in section table [in module %s]"),
11514 id
, dwp_file
->name
);
11516 if (ids_seen
[id
] != -1)
11518 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11519 " id %d in section table [in module %s]"),
11520 id
, dwp_file
->name
);
11525 /* Must have seen an info section. */
11526 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11528 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11529 " DWO info/types section [in module %s]"),
11532 /* Must have an abbrev section. */
11533 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11535 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11536 " section [in module %s]"),
11539 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11540 htab
->section_pool
.v5
.sizes
11541 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11542 * nr_units
* nr_columns
);
11543 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11544 * nr_units
* nr_columns
))
11547 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11548 " [in module %s]"),
11556 /* Update SECTIONS with the data from SECTP.
11558 This function is like the other "locate" section routines, but in
11559 this context the sections to read comes from the DWP V1 hash table,
11560 not the full ELF section table.
11562 The result is non-zero for success, or zero if an error was found. */
11565 locate_v1_virtual_dwo_sections (asection
*sectp
,
11566 struct virtual_v1_dwo_sections
*sections
)
11568 const struct dwop_section_names
*names
= &dwop_section_names
;
11570 if (names
->abbrev_dwo
.matches (sectp
->name
))
11572 /* There can be only one. */
11573 if (sections
->abbrev
.s
.section
!= NULL
)
11575 sections
->abbrev
.s
.section
= sectp
;
11576 sections
->abbrev
.size
= bfd_section_size (sectp
);
11578 else if (names
->info_dwo
.matches (sectp
->name
)
11579 || names
->types_dwo
.matches (sectp
->name
))
11581 /* There can be only one. */
11582 if (sections
->info_or_types
.s
.section
!= NULL
)
11584 sections
->info_or_types
.s
.section
= sectp
;
11585 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11587 else if (names
->line_dwo
.matches (sectp
->name
))
11589 /* There can be only one. */
11590 if (sections
->line
.s
.section
!= NULL
)
11592 sections
->line
.s
.section
= sectp
;
11593 sections
->line
.size
= bfd_section_size (sectp
);
11595 else if (names
->loc_dwo
.matches (sectp
->name
))
11597 /* There can be only one. */
11598 if (sections
->loc
.s
.section
!= NULL
)
11600 sections
->loc
.s
.section
= sectp
;
11601 sections
->loc
.size
= bfd_section_size (sectp
);
11603 else if (names
->macinfo_dwo
.matches (sectp
->name
))
11605 /* There can be only one. */
11606 if (sections
->macinfo
.s
.section
!= NULL
)
11608 sections
->macinfo
.s
.section
= sectp
;
11609 sections
->macinfo
.size
= bfd_section_size (sectp
);
11611 else if (names
->macro_dwo
.matches (sectp
->name
))
11613 /* There can be only one. */
11614 if (sections
->macro
.s
.section
!= NULL
)
11616 sections
->macro
.s
.section
= sectp
;
11617 sections
->macro
.size
= bfd_section_size (sectp
);
11619 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
11621 /* There can be only one. */
11622 if (sections
->str_offsets
.s
.section
!= NULL
)
11624 sections
->str_offsets
.s
.section
= sectp
;
11625 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11629 /* No other kind of section is valid. */
11636 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11637 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11638 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11639 This is for DWP version 1 files. */
11641 static struct dwo_unit
*
11642 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
11643 struct dwp_file
*dwp_file
,
11644 uint32_t unit_index
,
11645 const char *comp_dir
,
11646 ULONGEST signature
, int is_debug_types
)
11648 const struct dwp_hash_table
*dwp_htab
=
11649 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11650 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11651 const char *kind
= is_debug_types
? "TU" : "CU";
11652 struct dwo_file
*dwo_file
;
11653 struct dwo_unit
*dwo_unit
;
11654 struct virtual_v1_dwo_sections sections
;
11655 void **dwo_file_slot
;
11658 gdb_assert (dwp_file
->version
== 1);
11660 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
11661 kind
, pulongest (unit_index
), hex_string (signature
),
11664 /* Fetch the sections of this DWO unit.
11665 Put a limit on the number of sections we look for so that bad data
11666 doesn't cause us to loop forever. */
11668 #define MAX_NR_V1_DWO_SECTIONS \
11669 (1 /* .debug_info or .debug_types */ \
11670 + 1 /* .debug_abbrev */ \
11671 + 1 /* .debug_line */ \
11672 + 1 /* .debug_loc */ \
11673 + 1 /* .debug_str_offsets */ \
11674 + 1 /* .debug_macro or .debug_macinfo */ \
11675 + 1 /* trailing zero */)
11677 memset (§ions
, 0, sizeof (sections
));
11679 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11682 uint32_t section_nr
=
11683 read_4_bytes (dbfd
,
11684 dwp_htab
->section_pool
.v1
.indices
11685 + (unit_index
+ i
) * sizeof (uint32_t));
11687 if (section_nr
== 0)
11689 if (section_nr
>= dwp_file
->num_sections
)
11691 error (_("Dwarf Error: bad DWP hash table, section number too large"
11692 " [in module %s]"),
11696 sectp
= dwp_file
->elf_sections
[section_nr
];
11697 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11699 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11700 " [in module %s]"),
11706 || sections
.info_or_types
.empty ()
11707 || sections
.abbrev
.empty ())
11709 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11710 " [in module %s]"),
11713 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11715 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11716 " [in module %s]"),
11720 /* It's easier for the rest of the code if we fake a struct dwo_file and
11721 have dwo_unit "live" in that. At least for now.
11723 The DWP file can be made up of a random collection of CUs and TUs.
11724 However, for each CU + set of TUs that came from the same original DWO
11725 file, we can combine them back into a virtual DWO file to save space
11726 (fewer struct dwo_file objects to allocate). Remember that for really
11727 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11729 std::string virtual_dwo_name
=
11730 string_printf ("virtual-dwo/%d-%d-%d-%d",
11731 sections
.abbrev
.get_id (),
11732 sections
.line
.get_id (),
11733 sections
.loc
.get_id (),
11734 sections
.str_offsets
.get_id ());
11735 /* Can we use an existing virtual DWO file? */
11736 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11738 /* Create one if necessary. */
11739 if (*dwo_file_slot
== NULL
)
11741 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11742 virtual_dwo_name
.c_str ());
11744 dwo_file
= new struct dwo_file
;
11745 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11746 dwo_file
->comp_dir
= comp_dir
;
11747 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11748 dwo_file
->sections
.line
= sections
.line
;
11749 dwo_file
->sections
.loc
= sections
.loc
;
11750 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11751 dwo_file
->sections
.macro
= sections
.macro
;
11752 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11753 /* The "str" section is global to the entire DWP file. */
11754 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11755 /* The info or types section is assigned below to dwo_unit,
11756 there's no need to record it in dwo_file.
11757 Also, we can't simply record type sections in dwo_file because
11758 we record a pointer into the vector in dwo_unit. As we collect more
11759 types we'll grow the vector and eventually have to reallocate space
11760 for it, invalidating all copies of pointers into the previous
11762 *dwo_file_slot
= dwo_file
;
11766 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11767 virtual_dwo_name
.c_str ());
11769 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11772 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11773 dwo_unit
->dwo_file
= dwo_file
;
11774 dwo_unit
->signature
= signature
;
11775 dwo_unit
->section
=
11776 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11777 *dwo_unit
->section
= sections
.info_or_types
;
11778 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11783 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
11784 simplify them. Given a pointer to the containing section SECTION, and
11785 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
11786 virtual section of just that piece. */
11788 static struct dwarf2_section_info
11789 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
11790 struct dwarf2_section_info
*section
,
11791 bfd_size_type offset
, bfd_size_type size
)
11793 struct dwarf2_section_info result
;
11796 gdb_assert (section
!= NULL
);
11797 gdb_assert (!section
->is_virtual
);
11799 memset (&result
, 0, sizeof (result
));
11800 result
.s
.containing_section
= section
;
11801 result
.is_virtual
= true;
11806 sectp
= section
->get_bfd_section ();
11808 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11809 bounds of the real section. This is a pretty-rare event, so just
11810 flag an error (easier) instead of a warning and trying to cope. */
11812 || offset
+ size
> bfd_section_size (sectp
))
11814 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
11815 " in section %s [in module %s]"),
11816 sectp
? bfd_section_name (sectp
) : "<unknown>",
11817 objfile_name (per_objfile
->objfile
));
11820 result
.virtual_offset
= offset
;
11821 result
.size
= size
;
11825 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11826 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11827 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11828 This is for DWP version 2 files. */
11830 static struct dwo_unit
*
11831 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
11832 struct dwp_file
*dwp_file
,
11833 uint32_t unit_index
,
11834 const char *comp_dir
,
11835 ULONGEST signature
, int is_debug_types
)
11837 const struct dwp_hash_table
*dwp_htab
=
11838 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11839 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11840 const char *kind
= is_debug_types
? "TU" : "CU";
11841 struct dwo_file
*dwo_file
;
11842 struct dwo_unit
*dwo_unit
;
11843 struct virtual_v2_or_v5_dwo_sections sections
;
11844 void **dwo_file_slot
;
11847 gdb_assert (dwp_file
->version
== 2);
11849 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
11850 kind
, pulongest (unit_index
), hex_string (signature
),
11853 /* Fetch the section offsets of this DWO unit. */
11855 memset (§ions
, 0, sizeof (sections
));
11857 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11859 uint32_t offset
= read_4_bytes (dbfd
,
11860 dwp_htab
->section_pool
.v2
.offsets
11861 + (((unit_index
- 1) * dwp_htab
->nr_columns
11863 * sizeof (uint32_t)));
11864 uint32_t size
= read_4_bytes (dbfd
,
11865 dwp_htab
->section_pool
.v2
.sizes
11866 + (((unit_index
- 1) * dwp_htab
->nr_columns
11868 * sizeof (uint32_t)));
11870 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11873 case DW_SECT_TYPES
:
11874 sections
.info_or_types_offset
= offset
;
11875 sections
.info_or_types_size
= size
;
11877 case DW_SECT_ABBREV
:
11878 sections
.abbrev_offset
= offset
;
11879 sections
.abbrev_size
= size
;
11882 sections
.line_offset
= offset
;
11883 sections
.line_size
= size
;
11886 sections
.loc_offset
= offset
;
11887 sections
.loc_size
= size
;
11889 case DW_SECT_STR_OFFSETS
:
11890 sections
.str_offsets_offset
= offset
;
11891 sections
.str_offsets_size
= size
;
11893 case DW_SECT_MACINFO
:
11894 sections
.macinfo_offset
= offset
;
11895 sections
.macinfo_size
= size
;
11897 case DW_SECT_MACRO
:
11898 sections
.macro_offset
= offset
;
11899 sections
.macro_size
= size
;
11904 /* It's easier for the rest of the code if we fake a struct dwo_file and
11905 have dwo_unit "live" in that. At least for now.
11907 The DWP file can be made up of a random collection of CUs and TUs.
11908 However, for each CU + set of TUs that came from the same original DWO
11909 file, we can combine them back into a virtual DWO file to save space
11910 (fewer struct dwo_file objects to allocate). Remember that for really
11911 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11913 std::string virtual_dwo_name
=
11914 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11915 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11916 (long) (sections
.line_size
? sections
.line_offset
: 0),
11917 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11918 (long) (sections
.str_offsets_size
11919 ? sections
.str_offsets_offset
: 0));
11920 /* Can we use an existing virtual DWO file? */
11921 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
11923 /* Create one if necessary. */
11924 if (*dwo_file_slot
== NULL
)
11926 dwarf_read_debug_printf ("Creating virtual DWO: %s",
11927 virtual_dwo_name
.c_str ());
11929 dwo_file
= new struct dwo_file
;
11930 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
11931 dwo_file
->comp_dir
= comp_dir
;
11932 dwo_file
->sections
.abbrev
=
11933 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
11934 sections
.abbrev_offset
,
11935 sections
.abbrev_size
);
11936 dwo_file
->sections
.line
=
11937 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
11938 sections
.line_offset
,
11939 sections
.line_size
);
11940 dwo_file
->sections
.loc
=
11941 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
11942 sections
.loc_offset
, sections
.loc_size
);
11943 dwo_file
->sections
.macinfo
=
11944 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
11945 sections
.macinfo_offset
,
11946 sections
.macinfo_size
);
11947 dwo_file
->sections
.macro
=
11948 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
11949 sections
.macro_offset
,
11950 sections
.macro_size
);
11951 dwo_file
->sections
.str_offsets
=
11952 create_dwp_v2_or_v5_section (per_objfile
,
11953 &dwp_file
->sections
.str_offsets
,
11954 sections
.str_offsets_offset
,
11955 sections
.str_offsets_size
);
11956 /* The "str" section is global to the entire DWP file. */
11957 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11958 /* The info or types section is assigned below to dwo_unit,
11959 there's no need to record it in dwo_file.
11960 Also, we can't simply record type sections in dwo_file because
11961 we record a pointer into the vector in dwo_unit. As we collect more
11962 types we'll grow the vector and eventually have to reallocate space
11963 for it, invalidating all copies of pointers into the previous
11965 *dwo_file_slot
= dwo_file
;
11969 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
11970 virtual_dwo_name
.c_str ());
11972 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11975 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
11976 dwo_unit
->dwo_file
= dwo_file
;
11977 dwo_unit
->signature
= signature
;
11978 dwo_unit
->section
=
11979 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
11980 *dwo_unit
->section
= create_dwp_v2_or_v5_section
11983 ? &dwp_file
->sections
.types
11984 : &dwp_file
->sections
.info
,
11985 sections
.info_or_types_offset
,
11986 sections
.info_or_types_size
);
11987 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11992 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11993 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11994 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11995 This is for DWP version 5 files. */
11997 static struct dwo_unit
*
11998 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
11999 struct dwp_file
*dwp_file
,
12000 uint32_t unit_index
,
12001 const char *comp_dir
,
12002 ULONGEST signature
, int is_debug_types
)
12004 const struct dwp_hash_table
*dwp_htab
12005 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12006 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12007 const char *kind
= is_debug_types
? "TU" : "CU";
12008 struct dwo_file
*dwo_file
;
12009 struct dwo_unit
*dwo_unit
;
12010 struct virtual_v2_or_v5_dwo_sections sections
{};
12011 void **dwo_file_slot
;
12013 gdb_assert (dwp_file
->version
== 5);
12015 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
12016 kind
, pulongest (unit_index
), hex_string (signature
),
12019 /* Fetch the section offsets of this DWO unit. */
12021 /* memset (§ions, 0, sizeof (sections)); */
12023 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12025 uint32_t offset
= read_4_bytes (dbfd
,
12026 dwp_htab
->section_pool
.v5
.offsets
12027 + (((unit_index
- 1)
12028 * dwp_htab
->nr_columns
12030 * sizeof (uint32_t)));
12031 uint32_t size
= read_4_bytes (dbfd
,
12032 dwp_htab
->section_pool
.v5
.sizes
12033 + (((unit_index
- 1) * dwp_htab
->nr_columns
12035 * sizeof (uint32_t)));
12037 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
12039 case DW_SECT_ABBREV_V5
:
12040 sections
.abbrev_offset
= offset
;
12041 sections
.abbrev_size
= size
;
12043 case DW_SECT_INFO_V5
:
12044 sections
.info_or_types_offset
= offset
;
12045 sections
.info_or_types_size
= size
;
12047 case DW_SECT_LINE_V5
:
12048 sections
.line_offset
= offset
;
12049 sections
.line_size
= size
;
12051 case DW_SECT_LOCLISTS_V5
:
12052 sections
.loclists_offset
= offset
;
12053 sections
.loclists_size
= size
;
12055 case DW_SECT_MACRO_V5
:
12056 sections
.macro_offset
= offset
;
12057 sections
.macro_size
= size
;
12059 case DW_SECT_RNGLISTS_V5
:
12060 sections
.rnglists_offset
= offset
;
12061 sections
.rnglists_size
= size
;
12063 case DW_SECT_STR_OFFSETS_V5
:
12064 sections
.str_offsets_offset
= offset
;
12065 sections
.str_offsets_size
= size
;
12067 case DW_SECT_RESERVED_V5
:
12073 /* It's easier for the rest of the code if we fake a struct dwo_file and
12074 have dwo_unit "live" in that. At least for now.
12076 The DWP file can be made up of a random collection of CUs and TUs.
12077 However, for each CU + set of TUs that came from the same original DWO
12078 file, we can combine them back into a virtual DWO file to save space
12079 (fewer struct dwo_file objects to allocate). Remember that for really
12080 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12082 std::string virtual_dwo_name
=
12083 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
12084 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12085 (long) (sections
.line_size
? sections
.line_offset
: 0),
12086 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
12087 (long) (sections
.str_offsets_size
12088 ? sections
.str_offsets_offset
: 0),
12089 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
12090 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
12091 /* Can we use an existing virtual DWO file? */
12092 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
12093 virtual_dwo_name
.c_str (),
12095 /* Create one if necessary. */
12096 if (*dwo_file_slot
== NULL
)
12098 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12099 virtual_dwo_name
.c_str ());
12101 dwo_file
= new struct dwo_file
;
12102 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12103 dwo_file
->comp_dir
= comp_dir
;
12104 dwo_file
->sections
.abbrev
=
12105 create_dwp_v2_or_v5_section (per_objfile
,
12106 &dwp_file
->sections
.abbrev
,
12107 sections
.abbrev_offset
,
12108 sections
.abbrev_size
);
12109 dwo_file
->sections
.line
=
12110 create_dwp_v2_or_v5_section (per_objfile
,
12111 &dwp_file
->sections
.line
,
12112 sections
.line_offset
, sections
.line_size
);
12113 dwo_file
->sections
.macro
=
12114 create_dwp_v2_or_v5_section (per_objfile
,
12115 &dwp_file
->sections
.macro
,
12116 sections
.macro_offset
,
12117 sections
.macro_size
);
12118 dwo_file
->sections
.loclists
=
12119 create_dwp_v2_or_v5_section (per_objfile
,
12120 &dwp_file
->sections
.loclists
,
12121 sections
.loclists_offset
,
12122 sections
.loclists_size
);
12123 dwo_file
->sections
.rnglists
=
12124 create_dwp_v2_or_v5_section (per_objfile
,
12125 &dwp_file
->sections
.rnglists
,
12126 sections
.rnglists_offset
,
12127 sections
.rnglists_size
);
12128 dwo_file
->sections
.str_offsets
=
12129 create_dwp_v2_or_v5_section (per_objfile
,
12130 &dwp_file
->sections
.str_offsets
,
12131 sections
.str_offsets_offset
,
12132 sections
.str_offsets_size
);
12133 /* The "str" section is global to the entire DWP file. */
12134 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12135 /* The info or types section is assigned below to dwo_unit,
12136 there's no need to record it in dwo_file.
12137 Also, we can't simply record type sections in dwo_file because
12138 we record a pointer into the vector in dwo_unit. As we collect more
12139 types we'll grow the vector and eventually have to reallocate space
12140 for it, invalidating all copies of pointers into the previous
12142 *dwo_file_slot
= dwo_file
;
12146 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12147 virtual_dwo_name
.c_str ());
12149 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12152 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12153 dwo_unit
->dwo_file
= dwo_file
;
12154 dwo_unit
->signature
= signature
;
12156 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12157 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12158 &dwp_file
->sections
.info
,
12159 sections
.info_or_types_offset
,
12160 sections
.info_or_types_size
);
12161 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12166 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12167 Returns NULL if the signature isn't found. */
12169 static struct dwo_unit
*
12170 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12171 struct dwp_file
*dwp_file
, const char *comp_dir
,
12172 ULONGEST signature
, int is_debug_types
)
12174 const struct dwp_hash_table
*dwp_htab
=
12175 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12176 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12177 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12178 uint32_t hash
= signature
& mask
;
12179 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12182 struct dwo_unit find_dwo_cu
;
12184 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12185 find_dwo_cu
.signature
= signature
;
12186 slot
= htab_find_slot (is_debug_types
12187 ? dwp_file
->loaded_tus
.get ()
12188 : dwp_file
->loaded_cus
.get (),
12189 &find_dwo_cu
, INSERT
);
12192 return (struct dwo_unit
*) *slot
;
12194 /* Use a for loop so that we don't loop forever on bad debug info. */
12195 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12197 ULONGEST signature_in_table
;
12199 signature_in_table
=
12200 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12201 if (signature_in_table
== signature
)
12203 uint32_t unit_index
=
12204 read_4_bytes (dbfd
,
12205 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12207 if (dwp_file
->version
== 1)
12209 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12210 unit_index
, comp_dir
,
12211 signature
, is_debug_types
);
12213 else if (dwp_file
->version
== 2)
12215 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12216 unit_index
, comp_dir
,
12217 signature
, is_debug_types
);
12219 else /* version == 5 */
12221 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12222 unit_index
, comp_dir
,
12223 signature
, is_debug_types
);
12225 return (struct dwo_unit
*) *slot
;
12227 if (signature_in_table
== 0)
12229 hash
= (hash
+ hash2
) & mask
;
12232 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12233 " [in module %s]"),
12237 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12238 Open the file specified by FILE_NAME and hand it off to BFD for
12239 preliminary analysis. Return a newly initialized bfd *, which
12240 includes a canonicalized copy of FILE_NAME.
12241 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12242 SEARCH_CWD is true if the current directory is to be searched.
12243 It will be searched before debug-file-directory.
12244 If successful, the file is added to the bfd include table of the
12245 objfile's bfd (see gdb_bfd_record_inclusion).
12246 If unable to find/open the file, return NULL.
12247 NOTE: This function is derived from symfile_bfd_open. */
12249 static gdb_bfd_ref_ptr
12250 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12251 const char *file_name
, int is_dwp
, int search_cwd
)
12254 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12255 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12256 to debug_file_directory. */
12257 const char *search_path
;
12258 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12260 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12263 if (*debug_file_directory
!= '\0')
12265 search_path_holder
.reset (concat (".", dirname_separator_string
,
12266 debug_file_directory
,
12268 search_path
= search_path_holder
.get ();
12274 search_path
= debug_file_directory
;
12276 /* Add the path for the executable binary to the list of search paths. */
12277 std::string objfile_dir
= ldirname (objfile_name (per_objfile
->objfile
));
12278 search_path_holder
.reset (concat (objfile_dir
.c_str (),
12279 dirname_separator_string
,
12280 search_path
, nullptr));
12281 search_path
= search_path_holder
.get ();
12283 openp_flags flags
= OPF_RETURN_REALPATH
;
12285 flags
|= OPF_SEARCH_IN_PATH
;
12287 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12288 desc
= openp (search_path
, flags
, file_name
,
12289 O_RDONLY
| O_BINARY
, &absolute_name
);
12293 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12295 if (sym_bfd
== NULL
)
12297 bfd_set_cacheable (sym_bfd
.get (), 1);
12299 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12302 /* Success. Record the bfd as having been included by the objfile's bfd.
12303 This is important because things like demangled_names_hash lives in the
12304 objfile's per_bfd space and may have references to things like symbol
12305 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12306 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12311 /* Try to open DWO file FILE_NAME.
12312 COMP_DIR is the DW_AT_comp_dir attribute.
12313 The result is the bfd handle of the file.
12314 If there is a problem finding or opening the file, return NULL.
12315 Upon success, the canonicalized path of the file is stored in the bfd,
12316 same as symfile_bfd_open. */
12318 static gdb_bfd_ref_ptr
12319 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12320 const char *file_name
, const char *comp_dir
)
12322 if (IS_ABSOLUTE_PATH (file_name
))
12323 return try_open_dwop_file (per_objfile
, file_name
,
12324 0 /*is_dwp*/, 0 /*search_cwd*/);
12326 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12328 if (comp_dir
!= NULL
)
12330 gdb::unique_xmalloc_ptr
<char> path_to_try
12331 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12333 /* NOTE: If comp_dir is a relative path, this will also try the
12334 search path, which seems useful. */
12335 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12337 1 /*search_cwd*/));
12342 /* That didn't work, try debug-file-directory, which, despite its name,
12343 is a list of paths. */
12345 if (*debug_file_directory
== '\0')
12348 return try_open_dwop_file (per_objfile
, file_name
,
12349 0 /*is_dwp*/, 1 /*search_cwd*/);
12352 /* This function is mapped across the sections and remembers the offset and
12353 size of each of the DWO debugging sections we are interested in. */
12356 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12357 dwo_sections
*dwo_sections
)
12359 const struct dwop_section_names
*names
= &dwop_section_names
;
12361 if (names
->abbrev_dwo
.matches (sectp
->name
))
12363 dwo_sections
->abbrev
.s
.section
= sectp
;
12364 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12366 else if (names
->info_dwo
.matches (sectp
->name
))
12368 dwo_sections
->info
.s
.section
= sectp
;
12369 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12371 else if (names
->line_dwo
.matches (sectp
->name
))
12373 dwo_sections
->line
.s
.section
= sectp
;
12374 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12376 else if (names
->loc_dwo
.matches (sectp
->name
))
12378 dwo_sections
->loc
.s
.section
= sectp
;
12379 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12381 else if (names
->loclists_dwo
.matches (sectp
->name
))
12383 dwo_sections
->loclists
.s
.section
= sectp
;
12384 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12386 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12388 dwo_sections
->macinfo
.s
.section
= sectp
;
12389 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12391 else if (names
->macro_dwo
.matches (sectp
->name
))
12393 dwo_sections
->macro
.s
.section
= sectp
;
12394 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12396 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12398 dwo_sections
->rnglists
.s
.section
= sectp
;
12399 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12401 else if (names
->str_dwo
.matches (sectp
->name
))
12403 dwo_sections
->str
.s
.section
= sectp
;
12404 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12406 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12408 dwo_sections
->str_offsets
.s
.section
= sectp
;
12409 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12411 else if (names
->types_dwo
.matches (sectp
->name
))
12413 struct dwarf2_section_info type_section
;
12415 memset (&type_section
, 0, sizeof (type_section
));
12416 type_section
.s
.section
= sectp
;
12417 type_section
.size
= bfd_section_size (sectp
);
12418 dwo_sections
->types
.push_back (type_section
);
12422 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12423 by PER_CU. This is for the non-DWP case.
12424 The result is NULL if DWO_NAME can't be found. */
12426 static struct dwo_file
*
12427 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12428 const char *comp_dir
)
12430 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12432 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12435 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12440 dwo_file_up
dwo_file (new struct dwo_file
);
12441 dwo_file
->dwo_name
= dwo_name
;
12442 dwo_file
->comp_dir
= comp_dir
;
12443 dwo_file
->dbfd
= std::move (dbfd
);
12445 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12446 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12447 &dwo_file
->sections
);
12449 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12452 if (cu
->per_cu
->dwarf_version
< 5)
12454 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12455 dwo_file
->sections
.types
, dwo_file
->tus
);
12459 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12460 &dwo_file
->sections
.info
, dwo_file
->tus
,
12461 rcuh_kind::COMPILE
);
12464 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12466 return dwo_file
.release ();
12469 /* This function is mapped across the sections and remembers the offset and
12470 size of each of the DWP debugging sections common to version 1 and 2 that
12471 we are interested in. */
12474 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12475 dwp_file
*dwp_file
)
12477 const struct dwop_section_names
*names
= &dwop_section_names
;
12478 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12480 /* Record the ELF section number for later lookup: this is what the
12481 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12482 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12483 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12485 /* Look for specific sections that we need. */
12486 if (names
->str_dwo
.matches (sectp
->name
))
12488 dwp_file
->sections
.str
.s
.section
= sectp
;
12489 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12491 else if (names
->cu_index
.matches (sectp
->name
))
12493 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12494 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12496 else if (names
->tu_index
.matches (sectp
->name
))
12498 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12499 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12503 /* This function is mapped across the sections and remembers the offset and
12504 size of each of the DWP version 2 debugging sections that we are interested
12505 in. This is split into a separate function because we don't know if we
12506 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12509 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12511 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12512 const struct dwop_section_names
*names
= &dwop_section_names
;
12513 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12515 /* Record the ELF section number for later lookup: this is what the
12516 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12517 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12518 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12520 /* Look for specific sections that we need. */
12521 if (names
->abbrev_dwo
.matches (sectp
->name
))
12523 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12524 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12526 else if (names
->info_dwo
.matches (sectp
->name
))
12528 dwp_file
->sections
.info
.s
.section
= sectp
;
12529 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12531 else if (names
->line_dwo
.matches (sectp
->name
))
12533 dwp_file
->sections
.line
.s
.section
= sectp
;
12534 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12536 else if (names
->loc_dwo
.matches (sectp
->name
))
12538 dwp_file
->sections
.loc
.s
.section
= sectp
;
12539 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12541 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12543 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12544 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12546 else if (names
->macro_dwo
.matches (sectp
->name
))
12548 dwp_file
->sections
.macro
.s
.section
= sectp
;
12549 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12551 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12553 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12554 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12556 else if (names
->types_dwo
.matches (sectp
->name
))
12558 dwp_file
->sections
.types
.s
.section
= sectp
;
12559 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12563 /* This function is mapped across the sections and remembers the offset and
12564 size of each of the DWP version 5 debugging sections that we are interested
12565 in. This is split into a separate function because we don't know if we
12566 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12569 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12571 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12572 const struct dwop_section_names
*names
= &dwop_section_names
;
12573 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12575 /* Record the ELF section number for later lookup: this is what the
12576 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12577 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12578 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12580 /* Look for specific sections that we need. */
12581 if (names
->abbrev_dwo
.matches (sectp
->name
))
12583 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12584 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12586 else if (names
->info_dwo
.matches (sectp
->name
))
12588 dwp_file
->sections
.info
.s
.section
= sectp
;
12589 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12591 else if (names
->line_dwo
.matches (sectp
->name
))
12593 dwp_file
->sections
.line
.s
.section
= sectp
;
12594 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12596 else if (names
->loclists_dwo
.matches (sectp
->name
))
12598 dwp_file
->sections
.loclists
.s
.section
= sectp
;
12599 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
12601 else if (names
->macro_dwo
.matches (sectp
->name
))
12603 dwp_file
->sections
.macro
.s
.section
= sectp
;
12604 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12606 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12608 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
12609 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
12611 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12613 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12614 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12618 /* Hash function for dwp_file loaded CUs/TUs. */
12621 hash_dwp_loaded_cutus (const void *item
)
12623 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12625 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12626 return dwo_unit
->signature
;
12629 /* Equality function for dwp_file loaded CUs/TUs. */
12632 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12634 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12635 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12637 return dua
->signature
== dub
->signature
;
12640 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12643 allocate_dwp_loaded_cutus_table ()
12645 return htab_up (htab_create_alloc (3,
12646 hash_dwp_loaded_cutus
,
12647 eq_dwp_loaded_cutus
,
12648 NULL
, xcalloc
, xfree
));
12651 /* Try to open DWP file FILE_NAME.
12652 The result is the bfd handle of the file.
12653 If there is a problem finding or opening the file, return NULL.
12654 Upon success, the canonicalized path of the file is stored in the bfd,
12655 same as symfile_bfd_open. */
12657 static gdb_bfd_ref_ptr
12658 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
12660 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
12662 1 /*search_cwd*/));
12666 /* Work around upstream bug 15652.
12667 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12668 [Whether that's a "bug" is debatable, but it is getting in our way.]
12669 We have no real idea where the dwp file is, because gdb's realpath-ing
12670 of the executable's path may have discarded the needed info.
12671 [IWBN if the dwp file name was recorded in the executable, akin to
12672 .gnu_debuglink, but that doesn't exist yet.]
12673 Strip the directory from FILE_NAME and search again. */
12674 if (*debug_file_directory
!= '\0')
12676 /* Don't implicitly search the current directory here.
12677 If the user wants to search "." to handle this case,
12678 it must be added to debug-file-directory. */
12679 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
12687 /* Initialize the use of the DWP file for the current objfile.
12688 By convention the name of the DWP file is ${objfile}.dwp.
12689 The result is NULL if it can't be found. */
12691 static std::unique_ptr
<struct dwp_file
>
12692 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
12694 struct objfile
*objfile
= per_objfile
->objfile
;
12696 /* Try to find first .dwp for the binary file before any symbolic links
12699 /* If the objfile is a debug file, find the name of the real binary
12700 file and get the name of dwp file from there. */
12701 std::string dwp_name
;
12702 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12704 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12705 const char *backlink_basename
= lbasename (backlink
->original_name
);
12707 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12710 dwp_name
= objfile
->original_name
;
12712 dwp_name
+= ".dwp";
12714 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
12716 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12718 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12719 dwp_name
= objfile_name (objfile
);
12720 dwp_name
+= ".dwp";
12721 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
12726 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
12728 return std::unique_ptr
<dwp_file
> ();
12731 const char *name
= bfd_get_filename (dbfd
.get ());
12732 std::unique_ptr
<struct dwp_file
> dwp_file
12733 (new struct dwp_file (name
, std::move (dbfd
)));
12735 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12736 dwp_file
->elf_sections
=
12737 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
12738 dwp_file
->num_sections
, asection
*);
12740 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12741 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12744 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
12746 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
12748 /* The DWP file version is stored in the hash table. Oh well. */
12749 if (dwp_file
->cus
&& dwp_file
->tus
12750 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12752 /* Technically speaking, we should try to limp along, but this is
12753 pretty bizarre. We use pulongest here because that's the established
12754 portability solution (e.g, we cannot use %u for uint32_t). */
12755 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12756 " TU version %s [in DWP file %s]"),
12757 pulongest (dwp_file
->cus
->version
),
12758 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12762 dwp_file
->version
= dwp_file
->cus
->version
;
12763 else if (dwp_file
->tus
)
12764 dwp_file
->version
= dwp_file
->tus
->version
;
12766 dwp_file
->version
= 2;
12768 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
12770 if (dwp_file
->version
== 2)
12771 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12774 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
12778 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12779 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12781 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
12782 dwarf_read_debug_printf (" %s CUs, %s TUs",
12783 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12784 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12789 /* Wrapper around open_and_init_dwp_file, only open it once. */
12791 static struct dwp_file
*
12792 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
12794 if (!per_objfile
->per_bfd
->dwp_checked
)
12796 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
12797 per_objfile
->per_bfd
->dwp_checked
= 1;
12799 return per_objfile
->per_bfd
->dwp_file
.get ();
12802 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12803 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12804 or in the DWP file for the objfile, referenced by THIS_UNIT.
12805 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12806 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12808 This is called, for example, when wanting to read a variable with a
12809 complex location. Therefore we don't want to do file i/o for every call.
12810 Therefore we don't want to look for a DWO file on every call.
12811 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12812 then we check if we've already seen DWO_NAME, and only THEN do we check
12815 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12816 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12818 static struct dwo_unit
*
12819 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12820 ULONGEST signature
, int is_debug_types
)
12822 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12823 struct objfile
*objfile
= per_objfile
->objfile
;
12824 const char *kind
= is_debug_types
? "TU" : "CU";
12825 void **dwo_file_slot
;
12826 struct dwo_file
*dwo_file
;
12827 struct dwp_file
*dwp_file
;
12829 /* First see if there's a DWP file.
12830 If we have a DWP file but didn't find the DWO inside it, don't
12831 look for the original DWO file. It makes gdb behave differently
12832 depending on whether one is debugging in the build tree. */
12834 dwp_file
= get_dwp_file (per_objfile
);
12835 if (dwp_file
!= NULL
)
12837 const struct dwp_hash_table
*dwp_htab
=
12838 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12840 if (dwp_htab
!= NULL
)
12842 struct dwo_unit
*dwo_cutu
=
12843 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
12846 if (dwo_cutu
!= NULL
)
12848 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
12849 kind
, hex_string (signature
),
12850 host_address_to_string (dwo_cutu
));
12858 /* No DWP file, look for the DWO file. */
12860 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
12861 if (*dwo_file_slot
== NULL
)
12863 /* Read in the file and build a table of the CUs/TUs it contains. */
12864 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
12866 /* NOTE: This will be NULL if unable to open the file. */
12867 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12869 if (dwo_file
!= NULL
)
12871 struct dwo_unit
*dwo_cutu
= NULL
;
12873 if (is_debug_types
&& dwo_file
->tus
)
12875 struct dwo_unit find_dwo_cutu
;
12877 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12878 find_dwo_cutu
.signature
= signature
;
12880 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12883 else if (!is_debug_types
&& dwo_file
->cus
)
12885 struct dwo_unit find_dwo_cutu
;
12887 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12888 find_dwo_cutu
.signature
= signature
;
12889 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12893 if (dwo_cutu
!= NULL
)
12895 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
12896 kind
, dwo_name
, hex_string (signature
),
12897 host_address_to_string (dwo_cutu
));
12904 /* We didn't find it. This could mean a dwo_id mismatch, or
12905 someone deleted the DWO/DWP file, or the search path isn't set up
12906 correctly to find the file. */
12908 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
12909 kind
, dwo_name
, hex_string (signature
));
12911 /* This is a warning and not a complaint because it can be caused by
12912 pilot error (e.g., user accidentally deleting the DWO). */
12914 /* Print the name of the DWP file if we looked there, helps the user
12915 better diagnose the problem. */
12916 std::string dwp_text
;
12918 if (dwp_file
!= NULL
)
12919 dwp_text
= string_printf (" [in DWP file %s]",
12920 lbasename (dwp_file
->name
));
12922 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12923 " [in module %s]"),
12924 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
12925 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
12930 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12931 See lookup_dwo_cutu_unit for details. */
12933 static struct dwo_unit
*
12934 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
12935 ULONGEST signature
)
12937 gdb_assert (!cu
->per_cu
->is_debug_types
);
12939 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
12942 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12943 See lookup_dwo_cutu_unit for details. */
12945 static struct dwo_unit
*
12946 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
12948 gdb_assert (cu
->per_cu
->is_debug_types
);
12950 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
12952 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
12955 /* Traversal function for queue_and_load_all_dwo_tus. */
12958 queue_and_load_dwo_tu (void **slot
, void *info
)
12960 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12961 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
12962 ULONGEST signature
= dwo_unit
->signature
;
12963 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
12965 if (sig_type
!= NULL
)
12967 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12968 a real dependency of PER_CU on SIG_TYPE. That is detected later
12969 while processing PER_CU. */
12970 if (maybe_queue_comp_unit (NULL
, sig_type
, cu
->per_objfile
,
12972 load_full_type_unit (sig_type
, cu
->per_objfile
);
12973 cu
->per_cu
->imported_symtabs_push (sig_type
);
12979 /* Queue all TUs contained in the DWO of CU to be read in.
12980 The DWO may have the only definition of the type, though it may not be
12981 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12982 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12985 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
12987 struct dwo_unit
*dwo_unit
;
12988 struct dwo_file
*dwo_file
;
12990 gdb_assert (cu
!= nullptr);
12991 gdb_assert (!cu
->per_cu
->is_debug_types
);
12992 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
12994 dwo_unit
= cu
->dwo_unit
;
12995 gdb_assert (dwo_unit
!= NULL
);
12997 dwo_file
= dwo_unit
->dwo_file
;
12998 if (dwo_file
->tus
!= NULL
)
12999 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
13002 /* Read in various DIEs. */
13004 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13005 Inherit only the children of the DW_AT_abstract_origin DIE not being
13006 already referenced by DW_AT_abstract_origin from the children of the
13010 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13012 struct die_info
*child_die
;
13013 sect_offset
*offsetp
;
13014 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13015 struct die_info
*origin_die
;
13016 /* Iterator of the ORIGIN_DIE children. */
13017 struct die_info
*origin_child_die
;
13018 struct attribute
*attr
;
13019 struct dwarf2_cu
*origin_cu
;
13020 struct pending
**origin_previous_list_in_scope
;
13022 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13026 /* Note that following die references may follow to a die in a
13030 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13032 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13034 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13035 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13037 if (die
->tag
!= origin_die
->tag
13038 && !(die
->tag
== DW_TAG_inlined_subroutine
13039 && origin_die
->tag
== DW_TAG_subprogram
))
13040 complaint (_("DIE %s and its abstract origin %s have different tags"),
13041 sect_offset_str (die
->sect_off
),
13042 sect_offset_str (origin_die
->sect_off
));
13044 /* Find if the concrete and abstract trees are structurally the
13045 same. This is a shallow traversal and it is not bullet-proof;
13046 the compiler can trick the debugger into believing that the trees
13047 are isomorphic, whereas they actually are not. However, the
13048 likelyhood of this happening is pretty low, and a full-fledged
13049 check would be an overkill. */
13050 bool are_isomorphic
= true;
13051 die_info
*concrete_child
= die
->child
;
13052 die_info
*abstract_child
= origin_die
->child
;
13053 while (concrete_child
!= nullptr || abstract_child
!= nullptr)
13055 if (concrete_child
== nullptr
13056 || abstract_child
== nullptr
13057 || concrete_child
->tag
!= abstract_child
->tag
)
13059 are_isomorphic
= false;
13063 concrete_child
= concrete_child
->sibling
;
13064 abstract_child
= abstract_child
->sibling
;
13067 /* Walk the origin's children in parallel to the concrete children.
13068 This helps match an origin child in case the debug info misses
13069 DW_AT_abstract_origin attributes. Keep in mind that the abstract
13070 origin tree may not have the same tree structure as the concrete
13072 die_info
*corresponding_abstract_child
13073 = are_isomorphic
? origin_die
->child
: nullptr;
13075 std::vector
<sect_offset
> offsets
;
13077 for (child_die
= die
->child
;
13078 child_die
&& child_die
->tag
;
13079 child_die
= child_die
->sibling
)
13081 struct die_info
*child_origin_die
;
13082 struct dwarf2_cu
*child_origin_cu
;
13084 /* We are trying to process concrete instance entries:
13085 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13086 it's not relevant to our analysis here. i.e. detecting DIEs that are
13087 present in the abstract instance but not referenced in the concrete
13089 if (child_die
->tag
== DW_TAG_call_site
13090 || child_die
->tag
== DW_TAG_GNU_call_site
)
13092 if (are_isomorphic
)
13093 corresponding_abstract_child
13094 = corresponding_abstract_child
->sibling
;
13098 /* For each CHILD_DIE, find the corresponding child of
13099 ORIGIN_DIE. If there is more than one layer of
13100 DW_AT_abstract_origin, follow them all; there shouldn't be,
13101 but GCC versions at least through 4.4 generate this (GCC PR
13103 child_origin_die
= child_die
;
13104 child_origin_cu
= cu
;
13107 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13111 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13115 /* If missing DW_AT_abstract_origin, try the corresponding child
13116 of the origin. Clang emits such lexical scopes. */
13117 if (child_origin_die
== child_die
13118 && dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
) == nullptr
13120 && child_die
->tag
== DW_TAG_lexical_block
)
13121 child_origin_die
= corresponding_abstract_child
;
13123 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13124 counterpart may exist. */
13125 if (child_origin_die
!= child_die
)
13127 if (child_die
->tag
!= child_origin_die
->tag
13128 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13129 && child_origin_die
->tag
== DW_TAG_subprogram
))
13130 complaint (_("Child DIE %s and its abstract origin %s have "
13132 sect_offset_str (child_die
->sect_off
),
13133 sect_offset_str (child_origin_die
->sect_off
));
13134 if (child_origin_die
->parent
!= origin_die
)
13135 complaint (_("Child DIE %s and its abstract origin %s have "
13136 "different parents"),
13137 sect_offset_str (child_die
->sect_off
),
13138 sect_offset_str (child_origin_die
->sect_off
));
13140 offsets
.push_back (child_origin_die
->sect_off
);
13143 if (are_isomorphic
)
13144 corresponding_abstract_child
= corresponding_abstract_child
->sibling
;
13146 std::sort (offsets
.begin (), offsets
.end ());
13147 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13148 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13149 if (offsetp
[-1] == *offsetp
)
13150 complaint (_("Multiple children of DIE %s refer "
13151 "to DIE %s as their abstract origin"),
13152 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13154 offsetp
= offsets
.data ();
13155 origin_child_die
= origin_die
->child
;
13156 while (origin_child_die
&& origin_child_die
->tag
)
13158 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13159 while (offsetp
< offsets_end
13160 && *offsetp
< origin_child_die
->sect_off
)
13162 if (offsetp
>= offsets_end
13163 || *offsetp
> origin_child_die
->sect_off
)
13165 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13166 Check whether we're already processing ORIGIN_CHILD_DIE.
13167 This can happen with mutually referenced abstract_origins.
13169 if (!origin_child_die
->in_process
)
13170 process_die (origin_child_die
, origin_cu
);
13172 origin_child_die
= origin_child_die
->sibling
;
13174 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13176 if (cu
!= origin_cu
)
13177 compute_delayed_physnames (origin_cu
);
13181 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13183 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13184 struct gdbarch
*gdbarch
= objfile
->arch ();
13185 struct context_stack
*newobj
;
13188 struct die_info
*child_die
;
13189 struct attribute
*attr
, *call_line
, *call_file
;
13191 CORE_ADDR baseaddr
;
13192 struct block
*block
;
13193 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13194 std::vector
<struct symbol
*> template_args
;
13195 struct template_symbol
*templ_func
= NULL
;
13199 /* If we do not have call site information, we can't show the
13200 caller of this inlined function. That's too confusing, so
13201 only use the scope for local variables. */
13202 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13203 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13204 if (call_line
== NULL
|| call_file
== NULL
)
13206 read_lexical_block_scope (die
, cu
);
13211 baseaddr
= objfile
->text_section_offset ();
13213 name
= dwarf2_name (die
, cu
);
13215 /* Ignore functions with missing or empty names. These are actually
13216 illegal according to the DWARF standard. */
13219 complaint (_("missing name for subprogram DIE at %s"),
13220 sect_offset_str (die
->sect_off
));
13224 /* Ignore functions with missing or invalid low and high pc attributes. */
13225 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13226 <= PC_BOUNDS_INVALID
)
13228 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13229 if (attr
== nullptr || !attr
->as_boolean ())
13230 complaint (_("cannot get low and high bounds "
13231 "for subprogram DIE at %s"),
13232 sect_offset_str (die
->sect_off
));
13236 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13237 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13239 /* If we have any template arguments, then we must allocate a
13240 different sort of symbol. */
13241 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13243 if (child_die
->tag
== DW_TAG_template_type_param
13244 || child_die
->tag
== DW_TAG_template_value_param
)
13246 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13247 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13252 gdb_assert (cu
->get_builder () != nullptr);
13253 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13254 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13255 (struct symbol
*) templ_func
);
13257 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13258 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13261 /* If there is a location expression for DW_AT_frame_base, record
13263 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13264 if (attr
!= nullptr)
13265 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13267 /* If there is a location for the static link, record it. */
13268 newobj
->static_link
= NULL
;
13269 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13270 if (attr
!= nullptr)
13272 newobj
->static_link
13273 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13274 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13278 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13280 if (die
->child
!= NULL
)
13282 child_die
= die
->child
;
13283 while (child_die
&& child_die
->tag
)
13285 if (child_die
->tag
== DW_TAG_template_type_param
13286 || child_die
->tag
== DW_TAG_template_value_param
)
13288 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13291 template_args
.push_back (arg
);
13294 process_die (child_die
, cu
);
13295 child_die
= child_die
->sibling
;
13299 inherit_abstract_dies (die
, cu
);
13301 /* If we have a DW_AT_specification, we might need to import using
13302 directives from the context of the specification DIE. See the
13303 comment in determine_prefix. */
13304 if (cu
->language
== language_cplus
13305 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13307 struct dwarf2_cu
*spec_cu
= cu
;
13308 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13312 child_die
= spec_die
->child
;
13313 while (child_die
&& child_die
->tag
)
13315 if (child_die
->tag
== DW_TAG_imported_module
)
13316 process_die (child_die
, spec_cu
);
13317 child_die
= child_die
->sibling
;
13320 /* In some cases, GCC generates specification DIEs that
13321 themselves contain DW_AT_specification attributes. */
13322 spec_die
= die_specification (spec_die
, &spec_cu
);
13326 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13327 /* Make a block for the local symbols within. */
13328 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13329 cstk
.static_link
, lowpc
, highpc
);
13331 /* For C++, set the block's scope. */
13332 if ((cu
->language
== language_cplus
13333 || cu
->language
== language_fortran
13334 || cu
->language
== language_d
13335 || cu
->language
== language_rust
)
13336 && cu
->processing_has_namespace_info
)
13337 block_set_scope (block
, determine_prefix (die
, cu
),
13338 &objfile
->objfile_obstack
);
13340 /* If we have address ranges, record them. */
13341 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13343 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13345 /* Attach template arguments to function. */
13346 if (!template_args
.empty ())
13348 gdb_assert (templ_func
!= NULL
);
13350 templ_func
->n_template_arguments
= template_args
.size ();
13351 templ_func
->template_arguments
13352 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13353 templ_func
->n_template_arguments
);
13354 memcpy (templ_func
->template_arguments
,
13355 template_args
.data (),
13356 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13358 /* Make sure that the symtab is set on the new symbols. Even
13359 though they don't appear in this symtab directly, other parts
13360 of gdb assume that symbols do, and this is reasonably
13362 for (symbol
*sym
: template_args
)
13363 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13366 /* In C++, we can have functions nested inside functions (e.g., when
13367 a function declares a class that has methods). This means that
13368 when we finish processing a function scope, we may need to go
13369 back to building a containing block's symbol lists. */
13370 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13371 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13373 /* If we've finished processing a top-level function, subsequent
13374 symbols go in the file symbol list. */
13375 if (cu
->get_builder ()->outermost_context_p ())
13376 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13379 /* Process all the DIES contained within a lexical block scope. Start
13380 a new scope, process the dies, and then close the scope. */
13383 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13385 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13386 struct gdbarch
*gdbarch
= objfile
->arch ();
13387 CORE_ADDR lowpc
, highpc
;
13388 struct die_info
*child_die
;
13389 CORE_ADDR baseaddr
;
13391 baseaddr
= objfile
->text_section_offset ();
13393 /* Ignore blocks with missing or invalid low and high pc attributes. */
13394 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13395 as multiple lexical blocks? Handling children in a sane way would
13396 be nasty. Might be easier to properly extend generic blocks to
13397 describe ranges. */
13398 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13400 case PC_BOUNDS_NOT_PRESENT
:
13401 /* DW_TAG_lexical_block has no attributes, process its children as if
13402 there was no wrapping by that DW_TAG_lexical_block.
13403 GCC does no longer produces such DWARF since GCC r224161. */
13404 for (child_die
= die
->child
;
13405 child_die
!= NULL
&& child_die
->tag
;
13406 child_die
= child_die
->sibling
)
13408 /* We might already be processing this DIE. This can happen
13409 in an unusual circumstance -- where a subroutine A
13410 appears lexically in another subroutine B, but A actually
13411 inlines B. The recursion is broken here, rather than in
13412 inherit_abstract_dies, because it seems better to simply
13413 drop concrete children here. */
13414 if (!child_die
->in_process
)
13415 process_die (child_die
, cu
);
13418 case PC_BOUNDS_INVALID
:
13421 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13422 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13424 cu
->get_builder ()->push_context (0, lowpc
);
13425 if (die
->child
!= NULL
)
13427 child_die
= die
->child
;
13428 while (child_die
&& child_die
->tag
)
13430 process_die (child_die
, cu
);
13431 child_die
= child_die
->sibling
;
13434 inherit_abstract_dies (die
, cu
);
13435 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13437 if (*cu
->get_builder ()->get_local_symbols () != NULL
13438 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13440 struct block
*block
13441 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13442 cstk
.start_addr
, highpc
);
13444 /* Note that recording ranges after traversing children, as we
13445 do here, means that recording a parent's ranges entails
13446 walking across all its children's ranges as they appear in
13447 the address map, which is quadratic behavior.
13449 It would be nicer to record the parent's ranges before
13450 traversing its children, simply overriding whatever you find
13451 there. But since we don't even decide whether to create a
13452 block until after we've traversed its children, that's hard
13454 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13456 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13457 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13460 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13463 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13465 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13466 struct objfile
*objfile
= per_objfile
->objfile
;
13467 struct gdbarch
*gdbarch
= objfile
->arch ();
13468 CORE_ADDR pc
, baseaddr
;
13469 struct attribute
*attr
;
13470 struct call_site
*call_site
, call_site_local
;
13473 struct die_info
*child_die
;
13475 baseaddr
= objfile
->text_section_offset ();
13477 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13480 /* This was a pre-DWARF-5 GNU extension alias
13481 for DW_AT_call_return_pc. */
13482 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13486 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13487 "DIE %s [in module %s]"),
13488 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13491 pc
= attr
->as_address () + baseaddr
;
13492 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13494 if (cu
->call_site_htab
== NULL
)
13495 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13496 NULL
, &objfile
->objfile_obstack
,
13497 hashtab_obstack_allocate
, NULL
);
13498 call_site_local
.pc
= pc
;
13499 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13502 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13503 "DIE %s [in module %s]"),
13504 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13505 objfile_name (objfile
));
13509 /* Count parameters at the caller. */
13512 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13513 child_die
= child_die
->sibling
)
13515 if (child_die
->tag
!= DW_TAG_call_site_parameter
13516 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13518 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13519 "DW_TAG_call_site child DIE %s [in module %s]"),
13520 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13521 objfile_name (objfile
));
13529 = ((struct call_site
*)
13530 obstack_alloc (&objfile
->objfile_obstack
,
13531 sizeof (*call_site
)
13532 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13534 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13535 call_site
->pc
= pc
;
13537 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13538 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13540 struct die_info
*func_die
;
13542 /* Skip also over DW_TAG_inlined_subroutine. */
13543 for (func_die
= die
->parent
;
13544 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13545 && func_die
->tag
!= DW_TAG_subroutine_type
;
13546 func_die
= func_die
->parent
);
13548 /* DW_AT_call_all_calls is a superset
13549 of DW_AT_call_all_tail_calls. */
13551 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13552 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13553 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13554 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13556 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13557 not complete. But keep CALL_SITE for look ups via call_site_htab,
13558 both the initial caller containing the real return address PC and
13559 the final callee containing the current PC of a chain of tail
13560 calls do not need to have the tail call list complete. But any
13561 function candidate for a virtual tail call frame searched via
13562 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13563 determined unambiguously. */
13567 struct type
*func_type
= NULL
;
13570 func_type
= get_die_type (func_die
, cu
);
13571 if (func_type
!= NULL
)
13573 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13575 /* Enlist this call site to the function. */
13576 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13577 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13580 complaint (_("Cannot find function owning DW_TAG_call_site "
13581 "DIE %s [in module %s]"),
13582 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13586 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13588 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13590 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13593 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13594 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13596 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13597 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13598 /* Keep NULL DWARF_BLOCK. */;
13599 else if (attr
->form_is_block ())
13601 struct dwarf2_locexpr_baton
*dlbaton
;
13602 struct dwarf_block
*block
= attr
->as_block ();
13604 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13605 dlbaton
->data
= block
->data
;
13606 dlbaton
->size
= block
->size
;
13607 dlbaton
->per_objfile
= per_objfile
;
13608 dlbaton
->per_cu
= cu
->per_cu
;
13610 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13612 else if (attr
->form_is_ref ())
13614 struct dwarf2_cu
*target_cu
= cu
;
13615 struct die_info
*target_die
;
13617 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13618 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13619 if (die_is_declaration (target_die
, target_cu
))
13621 const char *target_physname
;
13623 /* Prefer the mangled name; otherwise compute the demangled one. */
13624 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13625 if (target_physname
== NULL
)
13626 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13627 if (target_physname
== NULL
)
13628 complaint (_("DW_AT_call_target target DIE has invalid "
13629 "physname, for referencing DIE %s [in module %s]"),
13630 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13632 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13638 /* DW_AT_entry_pc should be preferred. */
13639 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13640 <= PC_BOUNDS_INVALID
)
13641 complaint (_("DW_AT_call_target target DIE has invalid "
13642 "low pc, for referencing DIE %s [in module %s]"),
13643 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13646 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13647 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13652 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13653 "block nor reference, for DIE %s [in module %s]"),
13654 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13656 call_site
->per_cu
= cu
->per_cu
;
13657 call_site
->per_objfile
= per_objfile
;
13659 for (child_die
= die
->child
;
13660 child_die
&& child_die
->tag
;
13661 child_die
= child_die
->sibling
)
13663 struct call_site_parameter
*parameter
;
13664 struct attribute
*loc
, *origin
;
13666 if (child_die
->tag
!= DW_TAG_call_site_parameter
13667 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13669 /* Already printed the complaint above. */
13673 gdb_assert (call_site
->parameter_count
< nparams
);
13674 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13676 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13677 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13678 register is contained in DW_AT_call_value. */
13680 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13681 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13682 if (origin
== NULL
)
13684 /* This was a pre-DWARF-5 GNU extension alias
13685 for DW_AT_call_parameter. */
13686 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13688 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13690 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13692 sect_offset sect_off
= origin
->get_ref_die_offset ();
13693 if (!cu
->header
.offset_in_cu_p (sect_off
))
13695 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13696 binding can be done only inside one CU. Such referenced DIE
13697 therefore cannot be even moved to DW_TAG_partial_unit. */
13698 complaint (_("DW_AT_call_parameter offset is not in CU for "
13699 "DW_TAG_call_site child DIE %s [in module %s]"),
13700 sect_offset_str (child_die
->sect_off
),
13701 objfile_name (objfile
));
13704 parameter
->u
.param_cu_off
13705 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13707 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13709 complaint (_("No DW_FORM_block* DW_AT_location for "
13710 "DW_TAG_call_site child DIE %s [in module %s]"),
13711 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13716 struct dwarf_block
*block
= loc
->as_block ();
13718 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13719 (block
->data
, &block
->data
[block
->size
]);
13720 if (parameter
->u
.dwarf_reg
!= -1)
13721 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13722 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
13723 &block
->data
[block
->size
],
13724 ¶meter
->u
.fb_offset
))
13725 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13728 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13729 "for DW_FORM_block* DW_AT_location is supported for "
13730 "DW_TAG_call_site child DIE %s "
13732 sect_offset_str (child_die
->sect_off
),
13733 objfile_name (objfile
));
13738 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13740 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13741 if (attr
== NULL
|| !attr
->form_is_block ())
13743 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13744 "DW_TAG_call_site child DIE %s [in module %s]"),
13745 sect_offset_str (child_die
->sect_off
),
13746 objfile_name (objfile
));
13750 struct dwarf_block
*block
= attr
->as_block ();
13751 parameter
->value
= block
->data
;
13752 parameter
->value_size
= block
->size
;
13754 /* Parameters are not pre-cleared by memset above. */
13755 parameter
->data_value
= NULL
;
13756 parameter
->data_value_size
= 0;
13757 call_site
->parameter_count
++;
13759 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13761 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13762 if (attr
!= nullptr)
13764 if (!attr
->form_is_block ())
13765 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13766 "DW_TAG_call_site child DIE %s [in module %s]"),
13767 sect_offset_str (child_die
->sect_off
),
13768 objfile_name (objfile
));
13771 block
= attr
->as_block ();
13772 parameter
->data_value
= block
->data
;
13773 parameter
->data_value_size
= block
->size
;
13779 /* Helper function for read_variable. If DIE represents a virtual
13780 table, then return the type of the concrete object that is
13781 associated with the virtual table. Otherwise, return NULL. */
13783 static struct type
*
13784 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13786 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13790 /* Find the type DIE. */
13791 struct die_info
*type_die
= NULL
;
13792 struct dwarf2_cu
*type_cu
= cu
;
13794 if (attr
->form_is_ref ())
13795 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13796 if (type_die
== NULL
)
13799 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13801 return die_containing_type (type_die
, type_cu
);
13804 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13807 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13809 struct rust_vtable_symbol
*storage
= NULL
;
13811 if (cu
->language
== language_rust
)
13813 struct type
*containing_type
= rust_containing_type (die
, cu
);
13815 if (containing_type
!= NULL
)
13817 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13819 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
13820 storage
->concrete_type
= containing_type
;
13821 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13825 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13826 struct attribute
*abstract_origin
13827 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13828 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13829 if (res
== NULL
&& loc
&& abstract_origin
)
13831 /* We have a variable without a name, but with a location and an abstract
13832 origin. This may be a concrete instance of an abstract variable
13833 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13835 struct dwarf2_cu
*origin_cu
= cu
;
13836 struct die_info
*origin_die
13837 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13838 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13839 per_objfile
->per_bfd
->abstract_to_concrete
13840 [origin_die
->sect_off
].push_back (die
->sect_off
);
13844 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13845 reading .debug_rnglists.
13846 Callback's type should be:
13847 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13848 Return true if the attributes are present and valid, otherwise,
13851 template <typename Callback
>
13853 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13854 dwarf_tag tag
, Callback
&&callback
)
13856 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13857 struct objfile
*objfile
= per_objfile
->objfile
;
13858 bfd
*obfd
= objfile
->obfd
;
13859 /* Base address selection entry. */
13860 gdb::optional
<CORE_ADDR
> base
;
13861 const gdb_byte
*buffer
;
13862 CORE_ADDR baseaddr
;
13863 bool overflow
= false;
13864 ULONGEST addr_index
;
13865 struct dwarf2_section_info
*rnglists_section
;
13867 base
= cu
->base_address
;
13868 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
13869 rnglists_section
->read (objfile
);
13871 if (offset
>= rnglists_section
->size
)
13873 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13877 buffer
= rnglists_section
->buffer
+ offset
;
13879 baseaddr
= objfile
->text_section_offset ();
13883 /* Initialize it due to a false compiler warning. */
13884 CORE_ADDR range_beginning
= 0, range_end
= 0;
13885 const gdb_byte
*buf_end
= (rnglists_section
->buffer
13886 + rnglists_section
->size
);
13887 unsigned int bytes_read
;
13889 if (buffer
== buf_end
)
13894 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13897 case DW_RLE_end_of_list
:
13899 case DW_RLE_base_address
:
13900 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13905 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13906 buffer
+= bytes_read
;
13908 case DW_RLE_base_addressx
:
13909 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13910 buffer
+= bytes_read
;
13911 base
= read_addr_index (cu
, addr_index
);
13913 case DW_RLE_start_length
:
13914 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13919 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13921 buffer
+= bytes_read
;
13922 range_end
= (range_beginning
13923 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13924 buffer
+= bytes_read
;
13925 if (buffer
> buf_end
)
13931 case DW_RLE_startx_length
:
13932 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13933 buffer
+= bytes_read
;
13934 range_beginning
= read_addr_index (cu
, addr_index
);
13935 if (buffer
> buf_end
)
13940 range_end
= (range_beginning
13941 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13942 buffer
+= bytes_read
;
13944 case DW_RLE_offset_pair
:
13945 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13946 buffer
+= bytes_read
;
13947 if (buffer
> buf_end
)
13952 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13953 buffer
+= bytes_read
;
13954 if (buffer
> buf_end
)
13960 case DW_RLE_start_end
:
13961 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13966 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13968 buffer
+= bytes_read
;
13969 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13970 buffer
+= bytes_read
;
13972 case DW_RLE_startx_endx
:
13973 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13974 buffer
+= bytes_read
;
13975 range_beginning
= read_addr_index (cu
, addr_index
);
13976 if (buffer
> buf_end
)
13981 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13982 buffer
+= bytes_read
;
13983 range_end
= read_addr_index (cu
, addr_index
);
13986 complaint (_("Invalid .debug_rnglists data (no base address)"));
13989 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13991 if (rlet
== DW_RLE_base_address
)
13994 if (range_beginning
> range_end
)
13996 /* Inverted range entries are invalid. */
13997 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14001 /* Empty range entries have no effect. */
14002 if (range_beginning
== range_end
)
14005 /* Only DW_RLE_offset_pair needs the base address added. */
14006 if (rlet
== DW_RLE_offset_pair
)
14008 if (!base
.has_value ())
14010 /* We have no valid base address for the DW_RLE_offset_pair. */
14011 complaint (_("Invalid .debug_rnglists data (no base address for "
14012 "DW_RLE_offset_pair)"));
14016 range_beginning
+= *base
;
14017 range_end
+= *base
;
14020 /* A not-uncommon case of bad debug info.
14021 Don't pollute the addrmap with bad data. */
14022 if (range_beginning
+ baseaddr
== 0
14023 && !per_objfile
->per_bfd
->has_section_at_zero
)
14025 complaint (_(".debug_rnglists entry has start address of zero"
14026 " [in module %s]"), objfile_name (objfile
));
14030 callback (range_beginning
, range_end
);
14035 complaint (_("Offset %d is not terminated "
14036 "for DW_AT_ranges attribute"),
14044 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14045 Callback's type should be:
14046 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14047 Return 1 if the attributes are present and valid, otherwise, return 0. */
14049 template <typename Callback
>
14051 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
14052 Callback
&&callback
)
14054 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14055 struct objfile
*objfile
= per_objfile
->objfile
;
14056 struct comp_unit_head
*cu_header
= &cu
->header
;
14057 bfd
*obfd
= objfile
->obfd
;
14058 unsigned int addr_size
= cu_header
->addr_size
;
14059 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14060 /* Base address selection entry. */
14061 gdb::optional
<CORE_ADDR
> base
;
14062 unsigned int dummy
;
14063 const gdb_byte
*buffer
;
14064 CORE_ADDR baseaddr
;
14066 if (cu_header
->version
>= 5)
14067 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
14069 base
= cu
->base_address
;
14071 per_objfile
->per_bfd
->ranges
.read (objfile
);
14072 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
14074 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14078 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
14080 baseaddr
= objfile
->text_section_offset ();
14084 CORE_ADDR range_beginning
, range_end
;
14086 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14087 buffer
+= addr_size
;
14088 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14089 buffer
+= addr_size
;
14090 offset
+= 2 * addr_size
;
14092 /* An end of list marker is a pair of zero addresses. */
14093 if (range_beginning
== 0 && range_end
== 0)
14094 /* Found the end of list entry. */
14097 /* Each base address selection entry is a pair of 2 values.
14098 The first is the largest possible address, the second is
14099 the base address. Check for a base address here. */
14100 if ((range_beginning
& mask
) == mask
)
14102 /* If we found the largest possible address, then we already
14103 have the base address in range_end. */
14108 if (!base
.has_value ())
14110 /* We have no valid base address for the ranges
14112 complaint (_("Invalid .debug_ranges data (no base address)"));
14116 if (range_beginning
> range_end
)
14118 /* Inverted range entries are invalid. */
14119 complaint (_("Invalid .debug_ranges data (inverted range)"));
14123 /* Empty range entries have no effect. */
14124 if (range_beginning
== range_end
)
14127 range_beginning
+= *base
;
14128 range_end
+= *base
;
14130 /* A not-uncommon case of bad debug info.
14131 Don't pollute the addrmap with bad data. */
14132 if (range_beginning
+ baseaddr
== 0
14133 && !per_objfile
->per_bfd
->has_section_at_zero
)
14135 complaint (_(".debug_ranges entry has start address of zero"
14136 " [in module %s]"), objfile_name (objfile
));
14140 callback (range_beginning
, range_end
);
14146 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14147 Return 1 if the attributes are present and valid, otherwise, return 0.
14148 If RANGES_PST is not NULL we should set up the `psymtabs_addrmap'. */
14151 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14152 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14153 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
14155 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14156 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
14157 struct gdbarch
*gdbarch
= objfile
->arch ();
14158 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14161 CORE_ADDR high
= 0;
14164 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14165 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14167 if (ranges_pst
!= NULL
)
14172 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14173 range_beginning
+ baseaddr
)
14175 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14176 range_end
+ baseaddr
)
14178 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
14179 lowpc
, highpc
- 1, ranges_pst
);
14182 /* FIXME: This is recording everything as a low-high
14183 segment of consecutive addresses. We should have a
14184 data structure for discontiguous block ranges
14188 low
= range_beginning
;
14194 if (range_beginning
< low
)
14195 low
= range_beginning
;
14196 if (range_end
> high
)
14204 /* If the first entry is an end-of-list marker, the range
14205 describes an empty scope, i.e. no instructions. */
14211 *high_return
= high
;
14215 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14216 definition for the return value. *LOWPC and *HIGHPC are set iff
14217 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14219 static enum pc_bounds_kind
14220 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14221 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14222 dwarf2_psymtab
*pst
)
14224 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14225 struct attribute
*attr
;
14226 struct attribute
*attr_high
;
14228 CORE_ADDR high
= 0;
14229 enum pc_bounds_kind ret
;
14231 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14234 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14235 if (attr
!= nullptr)
14237 low
= attr
->as_address ();
14238 high
= attr_high
->as_address ();
14239 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14243 /* Found high w/o low attribute. */
14244 return PC_BOUNDS_INVALID
;
14246 /* Found consecutive range of addresses. */
14247 ret
= PC_BOUNDS_HIGH_LOW
;
14251 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14252 if (attr
!= nullptr && attr
->form_is_unsigned ())
14254 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14255 on DWARF version). */
14256 ULONGEST ranges_offset
= attr
->as_unsigned ();
14258 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14260 if (die
->tag
!= DW_TAG_compile_unit
)
14261 ranges_offset
+= cu
->gnu_ranges_base
;
14263 /* Value of the DW_AT_ranges attribute is the offset in the
14264 .debug_ranges section. */
14265 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14267 return PC_BOUNDS_INVALID
;
14268 /* Found discontinuous range of addresses. */
14269 ret
= PC_BOUNDS_RANGES
;
14272 return PC_BOUNDS_NOT_PRESENT
;
14275 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14277 return PC_BOUNDS_INVALID
;
14279 /* When using the GNU linker, .gnu.linkonce. sections are used to
14280 eliminate duplicate copies of functions and vtables and such.
14281 The linker will arbitrarily choose one and discard the others.
14282 The AT_*_pc values for such functions refer to local labels in
14283 these sections. If the section from that file was discarded, the
14284 labels are not in the output, so the relocs get a value of 0.
14285 If this is a discarded function, mark the pc bounds as invalid,
14286 so that GDB will ignore it. */
14287 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14288 return PC_BOUNDS_INVALID
;
14296 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14297 its low and high PC addresses. Do nothing if these addresses could not
14298 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14299 and HIGHPC to the high address if greater than HIGHPC. */
14302 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14303 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14304 struct dwarf2_cu
*cu
)
14306 CORE_ADDR low
, high
;
14307 struct die_info
*child
= die
->child
;
14309 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14311 *lowpc
= std::min (*lowpc
, low
);
14312 *highpc
= std::max (*highpc
, high
);
14315 /* If the language does not allow nested subprograms (either inside
14316 subprograms or lexical blocks), we're done. */
14317 if (cu
->language
!= language_ada
)
14320 /* Check all the children of the given DIE. If it contains nested
14321 subprograms, then check their pc bounds. Likewise, we need to
14322 check lexical blocks as well, as they may also contain subprogram
14324 while (child
&& child
->tag
)
14326 if (child
->tag
== DW_TAG_subprogram
14327 || child
->tag
== DW_TAG_lexical_block
)
14328 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14329 child
= child
->sibling
;
14333 /* Get the low and high pc's represented by the scope DIE, and store
14334 them in *LOWPC and *HIGHPC. If the correct values can't be
14335 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14338 get_scope_pc_bounds (struct die_info
*die
,
14339 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14340 struct dwarf2_cu
*cu
)
14342 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14343 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14344 CORE_ADDR current_low
, current_high
;
14346 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14347 >= PC_BOUNDS_RANGES
)
14349 best_low
= current_low
;
14350 best_high
= current_high
;
14354 struct die_info
*child
= die
->child
;
14356 while (child
&& child
->tag
)
14358 switch (child
->tag
) {
14359 case DW_TAG_subprogram
:
14360 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14362 case DW_TAG_namespace
:
14363 case DW_TAG_module
:
14364 /* FIXME: carlton/2004-01-16: Should we do this for
14365 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14366 that current GCC's always emit the DIEs corresponding
14367 to definitions of methods of classes as children of a
14368 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14369 the DIEs giving the declarations, which could be
14370 anywhere). But I don't see any reason why the
14371 standards says that they have to be there. */
14372 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14374 if (current_low
!= ((CORE_ADDR
) -1))
14376 best_low
= std::min (best_low
, current_low
);
14377 best_high
= std::max (best_high
, current_high
);
14385 child
= child
->sibling
;
14390 *highpc
= best_high
;
14393 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14397 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14398 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14400 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14401 struct gdbarch
*gdbarch
= objfile
->arch ();
14402 struct attribute
*attr
;
14403 struct attribute
*attr_high
;
14405 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14408 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14409 if (attr
!= nullptr)
14411 CORE_ADDR low
= attr
->as_address ();
14412 CORE_ADDR high
= attr_high
->as_address ();
14414 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14417 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14418 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14419 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14423 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14424 if (attr
!= nullptr && attr
->form_is_unsigned ())
14426 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14427 on DWARF version). */
14428 ULONGEST ranges_offset
= attr
->as_unsigned ();
14430 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14432 if (die
->tag
!= DW_TAG_compile_unit
)
14433 ranges_offset
+= cu
->gnu_ranges_base
;
14435 std::vector
<blockrange
> blockvec
;
14436 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14437 [&] (CORE_ADDR start
, CORE_ADDR end
)
14441 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14442 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14443 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14444 blockvec
.emplace_back (start
, end
);
14447 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14451 /* Check whether the producer field indicates either of GCC < 4.6, or the
14452 Intel C/C++ compiler, and cache the result in CU. */
14455 check_producer (struct dwarf2_cu
*cu
)
14459 if (cu
->producer
== NULL
)
14461 /* For unknown compilers expect their behavior is DWARF version
14464 GCC started to support .debug_types sections by -gdwarf-4 since
14465 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14466 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14467 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14468 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14470 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14472 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14473 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14475 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14477 cu
->producer_is_icc
= true;
14478 cu
->producer_is_icc_lt_14
= major
< 14;
14480 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14481 cu
->producer_is_codewarrior
= true;
14484 /* For other non-GCC compilers, expect their behavior is DWARF version
14488 cu
->checked_producer
= true;
14491 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14492 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14493 during 4.6.0 experimental. */
14496 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14498 if (!cu
->checked_producer
)
14499 check_producer (cu
);
14501 return cu
->producer_is_gxx_lt_4_6
;
14505 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14506 with incorrect is_stmt attributes. */
14509 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14511 if (!cu
->checked_producer
)
14512 check_producer (cu
);
14514 return cu
->producer_is_codewarrior
;
14517 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14518 If that attribute is not available, return the appropriate
14521 static enum dwarf_access_attribute
14522 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14524 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14525 if (attr
!= nullptr)
14527 LONGEST value
= attr
->constant_value (-1);
14528 if (value
== DW_ACCESS_public
14529 || value
== DW_ACCESS_protected
14530 || value
== DW_ACCESS_private
)
14531 return (dwarf_access_attribute
) value
;
14532 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14536 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14538 /* The default DWARF 2 accessibility for members is public, the default
14539 accessibility for inheritance is private. */
14541 if (die
->tag
!= DW_TAG_inheritance
)
14542 return DW_ACCESS_public
;
14544 return DW_ACCESS_private
;
14548 /* DWARF 3+ defines the default accessibility a different way. The same
14549 rules apply now for DW_TAG_inheritance as for the members and it only
14550 depends on the container kind. */
14552 if (die
->parent
->tag
== DW_TAG_class_type
)
14553 return DW_ACCESS_private
;
14555 return DW_ACCESS_public
;
14559 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14560 offset. If the attribute was not found return 0, otherwise return
14561 1. If it was found but could not properly be handled, set *OFFSET
14565 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14568 struct attribute
*attr
;
14570 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14575 /* Note that we do not check for a section offset first here.
14576 This is because DW_AT_data_member_location is new in DWARF 4,
14577 so if we see it, we can assume that a constant form is really
14578 a constant and not a section offset. */
14579 if (attr
->form_is_constant ())
14580 *offset
= attr
->constant_value (0);
14581 else if (attr
->form_is_section_offset ())
14582 dwarf2_complex_location_expr_complaint ();
14583 else if (attr
->form_is_block ())
14584 *offset
= decode_locdesc (attr
->as_block (), cu
);
14586 dwarf2_complex_location_expr_complaint ();
14594 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14597 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14598 struct field
*field
)
14600 struct attribute
*attr
;
14602 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14605 if (attr
->form_is_constant ())
14607 LONGEST offset
= attr
->constant_value (0);
14608 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14610 else if (attr
->form_is_section_offset ())
14611 dwarf2_complex_location_expr_complaint ();
14612 else if (attr
->form_is_block ())
14615 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14617 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14620 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14621 struct objfile
*objfile
= per_objfile
->objfile
;
14622 struct dwarf2_locexpr_baton
*dlbaton
14623 = XOBNEW (&objfile
->objfile_obstack
,
14624 struct dwarf2_locexpr_baton
);
14625 dlbaton
->data
= attr
->as_block ()->data
;
14626 dlbaton
->size
= attr
->as_block ()->size
;
14627 /* When using this baton, we want to compute the address
14628 of the field, not the value. This is why
14629 is_reference is set to false here. */
14630 dlbaton
->is_reference
= false;
14631 dlbaton
->per_objfile
= per_objfile
;
14632 dlbaton
->per_cu
= cu
->per_cu
;
14634 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14638 dwarf2_complex_location_expr_complaint ();
14642 /* Add an aggregate field to the field list. */
14645 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14646 struct dwarf2_cu
*cu
)
14648 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14649 struct gdbarch
*gdbarch
= objfile
->arch ();
14650 struct nextfield
*new_field
;
14651 struct attribute
*attr
;
14653 const char *fieldname
= "";
14655 if (die
->tag
== DW_TAG_inheritance
)
14657 fip
->baseclasses
.emplace_back ();
14658 new_field
= &fip
->baseclasses
.back ();
14662 fip
->fields
.emplace_back ();
14663 new_field
= &fip
->fields
.back ();
14666 new_field
->offset
= die
->sect_off
;
14668 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
14669 if (new_field
->accessibility
!= DW_ACCESS_public
)
14670 fip
->non_public_fields
= true;
14672 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14673 if (attr
!= nullptr)
14674 new_field
->virtuality
= attr
->as_virtuality ();
14676 new_field
->virtuality
= DW_VIRTUALITY_none
;
14678 fp
= &new_field
->field
;
14680 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14682 /* Data member other than a C++ static data member. */
14684 /* Get type of field. */
14685 fp
->set_type (die_type (die
, cu
));
14687 SET_FIELD_BITPOS (*fp
, 0);
14689 /* Get bit size of field (zero if none). */
14690 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14691 if (attr
!= nullptr)
14693 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
14697 FIELD_BITSIZE (*fp
) = 0;
14700 /* Get bit offset of field. */
14701 handle_data_member_location (die
, cu
, fp
);
14702 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14703 if (attr
!= nullptr && attr
->form_is_constant ())
14705 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14707 /* For big endian bits, the DW_AT_bit_offset gives the
14708 additional bit offset from the MSB of the containing
14709 anonymous object to the MSB of the field. We don't
14710 have to do anything special since we don't need to
14711 know the size of the anonymous object. */
14712 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14713 + attr
->constant_value (0)));
14717 /* For little endian bits, compute the bit offset to the
14718 MSB of the anonymous object, subtract off the number of
14719 bits from the MSB of the field to the MSB of the
14720 object, and then subtract off the number of bits of
14721 the field itself. The result is the bit offset of
14722 the LSB of the field. */
14723 int anonymous_size
;
14724 int bit_offset
= attr
->constant_value (0);
14726 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14727 if (attr
!= nullptr && attr
->form_is_constant ())
14729 /* The size of the anonymous object containing
14730 the bit field is explicit, so use the
14731 indicated size (in bytes). */
14732 anonymous_size
= attr
->constant_value (0);
14736 /* The size of the anonymous object containing
14737 the bit field must be inferred from the type
14738 attribute of the data member containing the
14740 anonymous_size
= TYPE_LENGTH (fp
->type ());
14742 SET_FIELD_BITPOS (*fp
,
14743 (FIELD_BITPOS (*fp
)
14744 + anonymous_size
* bits_per_byte
14745 - bit_offset
- FIELD_BITSIZE (*fp
)));
14748 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14750 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14751 + attr
->constant_value (0)));
14753 /* Get name of field. */
14754 fieldname
= dwarf2_name (die
, cu
);
14755 if (fieldname
== NULL
)
14758 /* The name is already allocated along with this objfile, so we don't
14759 need to duplicate it for the type. */
14760 fp
->name
= fieldname
;
14762 /* Change accessibility for artificial fields (e.g. virtual table
14763 pointer or virtual base class pointer) to private. */
14764 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14766 FIELD_ARTIFICIAL (*fp
) = 1;
14767 new_field
->accessibility
= DW_ACCESS_private
;
14768 fip
->non_public_fields
= true;
14771 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14773 /* C++ static member. */
14775 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14776 is a declaration, but all versions of G++ as of this writing
14777 (so through at least 3.2.1) incorrectly generate
14778 DW_TAG_variable tags. */
14780 const char *physname
;
14782 /* Get name of field. */
14783 fieldname
= dwarf2_name (die
, cu
);
14784 if (fieldname
== NULL
)
14787 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14789 /* Only create a symbol if this is an external value.
14790 new_symbol checks this and puts the value in the global symbol
14791 table, which we want. If it is not external, new_symbol
14792 will try to put the value in cu->list_in_scope which is wrong. */
14793 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14795 /* A static const member, not much different than an enum as far as
14796 we're concerned, except that we can support more types. */
14797 new_symbol (die
, NULL
, cu
);
14800 /* Get physical name. */
14801 physname
= dwarf2_physname (fieldname
, die
, cu
);
14803 /* The name is already allocated along with this objfile, so we don't
14804 need to duplicate it for the type. */
14805 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14806 fp
->set_type (die_type (die
, cu
));
14807 FIELD_NAME (*fp
) = fieldname
;
14809 else if (die
->tag
== DW_TAG_inheritance
)
14811 /* C++ base class field. */
14812 handle_data_member_location (die
, cu
, fp
);
14813 FIELD_BITSIZE (*fp
) = 0;
14814 fp
->set_type (die_type (die
, cu
));
14815 FIELD_NAME (*fp
) = fp
->type ()->name ();
14818 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14821 /* Can the type given by DIE define another type? */
14824 type_can_define_types (const struct die_info
*die
)
14828 case DW_TAG_typedef
:
14829 case DW_TAG_class_type
:
14830 case DW_TAG_structure_type
:
14831 case DW_TAG_union_type
:
14832 case DW_TAG_enumeration_type
:
14840 /* Add a type definition defined in the scope of the FIP's class. */
14843 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14844 struct dwarf2_cu
*cu
)
14846 struct decl_field fp
;
14847 memset (&fp
, 0, sizeof (fp
));
14849 gdb_assert (type_can_define_types (die
));
14851 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14852 fp
.name
= dwarf2_name (die
, cu
);
14853 fp
.type
= read_type_die (die
, cu
);
14855 /* Save accessibility. */
14856 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
14857 switch (accessibility
)
14859 case DW_ACCESS_public
:
14860 /* The assumed value if neither private nor protected. */
14862 case DW_ACCESS_private
:
14865 case DW_ACCESS_protected
:
14866 fp
.is_protected
= 1;
14870 if (die
->tag
== DW_TAG_typedef
)
14871 fip
->typedef_field_list
.push_back (fp
);
14873 fip
->nested_types_list
.push_back (fp
);
14876 /* A convenience typedef that's used when finding the discriminant
14877 field for a variant part. */
14878 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
14881 /* Compute the discriminant range for a given variant. OBSTACK is
14882 where the results will be stored. VARIANT is the variant to
14883 process. IS_UNSIGNED indicates whether the discriminant is signed
14886 static const gdb::array_view
<discriminant_range
>
14887 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
14890 std::vector
<discriminant_range
> ranges
;
14892 if (variant
.default_branch
)
14895 if (variant
.discr_list_data
== nullptr)
14897 discriminant_range r
14898 = {variant
.discriminant_value
, variant
.discriminant_value
};
14899 ranges
.push_back (r
);
14903 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
14904 variant
.discr_list_data
->size
);
14905 while (!data
.empty ())
14907 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
14909 complaint (_("invalid discriminant marker: %d"), data
[0]);
14912 bool is_range
= data
[0] == DW_DSC_range
;
14913 data
= data
.slice (1);
14915 ULONGEST low
, high
;
14916 unsigned int bytes_read
;
14920 complaint (_("DW_AT_discr_list missing low value"));
14924 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
14926 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
14928 data
= data
.slice (bytes_read
);
14934 complaint (_("DW_AT_discr_list missing high value"));
14938 high
= read_unsigned_leb128 (nullptr, data
.data (),
14941 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
14943 data
= data
.slice (bytes_read
);
14948 ranges
.push_back ({ low
, high
});
14952 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
14954 std::copy (ranges
.begin (), ranges
.end (), result
);
14955 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
14958 static const gdb::array_view
<variant_part
> create_variant_parts
14959 (struct obstack
*obstack
,
14960 const offset_map_type
&offset_map
,
14961 struct field_info
*fi
,
14962 const std::vector
<variant_part_builder
> &variant_parts
);
14964 /* Fill in a "struct variant" for a given variant field. RESULT is
14965 the variant to fill in. OBSTACK is where any needed allocations
14966 will be done. OFFSET_MAP holds the mapping from section offsets to
14967 fields for the type. FI describes the fields of the type we're
14968 processing. FIELD is the variant field we're converting. */
14971 create_one_variant (variant
&result
, struct obstack
*obstack
,
14972 const offset_map_type
&offset_map
,
14973 struct field_info
*fi
, const variant_field
&field
)
14975 result
.discriminants
= convert_variant_range (obstack
, field
, false);
14976 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
14977 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
14978 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
14979 field
.variant_parts
);
14982 /* Fill in a "struct variant_part" for a given variant part. RESULT
14983 is the variant part to fill in. OBSTACK is where any needed
14984 allocations will be done. OFFSET_MAP holds the mapping from
14985 section offsets to fields for the type. FI describes the fields of
14986 the type we're processing. BUILDER is the variant part to be
14990 create_one_variant_part (variant_part
&result
,
14991 struct obstack
*obstack
,
14992 const offset_map_type
&offset_map
,
14993 struct field_info
*fi
,
14994 const variant_part_builder
&builder
)
14996 auto iter
= offset_map
.find (builder
.discriminant_offset
);
14997 if (iter
== offset_map
.end ())
14999 result
.discriminant_index
= -1;
15000 /* Doesn't matter. */
15001 result
.is_unsigned
= false;
15005 result
.discriminant_index
= iter
->second
;
15007 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
15010 size_t n
= builder
.variants
.size ();
15011 variant
*output
= new (obstack
) variant
[n
];
15012 for (size_t i
= 0; i
< n
; ++i
)
15013 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
15014 builder
.variants
[i
]);
15016 result
.variants
= gdb::array_view
<variant
> (output
, n
);
15019 /* Create a vector of variant parts that can be attached to a type.
15020 OBSTACK is where any needed allocations will be done. OFFSET_MAP
15021 holds the mapping from section offsets to fields for the type. FI
15022 describes the fields of the type we're processing. VARIANT_PARTS
15023 is the vector to convert. */
15025 static const gdb::array_view
<variant_part
>
15026 create_variant_parts (struct obstack
*obstack
,
15027 const offset_map_type
&offset_map
,
15028 struct field_info
*fi
,
15029 const std::vector
<variant_part_builder
> &variant_parts
)
15031 if (variant_parts
.empty ())
15034 size_t n
= variant_parts
.size ();
15035 variant_part
*result
= new (obstack
) variant_part
[n
];
15036 for (size_t i
= 0; i
< n
; ++i
)
15037 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
15040 return gdb::array_view
<variant_part
> (result
, n
);
15043 /* Compute the variant part vector for FIP, attaching it to TYPE when
15047 add_variant_property (struct field_info
*fip
, struct type
*type
,
15048 struct dwarf2_cu
*cu
)
15050 /* Map section offsets of fields to their field index. Note the
15051 field index here does not take the number of baseclasses into
15053 offset_map_type offset_map
;
15054 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
15055 offset_map
[fip
->fields
[i
].offset
] = i
;
15057 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15058 gdb::array_view
<variant_part
> parts
15059 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
15060 fip
->variant_parts
);
15062 struct dynamic_prop prop
;
15063 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
15064 obstack_copy (&objfile
->objfile_obstack
, &parts
,
15067 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
15070 /* Create the vector of fields, and attach it to the type. */
15073 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15074 struct dwarf2_cu
*cu
)
15076 int nfields
= fip
->nfields ();
15078 /* Record the field count, allocate space for the array of fields,
15079 and create blank accessibility bitfields if necessary. */
15080 type
->set_num_fields (nfields
);
15082 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
15084 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15086 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15088 TYPE_FIELD_PRIVATE_BITS (type
) =
15089 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15090 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15092 TYPE_FIELD_PROTECTED_BITS (type
) =
15093 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15094 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15096 TYPE_FIELD_IGNORE_BITS (type
) =
15097 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15098 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15101 /* If the type has baseclasses, allocate and clear a bit vector for
15102 TYPE_FIELD_VIRTUAL_BITS. */
15103 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15105 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15106 unsigned char *pointer
;
15108 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15109 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15110 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15111 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15112 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15115 if (!fip
->variant_parts
.empty ())
15116 add_variant_property (fip
, type
, cu
);
15118 /* Copy the saved-up fields into the field vector. */
15119 for (int i
= 0; i
< nfields
; ++i
)
15121 struct nextfield
&field
15122 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15123 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15125 type
->field (i
) = field
.field
;
15126 switch (field
.accessibility
)
15128 case DW_ACCESS_private
:
15129 if (cu
->language
!= language_ada
)
15130 SET_TYPE_FIELD_PRIVATE (type
, i
);
15133 case DW_ACCESS_protected
:
15134 if (cu
->language
!= language_ada
)
15135 SET_TYPE_FIELD_PROTECTED (type
, i
);
15138 case DW_ACCESS_public
:
15142 /* Unknown accessibility. Complain and treat it as public. */
15144 complaint (_("unsupported accessibility %d"),
15145 field
.accessibility
);
15149 if (i
< fip
->baseclasses
.size ())
15151 switch (field
.virtuality
)
15153 case DW_VIRTUALITY_virtual
:
15154 case DW_VIRTUALITY_pure_virtual
:
15155 if (cu
->language
== language_ada
)
15156 error (_("unexpected virtuality in component of Ada type"));
15157 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15164 /* Return true if this member function is a constructor, false
15168 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15170 const char *fieldname
;
15171 const char *type_name
;
15174 if (die
->parent
== NULL
)
15177 if (die
->parent
->tag
!= DW_TAG_structure_type
15178 && die
->parent
->tag
!= DW_TAG_union_type
15179 && die
->parent
->tag
!= DW_TAG_class_type
)
15182 fieldname
= dwarf2_name (die
, cu
);
15183 type_name
= dwarf2_name (die
->parent
, cu
);
15184 if (fieldname
== NULL
|| type_name
== NULL
)
15187 len
= strlen (fieldname
);
15188 return (strncmp (fieldname
, type_name
, len
) == 0
15189 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15192 /* Add a member function to the proper fieldlist. */
15195 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15196 struct type
*type
, struct dwarf2_cu
*cu
)
15198 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15199 struct attribute
*attr
;
15201 struct fnfieldlist
*flp
= nullptr;
15202 struct fn_field
*fnp
;
15203 const char *fieldname
;
15204 struct type
*this_type
;
15206 if (cu
->language
== language_ada
)
15207 error (_("unexpected member function in Ada type"));
15209 /* Get name of member function. */
15210 fieldname
= dwarf2_name (die
, cu
);
15211 if (fieldname
== NULL
)
15214 /* Look up member function name in fieldlist. */
15215 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15217 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15219 flp
= &fip
->fnfieldlists
[i
];
15224 /* Create a new fnfieldlist if necessary. */
15225 if (flp
== nullptr)
15227 fip
->fnfieldlists
.emplace_back ();
15228 flp
= &fip
->fnfieldlists
.back ();
15229 flp
->name
= fieldname
;
15230 i
= fip
->fnfieldlists
.size () - 1;
15233 /* Create a new member function field and add it to the vector of
15235 flp
->fnfields
.emplace_back ();
15236 fnp
= &flp
->fnfields
.back ();
15238 /* Delay processing of the physname until later. */
15239 if (cu
->language
== language_cplus
)
15240 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15244 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15245 fnp
->physname
= physname
? physname
: "";
15248 fnp
->type
= alloc_type (objfile
);
15249 this_type
= read_type_die (die
, cu
);
15250 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15252 int nparams
= this_type
->num_fields ();
15254 /* TYPE is the domain of this method, and THIS_TYPE is the type
15255 of the method itself (TYPE_CODE_METHOD). */
15256 smash_to_method_type (fnp
->type
, type
,
15257 TYPE_TARGET_TYPE (this_type
),
15258 this_type
->fields (),
15259 this_type
->num_fields (),
15260 this_type
->has_varargs ());
15262 /* Handle static member functions.
15263 Dwarf2 has no clean way to discern C++ static and non-static
15264 member functions. G++ helps GDB by marking the first
15265 parameter for non-static member functions (which is the this
15266 pointer) as artificial. We obtain this information from
15267 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15268 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15269 fnp
->voffset
= VOFFSET_STATIC
;
15272 complaint (_("member function type missing for '%s'"),
15273 dwarf2_full_name (fieldname
, die
, cu
));
15275 /* Get fcontext from DW_AT_containing_type if present. */
15276 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15277 fnp
->fcontext
= die_containing_type (die
, cu
);
15279 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15280 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15282 /* Get accessibility. */
15283 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15284 switch (accessibility
)
15286 case DW_ACCESS_private
:
15287 fnp
->is_private
= 1;
15289 case DW_ACCESS_protected
:
15290 fnp
->is_protected
= 1;
15294 /* Check for artificial methods. */
15295 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15296 if (attr
&& attr
->as_boolean ())
15297 fnp
->is_artificial
= 1;
15299 /* Check for defaulted methods. */
15300 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15301 if (attr
!= nullptr)
15302 fnp
->defaulted
= attr
->defaulted ();
15304 /* Check for deleted methods. */
15305 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15306 if (attr
!= nullptr && attr
->as_boolean ())
15307 fnp
->is_deleted
= 1;
15309 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15311 /* Get index in virtual function table if it is a virtual member
15312 function. For older versions of GCC, this is an offset in the
15313 appropriate virtual table, as specified by DW_AT_containing_type.
15314 For everyone else, it is an expression to be evaluated relative
15315 to the object address. */
15317 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15318 if (attr
!= nullptr)
15320 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15322 struct dwarf_block
*block
= attr
->as_block ();
15324 if (block
->data
[0] == DW_OP_constu
)
15326 /* Old-style GCC. */
15327 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15329 else if (block
->data
[0] == DW_OP_deref
15330 || (block
->size
> 1
15331 && block
->data
[0] == DW_OP_deref_size
15332 && block
->data
[1] == cu
->header
.addr_size
))
15334 fnp
->voffset
= decode_locdesc (block
, cu
);
15335 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15336 dwarf2_complex_location_expr_complaint ();
15338 fnp
->voffset
/= cu
->header
.addr_size
;
15342 dwarf2_complex_location_expr_complaint ();
15344 if (!fnp
->fcontext
)
15346 /* If there is no `this' field and no DW_AT_containing_type,
15347 we cannot actually find a base class context for the
15349 if (this_type
->num_fields () == 0
15350 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15352 complaint (_("cannot determine context for virtual member "
15353 "function \"%s\" (offset %s)"),
15354 fieldname
, sect_offset_str (die
->sect_off
));
15359 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15363 else if (attr
->form_is_section_offset ())
15365 dwarf2_complex_location_expr_complaint ();
15369 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15375 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15376 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15378 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15379 complaint (_("Member function \"%s\" (offset %s) is virtual "
15380 "but the vtable offset is not specified"),
15381 fieldname
, sect_offset_str (die
->sect_off
));
15382 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15383 TYPE_CPLUS_DYNAMIC (type
) = 1;
15388 /* Create the vector of member function fields, and attach it to the type. */
15391 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15392 struct dwarf2_cu
*cu
)
15394 if (cu
->language
== language_ada
)
15395 error (_("unexpected member functions in Ada type"));
15397 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15398 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15400 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15402 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15404 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15405 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15407 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15408 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15409 fn_flp
->fn_fields
= (struct fn_field
*)
15410 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15412 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15413 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15416 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15419 /* Returns non-zero if NAME is the name of a vtable member in CU's
15420 language, zero otherwise. */
15422 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15424 static const char vptr
[] = "_vptr";
15426 /* Look for the C++ form of the vtable. */
15427 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15433 /* GCC outputs unnamed structures that are really pointers to member
15434 functions, with the ABI-specified layout. If TYPE describes
15435 such a structure, smash it into a member function type.
15437 GCC shouldn't do this; it should just output pointer to member DIEs.
15438 This is GCC PR debug/28767. */
15441 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15443 struct type
*pfn_type
, *self_type
, *new_type
;
15445 /* Check for a structure with no name and two children. */
15446 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15449 /* Check for __pfn and __delta members. */
15450 if (TYPE_FIELD_NAME (type
, 0) == NULL
15451 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15452 || TYPE_FIELD_NAME (type
, 1) == NULL
15453 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15456 /* Find the type of the method. */
15457 pfn_type
= type
->field (0).type ();
15458 if (pfn_type
== NULL
15459 || pfn_type
->code () != TYPE_CODE_PTR
15460 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15463 /* Look for the "this" argument. */
15464 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15465 if (pfn_type
->num_fields () == 0
15466 /* || pfn_type->field (0).type () == NULL */
15467 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15470 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15471 new_type
= alloc_type (objfile
);
15472 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15473 pfn_type
->fields (), pfn_type
->num_fields (),
15474 pfn_type
->has_varargs ());
15475 smash_to_methodptr_type (type
, new_type
);
15478 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15479 requires rewriting, then copy it and return the updated copy.
15480 Otherwise return nullptr. */
15482 static struct type
*
15483 rewrite_array_type (struct type
*type
)
15485 if (type
->code () != TYPE_CODE_ARRAY
)
15488 struct type
*index_type
= type
->index_type ();
15489 range_bounds
*current_bounds
= index_type
->bounds ();
15491 /* Handle multi-dimensional arrays. */
15492 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15493 if (new_target
== nullptr)
15495 /* Maybe we don't need to rewrite this array. */
15496 if (current_bounds
->low
.kind () == PROP_CONST
15497 && current_bounds
->high
.kind () == PROP_CONST
)
15501 /* Either the target type was rewritten, or the bounds have to be
15502 updated. Either way we want to copy the type and update
15504 struct type
*copy
= copy_type (type
);
15505 int nfields
= copy
->num_fields ();
15507 = ((struct field
*) TYPE_ZALLOC (copy
,
15508 nfields
* sizeof (struct field
)));
15509 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15510 copy
->set_fields (new_fields
);
15511 if (new_target
!= nullptr)
15512 TYPE_TARGET_TYPE (copy
) = new_target
;
15514 struct type
*index_copy
= copy_type (index_type
);
15515 range_bounds
*bounds
15516 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15517 sizeof (range_bounds
));
15518 *bounds
= *current_bounds
;
15519 bounds
->low
.set_const_val (1);
15520 bounds
->high
.set_const_val (0);
15521 index_copy
->set_bounds (bounds
);
15522 copy
->set_index_type (index_copy
);
15527 /* While some versions of GCC will generate complicated DWARF for an
15528 array (see quirk_ada_thick_pointer), more recent versions were
15529 modified to emit an explicit thick pointer structure. However, in
15530 this case, the array still has DWARF expressions for its ranges,
15531 and these must be ignored. */
15534 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15537 gdb_assert (cu
->language
== language_ada
);
15539 /* Check for a structure with two children. */
15540 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15543 /* Check for P_ARRAY and P_BOUNDS members. */
15544 if (TYPE_FIELD_NAME (type
, 0) == NULL
15545 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
15546 || TYPE_FIELD_NAME (type
, 1) == NULL
15547 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
15550 /* Make sure we're looking at a pointer to an array. */
15551 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15554 /* The Ada code already knows how to handle these types, so all that
15555 we need to do is turn the bounds into static bounds. However, we
15556 don't want to rewrite existing array or index types in-place,
15557 because those may be referenced in other contexts where this
15558 rewriting is undesirable. */
15559 struct type
*new_ary_type
15560 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15561 if (new_ary_type
!= nullptr)
15562 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15565 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15566 appropriate error checking and issuing complaints if there is a
15570 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15572 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15574 if (attr
== nullptr)
15577 if (!attr
->form_is_constant ())
15579 complaint (_("DW_AT_alignment must have constant form"
15580 " - DIE at %s [in module %s]"),
15581 sect_offset_str (die
->sect_off
),
15582 objfile_name (cu
->per_objfile
->objfile
));
15586 LONGEST val
= attr
->constant_value (0);
15589 complaint (_("DW_AT_alignment value must not be negative"
15590 " - DIE at %s [in module %s]"),
15591 sect_offset_str (die
->sect_off
),
15592 objfile_name (cu
->per_objfile
->objfile
));
15595 ULONGEST align
= val
;
15599 complaint (_("DW_AT_alignment value must not be zero"
15600 " - DIE at %s [in module %s]"),
15601 sect_offset_str (die
->sect_off
),
15602 objfile_name (cu
->per_objfile
->objfile
));
15605 if ((align
& (align
- 1)) != 0)
15607 complaint (_("DW_AT_alignment value must be a power of 2"
15608 " - DIE at %s [in module %s]"),
15609 sect_offset_str (die
->sect_off
),
15610 objfile_name (cu
->per_objfile
->objfile
));
15617 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15618 the alignment for TYPE. */
15621 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15624 if (!set_type_align (type
, get_alignment (cu
, die
)))
15625 complaint (_("DW_AT_alignment value too large"
15626 " - DIE at %s [in module %s]"),
15627 sect_offset_str (die
->sect_off
),
15628 objfile_name (cu
->per_objfile
->objfile
));
15631 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15632 constant for a type, according to DWARF5 spec, Table 5.5. */
15635 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15640 case DW_CC_pass_by_reference
:
15641 case DW_CC_pass_by_value
:
15645 complaint (_("unrecognized DW_AT_calling_convention value "
15646 "(%s) for a type"), pulongest (value
));
15651 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15652 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15653 also according to GNU-specific values (see include/dwarf2.h). */
15656 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15661 case DW_CC_program
:
15665 case DW_CC_GNU_renesas_sh
:
15666 case DW_CC_GNU_borland_fastcall_i386
:
15667 case DW_CC_GDB_IBM_OpenCL
:
15671 complaint (_("unrecognized DW_AT_calling_convention value "
15672 "(%s) for a subroutine"), pulongest (value
));
15677 /* Called when we find the DIE that starts a structure or union scope
15678 (definition) to create a type for the structure or union. Fill in
15679 the type's name and general properties; the members will not be
15680 processed until process_structure_scope. A symbol table entry for
15681 the type will also not be done until process_structure_scope (assuming
15682 the type has a name).
15684 NOTE: we need to call these functions regardless of whether or not the
15685 DIE has a DW_AT_name attribute, since it might be an anonymous
15686 structure or union. This gets the type entered into our set of
15687 user defined types. */
15689 static struct type
*
15690 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15692 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15694 struct attribute
*attr
;
15697 /* If the definition of this type lives in .debug_types, read that type.
15698 Don't follow DW_AT_specification though, that will take us back up
15699 the chain and we want to go down. */
15700 attr
= die
->attr (DW_AT_signature
);
15701 if (attr
!= nullptr)
15703 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15705 /* The type's CU may not be the same as CU.
15706 Ensure TYPE is recorded with CU in die_type_hash. */
15707 return set_die_type (die
, type
, cu
);
15710 type
= alloc_type (objfile
);
15711 INIT_CPLUS_SPECIFIC (type
);
15713 name
= dwarf2_name (die
, cu
);
15716 if (cu
->language
== language_cplus
15717 || cu
->language
== language_d
15718 || cu
->language
== language_rust
)
15720 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15722 /* dwarf2_full_name might have already finished building the DIE's
15723 type. If so, there is no need to continue. */
15724 if (get_die_type (die
, cu
) != NULL
)
15725 return get_die_type (die
, cu
);
15727 type
->set_name (full_name
);
15731 /* The name is already allocated along with this objfile, so
15732 we don't need to duplicate it for the type. */
15733 type
->set_name (name
);
15737 if (die
->tag
== DW_TAG_structure_type
)
15739 type
->set_code (TYPE_CODE_STRUCT
);
15741 else if (die
->tag
== DW_TAG_union_type
)
15743 type
->set_code (TYPE_CODE_UNION
);
15747 type
->set_code (TYPE_CODE_STRUCT
);
15750 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15751 type
->set_is_declared_class (true);
15753 /* Store the calling convention in the type if it's available in
15754 the die. Otherwise the calling convention remains set to
15755 the default value DW_CC_normal. */
15756 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15757 if (attr
!= nullptr
15758 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
15760 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15761 TYPE_CPLUS_CALLING_CONVENTION (type
)
15762 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
15765 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15766 if (attr
!= nullptr)
15768 if (attr
->form_is_constant ())
15769 TYPE_LENGTH (type
) = attr
->constant_value (0);
15772 struct dynamic_prop prop
;
15773 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
15774 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
15775 TYPE_LENGTH (type
) = 0;
15780 TYPE_LENGTH (type
) = 0;
15783 maybe_set_alignment (cu
, die
, type
);
15785 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15787 /* ICC<14 does not output the required DW_AT_declaration on
15788 incomplete types, but gives them a size of zero. */
15789 type
->set_is_stub (true);
15792 type
->set_stub_is_supported (true);
15794 if (die_is_declaration (die
, cu
))
15795 type
->set_is_stub (true);
15796 else if (attr
== NULL
&& die
->child
== NULL
15797 && producer_is_realview (cu
->producer
))
15798 /* RealView does not output the required DW_AT_declaration
15799 on incomplete types. */
15800 type
->set_is_stub (true);
15802 /* We need to add the type field to the die immediately so we don't
15803 infinitely recurse when dealing with pointers to the structure
15804 type within the structure itself. */
15805 set_die_type (die
, type
, cu
);
15807 /* set_die_type should be already done. */
15808 set_descriptive_type (type
, die
, cu
);
15813 static void handle_struct_member_die
15814 (struct die_info
*child_die
,
15816 struct field_info
*fi
,
15817 std::vector
<struct symbol
*> *template_args
,
15818 struct dwarf2_cu
*cu
);
15820 /* A helper for handle_struct_member_die that handles
15821 DW_TAG_variant_part. */
15824 handle_variant_part (struct die_info
*die
, struct type
*type
,
15825 struct field_info
*fi
,
15826 std::vector
<struct symbol
*> *template_args
,
15827 struct dwarf2_cu
*cu
)
15829 variant_part_builder
*new_part
;
15830 if (fi
->current_variant_part
== nullptr)
15832 fi
->variant_parts
.emplace_back ();
15833 new_part
= &fi
->variant_parts
.back ();
15835 else if (!fi
->current_variant_part
->processing_variant
)
15837 complaint (_("nested DW_TAG_variant_part seen "
15838 "- DIE at %s [in module %s]"),
15839 sect_offset_str (die
->sect_off
),
15840 objfile_name (cu
->per_objfile
->objfile
));
15845 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
15846 current
.variant_parts
.emplace_back ();
15847 new_part
= ¤t
.variant_parts
.back ();
15850 /* When we recurse, we want callees to add to this new variant
15852 scoped_restore save_current_variant_part
15853 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
15855 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15858 /* It's a univariant form, an extension we support. */
15860 else if (discr
->form_is_ref ())
15862 struct dwarf2_cu
*target_cu
= cu
;
15863 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15865 new_part
->discriminant_offset
= target_die
->sect_off
;
15869 complaint (_("DW_AT_discr does not have DIE reference form"
15870 " - DIE at %s [in module %s]"),
15871 sect_offset_str (die
->sect_off
),
15872 objfile_name (cu
->per_objfile
->objfile
));
15875 for (die_info
*child_die
= die
->child
;
15877 child_die
= child_die
->sibling
)
15878 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
15881 /* A helper for handle_struct_member_die that handles
15885 handle_variant (struct die_info
*die
, struct type
*type
,
15886 struct field_info
*fi
,
15887 std::vector
<struct symbol
*> *template_args
,
15888 struct dwarf2_cu
*cu
)
15890 if (fi
->current_variant_part
== nullptr)
15892 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
15893 "- DIE at %s [in module %s]"),
15894 sect_offset_str (die
->sect_off
),
15895 objfile_name (cu
->per_objfile
->objfile
));
15898 if (fi
->current_variant_part
->processing_variant
)
15900 complaint (_("nested DW_TAG_variant seen "
15901 "- DIE at %s [in module %s]"),
15902 sect_offset_str (die
->sect_off
),
15903 objfile_name (cu
->per_objfile
->objfile
));
15907 scoped_restore save_processing_variant
15908 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
15911 fi
->current_variant_part
->variants
.emplace_back ();
15912 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
15913 variant
.first_field
= fi
->fields
.size ();
15915 /* In a variant we want to get the discriminant and also add a
15916 field for our sole member child. */
15917 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
15918 if (discr
== nullptr || !discr
->form_is_constant ())
15920 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
15921 if (discr
== nullptr || discr
->as_block ()->size
== 0)
15922 variant
.default_branch
= true;
15924 variant
.discr_list_data
= discr
->as_block ();
15927 variant
.discriminant_value
= discr
->constant_value (0);
15929 for (die_info
*variant_child
= die
->child
;
15930 variant_child
!= NULL
;
15931 variant_child
= variant_child
->sibling
)
15932 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
15934 variant
.last_field
= fi
->fields
.size ();
15937 /* A helper for process_structure_scope that handles a single member
15941 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15942 struct field_info
*fi
,
15943 std::vector
<struct symbol
*> *template_args
,
15944 struct dwarf2_cu
*cu
)
15946 if (child_die
->tag
== DW_TAG_member
15947 || child_die
->tag
== DW_TAG_variable
)
15949 /* NOTE: carlton/2002-11-05: A C++ static data member
15950 should be a DW_TAG_member that is a declaration, but
15951 all versions of G++ as of this writing (so through at
15952 least 3.2.1) incorrectly generate DW_TAG_variable
15953 tags for them instead. */
15954 dwarf2_add_field (fi
, child_die
, cu
);
15956 else if (child_die
->tag
== DW_TAG_subprogram
)
15958 /* Rust doesn't have member functions in the C++ sense.
15959 However, it does emit ordinary functions as children
15960 of a struct DIE. */
15961 if (cu
->language
== language_rust
)
15962 read_func_scope (child_die
, cu
);
15965 /* C++ member function. */
15966 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15969 else if (child_die
->tag
== DW_TAG_inheritance
)
15971 /* C++ base class field. */
15972 dwarf2_add_field (fi
, child_die
, cu
);
15974 else if (type_can_define_types (child_die
))
15975 dwarf2_add_type_defn (fi
, child_die
, cu
);
15976 else if (child_die
->tag
== DW_TAG_template_type_param
15977 || child_die
->tag
== DW_TAG_template_value_param
)
15979 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15982 template_args
->push_back (arg
);
15984 else if (child_die
->tag
== DW_TAG_variant_part
)
15985 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
15986 else if (child_die
->tag
== DW_TAG_variant
)
15987 handle_variant (child_die
, type
, fi
, template_args
, cu
);
15990 /* Finish creating a structure or union type, including filling in
15991 its members and creating a symbol for it. */
15994 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15996 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15997 struct die_info
*child_die
;
16000 type
= get_die_type (die
, cu
);
16002 type
= read_structure_type (die
, cu
);
16004 bool has_template_parameters
= false;
16005 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16007 struct field_info fi
;
16008 std::vector
<struct symbol
*> template_args
;
16010 child_die
= die
->child
;
16012 while (child_die
&& child_die
->tag
)
16014 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16015 child_die
= child_die
->sibling
;
16018 /* Attach template arguments to type. */
16019 if (!template_args
.empty ())
16021 has_template_parameters
= true;
16022 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16023 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16024 TYPE_TEMPLATE_ARGUMENTS (type
)
16025 = XOBNEWVEC (&objfile
->objfile_obstack
,
16027 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16028 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16029 template_args
.data (),
16030 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16031 * sizeof (struct symbol
*)));
16034 /* Attach fields and member functions to the type. */
16035 if (fi
.nfields () > 0)
16036 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16037 if (!fi
.fnfieldlists
.empty ())
16039 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16041 /* Get the type which refers to the base class (possibly this
16042 class itself) which contains the vtable pointer for the current
16043 class from the DW_AT_containing_type attribute. This use of
16044 DW_AT_containing_type is a GNU extension. */
16046 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16048 struct type
*t
= die_containing_type (die
, cu
);
16050 set_type_vptr_basetype (type
, t
);
16055 /* Our own class provides vtbl ptr. */
16056 for (i
= t
->num_fields () - 1;
16057 i
>= TYPE_N_BASECLASSES (t
);
16060 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16062 if (is_vtable_name (fieldname
, cu
))
16064 set_type_vptr_fieldno (type
, i
);
16069 /* Complain if virtual function table field not found. */
16070 if (i
< TYPE_N_BASECLASSES (t
))
16071 complaint (_("virtual function table pointer "
16072 "not found when defining class '%s'"),
16073 type
->name () ? type
->name () : "");
16077 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16080 else if (cu
->producer
16081 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16083 /* The IBM XLC compiler does not provide direct indication
16084 of the containing type, but the vtable pointer is
16085 always named __vfp. */
16089 for (i
= type
->num_fields () - 1;
16090 i
>= TYPE_N_BASECLASSES (type
);
16093 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16095 set_type_vptr_fieldno (type
, i
);
16096 set_type_vptr_basetype (type
, type
);
16103 /* Copy fi.typedef_field_list linked list elements content into the
16104 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16105 if (!fi
.typedef_field_list
.empty ())
16107 int count
= fi
.typedef_field_list
.size ();
16109 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16110 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16111 = ((struct decl_field
*)
16113 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16114 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16116 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16117 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16120 /* Copy fi.nested_types_list linked list elements content into the
16121 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16122 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16124 int count
= fi
.nested_types_list
.size ();
16126 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16127 TYPE_NESTED_TYPES_ARRAY (type
)
16128 = ((struct decl_field
*)
16129 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16130 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16132 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16133 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16137 quirk_gcc_member_function_pointer (type
, objfile
);
16138 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16139 cu
->rust_unions
.push_back (type
);
16140 else if (cu
->language
== language_ada
)
16141 quirk_ada_thick_pointer_struct (die
, cu
, type
);
16143 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16144 snapshots) has been known to create a die giving a declaration
16145 for a class that has, as a child, a die giving a definition for a
16146 nested class. So we have to process our children even if the
16147 current die is a declaration. Normally, of course, a declaration
16148 won't have any children at all. */
16150 child_die
= die
->child
;
16152 while (child_die
!= NULL
&& child_die
->tag
)
16154 if (child_die
->tag
== DW_TAG_member
16155 || child_die
->tag
== DW_TAG_variable
16156 || child_die
->tag
== DW_TAG_inheritance
16157 || child_die
->tag
== DW_TAG_template_value_param
16158 || child_die
->tag
== DW_TAG_template_type_param
)
16163 process_die (child_die
, cu
);
16165 child_die
= child_die
->sibling
;
16168 /* Do not consider external references. According to the DWARF standard,
16169 these DIEs are identified by the fact that they have no byte_size
16170 attribute, and a declaration attribute. */
16171 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16172 || !die_is_declaration (die
, cu
)
16173 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16175 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16177 if (has_template_parameters
)
16179 struct symtab
*symtab
;
16180 if (sym
!= nullptr)
16181 symtab
= symbol_symtab (sym
);
16182 else if (cu
->line_header
!= nullptr)
16184 /* Any related symtab will do. */
16186 = cu
->line_header
->file_names ()[0].symtab
;
16191 complaint (_("could not find suitable "
16192 "symtab for template parameter"
16193 " - DIE at %s [in module %s]"),
16194 sect_offset_str (die
->sect_off
),
16195 objfile_name (objfile
));
16198 if (symtab
!= nullptr)
16200 /* Make sure that the symtab is set on the new symbols.
16201 Even though they don't appear in this symtab directly,
16202 other parts of gdb assume that symbols do, and this is
16203 reasonably true. */
16204 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16205 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16211 /* Assuming DIE is an enumeration type, and TYPE is its associated
16212 type, update TYPE using some information only available in DIE's
16213 children. In particular, the fields are computed. */
16216 update_enumeration_type_from_children (struct die_info
*die
,
16218 struct dwarf2_cu
*cu
)
16220 struct die_info
*child_die
;
16221 int unsigned_enum
= 1;
16224 auto_obstack obstack
;
16225 std::vector
<struct field
> fields
;
16227 for (child_die
= die
->child
;
16228 child_die
!= NULL
&& child_die
->tag
;
16229 child_die
= child_die
->sibling
)
16231 struct attribute
*attr
;
16233 const gdb_byte
*bytes
;
16234 struct dwarf2_locexpr_baton
*baton
;
16237 if (child_die
->tag
!= DW_TAG_enumerator
)
16240 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16244 name
= dwarf2_name (child_die
, cu
);
16246 name
= "<anonymous enumerator>";
16248 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16249 &value
, &bytes
, &baton
);
16257 if (count_one_bits_ll (value
) >= 2)
16261 fields
.emplace_back ();
16262 struct field
&field
= fields
.back ();
16263 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16264 SET_FIELD_ENUMVAL (field
, value
);
16267 if (!fields
.empty ())
16269 type
->set_num_fields (fields
.size ());
16272 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16273 memcpy (type
->fields (), fields
.data (),
16274 sizeof (struct field
) * fields
.size ());
16278 type
->set_is_unsigned (true);
16281 type
->set_is_flag_enum (true);
16284 /* Given a DW_AT_enumeration_type die, set its type. We do not
16285 complete the type's fields yet, or create any symbols. */
16287 static struct type
*
16288 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16290 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16292 struct attribute
*attr
;
16295 /* If the definition of this type lives in .debug_types, read that type.
16296 Don't follow DW_AT_specification though, that will take us back up
16297 the chain and we want to go down. */
16298 attr
= die
->attr (DW_AT_signature
);
16299 if (attr
!= nullptr)
16301 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16303 /* The type's CU may not be the same as CU.
16304 Ensure TYPE is recorded with CU in die_type_hash. */
16305 return set_die_type (die
, type
, cu
);
16308 type
= alloc_type (objfile
);
16310 type
->set_code (TYPE_CODE_ENUM
);
16311 name
= dwarf2_full_name (NULL
, die
, cu
);
16313 type
->set_name (name
);
16315 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16318 struct type
*underlying_type
= die_type (die
, cu
);
16320 TYPE_TARGET_TYPE (type
) = underlying_type
;
16323 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16324 if (attr
!= nullptr)
16326 TYPE_LENGTH (type
) = attr
->constant_value (0);
16330 TYPE_LENGTH (type
) = 0;
16333 maybe_set_alignment (cu
, die
, type
);
16335 /* The enumeration DIE can be incomplete. In Ada, any type can be
16336 declared as private in the package spec, and then defined only
16337 inside the package body. Such types are known as Taft Amendment
16338 Types. When another package uses such a type, an incomplete DIE
16339 may be generated by the compiler. */
16340 if (die_is_declaration (die
, cu
))
16341 type
->set_is_stub (true);
16343 /* If this type has an underlying type that is not a stub, then we
16344 may use its attributes. We always use the "unsigned" attribute
16345 in this situation, because ordinarily we guess whether the type
16346 is unsigned -- but the guess can be wrong and the underlying type
16347 can tell us the reality. However, we defer to a local size
16348 attribute if one exists, because this lets the compiler override
16349 the underlying type if needed. */
16350 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16352 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16353 underlying_type
= check_typedef (underlying_type
);
16355 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16357 if (TYPE_LENGTH (type
) == 0)
16358 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16360 if (TYPE_RAW_ALIGN (type
) == 0
16361 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16362 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16365 type
->set_is_declared_class (dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
));
16367 set_die_type (die
, type
, cu
);
16369 /* Finish the creation of this type by using the enum's children.
16370 Note that, as usual, this must come after set_die_type to avoid
16371 infinite recursion when trying to compute the names of the
16373 update_enumeration_type_from_children (die
, type
, cu
);
16378 /* Given a pointer to a die which begins an enumeration, process all
16379 the dies that define the members of the enumeration, and create the
16380 symbol for the enumeration type.
16382 NOTE: We reverse the order of the element list. */
16385 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16387 struct type
*this_type
;
16389 this_type
= get_die_type (die
, cu
);
16390 if (this_type
== NULL
)
16391 this_type
= read_enumeration_type (die
, cu
);
16393 if (die
->child
!= NULL
)
16395 struct die_info
*child_die
;
16398 child_die
= die
->child
;
16399 while (child_die
&& child_die
->tag
)
16401 if (child_die
->tag
!= DW_TAG_enumerator
)
16403 process_die (child_die
, cu
);
16407 name
= dwarf2_name (child_die
, cu
);
16409 new_symbol (child_die
, this_type
, cu
);
16412 child_die
= child_die
->sibling
;
16416 /* If we are reading an enum from a .debug_types unit, and the enum
16417 is a declaration, and the enum is not the signatured type in the
16418 unit, then we do not want to add a symbol for it. Adding a
16419 symbol would in some cases obscure the true definition of the
16420 enum, giving users an incomplete type when the definition is
16421 actually available. Note that we do not want to do this for all
16422 enums which are just declarations, because C++0x allows forward
16423 enum declarations. */
16424 if (cu
->per_cu
->is_debug_types
16425 && die_is_declaration (die
, cu
))
16427 struct signatured_type
*sig_type
;
16429 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16430 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16431 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16435 new_symbol (die
, this_type
, cu
);
16438 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16439 expression for an index type and finds the corresponding field
16440 offset in the hidden "P_BOUNDS" structure. Returns true on success
16441 and updates *FIELD, false if it fails to recognize an
16445 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16446 int *bounds_offset
, struct field
*field
,
16447 struct dwarf2_cu
*cu
)
16449 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16450 if (attr
== nullptr || !attr
->form_is_block ())
16453 const struct dwarf_block
*block
= attr
->as_block ();
16454 const gdb_byte
*start
= block
->data
;
16455 const gdb_byte
*end
= block
->data
+ block
->size
;
16457 /* The expression to recognize generally looks like:
16459 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16460 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16462 However, the second "plus_uconst" may be missing:
16464 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16465 DW_OP_deref_size: 4)
16467 This happens when the field is at the start of the structure.
16469 Also, the final deref may not be sized:
16471 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16474 This happens when the size of the index type happens to be the
16475 same as the architecture's word size. This can occur with or
16476 without the second plus_uconst. */
16478 if (end
- start
< 2)
16480 if (*start
++ != DW_OP_push_object_address
)
16482 if (*start
++ != DW_OP_plus_uconst
)
16485 uint64_t this_bound_off
;
16486 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16487 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16489 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16490 is consistent among all bounds. */
16491 if (*bounds_offset
== -1)
16492 *bounds_offset
= this_bound_off
;
16493 else if (*bounds_offset
!= this_bound_off
)
16496 if (start
== end
|| *start
++ != DW_OP_deref
)
16502 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16504 /* This means an offset of 0. */
16506 else if (*start
++ != DW_OP_plus_uconst
)
16510 /* The size is the parameter to DW_OP_plus_uconst. */
16512 start
= gdb_read_uleb128 (start
, end
, &val
);
16513 if (start
== nullptr)
16515 if ((int) val
!= val
)
16524 if (*start
== DW_OP_deref_size
)
16526 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16527 if (start
== nullptr)
16530 else if (*start
== DW_OP_deref
)
16532 size
= cu
->header
.addr_size
;
16538 SET_FIELD_BITPOS (*field
, 8 * offset
);
16539 if (size
!= TYPE_LENGTH (field
->type ()))
16540 FIELD_BITSIZE (*field
) = 8 * size
;
16545 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16546 some kinds of Ada arrays:
16548 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16549 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16550 <11e0> DW_AT_data_location: 2 byte block: 97 6
16551 (DW_OP_push_object_address; DW_OP_deref)
16552 <11e3> DW_AT_type : <0x1173>
16553 <11e7> DW_AT_sibling : <0x1201>
16554 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16555 <11ec> DW_AT_type : <0x1206>
16556 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16557 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16558 DW_OP_deref_size: 4)
16559 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16560 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16561 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16563 This actually represents a "thick pointer", which is a structure
16564 with two elements: one that is a pointer to the array data, and one
16565 that is a pointer to another structure; this second structure holds
16568 This returns a new type on success, or nullptr if this didn't
16569 recognize the type. */
16571 static struct type
*
16572 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16575 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16576 /* So far we've only seen this with block form. */
16577 if (attr
== nullptr || !attr
->form_is_block ())
16580 /* Note that this will fail if the structure layout is changed by
16581 the compiler. However, we have no good way to recognize some
16582 other layout, because we don't know what expression the compiler
16583 might choose to emit should this happen. */
16584 struct dwarf_block
*blk
= attr
->as_block ();
16586 || blk
->data
[0] != DW_OP_push_object_address
16587 || blk
->data
[1] != DW_OP_deref
)
16590 int bounds_offset
= -1;
16591 int max_align
= -1;
16592 std::vector
<struct field
> range_fields
;
16593 for (struct die_info
*child_die
= die
->child
;
16595 child_die
= child_die
->sibling
)
16597 if (child_die
->tag
== DW_TAG_subrange_type
)
16599 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16601 int this_align
= type_align (underlying
);
16602 if (this_align
> max_align
)
16603 max_align
= this_align
;
16605 range_fields
.emplace_back ();
16606 range_fields
.emplace_back ();
16608 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16609 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16611 lower
.set_type (underlying
);
16612 FIELD_ARTIFICIAL (lower
) = 1;
16614 upper
.set_type (underlying
);
16615 FIELD_ARTIFICIAL (upper
) = 1;
16617 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16618 &bounds_offset
, &lower
, cu
)
16619 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16620 &bounds_offset
, &upper
, cu
))
16625 /* This shouldn't really happen, but double-check that we found
16626 where the bounds are stored. */
16627 if (bounds_offset
== -1)
16630 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16631 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16635 /* Set the name of each field in the bounds. */
16636 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16637 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
16638 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16639 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
16642 struct type
*bounds
= alloc_type (objfile
);
16643 bounds
->set_code (TYPE_CODE_STRUCT
);
16645 bounds
->set_num_fields (range_fields
.size ());
16647 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
16648 * sizeof (struct field
))));
16649 memcpy (bounds
->fields (), range_fields
.data (),
16650 bounds
->num_fields () * sizeof (struct field
));
16652 int last_fieldno
= range_fields
.size () - 1;
16653 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
16654 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
16655 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
16657 /* Rewrite the existing array type in place. Specifically, we
16658 remove any dynamic properties we might have read, and we replace
16659 the index types. */
16660 struct type
*iter
= type
;
16661 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16663 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
16664 iter
->main_type
->dyn_prop_list
= nullptr;
16665 iter
->set_index_type
16666 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
16667 iter
= TYPE_TARGET_TYPE (iter
);
16670 struct type
*result
= alloc_type (objfile
);
16671 result
->set_code (TYPE_CODE_STRUCT
);
16673 result
->set_num_fields (2);
16675 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
16676 * sizeof (struct field
))));
16678 /* The names are chosen to coincide with what the compiler does with
16679 -fgnat-encodings=all, which the Ada code in gdb already
16681 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
16682 result
->field (0).set_type (lookup_pointer_type (type
));
16684 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
16685 result
->field (1).set_type (lookup_pointer_type (bounds
));
16686 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
16688 result
->set_name (type
->name ());
16689 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
16690 + TYPE_LENGTH (result
->field (1).type ()));
16695 /* Extract all information from a DW_TAG_array_type DIE and put it in
16696 the DIE's type field. For now, this only handles one dimensional
16699 static struct type
*
16700 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16702 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16703 struct die_info
*child_die
;
16705 struct type
*element_type
, *range_type
, *index_type
;
16706 struct attribute
*attr
;
16708 struct dynamic_prop
*byte_stride_prop
= NULL
;
16709 unsigned int bit_stride
= 0;
16711 element_type
= die_type (die
, cu
);
16713 /* The die_type call above may have already set the type for this DIE. */
16714 type
= get_die_type (die
, cu
);
16718 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16722 struct type
*prop_type
= cu
->addr_sized_int_type (false);
16725 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16726 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16730 complaint (_("unable to read array DW_AT_byte_stride "
16731 " - DIE at %s [in module %s]"),
16732 sect_offset_str (die
->sect_off
),
16733 objfile_name (cu
->per_objfile
->objfile
));
16734 /* Ignore this attribute. We will likely not be able to print
16735 arrays of this type correctly, but there is little we can do
16736 to help if we cannot read the attribute's value. */
16737 byte_stride_prop
= NULL
;
16741 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16743 bit_stride
= attr
->constant_value (0);
16745 /* Irix 6.2 native cc creates array types without children for
16746 arrays with unspecified length. */
16747 if (die
->child
== NULL
)
16749 index_type
= objfile_type (objfile
)->builtin_int
;
16750 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16751 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16752 byte_stride_prop
, bit_stride
);
16753 return set_die_type (die
, type
, cu
);
16756 std::vector
<struct type
*> range_types
;
16757 child_die
= die
->child
;
16758 while (child_die
&& child_die
->tag
)
16760 if (child_die
->tag
== DW_TAG_subrange_type
)
16762 struct type
*child_type
= read_type_die (child_die
, cu
);
16764 if (child_type
!= NULL
)
16766 /* The range type was succesfully read. Save it for the
16767 array type creation. */
16768 range_types
.push_back (child_type
);
16771 child_die
= child_die
->sibling
;
16774 if (range_types
.empty ())
16776 complaint (_("unable to find array range - DIE at %s [in module %s]"),
16777 sect_offset_str (die
->sect_off
),
16778 objfile_name (cu
->per_objfile
->objfile
));
16782 /* Dwarf2 dimensions are output from left to right, create the
16783 necessary array types in backwards order. */
16785 type
= element_type
;
16787 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16791 while (i
< range_types
.size ())
16793 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16794 byte_stride_prop
, bit_stride
);
16796 byte_stride_prop
= nullptr;
16801 size_t ndim
= range_types
.size ();
16804 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16805 byte_stride_prop
, bit_stride
);
16807 byte_stride_prop
= nullptr;
16811 gdb_assert (type
!= element_type
);
16813 /* Understand Dwarf2 support for vector types (like they occur on
16814 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16815 array type. This is not part of the Dwarf2/3 standard yet, but a
16816 custom vendor extension. The main difference between a regular
16817 array and the vector variant is that vectors are passed by value
16819 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16820 if (attr
!= nullptr)
16821 make_vector_type (type
);
16823 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16824 implementation may choose to implement triple vectors using this
16826 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16827 if (attr
!= nullptr && attr
->form_is_unsigned ())
16829 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
16830 TYPE_LENGTH (type
) = attr
->as_unsigned ();
16832 complaint (_("DW_AT_byte_size for array type smaller "
16833 "than the total size of elements"));
16836 name
= dwarf2_name (die
, cu
);
16838 type
->set_name (name
);
16840 maybe_set_alignment (cu
, die
, type
);
16842 struct type
*replacement_type
= nullptr;
16843 if (cu
->language
== language_ada
)
16845 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
16846 if (replacement_type
!= nullptr)
16847 type
= replacement_type
;
16850 /* Install the type in the die. */
16851 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
16853 /* set_die_type should be already done. */
16854 set_descriptive_type (type
, die
, cu
);
16859 static enum dwarf_array_dim_ordering
16860 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16862 struct attribute
*attr
;
16864 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16866 if (attr
!= nullptr)
16868 LONGEST val
= attr
->constant_value (-1);
16869 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
16870 return (enum dwarf_array_dim_ordering
) val
;
16873 /* GNU F77 is a special case, as at 08/2004 array type info is the
16874 opposite order to the dwarf2 specification, but data is still
16875 laid out as per normal fortran.
16877 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16878 version checking. */
16880 if (cu
->language
== language_fortran
16881 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16883 return DW_ORD_row_major
;
16886 switch (cu
->language_defn
->array_ordering ())
16888 case array_column_major
:
16889 return DW_ORD_col_major
;
16890 case array_row_major
:
16892 return DW_ORD_row_major
;
16896 /* Extract all information from a DW_TAG_set_type DIE and put it in
16897 the DIE's type field. */
16899 static struct type
*
16900 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16902 struct type
*domain_type
, *set_type
;
16903 struct attribute
*attr
;
16905 domain_type
= die_type (die
, cu
);
16907 /* The die_type call above may have already set the type for this DIE. */
16908 set_type
= get_die_type (die
, cu
);
16912 set_type
= create_set_type (NULL
, domain_type
);
16914 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16915 if (attr
!= nullptr && attr
->form_is_unsigned ())
16916 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
16918 maybe_set_alignment (cu
, die
, set_type
);
16920 return set_die_type (die
, set_type
, cu
);
16923 /* A helper for read_common_block that creates a locexpr baton.
16924 SYM is the symbol which we are marking as computed.
16925 COMMON_DIE is the DIE for the common block.
16926 COMMON_LOC is the location expression attribute for the common
16928 MEMBER_LOC is the location expression attribute for the particular
16929 member of the common block that we are processing.
16930 CU is the CU from which the above come. */
16933 mark_common_block_symbol_computed (struct symbol
*sym
,
16934 struct die_info
*common_die
,
16935 struct attribute
*common_loc
,
16936 struct attribute
*member_loc
,
16937 struct dwarf2_cu
*cu
)
16939 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
16940 struct objfile
*objfile
= per_objfile
->objfile
;
16941 struct dwarf2_locexpr_baton
*baton
;
16943 unsigned int cu_off
;
16944 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
16945 LONGEST offset
= 0;
16947 gdb_assert (common_loc
&& member_loc
);
16948 gdb_assert (common_loc
->form_is_block ());
16949 gdb_assert (member_loc
->form_is_block ()
16950 || member_loc
->form_is_constant ());
16952 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16953 baton
->per_objfile
= per_objfile
;
16954 baton
->per_cu
= cu
->per_cu
;
16955 gdb_assert (baton
->per_cu
);
16957 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16959 if (member_loc
->form_is_constant ())
16961 offset
= member_loc
->constant_value (0);
16962 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16965 baton
->size
+= member_loc
->as_block ()->size
;
16967 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16970 *ptr
++ = DW_OP_call4
;
16971 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16972 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16975 if (member_loc
->form_is_constant ())
16977 *ptr
++ = DW_OP_addr
;
16978 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16979 ptr
+= cu
->header
.addr_size
;
16983 /* We have to copy the data here, because DW_OP_call4 will only
16984 use a DW_AT_location attribute. */
16985 struct dwarf_block
*block
= member_loc
->as_block ();
16986 memcpy (ptr
, block
->data
, block
->size
);
16987 ptr
+= block
->size
;
16990 *ptr
++ = DW_OP_plus
;
16991 gdb_assert (ptr
- baton
->data
== baton
->size
);
16993 SYMBOL_LOCATION_BATON (sym
) = baton
;
16994 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16997 /* Create appropriate locally-scoped variables for all the
16998 DW_TAG_common_block entries. Also create a struct common_block
16999 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
17000 is used to separate the common blocks name namespace from regular
17004 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
17006 struct attribute
*attr
;
17008 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17009 if (attr
!= nullptr)
17011 /* Support the .debug_loc offsets. */
17012 if (attr
->form_is_block ())
17016 else if (attr
->form_is_section_offset ())
17018 dwarf2_complex_location_expr_complaint ();
17023 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17024 "common block member");
17029 if (die
->child
!= NULL
)
17031 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17032 struct die_info
*child_die
;
17033 size_t n_entries
= 0, size
;
17034 struct common_block
*common_block
;
17035 struct symbol
*sym
;
17037 for (child_die
= die
->child
;
17038 child_die
&& child_die
->tag
;
17039 child_die
= child_die
->sibling
)
17042 size
= (sizeof (struct common_block
)
17043 + (n_entries
- 1) * sizeof (struct symbol
*));
17045 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17047 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17048 common_block
->n_entries
= 0;
17050 for (child_die
= die
->child
;
17051 child_die
&& child_die
->tag
;
17052 child_die
= child_die
->sibling
)
17054 /* Create the symbol in the DW_TAG_common_block block in the current
17056 sym
= new_symbol (child_die
, NULL
, cu
);
17059 struct attribute
*member_loc
;
17061 common_block
->contents
[common_block
->n_entries
++] = sym
;
17063 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17067 /* GDB has handled this for a long time, but it is
17068 not specified by DWARF. It seems to have been
17069 emitted by gfortran at least as recently as:
17070 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17071 complaint (_("Variable in common block has "
17072 "DW_AT_data_member_location "
17073 "- DIE at %s [in module %s]"),
17074 sect_offset_str (child_die
->sect_off
),
17075 objfile_name (objfile
));
17077 if (member_loc
->form_is_section_offset ())
17078 dwarf2_complex_location_expr_complaint ();
17079 else if (member_loc
->form_is_constant ()
17080 || member_loc
->form_is_block ())
17082 if (attr
!= nullptr)
17083 mark_common_block_symbol_computed (sym
, die
, attr
,
17087 dwarf2_complex_location_expr_complaint ();
17092 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17093 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17097 /* Create a type for a C++ namespace. */
17099 static struct type
*
17100 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17102 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17103 const char *previous_prefix
, *name
;
17107 /* For extensions, reuse the type of the original namespace. */
17108 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17110 struct die_info
*ext_die
;
17111 struct dwarf2_cu
*ext_cu
= cu
;
17113 ext_die
= dwarf2_extension (die
, &ext_cu
);
17114 type
= read_type_die (ext_die
, ext_cu
);
17116 /* EXT_CU may not be the same as CU.
17117 Ensure TYPE is recorded with CU in die_type_hash. */
17118 return set_die_type (die
, type
, cu
);
17121 name
= namespace_name (die
, &is_anonymous
, cu
);
17123 /* Now build the name of the current namespace. */
17125 previous_prefix
= determine_prefix (die
, cu
);
17126 if (previous_prefix
[0] != '\0')
17127 name
= typename_concat (&objfile
->objfile_obstack
,
17128 previous_prefix
, name
, 0, cu
);
17130 /* Create the type. */
17131 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17133 return set_die_type (die
, type
, cu
);
17136 /* Read a namespace scope. */
17139 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17141 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17144 /* Add a symbol associated to this if we haven't seen the namespace
17145 before. Also, add a using directive if it's an anonymous
17148 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17152 type
= read_type_die (die
, cu
);
17153 new_symbol (die
, type
, cu
);
17155 namespace_name (die
, &is_anonymous
, cu
);
17158 const char *previous_prefix
= determine_prefix (die
, cu
);
17160 std::vector
<const char *> excludes
;
17161 add_using_directive (using_directives (cu
),
17162 previous_prefix
, type
->name (), NULL
,
17163 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17167 if (die
->child
!= NULL
)
17169 struct die_info
*child_die
= die
->child
;
17171 while (child_die
&& child_die
->tag
)
17173 process_die (child_die
, cu
);
17174 child_die
= child_die
->sibling
;
17179 /* Read a Fortran module as type. This DIE can be only a declaration used for
17180 imported module. Still we need that type as local Fortran "use ... only"
17181 declaration imports depend on the created type in determine_prefix. */
17183 static struct type
*
17184 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17186 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17187 const char *module_name
;
17190 module_name
= dwarf2_name (die
, cu
);
17191 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17193 return set_die_type (die
, type
, cu
);
17196 /* Read a Fortran module. */
17199 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17201 struct die_info
*child_die
= die
->child
;
17204 type
= read_type_die (die
, cu
);
17205 new_symbol (die
, type
, cu
);
17207 while (child_die
&& child_die
->tag
)
17209 process_die (child_die
, cu
);
17210 child_die
= child_die
->sibling
;
17214 /* Return the name of the namespace represented by DIE. Set
17215 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17218 static const char *
17219 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17221 struct die_info
*current_die
;
17222 const char *name
= NULL
;
17224 /* Loop through the extensions until we find a name. */
17226 for (current_die
= die
;
17227 current_die
!= NULL
;
17228 current_die
= dwarf2_extension (die
, &cu
))
17230 /* We don't use dwarf2_name here so that we can detect the absence
17231 of a name -> anonymous namespace. */
17232 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17238 /* Is it an anonymous namespace? */
17240 *is_anonymous
= (name
== NULL
);
17242 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17247 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17248 the user defined type vector. */
17250 static struct type
*
17251 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17253 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17254 struct comp_unit_head
*cu_header
= &cu
->header
;
17256 struct attribute
*attr_byte_size
;
17257 struct attribute
*attr_address_class
;
17258 int byte_size
, addr_class
;
17259 struct type
*target_type
;
17261 target_type
= die_type (die
, cu
);
17263 /* The die_type call above may have already set the type for this DIE. */
17264 type
= get_die_type (die
, cu
);
17268 type
= lookup_pointer_type (target_type
);
17270 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17271 if (attr_byte_size
)
17272 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17274 byte_size
= cu_header
->addr_size
;
17276 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17277 if (attr_address_class
)
17278 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17280 addr_class
= DW_ADDR_none
;
17282 ULONGEST alignment
= get_alignment (cu
, die
);
17284 /* If the pointer size, alignment, or address class is different
17285 than the default, create a type variant marked as such and set
17286 the length accordingly. */
17287 if (TYPE_LENGTH (type
) != byte_size
17288 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17289 && alignment
!= TYPE_RAW_ALIGN (type
))
17290 || addr_class
!= DW_ADDR_none
)
17292 if (gdbarch_address_class_type_flags_p (gdbarch
))
17294 type_instance_flags type_flags
17295 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17297 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17299 type
= make_type_with_address_space (type
, type_flags
);
17301 else if (TYPE_LENGTH (type
) != byte_size
)
17303 complaint (_("invalid pointer size %d"), byte_size
);
17305 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17307 complaint (_("Invalid DW_AT_alignment"
17308 " - DIE at %s [in module %s]"),
17309 sect_offset_str (die
->sect_off
),
17310 objfile_name (cu
->per_objfile
->objfile
));
17314 /* Should we also complain about unhandled address classes? */
17318 TYPE_LENGTH (type
) = byte_size
;
17319 set_type_align (type
, alignment
);
17320 return set_die_type (die
, type
, cu
);
17323 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17324 the user defined type vector. */
17326 static struct type
*
17327 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17330 struct type
*to_type
;
17331 struct type
*domain
;
17333 to_type
= die_type (die
, cu
);
17334 domain
= die_containing_type (die
, cu
);
17336 /* The calls above may have already set the type for this DIE. */
17337 type
= get_die_type (die
, cu
);
17341 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17342 type
= lookup_methodptr_type (to_type
);
17343 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17345 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17347 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17348 to_type
->fields (), to_type
->num_fields (),
17349 to_type
->has_varargs ());
17350 type
= lookup_methodptr_type (new_type
);
17353 type
= lookup_memberptr_type (to_type
, domain
);
17355 return set_die_type (die
, type
, cu
);
17358 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17359 the user defined type vector. */
17361 static struct type
*
17362 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17363 enum type_code refcode
)
17365 struct comp_unit_head
*cu_header
= &cu
->header
;
17366 struct type
*type
, *target_type
;
17367 struct attribute
*attr
;
17369 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17371 target_type
= die_type (die
, cu
);
17373 /* The die_type call above may have already set the type for this DIE. */
17374 type
= get_die_type (die
, cu
);
17378 type
= lookup_reference_type (target_type
, refcode
);
17379 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17380 if (attr
!= nullptr)
17382 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17386 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17388 maybe_set_alignment (cu
, die
, type
);
17389 return set_die_type (die
, type
, cu
);
17392 /* Add the given cv-qualifiers to the element type of the array. GCC
17393 outputs DWARF type qualifiers that apply to an array, not the
17394 element type. But GDB relies on the array element type to carry
17395 the cv-qualifiers. This mimics section 6.7.3 of the C99
17398 static struct type
*
17399 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17400 struct type
*base_type
, int cnst
, int voltl
)
17402 struct type
*el_type
, *inner_array
;
17404 base_type
= copy_type (base_type
);
17405 inner_array
= base_type
;
17407 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17409 TYPE_TARGET_TYPE (inner_array
) =
17410 copy_type (TYPE_TARGET_TYPE (inner_array
));
17411 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17414 el_type
= TYPE_TARGET_TYPE (inner_array
);
17415 cnst
|= TYPE_CONST (el_type
);
17416 voltl
|= TYPE_VOLATILE (el_type
);
17417 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17419 return set_die_type (die
, base_type
, cu
);
17422 static struct type
*
17423 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17425 struct type
*base_type
, *cv_type
;
17427 base_type
= die_type (die
, cu
);
17429 /* The die_type call above may have already set the type for this DIE. */
17430 cv_type
= get_die_type (die
, cu
);
17434 /* In case the const qualifier is applied to an array type, the element type
17435 is so qualified, not the array type (section 6.7.3 of C99). */
17436 if (base_type
->code () == TYPE_CODE_ARRAY
)
17437 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17439 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17440 return set_die_type (die
, cv_type
, cu
);
17443 static struct type
*
17444 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17446 struct type
*base_type
, *cv_type
;
17448 base_type
= die_type (die
, cu
);
17450 /* The die_type call above may have already set the type for this DIE. */
17451 cv_type
= get_die_type (die
, cu
);
17455 /* In case the volatile qualifier is applied to an array type, the
17456 element type is so qualified, not the array type (section 6.7.3
17458 if (base_type
->code () == TYPE_CODE_ARRAY
)
17459 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17461 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17462 return set_die_type (die
, cv_type
, cu
);
17465 /* Handle DW_TAG_restrict_type. */
17467 static struct type
*
17468 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17470 struct type
*base_type
, *cv_type
;
17472 base_type
= die_type (die
, cu
);
17474 /* The die_type call above may have already set the type for this DIE. */
17475 cv_type
= get_die_type (die
, cu
);
17479 cv_type
= make_restrict_type (base_type
);
17480 return set_die_type (die
, cv_type
, cu
);
17483 /* Handle DW_TAG_atomic_type. */
17485 static struct type
*
17486 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17488 struct type
*base_type
, *cv_type
;
17490 base_type
= die_type (die
, cu
);
17492 /* The die_type call above may have already set the type for this DIE. */
17493 cv_type
= get_die_type (die
, cu
);
17497 cv_type
= make_atomic_type (base_type
);
17498 return set_die_type (die
, cv_type
, cu
);
17501 /* Extract all information from a DW_TAG_string_type DIE and add to
17502 the user defined type vector. It isn't really a user defined type,
17503 but it behaves like one, with other DIE's using an AT_user_def_type
17504 attribute to reference it. */
17506 static struct type
*
17507 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17509 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17510 struct gdbarch
*gdbarch
= objfile
->arch ();
17511 struct type
*type
, *range_type
, *index_type
, *char_type
;
17512 struct attribute
*attr
;
17513 struct dynamic_prop prop
;
17514 bool length_is_constant
= true;
17517 /* There are a couple of places where bit sizes might be made use of
17518 when parsing a DW_TAG_string_type, however, no producer that we know
17519 of make use of these. Handling bit sizes that are a multiple of the
17520 byte size is easy enough, but what about other bit sizes? Lets deal
17521 with that problem when we have to. Warn about these attributes being
17522 unsupported, then parse the type and ignore them like we always
17524 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17525 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17527 static bool warning_printed
= false;
17528 if (!warning_printed
)
17530 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17531 "currently supported on DW_TAG_string_type."));
17532 warning_printed
= true;
17536 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17537 if (attr
!= nullptr && !attr
->form_is_constant ())
17539 /* The string length describes the location at which the length of
17540 the string can be found. The size of the length field can be
17541 specified with one of the attributes below. */
17542 struct type
*prop_type
;
17543 struct attribute
*len
17544 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17545 if (len
== nullptr)
17546 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17547 if (len
!= nullptr && len
->form_is_constant ())
17549 /* Pass 0 as the default as we know this attribute is constant
17550 and the default value will not be returned. */
17551 LONGEST sz
= len
->constant_value (0);
17552 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17556 /* If the size is not specified then we assume it is the size of
17557 an address on this target. */
17558 prop_type
= cu
->addr_sized_int_type (true);
17561 /* Convert the attribute into a dynamic property. */
17562 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17565 length_is_constant
= false;
17567 else if (attr
!= nullptr)
17569 /* This DW_AT_string_length just contains the length with no
17570 indirection. There's no need to create a dynamic property in this
17571 case. Pass 0 for the default value as we know it will not be
17572 returned in this case. */
17573 length
= attr
->constant_value (0);
17575 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17577 /* We don't currently support non-constant byte sizes for strings. */
17578 length
= attr
->constant_value (1);
17582 /* Use 1 as a fallback length if we have nothing else. */
17586 index_type
= objfile_type (objfile
)->builtin_int
;
17587 if (length_is_constant
)
17588 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17591 struct dynamic_prop low_bound
;
17593 low_bound
.set_const_val (1);
17594 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17596 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17597 type
= create_string_type (NULL
, char_type
, range_type
);
17599 return set_die_type (die
, type
, cu
);
17602 /* Assuming that DIE corresponds to a function, returns nonzero
17603 if the function is prototyped. */
17606 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17608 struct attribute
*attr
;
17610 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17611 if (attr
&& attr
->as_boolean ())
17614 /* The DWARF standard implies that the DW_AT_prototyped attribute
17615 is only meaningful for C, but the concept also extends to other
17616 languages that allow unprototyped functions (Eg: Objective C).
17617 For all other languages, assume that functions are always
17619 if (cu
->language
!= language_c
17620 && cu
->language
!= language_objc
17621 && cu
->language
!= language_opencl
)
17624 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17625 prototyped and unprototyped functions; default to prototyped,
17626 since that is more common in modern code (and RealView warns
17627 about unprototyped functions). */
17628 if (producer_is_realview (cu
->producer
))
17634 /* Handle DIES due to C code like:
17638 int (*funcp)(int a, long l);
17642 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17644 static struct type
*
17645 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17647 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17648 struct type
*type
; /* Type that this function returns. */
17649 struct type
*ftype
; /* Function that returns above type. */
17650 struct attribute
*attr
;
17652 type
= die_type (die
, cu
);
17654 /* The die_type call above may have already set the type for this DIE. */
17655 ftype
= get_die_type (die
, cu
);
17659 ftype
= lookup_function_type (type
);
17661 if (prototyped_function_p (die
, cu
))
17662 ftype
->set_is_prototyped (true);
17664 /* Store the calling convention in the type if it's available in
17665 the subroutine die. Otherwise set the calling convention to
17666 the default value DW_CC_normal. */
17667 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17668 if (attr
!= nullptr
17669 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
17670 TYPE_CALLING_CONVENTION (ftype
)
17671 = (enum dwarf_calling_convention
) attr
->constant_value (0);
17672 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17673 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17675 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17677 /* Record whether the function returns normally to its caller or not
17678 if the DWARF producer set that information. */
17679 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17680 if (attr
&& attr
->as_boolean ())
17681 TYPE_NO_RETURN (ftype
) = 1;
17683 /* We need to add the subroutine type to the die immediately so
17684 we don't infinitely recurse when dealing with parameters
17685 declared as the same subroutine type. */
17686 set_die_type (die
, ftype
, cu
);
17688 if (die
->child
!= NULL
)
17690 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17691 struct die_info
*child_die
;
17692 int nparams
, iparams
;
17694 /* Count the number of parameters.
17695 FIXME: GDB currently ignores vararg functions, but knows about
17696 vararg member functions. */
17698 child_die
= die
->child
;
17699 while (child_die
&& child_die
->tag
)
17701 if (child_die
->tag
== DW_TAG_formal_parameter
)
17703 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17704 ftype
->set_has_varargs (true);
17706 child_die
= child_die
->sibling
;
17709 /* Allocate storage for parameters and fill them in. */
17710 ftype
->set_num_fields (nparams
);
17712 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
17714 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17715 even if we error out during the parameters reading below. */
17716 for (iparams
= 0; iparams
< nparams
; iparams
++)
17717 ftype
->field (iparams
).set_type (void_type
);
17720 child_die
= die
->child
;
17721 while (child_die
&& child_die
->tag
)
17723 if (child_die
->tag
== DW_TAG_formal_parameter
)
17725 struct type
*arg_type
;
17727 /* DWARF version 2 has no clean way to discern C++
17728 static and non-static member functions. G++ helps
17729 GDB by marking the first parameter for non-static
17730 member functions (which is the this pointer) as
17731 artificial. We pass this information to
17732 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17734 DWARF version 3 added DW_AT_object_pointer, which GCC
17735 4.5 does not yet generate. */
17736 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17737 if (attr
!= nullptr)
17738 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
17740 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17741 arg_type
= die_type (child_die
, cu
);
17743 /* RealView does not mark THIS as const, which the testsuite
17744 expects. GCC marks THIS as const in method definitions,
17745 but not in the class specifications (GCC PR 43053). */
17746 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17747 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17750 struct dwarf2_cu
*arg_cu
= cu
;
17751 const char *name
= dwarf2_name (child_die
, cu
);
17753 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17754 if (attr
!= nullptr)
17756 /* If the compiler emits this, use it. */
17757 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17760 else if (name
&& strcmp (name
, "this") == 0)
17761 /* Function definitions will have the argument names. */
17763 else if (name
== NULL
&& iparams
== 0)
17764 /* Declarations may not have the names, so like
17765 elsewhere in GDB, assume an artificial first
17766 argument is "this". */
17770 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17774 ftype
->field (iparams
).set_type (arg_type
);
17777 child_die
= child_die
->sibling
;
17784 static struct type
*
17785 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17787 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17788 const char *name
= NULL
;
17789 struct type
*this_type
, *target_type
;
17791 name
= dwarf2_full_name (NULL
, die
, cu
);
17792 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17793 this_type
->set_target_is_stub (true);
17794 set_die_type (die
, this_type
, cu
);
17795 target_type
= die_type (die
, cu
);
17796 if (target_type
!= this_type
)
17797 TYPE_TARGET_TYPE (this_type
) = target_type
;
17800 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17801 spec and cause infinite loops in GDB. */
17802 complaint (_("Self-referential DW_TAG_typedef "
17803 "- DIE at %s [in module %s]"),
17804 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17805 TYPE_TARGET_TYPE (this_type
) = NULL
;
17809 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
17810 anonymous typedefs, which is, strictly speaking, invalid DWARF.
17811 Handle these by just returning the target type, rather than
17812 constructing an anonymous typedef type and trying to handle this
17814 set_die_type (die
, target_type
, cu
);
17815 return target_type
;
17820 /* Helper for get_dwarf2_rational_constant that computes the value of
17821 a given gmp_mpz given an attribute. */
17824 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
17826 /* GCC will sometimes emit a 16-byte constant value as a DWARF
17827 location expression that pushes an implicit value. */
17828 if (attr
->form
== DW_FORM_exprloc
)
17830 dwarf_block
*blk
= attr
->as_block ();
17831 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
17834 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
17835 blk
->data
+ blk
->size
,
17837 if (ptr
- blk
->data
+ len
<= blk
->size
)
17839 mpz_import (value
->val
, len
,
17840 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17846 /* On failure set it to 1. */
17847 *value
= gdb_mpz (1);
17849 else if (attr
->form_is_block ())
17851 dwarf_block
*blk
= attr
->as_block ();
17852 mpz_import (value
->val
, blk
->size
,
17853 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
17854 1, 0, 0, blk
->data
);
17857 *value
= gdb_mpz (attr
->constant_value (1));
17860 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
17861 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
17863 If the numerator and/or numerator attribute is missing,
17864 a complaint is filed, and NUMERATOR and DENOMINATOR are left
17868 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
17869 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
17871 struct attribute
*num_attr
, *denom_attr
;
17873 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
17874 if (num_attr
== nullptr)
17875 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
17876 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17878 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
17879 if (denom_attr
== nullptr)
17880 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
17881 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
17883 if (num_attr
== nullptr || denom_attr
== nullptr)
17886 get_mpz (cu
, numerator
, num_attr
);
17887 get_mpz (cu
, denominator
, denom_attr
);
17890 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
17891 rational constant, rather than a signed one.
17893 If the rational constant has a negative value, a complaint
17894 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
17897 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
17898 struct dwarf2_cu
*cu
,
17899 gdb_mpz
*numerator
,
17900 gdb_mpz
*denominator
)
17905 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
17906 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
17908 mpz_neg (num
.val
, num
.val
);
17909 mpz_neg (denom
.val
, denom
.val
);
17911 else if (mpz_sgn (num
.val
) == -1)
17913 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
17915 sect_offset_str (die
->sect_off
));
17918 else if (mpz_sgn (denom
.val
) == -1)
17920 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
17922 sect_offset_str (die
->sect_off
));
17926 *numerator
= std::move (num
);
17927 *denominator
= std::move (denom
);
17930 /* Assuming that ENCODING is a string whose contents starting at the
17931 K'th character is "_nn" where "nn" is a decimal number, scan that
17932 number and set RESULT to the value. K is updated to point to the
17933 character immediately following the number.
17935 If the string does not conform to the format described above, false
17936 is returned, and K may or may not be changed. */
17939 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
17941 /* The next character should be an underscore ('_') followed
17943 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
17946 /* Skip the underscore. */
17950 /* Determine the number of digits for our number. */
17951 while (isdigit (encoding
[k
]))
17956 std::string
copy (&encoding
[start
], k
- start
);
17957 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
17963 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
17964 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
17965 DENOM, update OFFSET, and return true on success. Return false on
17969 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
17970 gdb_mpz
*num
, gdb_mpz
*denom
)
17972 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
17974 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
17977 /* Assuming DIE corresponds to a fixed point type, finish the creation
17978 of the corresponding TYPE by setting its type-specific data. CU is
17979 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
17980 encodings. It is nullptr if the GNAT encoding should be
17984 finish_fixed_point_type (struct type
*type
, const char *suffix
,
17985 struct die_info
*die
, struct dwarf2_cu
*cu
)
17987 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
17988 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
17990 /* If GNAT encodings are preferred, don't examine the
17992 struct attribute
*attr
= nullptr;
17993 if (suffix
== nullptr)
17995 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
17996 if (attr
== nullptr)
17997 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
17998 if (attr
== nullptr)
17999 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18002 /* Numerator and denominator of our fixed-point type's scaling factor.
18003 The default is a scaling factor of 1, which we use as a fallback
18004 when we are not able to decode it (problem with the debugging info,
18005 unsupported forms, bug in GDB, etc...). Using that as the default
18006 allows us to at least print the unscaled value, which might still
18007 be useful to a user. */
18008 gdb_mpz
scale_num (1);
18009 gdb_mpz
scale_denom (1);
18011 if (attr
== nullptr)
18014 if (suffix
!= nullptr
18015 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
18017 /* The number might be encoded as _nn_dd_nn_dd, where the
18018 second ratio is the 'small value. In this situation, we
18019 want the second value. */
18020 && (suffix
[offset
] != '_'
18021 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
18028 /* Scaling factor not found. Assume a scaling factor of 1,
18029 and hope for the best. At least the user will be able to
18030 see the encoded value. */
18033 complaint (_("no scale found for fixed-point type (DIE at %s)"),
18034 sect_offset_str (die
->sect_off
));
18037 else if (attr
->name
== DW_AT_binary_scale
)
18039 LONGEST scale_exp
= attr
->constant_value (0);
18040 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18042 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
18044 else if (attr
->name
== DW_AT_decimal_scale
)
18046 LONGEST scale_exp
= attr
->constant_value (0);
18047 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18049 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
18051 else if (attr
->name
== DW_AT_small
)
18053 struct die_info
*scale_die
;
18054 struct dwarf2_cu
*scale_cu
= cu
;
18056 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
18057 if (scale_die
->tag
== DW_TAG_constant
)
18058 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
18059 &scale_num
, &scale_denom
);
18061 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
18063 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18067 complaint (_("unsupported scale attribute %s for fixed-point type"
18069 dwarf_attr_name (attr
->name
),
18070 sect_offset_str (die
->sect_off
));
18073 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
18074 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
18075 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
18076 mpq_canonicalize (scaling_factor
.val
);
18079 /* The gnat-encoding suffix for fixed point. */
18081 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
18083 /* If NAME encodes an Ada fixed-point type, return a pointer to the
18084 "XF" suffix of the name. The text after this is what encodes the
18085 'small and 'delta information. Otherwise, return nullptr. */
18087 static const char *
18088 gnat_encoded_fixed_point_type_info (const char *name
)
18090 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
18093 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
18094 (which may be different from NAME) to the architecture back-end to allow
18095 it to guess the correct format if necessary. */
18097 static struct type
*
18098 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
18099 const char *name_hint
, enum bfd_endian byte_order
)
18101 struct gdbarch
*gdbarch
= objfile
->arch ();
18102 const struct floatformat
**format
;
18105 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
18107 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
18109 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18114 /* Allocate an integer type of size BITS and name NAME. */
18116 static struct type
*
18117 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
18118 int bits
, int unsigned_p
, const char *name
)
18122 /* Versions of Intel's C Compiler generate an integer type called "void"
18123 instead of using DW_TAG_unspecified_type. This has been seen on
18124 at least versions 14, 17, and 18. */
18125 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18126 && strcmp (name
, "void") == 0)
18127 type
= objfile_type (objfile
)->builtin_void
;
18129 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18134 /* Return true if DIE has a DW_AT_small attribute whose value is
18135 a constant rational, where both the numerator and denominator
18138 CU is the DIE's Compilation Unit. */
18141 has_zero_over_zero_small_attribute (struct die_info
*die
,
18142 struct dwarf2_cu
*cu
)
18144 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18145 if (attr
== nullptr)
18148 struct dwarf2_cu
*scale_cu
= cu
;
18149 struct die_info
*scale_die
18150 = follow_die_ref (die
, attr
, &scale_cu
);
18152 if (scale_die
->tag
!= DW_TAG_constant
)
18155 gdb_mpz
num (1), denom (1);
18156 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18157 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
18160 /* Initialise and return a floating point type of size BITS suitable for
18161 use as a component of a complex number. The NAME_HINT is passed through
18162 when initialising the floating point type and is the name of the complex
18165 As DWARF doesn't currently provide an explicit name for the components
18166 of a complex number, but it can be helpful to have these components
18167 named, we try to select a suitable name based on the size of the
18169 static struct type
*
18170 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18171 struct objfile
*objfile
,
18172 int bits
, const char *name_hint
,
18173 enum bfd_endian byte_order
)
18175 gdbarch
*gdbarch
= objfile
->arch ();
18176 struct type
*tt
= nullptr;
18178 /* Try to find a suitable floating point builtin type of size BITS.
18179 We're going to use the name of this type as the name for the complex
18180 target type that we are about to create. */
18181 switch (cu
->language
)
18183 case language_fortran
:
18187 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18190 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18192 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18194 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18202 tt
= builtin_type (gdbarch
)->builtin_float
;
18205 tt
= builtin_type (gdbarch
)->builtin_double
;
18207 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18209 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18215 /* If the type we found doesn't match the size we were looking for, then
18216 pretend we didn't find a type at all, the complex target type we
18217 create will then be nameless. */
18218 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18221 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18222 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18225 /* Find a representation of a given base type and install
18226 it in the TYPE field of the die. */
18228 static struct type
*
18229 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18231 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18233 struct attribute
*attr
;
18234 int encoding
= 0, bits
= 0;
18238 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18239 if (attr
!= nullptr && attr
->form_is_constant ())
18240 encoding
= attr
->constant_value (0);
18241 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18242 if (attr
!= nullptr)
18243 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18244 name
= dwarf2_name (die
, cu
);
18246 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18248 arch
= objfile
->arch ();
18249 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18251 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18252 if (attr
!= nullptr && attr
->form_is_constant ())
18254 int endianity
= attr
->constant_value (0);
18259 byte_order
= BFD_ENDIAN_BIG
;
18261 case DW_END_little
:
18262 byte_order
= BFD_ENDIAN_LITTLE
;
18265 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18270 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18271 && cu
->language
== language_ada
18272 && has_zero_over_zero_small_attribute (die
, cu
))
18274 /* brobecker/2018-02-24: This is a fixed point type for which
18275 the scaling factor is represented as fraction whose value
18276 does not make sense (zero divided by zero), so we should
18277 normally never see these. However, there is a small category
18278 of fixed point types for which GNAT is unable to provide
18279 the scaling factor via the standard DWARF mechanisms, and
18280 for which the info is provided via the GNAT encodings instead.
18281 This is likely what this DIE is about. */
18282 encoding
= (encoding
== DW_ATE_signed_fixed
18284 : DW_ATE_unsigned
);
18287 /* With GNAT encodings, fixed-point information will be encoded in
18288 the type name. Note that this can also occur with the above
18289 zero-over-zero case, which is why this is a separate "if" rather
18290 than an "else if". */
18291 const char *gnat_encoding_suffix
= nullptr;
18292 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18293 && cu
->language
== language_ada
18294 && name
!= nullptr)
18296 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18297 if (gnat_encoding_suffix
!= nullptr)
18299 gdb_assert (startswith (gnat_encoding_suffix
,
18300 GNAT_FIXED_POINT_SUFFIX
));
18301 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18302 name
, gnat_encoding_suffix
- name
);
18303 /* Use -1 here so that SUFFIX points at the "_" after the
18305 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18307 encoding
= (encoding
== DW_ATE_signed
18308 ? DW_ATE_signed_fixed
18309 : DW_ATE_unsigned_fixed
);
18315 case DW_ATE_address
:
18316 /* Turn DW_ATE_address into a void * pointer. */
18317 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18318 type
= init_pointer_type (objfile
, bits
, name
, type
);
18320 case DW_ATE_boolean
:
18321 type
= init_boolean_type (objfile
, bits
, 1, name
);
18323 case DW_ATE_complex_float
:
18324 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18326 if (type
->code () == TYPE_CODE_ERROR
)
18328 if (name
== nullptr)
18330 struct obstack
*obstack
18331 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18332 name
= obconcat (obstack
, "_Complex ", type
->name (),
18335 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18338 type
= init_complex_type (name
, type
);
18340 case DW_ATE_decimal_float
:
18341 type
= init_decfloat_type (objfile
, bits
, name
);
18344 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18346 case DW_ATE_signed
:
18347 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18349 case DW_ATE_unsigned
:
18350 if (cu
->language
== language_fortran
18352 && startswith (name
, "character("))
18353 type
= init_character_type (objfile
, bits
, 1, name
);
18355 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18357 case DW_ATE_signed_char
:
18358 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18359 || cu
->language
== language_pascal
18360 || cu
->language
== language_fortran
)
18361 type
= init_character_type (objfile
, bits
, 0, name
);
18363 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18365 case DW_ATE_unsigned_char
:
18366 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18367 || cu
->language
== language_pascal
18368 || cu
->language
== language_fortran
18369 || cu
->language
== language_rust
)
18370 type
= init_character_type (objfile
, bits
, 1, name
);
18372 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18377 type
= builtin_type (arch
)->builtin_char16
;
18378 else if (bits
== 32)
18379 type
= builtin_type (arch
)->builtin_char32
;
18382 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18384 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18386 return set_die_type (die
, type
, cu
);
18389 case DW_ATE_signed_fixed
:
18390 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18391 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18393 case DW_ATE_unsigned_fixed
:
18394 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18395 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18399 complaint (_("unsupported DW_AT_encoding: '%s'"),
18400 dwarf_type_encoding_name (encoding
));
18401 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18405 if (name
&& strcmp (name
, "char") == 0)
18406 type
->set_has_no_signedness (true);
18408 maybe_set_alignment (cu
, die
, type
);
18410 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18412 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18414 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18415 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18417 unsigned real_bit_size
= attr
->as_unsigned ();
18418 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18419 /* Only use the attributes if they make sense together. */
18420 if (attr
== nullptr
18421 || (attr
->as_unsigned () + real_bit_size
18422 <= 8 * TYPE_LENGTH (type
)))
18424 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18426 if (attr
!= nullptr)
18427 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18428 = attr
->as_unsigned ();
18433 return set_die_type (die
, type
, cu
);
18436 /* Parse dwarf attribute if it's a block, reference or constant and put the
18437 resulting value of the attribute into struct bound_prop.
18438 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18441 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18442 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18443 struct type
*default_type
)
18445 struct dwarf2_property_baton
*baton
;
18446 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18447 struct objfile
*objfile
= per_objfile
->objfile
;
18448 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18450 gdb_assert (default_type
!= NULL
);
18452 if (attr
== NULL
|| prop
== NULL
)
18455 if (attr
->form_is_block ())
18457 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18458 baton
->property_type
= default_type
;
18459 baton
->locexpr
.per_cu
= cu
->per_cu
;
18460 baton
->locexpr
.per_objfile
= per_objfile
;
18462 struct dwarf_block
*block
= attr
->as_block ();
18463 baton
->locexpr
.size
= block
->size
;
18464 baton
->locexpr
.data
= block
->data
;
18465 switch (attr
->name
)
18467 case DW_AT_string_length
:
18468 baton
->locexpr
.is_reference
= true;
18471 baton
->locexpr
.is_reference
= false;
18475 prop
->set_locexpr (baton
);
18476 gdb_assert (prop
->baton () != NULL
);
18478 else if (attr
->form_is_ref ())
18480 struct dwarf2_cu
*target_cu
= cu
;
18481 struct die_info
*target_die
;
18482 struct attribute
*target_attr
;
18484 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18485 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18486 if (target_attr
== NULL
)
18487 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18489 if (target_attr
== NULL
)
18492 switch (target_attr
->name
)
18494 case DW_AT_location
:
18495 if (target_attr
->form_is_section_offset ())
18497 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18498 baton
->property_type
= die_type (target_die
, target_cu
);
18499 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18500 prop
->set_loclist (baton
);
18501 gdb_assert (prop
->baton () != NULL
);
18503 else if (target_attr
->form_is_block ())
18505 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18506 baton
->property_type
= die_type (target_die
, target_cu
);
18507 baton
->locexpr
.per_cu
= cu
->per_cu
;
18508 baton
->locexpr
.per_objfile
= per_objfile
;
18509 struct dwarf_block
*block
= target_attr
->as_block ();
18510 baton
->locexpr
.size
= block
->size
;
18511 baton
->locexpr
.data
= block
->data
;
18512 baton
->locexpr
.is_reference
= true;
18513 prop
->set_locexpr (baton
);
18514 gdb_assert (prop
->baton () != NULL
);
18518 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18519 "dynamic property");
18523 case DW_AT_data_member_location
:
18527 if (!handle_data_member_location (target_die
, target_cu
,
18531 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18532 baton
->property_type
= read_type_die (target_die
->parent
,
18534 baton
->offset_info
.offset
= offset
;
18535 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18536 prop
->set_addr_offset (baton
);
18541 else if (attr
->form_is_constant ())
18542 prop
->set_const_val (attr
->constant_value (0));
18545 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18546 dwarf2_name (die
, cu
));
18556 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18558 struct type
*int_type
;
18560 /* Helper macro to examine the various builtin types. */
18561 #define TRY_TYPE(F) \
18562 int_type = (unsigned_p \
18563 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18564 : objfile_type (objfile)->builtin_ ## F); \
18565 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18572 TRY_TYPE (long_long
);
18576 gdb_assert_not_reached ("unable to find suitable integer type");
18582 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
18584 int addr_size
= this->per_cu
->addr_size ();
18585 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
18588 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18589 present (which is valid) then compute the default type based on the
18590 compilation units address size. */
18592 static struct type
*
18593 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18595 struct type
*index_type
= die_type (die
, cu
);
18597 /* Dwarf-2 specifications explicitly allows to create subrange types
18598 without specifying a base type.
18599 In that case, the base type must be set to the type of
18600 the lower bound, upper bound or count, in that order, if any of these
18601 three attributes references an object that has a type.
18602 If no base type is found, the Dwarf-2 specifications say that
18603 a signed integer type of size equal to the size of an address should
18605 For the following C code: `extern char gdb_int [];'
18606 GCC produces an empty range DIE.
18607 FIXME: muller/2010-05-28: Possible references to object for low bound,
18608 high bound or count are not yet handled by this code. */
18609 if (index_type
->code () == TYPE_CODE_VOID
)
18610 index_type
= cu
->addr_sized_int_type (false);
18615 /* Read the given DW_AT_subrange DIE. */
18617 static struct type
*
18618 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18620 struct type
*base_type
, *orig_base_type
;
18621 struct type
*range_type
;
18622 struct attribute
*attr
;
18623 struct dynamic_prop low
, high
;
18624 int low_default_is_valid
;
18625 int high_bound_is_count
= 0;
18627 ULONGEST negative_mask
;
18629 orig_base_type
= read_subrange_index_type (die
, cu
);
18631 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18632 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18633 creating the range type, but we use the result of check_typedef
18634 when examining properties of the type. */
18635 base_type
= check_typedef (orig_base_type
);
18637 /* The die_type call above may have already set the type for this DIE. */
18638 range_type
= get_die_type (die
, cu
);
18642 high
.set_const_val (0);
18644 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18645 omitting DW_AT_lower_bound. */
18646 switch (cu
->language
)
18649 case language_cplus
:
18650 low
.set_const_val (0);
18651 low_default_is_valid
= 1;
18653 case language_fortran
:
18654 low
.set_const_val (1);
18655 low_default_is_valid
= 1;
18658 case language_objc
:
18659 case language_rust
:
18660 low
.set_const_val (0);
18661 low_default_is_valid
= (cu
->header
.version
>= 4);
18665 case language_pascal
:
18666 low
.set_const_val (1);
18667 low_default_is_valid
= (cu
->header
.version
>= 4);
18670 low
.set_const_val (0);
18671 low_default_is_valid
= 0;
18675 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18676 if (attr
!= nullptr)
18677 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18678 else if (!low_default_is_valid
)
18679 complaint (_("Missing DW_AT_lower_bound "
18680 "- DIE at %s [in module %s]"),
18681 sect_offset_str (die
->sect_off
),
18682 objfile_name (cu
->per_objfile
->objfile
));
18684 struct attribute
*attr_ub
, *attr_count
;
18685 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18686 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18688 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18689 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18691 /* If bounds are constant do the final calculation here. */
18692 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
18693 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
18695 high_bound_is_count
= 1;
18699 if (attr_ub
!= NULL
)
18700 complaint (_("Unresolved DW_AT_upper_bound "
18701 "- DIE at %s [in module %s]"),
18702 sect_offset_str (die
->sect_off
),
18703 objfile_name (cu
->per_objfile
->objfile
));
18704 if (attr_count
!= NULL
)
18705 complaint (_("Unresolved DW_AT_count "
18706 "- DIE at %s [in module %s]"),
18707 sect_offset_str (die
->sect_off
),
18708 objfile_name (cu
->per_objfile
->objfile
));
18713 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18714 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
18715 bias
= bias_attr
->constant_value (0);
18717 /* Normally, the DWARF producers are expected to use a signed
18718 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18719 But this is unfortunately not always the case, as witnessed
18720 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18721 is used instead. To work around that ambiguity, we treat
18722 the bounds as signed, and thus sign-extend their values, when
18723 the base type is signed. */
18725 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18726 if (low
.kind () == PROP_CONST
18727 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
18728 low
.set_const_val (low
.const_val () | negative_mask
);
18729 if (high
.kind () == PROP_CONST
18730 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
18731 high
.set_const_val (high
.const_val () | negative_mask
);
18733 /* Check for bit and byte strides. */
18734 struct dynamic_prop byte_stride_prop
;
18735 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18736 if (attr_byte_stride
!= nullptr)
18738 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18739 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18743 struct dynamic_prop bit_stride_prop
;
18744 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18745 if (attr_bit_stride
!= nullptr)
18747 /* It only makes sense to have either a bit or byte stride. */
18748 if (attr_byte_stride
!= nullptr)
18750 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18751 "- DIE at %s [in module %s]"),
18752 sect_offset_str (die
->sect_off
),
18753 objfile_name (cu
->per_objfile
->objfile
));
18754 attr_bit_stride
= nullptr;
18758 struct type
*prop_type
= cu
->addr_sized_int_type (false);
18759 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18764 if (attr_byte_stride
!= nullptr
18765 || attr_bit_stride
!= nullptr)
18767 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18768 struct dynamic_prop
*stride
18769 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18772 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18773 &high
, bias
, stride
, byte_stride_p
);
18776 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18778 if (high_bound_is_count
)
18779 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
18781 /* Ada expects an empty array on no boundary attributes. */
18782 if (attr
== NULL
&& cu
->language
!= language_ada
)
18783 range_type
->bounds ()->high
.set_undefined ();
18785 name
= dwarf2_name (die
, cu
);
18787 range_type
->set_name (name
);
18789 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18790 if (attr
!= nullptr)
18791 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
18793 maybe_set_alignment (cu
, die
, range_type
);
18795 set_die_type (die
, range_type
, cu
);
18797 /* set_die_type should be already done. */
18798 set_descriptive_type (range_type
, die
, cu
);
18803 static struct type
*
18804 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18808 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
18809 type
->set_name (dwarf2_name (die
, cu
));
18811 /* In Ada, an unspecified type is typically used when the description
18812 of the type is deferred to a different unit. When encountering
18813 such a type, we treat it as a stub, and try to resolve it later on,
18815 if (cu
->language
== language_ada
)
18816 type
->set_is_stub (true);
18818 return set_die_type (die
, type
, cu
);
18821 /* Read a single die and all its descendents. Set the die's sibling
18822 field to NULL; set other fields in the die correctly, and set all
18823 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18824 location of the info_ptr after reading all of those dies. PARENT
18825 is the parent of the die in question. */
18827 static struct die_info
*
18828 read_die_and_children (const struct die_reader_specs
*reader
,
18829 const gdb_byte
*info_ptr
,
18830 const gdb_byte
**new_info_ptr
,
18831 struct die_info
*parent
)
18833 struct die_info
*die
;
18834 const gdb_byte
*cur_ptr
;
18836 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
18839 *new_info_ptr
= cur_ptr
;
18842 store_in_ref_table (die
, reader
->cu
);
18844 if (die
->has_children
)
18845 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18849 *new_info_ptr
= cur_ptr
;
18852 die
->sibling
= NULL
;
18853 die
->parent
= parent
;
18857 /* Read a die, all of its descendents, and all of its siblings; set
18858 all of the fields of all of the dies correctly. Arguments are as
18859 in read_die_and_children. */
18861 static struct die_info
*
18862 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18863 const gdb_byte
*info_ptr
,
18864 const gdb_byte
**new_info_ptr
,
18865 struct die_info
*parent
)
18867 struct die_info
*first_die
, *last_sibling
;
18868 const gdb_byte
*cur_ptr
;
18870 cur_ptr
= info_ptr
;
18871 first_die
= last_sibling
= NULL
;
18875 struct die_info
*die
18876 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18880 *new_info_ptr
= cur_ptr
;
18887 last_sibling
->sibling
= die
;
18889 last_sibling
= die
;
18893 /* Read a die, all of its descendents, and all of its siblings; set
18894 all of the fields of all of the dies correctly. Arguments are as
18895 in read_die_and_children.
18896 This the main entry point for reading a DIE and all its children. */
18898 static struct die_info
*
18899 read_die_and_siblings (const struct die_reader_specs
*reader
,
18900 const gdb_byte
*info_ptr
,
18901 const gdb_byte
**new_info_ptr
,
18902 struct die_info
*parent
)
18904 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18905 new_info_ptr
, parent
);
18907 if (dwarf_die_debug
)
18909 fprintf_unfiltered (gdb_stdlog
,
18910 "Read die from %s@0x%x of %s:\n",
18911 reader
->die_section
->get_name (),
18912 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18913 bfd_get_filename (reader
->abfd
));
18914 dump_die (die
, dwarf_die_debug
);
18920 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18922 The caller is responsible for filling in the extra attributes
18923 and updating (*DIEP)->num_attrs.
18924 Set DIEP to point to a newly allocated die with its information,
18925 except for its child, sibling, and parent fields. */
18927 static const gdb_byte
*
18928 read_full_die_1 (const struct die_reader_specs
*reader
,
18929 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18930 int num_extra_attrs
)
18932 unsigned int abbrev_number
, bytes_read
, i
;
18933 const struct abbrev_info
*abbrev
;
18934 struct die_info
*die
;
18935 struct dwarf2_cu
*cu
= reader
->cu
;
18936 bfd
*abfd
= reader
->abfd
;
18938 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18939 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18940 info_ptr
+= bytes_read
;
18941 if (!abbrev_number
)
18947 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18949 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18951 bfd_get_filename (abfd
));
18953 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18954 die
->sect_off
= sect_off
;
18955 die
->tag
= abbrev
->tag
;
18956 die
->abbrev
= abbrev_number
;
18957 die
->has_children
= abbrev
->has_children
;
18959 /* Make the result usable.
18960 The caller needs to update num_attrs after adding the extra
18962 die
->num_attrs
= abbrev
->num_attrs
;
18964 bool any_need_reprocess
= false;
18965 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18967 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18969 if (die
->attrs
[i
].requires_reprocessing_p ())
18970 any_need_reprocess
= true;
18973 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
18974 if (attr
!= nullptr && attr
->form_is_unsigned ())
18975 cu
->str_offsets_base
= attr
->as_unsigned ();
18977 attr
= die
->attr (DW_AT_loclists_base
);
18978 if (attr
!= nullptr)
18979 cu
->loclist_base
= attr
->as_unsigned ();
18981 auto maybe_addr_base
= die
->addr_base ();
18982 if (maybe_addr_base
.has_value ())
18983 cu
->addr_base
= *maybe_addr_base
;
18985 attr
= die
->attr (DW_AT_rnglists_base
);
18986 if (attr
!= nullptr)
18987 cu
->rnglists_base
= attr
->as_unsigned ();
18989 if (any_need_reprocess
)
18991 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18993 if (die
->attrs
[i
].requires_reprocessing_p ())
18994 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
19001 /* Read a die and all its attributes.
19002 Set DIEP to point to a newly allocated die with its information,
19003 except for its child, sibling, and parent fields. */
19005 static const gdb_byte
*
19006 read_full_die (const struct die_reader_specs
*reader
,
19007 struct die_info
**diep
, const gdb_byte
*info_ptr
)
19009 const gdb_byte
*result
;
19011 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
19013 if (dwarf_die_debug
)
19015 fprintf_unfiltered (gdb_stdlog
,
19016 "Read die from %s@0x%x of %s:\n",
19017 reader
->die_section
->get_name (),
19018 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19019 bfd_get_filename (reader
->abfd
));
19020 dump_die (*diep
, dwarf_die_debug
);
19027 /* Returns nonzero if TAG represents a type that we might generate a partial
19031 is_type_tag_for_partial (int tag
, enum language lang
)
19036 /* Some types that would be reasonable to generate partial symbols for,
19037 that we don't at present. Note that normally this does not
19038 matter, mainly because C compilers don't give names to these
19039 types, but instead emit DW_TAG_typedef. */
19040 case DW_TAG_file_type
:
19041 case DW_TAG_ptr_to_member_type
:
19042 case DW_TAG_set_type
:
19043 case DW_TAG_string_type
:
19044 case DW_TAG_subroutine_type
:
19047 /* GNAT may emit an array with a name, but no typedef, so we
19048 need to make a symbol in this case. */
19049 case DW_TAG_array_type
:
19050 return lang
== language_ada
;
19052 case DW_TAG_base_type
:
19053 case DW_TAG_class_type
:
19054 case DW_TAG_interface_type
:
19055 case DW_TAG_enumeration_type
:
19056 case DW_TAG_structure_type
:
19057 case DW_TAG_subrange_type
:
19058 case DW_TAG_typedef
:
19059 case DW_TAG_union_type
:
19066 /* Load all DIEs that are interesting for partial symbols into memory. */
19068 static struct partial_die_info
*
19069 load_partial_dies (const struct die_reader_specs
*reader
,
19070 const gdb_byte
*info_ptr
, int building_psymtab
)
19072 struct dwarf2_cu
*cu
= reader
->cu
;
19073 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19074 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
19075 unsigned int bytes_read
;
19076 unsigned int load_all
= 0;
19077 int nesting_level
= 1;
19082 gdb_assert (cu
->per_cu
!= NULL
);
19083 if (cu
->per_cu
->load_all_dies
)
19087 = htab_create_alloc_ex (cu
->header
.length
/ 12,
19091 &cu
->comp_unit_obstack
,
19092 hashtab_obstack_allocate
,
19093 dummy_obstack_deallocate
);
19097 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
19100 /* A NULL abbrev means the end of a series of children. */
19101 if (abbrev
== NULL
)
19103 if (--nesting_level
== 0)
19106 info_ptr
+= bytes_read
;
19107 last_die
= parent_die
;
19108 parent_die
= parent_die
->die_parent
;
19112 /* Check for template arguments. We never save these; if
19113 they're seen, we just mark the parent, and go on our way. */
19114 if (parent_die
!= NULL
19115 && cu
->language
== language_cplus
19116 && (abbrev
->tag
== DW_TAG_template_type_param
19117 || abbrev
->tag
== DW_TAG_template_value_param
))
19119 parent_die
->has_template_arguments
= 1;
19123 /* We don't need a partial DIE for the template argument. */
19124 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19129 /* We only recurse into c++ subprograms looking for template arguments.
19130 Skip their other children. */
19132 && cu
->language
== language_cplus
19133 && parent_die
!= NULL
19134 && parent_die
->tag
== DW_TAG_subprogram
19135 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19137 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19141 /* Check whether this DIE is interesting enough to save. Normally
19142 we would not be interested in members here, but there may be
19143 later variables referencing them via DW_AT_specification (for
19144 static members). */
19146 && !is_type_tag_for_partial (abbrev
->tag
, cu
->language
)
19147 && abbrev
->tag
!= DW_TAG_constant
19148 && abbrev
->tag
!= DW_TAG_enumerator
19149 && abbrev
->tag
!= DW_TAG_subprogram
19150 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19151 && abbrev
->tag
!= DW_TAG_lexical_block
19152 && abbrev
->tag
!= DW_TAG_variable
19153 && abbrev
->tag
!= DW_TAG_namespace
19154 && abbrev
->tag
!= DW_TAG_module
19155 && abbrev
->tag
!= DW_TAG_member
19156 && abbrev
->tag
!= DW_TAG_imported_unit
19157 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19159 /* Otherwise we skip to the next sibling, if any. */
19160 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19164 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19167 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19169 /* This two-pass algorithm for processing partial symbols has a
19170 high cost in cache pressure. Thus, handle some simple cases
19171 here which cover the majority of C partial symbols. DIEs
19172 which neither have specification tags in them, nor could have
19173 specification tags elsewhere pointing at them, can simply be
19174 processed and discarded.
19176 This segment is also optional; scan_partial_symbols and
19177 add_partial_symbol will handle these DIEs if we chain
19178 them in normally. When compilers which do not emit large
19179 quantities of duplicate debug information are more common,
19180 this code can probably be removed. */
19182 /* Any complete simple types at the top level (pretty much all
19183 of them, for a language without namespaces), can be processed
19185 if (parent_die
== NULL
19186 && pdi
.has_specification
== 0
19187 && pdi
.is_declaration
== 0
19188 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19189 || pdi
.tag
== DW_TAG_base_type
19190 || pdi
.tag
== DW_TAG_array_type
19191 || pdi
.tag
== DW_TAG_subrange_type
))
19193 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19194 add_partial_symbol (&pdi
, cu
);
19196 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19200 /* The exception for DW_TAG_typedef with has_children above is
19201 a workaround of GCC PR debug/47510. In the case of this complaint
19202 type_name_or_error will error on such types later.
19204 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19205 it could not find the child DIEs referenced later, this is checked
19206 above. In correct DWARF DW_TAG_typedef should have no children. */
19208 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19209 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19210 "- DIE at %s [in module %s]"),
19211 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19213 /* If we're at the second level, and we're an enumerator, and
19214 our parent has no specification (meaning possibly lives in a
19215 namespace elsewhere), then we can add the partial symbol now
19216 instead of queueing it. */
19217 if (pdi
.tag
== DW_TAG_enumerator
19218 && parent_die
!= NULL
19219 && parent_die
->die_parent
== NULL
19220 && parent_die
->tag
== DW_TAG_enumeration_type
19221 && parent_die
->has_specification
== 0)
19223 if (pdi
.raw_name
== NULL
)
19224 complaint (_("malformed enumerator DIE ignored"));
19225 else if (building_psymtab
)
19226 add_partial_symbol (&pdi
, cu
);
19228 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19232 struct partial_die_info
*part_die
19233 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19235 /* We'll save this DIE so link it in. */
19236 part_die
->die_parent
= parent_die
;
19237 part_die
->die_sibling
= NULL
;
19238 part_die
->die_child
= NULL
;
19240 if (last_die
&& last_die
== parent_die
)
19241 last_die
->die_child
= part_die
;
19243 last_die
->die_sibling
= part_die
;
19245 last_die
= part_die
;
19247 if (first_die
== NULL
)
19248 first_die
= part_die
;
19250 /* Maybe add the DIE to the hash table. Not all DIEs that we
19251 find interesting need to be in the hash table, because we
19252 also have the parent/sibling/child chains; only those that we
19253 might refer to by offset later during partial symbol reading.
19255 For now this means things that might have be the target of a
19256 DW_AT_specification, DW_AT_abstract_origin, or
19257 DW_AT_extension. DW_AT_extension will refer only to
19258 namespaces; DW_AT_abstract_origin refers to functions (and
19259 many things under the function DIE, but we do not recurse
19260 into function DIEs during partial symbol reading) and
19261 possibly variables as well; DW_AT_specification refers to
19262 declarations. Declarations ought to have the DW_AT_declaration
19263 flag. It happens that GCC forgets to put it in sometimes, but
19264 only for functions, not for types.
19266 Adding more things than necessary to the hash table is harmless
19267 except for the performance cost. Adding too few will result in
19268 wasted time in find_partial_die, when we reread the compilation
19269 unit with load_all_dies set. */
19272 || abbrev
->tag
== DW_TAG_constant
19273 || abbrev
->tag
== DW_TAG_subprogram
19274 || abbrev
->tag
== DW_TAG_variable
19275 || abbrev
->tag
== DW_TAG_namespace
19276 || part_die
->is_declaration
)
19280 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19281 to_underlying (part_die
->sect_off
),
19286 /* For some DIEs we want to follow their children (if any). For C
19287 we have no reason to follow the children of structures; for other
19288 languages we have to, so that we can get at method physnames
19289 to infer fully qualified class names, for DW_AT_specification,
19290 and for C++ template arguments. For C++, we also look one level
19291 inside functions to find template arguments (if the name of the
19292 function does not already contain the template arguments).
19294 For Ada and Fortran, we need to scan the children of subprograms
19295 and lexical blocks as well because these languages allow the
19296 definition of nested entities that could be interesting for the
19297 debugger, such as nested subprograms for instance. */
19298 if (last_die
->has_children
19300 || last_die
->tag
== DW_TAG_namespace
19301 || last_die
->tag
== DW_TAG_module
19302 || last_die
->tag
== DW_TAG_enumeration_type
19303 || (cu
->language
== language_cplus
19304 && last_die
->tag
== DW_TAG_subprogram
19305 && (last_die
->raw_name
== NULL
19306 || strchr (last_die
->raw_name
, '<') == NULL
))
19307 || (cu
->language
!= language_c
19308 && (last_die
->tag
== DW_TAG_class_type
19309 || last_die
->tag
== DW_TAG_interface_type
19310 || last_die
->tag
== DW_TAG_structure_type
19311 || last_die
->tag
== DW_TAG_union_type
))
19312 || ((cu
->language
== language_ada
19313 || cu
->language
== language_fortran
)
19314 && (last_die
->tag
== DW_TAG_subprogram
19315 || last_die
->tag
== DW_TAG_lexical_block
))))
19318 parent_die
= last_die
;
19322 /* Otherwise we skip to the next sibling, if any. */
19323 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19325 /* Back to the top, do it again. */
19329 partial_die_info::partial_die_info (sect_offset sect_off_
,
19330 const struct abbrev_info
*abbrev
)
19331 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19335 /* See class definition. */
19338 partial_die_info::name (dwarf2_cu
*cu
)
19340 if (!canonical_name
&& raw_name
!= nullptr)
19342 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19343 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19344 canonical_name
= 1;
19350 /* Read a minimal amount of information into the minimal die structure.
19351 INFO_PTR should point just after the initial uleb128 of a DIE. */
19354 partial_die_info::read (const struct die_reader_specs
*reader
,
19355 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19357 struct dwarf2_cu
*cu
= reader
->cu
;
19358 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19360 int has_low_pc_attr
= 0;
19361 int has_high_pc_attr
= 0;
19362 int high_pc_relative
= 0;
19364 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19367 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19368 /* String and address offsets that need to do the reprocessing have
19369 already been read at this point, so there is no need to wait until
19370 the loop terminates to do the reprocessing. */
19371 if (attr
.requires_reprocessing_p ())
19372 read_attribute_reprocess (reader
, &attr
, tag
);
19373 /* Store the data if it is of an attribute we want to keep in a
19374 partial symbol table. */
19380 case DW_TAG_compile_unit
:
19381 case DW_TAG_partial_unit
:
19382 case DW_TAG_type_unit
:
19383 /* Compilation units have a DW_AT_name that is a filename, not
19384 a source language identifier. */
19385 case DW_TAG_enumeration_type
:
19386 case DW_TAG_enumerator
:
19387 /* These tags always have simple identifiers already; no need
19388 to canonicalize them. */
19389 canonical_name
= 1;
19390 raw_name
= attr
.as_string ();
19393 canonical_name
= 0;
19394 raw_name
= attr
.as_string ();
19398 case DW_AT_linkage_name
:
19399 case DW_AT_MIPS_linkage_name
:
19400 /* Note that both forms of linkage name might appear. We
19401 assume they will be the same, and we only store the last
19403 linkage_name
= attr
.as_string ();
19406 has_low_pc_attr
= 1;
19407 lowpc
= attr
.as_address ();
19409 case DW_AT_high_pc
:
19410 has_high_pc_attr
= 1;
19411 highpc
= attr
.as_address ();
19412 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19413 high_pc_relative
= 1;
19415 case DW_AT_location
:
19416 /* Support the .debug_loc offsets. */
19417 if (attr
.form_is_block ())
19419 d
.locdesc
= attr
.as_block ();
19421 else if (attr
.form_is_section_offset ())
19423 dwarf2_complex_location_expr_complaint ();
19427 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19428 "partial symbol information");
19431 case DW_AT_external
:
19432 is_external
= attr
.as_boolean ();
19434 case DW_AT_declaration
:
19435 is_declaration
= attr
.as_boolean ();
19440 case DW_AT_abstract_origin
:
19441 case DW_AT_specification
:
19442 case DW_AT_extension
:
19443 has_specification
= 1;
19444 spec_offset
= attr
.get_ref_die_offset ();
19445 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19446 || cu
->per_cu
->is_dwz
);
19448 case DW_AT_sibling
:
19449 /* Ignore absolute siblings, they might point outside of
19450 the current compile unit. */
19451 if (attr
.form
== DW_FORM_ref_addr
)
19452 complaint (_("ignoring absolute DW_AT_sibling"));
19455 const gdb_byte
*buffer
= reader
->buffer
;
19456 sect_offset off
= attr
.get_ref_die_offset ();
19457 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19459 if (sibling_ptr
< info_ptr
)
19460 complaint (_("DW_AT_sibling points backwards"));
19461 else if (sibling_ptr
> reader
->buffer_end
)
19462 reader
->die_section
->overflow_complaint ();
19464 sibling
= sibling_ptr
;
19467 case DW_AT_byte_size
:
19470 case DW_AT_const_value
:
19471 has_const_value
= 1;
19473 case DW_AT_calling_convention
:
19474 /* DWARF doesn't provide a way to identify a program's source-level
19475 entry point. DW_AT_calling_convention attributes are only meant
19476 to describe functions' calling conventions.
19478 However, because it's a necessary piece of information in
19479 Fortran, and before DWARF 4 DW_CC_program was the only
19480 piece of debugging information whose definition refers to
19481 a 'main program' at all, several compilers marked Fortran
19482 main programs with DW_CC_program --- even when those
19483 functions use the standard calling conventions.
19485 Although DWARF now specifies a way to provide this
19486 information, we support this practice for backward
19488 if (attr
.constant_value (0) == DW_CC_program
19489 && cu
->language
== language_fortran
)
19490 main_subprogram
= 1;
19494 LONGEST value
= attr
.constant_value (-1);
19495 if (value
== DW_INL_inlined
19496 || value
== DW_INL_declared_inlined
)
19497 may_be_inlined
= 1;
19502 if (tag
== DW_TAG_imported_unit
)
19504 d
.sect_off
= attr
.get_ref_die_offset ();
19505 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19506 || cu
->per_cu
->is_dwz
);
19510 case DW_AT_main_subprogram
:
19511 main_subprogram
= attr
.as_boolean ();
19516 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19517 on DWARF version). */
19518 ULONGEST ranges_offset
= attr
.as_unsigned ();
19520 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19522 if (tag
!= DW_TAG_compile_unit
)
19523 ranges_offset
+= cu
->gnu_ranges_base
;
19525 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19536 /* For Ada, if both the name and the linkage name appear, we prefer
19537 the latter. This lets "catch exception" work better, regardless
19538 of the order in which the name and linkage name were emitted.
19539 Really, though, this is just a workaround for the fact that gdb
19540 doesn't store both the name and the linkage name. */
19541 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19542 raw_name
= linkage_name
;
19544 if (high_pc_relative
)
19547 if (has_low_pc_attr
&& has_high_pc_attr
)
19549 /* When using the GNU linker, .gnu.linkonce. sections are used to
19550 eliminate duplicate copies of functions and vtables and such.
19551 The linker will arbitrarily choose one and discard the others.
19552 The AT_*_pc values for such functions refer to local labels in
19553 these sections. If the section from that file was discarded, the
19554 labels are not in the output, so the relocs get a value of 0.
19555 If this is a discarded function, mark the pc bounds as invalid,
19556 so that GDB will ignore it. */
19557 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19559 struct objfile
*objfile
= per_objfile
->objfile
;
19560 struct gdbarch
*gdbarch
= objfile
->arch ();
19562 complaint (_("DW_AT_low_pc %s is zero "
19563 "for DIE at %s [in module %s]"),
19564 paddress (gdbarch
, lowpc
),
19565 sect_offset_str (sect_off
),
19566 objfile_name (objfile
));
19568 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19569 else if (lowpc
>= highpc
)
19571 struct objfile
*objfile
= per_objfile
->objfile
;
19572 struct gdbarch
*gdbarch
= objfile
->arch ();
19574 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19575 "for DIE at %s [in module %s]"),
19576 paddress (gdbarch
, lowpc
),
19577 paddress (gdbarch
, highpc
),
19578 sect_offset_str (sect_off
),
19579 objfile_name (objfile
));
19588 /* Find a cached partial DIE at OFFSET in CU. */
19590 struct partial_die_info
*
19591 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19593 struct partial_die_info
*lookup_die
= NULL
;
19594 struct partial_die_info
part_die (sect_off
);
19596 lookup_die
= ((struct partial_die_info
*)
19597 htab_find_with_hash (partial_dies
, &part_die
,
19598 to_underlying (sect_off
)));
19603 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19604 except in the case of .debug_types DIEs which do not reference
19605 outside their CU (they do however referencing other types via
19606 DW_FORM_ref_sig8). */
19608 static const struct cu_partial_die_info
19609 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19611 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19612 struct objfile
*objfile
= per_objfile
->objfile
;
19613 struct partial_die_info
*pd
= NULL
;
19615 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19616 && cu
->header
.offset_in_cu_p (sect_off
))
19618 pd
= cu
->find_partial_die (sect_off
);
19621 /* We missed recording what we needed.
19622 Load all dies and try again. */
19626 /* TUs don't reference other CUs/TUs (except via type signatures). */
19627 if (cu
->per_cu
->is_debug_types
)
19629 error (_("Dwarf Error: Type Unit at offset %s contains"
19630 " external reference to offset %s [in module %s].\n"),
19631 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19632 bfd_get_filename (objfile
->obfd
));
19634 dwarf2_per_cu_data
*per_cu
19635 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19638 cu
= per_objfile
->get_cu (per_cu
);
19639 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19640 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
19642 cu
= per_objfile
->get_cu (per_cu
);
19645 pd
= cu
->find_partial_die (sect_off
);
19648 /* If we didn't find it, and not all dies have been loaded,
19649 load them all and try again. */
19651 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
19653 cu
->per_cu
->load_all_dies
= 1;
19655 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19656 THIS_CU->cu may already be in use. So we can't just free it and
19657 replace its DIEs with the ones we read in. Instead, we leave those
19658 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19659 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19661 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
19663 pd
= cu
->find_partial_die (sect_off
);
19667 error (_("Dwarf Error: Cannot not find DIE at %s [from module %s]\n"),
19668 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19672 /* See if we can figure out if the class lives in a namespace. We do
19673 this by looking for a member function; its demangled name will
19674 contain namespace info, if there is any. */
19677 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19678 struct dwarf2_cu
*cu
)
19680 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19681 what template types look like, because the demangler
19682 frequently doesn't give the same name as the debug info. We
19683 could fix this by only using the demangled name to get the
19684 prefix (but see comment in read_structure_type). */
19686 struct partial_die_info
*real_pdi
;
19687 struct partial_die_info
*child_pdi
;
19689 /* If this DIE (this DIE's specification, if any) has a parent, then
19690 we should not do this. We'll prepend the parent's fully qualified
19691 name when we create the partial symbol. */
19693 real_pdi
= struct_pdi
;
19694 while (real_pdi
->has_specification
)
19696 auto res
= find_partial_die (real_pdi
->spec_offset
,
19697 real_pdi
->spec_is_dwz
, cu
);
19698 real_pdi
= res
.pdi
;
19702 if (real_pdi
->die_parent
!= NULL
)
19705 for (child_pdi
= struct_pdi
->die_child
;
19707 child_pdi
= child_pdi
->die_sibling
)
19709 if (child_pdi
->tag
== DW_TAG_subprogram
19710 && child_pdi
->linkage_name
!= NULL
)
19712 gdb::unique_xmalloc_ptr
<char> actual_class_name
19713 (cu
->language_defn
->class_name_from_physname
19714 (child_pdi
->linkage_name
));
19715 if (actual_class_name
!= NULL
)
19717 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19718 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
19719 struct_pdi
->canonical_name
= 1;
19726 /* Return true if a DIE with TAG may have the DW_AT_const_value
19730 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
19734 case DW_TAG_constant
:
19735 case DW_TAG_enumerator
:
19736 case DW_TAG_formal_parameter
:
19737 case DW_TAG_template_value_param
:
19738 case DW_TAG_variable
:
19746 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19748 /* Once we've fixed up a die, there's no point in doing so again.
19749 This also avoids a memory leak if we were to call
19750 guess_partial_die_structure_name multiple times. */
19754 /* If we found a reference attribute and the DIE has no name, try
19755 to find a name in the referred to DIE. */
19757 if (raw_name
== NULL
&& has_specification
)
19759 struct partial_die_info
*spec_die
;
19761 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19762 spec_die
= res
.pdi
;
19765 spec_die
->fixup (cu
);
19767 if (spec_die
->raw_name
)
19769 raw_name
= spec_die
->raw_name
;
19770 canonical_name
= spec_die
->canonical_name
;
19772 /* Copy DW_AT_external attribute if it is set. */
19773 if (spec_die
->is_external
)
19774 is_external
= spec_die
->is_external
;
19778 if (!has_const_value
&& has_specification
19779 && can_have_DW_AT_const_value_p (tag
))
19781 struct partial_die_info
*spec_die
;
19783 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19784 spec_die
= res
.pdi
;
19787 spec_die
->fixup (cu
);
19789 if (spec_die
->has_const_value
)
19791 /* Copy DW_AT_const_value attribute if it is set. */
19792 has_const_value
= spec_die
->has_const_value
;
19796 /* Set default names for some unnamed DIEs. */
19798 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
19800 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
19801 canonical_name
= 1;
19804 /* If there is no parent die to provide a namespace, and there are
19805 children, see if we can determine the namespace from their linkage
19807 if (cu
->language
== language_cplus
19808 && !cu
->per_objfile
->per_bfd
->types
.empty ()
19809 && die_parent
== NULL
19811 && (tag
== DW_TAG_class_type
19812 || tag
== DW_TAG_structure_type
19813 || tag
== DW_TAG_union_type
))
19814 guess_partial_die_structure_name (this, cu
);
19816 /* GCC might emit a nameless struct or union that has a linkage
19817 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19818 if (raw_name
== NULL
19819 && (tag
== DW_TAG_class_type
19820 || tag
== DW_TAG_interface_type
19821 || tag
== DW_TAG_structure_type
19822 || tag
== DW_TAG_union_type
)
19823 && linkage_name
!= NULL
)
19825 gdb::unique_xmalloc_ptr
<char> demangled
19826 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19827 if (demangled
!= nullptr)
19831 /* Strip any leading namespaces/classes, keep only the base name.
19832 DW_AT_name for named DIEs does not contain the prefixes. */
19833 base
= strrchr (demangled
.get (), ':');
19834 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19837 base
= demangled
.get ();
19839 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19840 raw_name
= objfile
->intern (base
);
19841 canonical_name
= 1;
19848 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
19849 contents from the given SECTION in the HEADER.
19851 HEADER_OFFSET is the offset of the header in the section. */
19853 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
19854 struct dwarf2_section_info
*section
,
19855 sect_offset header_offset
)
19857 unsigned int bytes_read
;
19858 bfd
*abfd
= section
->get_bfd_owner ();
19859 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
19861 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
19862 info_ptr
+= bytes_read
;
19864 header
->version
= read_2_bytes (abfd
, info_ptr
);
19867 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
19870 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
19873 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
19876 /* Return the DW_AT_loclists_base value for the CU. */
19878 lookup_loclist_base (struct dwarf2_cu
*cu
)
19880 /* For the .dwo unit, the loclist_base points to the first offset following
19881 the header. The header consists of the following entities-
19882 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
19884 2. version (2 bytes)
19885 3. address size (1 byte)
19886 4. segment selector size (1 byte)
19887 5. offset entry count (4 bytes)
19888 These sizes are derived as per the DWARFv5 standard. */
19889 if (cu
->dwo_unit
!= nullptr)
19891 if (cu
->header
.initial_length_size
== 4)
19892 return LOCLIST_HEADER_SIZE32
;
19893 return LOCLIST_HEADER_SIZE64
;
19895 return cu
->loclist_base
;
19898 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
19899 array of offsets in the .debug_loclists section. */
19902 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
19904 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19905 struct objfile
*objfile
= per_objfile
->objfile
;
19906 bfd
*abfd
= objfile
->obfd
;
19907 ULONGEST loclist_header_size
=
19908 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
19909 : LOCLIST_HEADER_SIZE64
);
19910 ULONGEST loclist_base
= lookup_loclist_base (cu
);
19912 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
19913 ULONGEST start_offset
=
19914 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
19916 /* Get loclists section. */
19917 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
19919 /* Read the loclists section content. */
19920 section
->read (objfile
);
19921 if (section
->buffer
== NULL
)
19922 error (_("DW_FORM_loclistx used without .debug_loclists "
19923 "section [in module %s]"), objfile_name (objfile
));
19925 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
19926 so if loclist_base is smaller than the header size, we have a problem. */
19927 if (loclist_base
< loclist_header_size
)
19928 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
19929 objfile_name (objfile
));
19931 /* Read the header of the loclists contribution. */
19932 struct loclists_rnglists_header header
;
19933 read_loclists_rnglists_header (&header
, section
,
19934 (sect_offset
) (loclist_base
- loclist_header_size
));
19936 /* Verify the loclist index is valid. */
19937 if (loclist_index
>= header
.offset_entry_count
)
19938 error (_("DW_FORM_loclistx pointing outside of "
19939 ".debug_loclists offset array [in module %s]"),
19940 objfile_name (objfile
));
19942 /* Validate that reading won't go beyond the end of the section. */
19943 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
19944 error (_("Reading DW_FORM_loclistx index beyond end of"
19945 ".debug_loclists section [in module %s]"),
19946 objfile_name (objfile
));
19948 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
19950 if (cu
->header
.offset_size
== 4)
19951 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
19953 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
19956 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
19957 array of offsets in the .debug_rnglists section. */
19960 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
19963 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
19964 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19965 bfd
*abfd
= objfile
->obfd
;
19966 ULONGEST rnglist_header_size
=
19967 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
19968 : RNGLIST_HEADER_SIZE64
);
19970 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
19971 .debug_rnglists.dwo section. The rnglists base given in the skeleton
19973 ULONGEST rnglist_base
=
19974 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
19976 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
19977 ULONGEST start_offset
=
19978 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
19980 /* Get rnglists section. */
19981 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
19983 /* Read the rnglists section content. */
19984 section
->read (objfile
);
19985 if (section
->buffer
== nullptr)
19986 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
19988 objfile_name (objfile
));
19990 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
19991 so if rnglist_base is smaller than the header size, we have a problem. */
19992 if (rnglist_base
< rnglist_header_size
)
19993 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
19994 objfile_name (objfile
));
19996 /* Read the header of the rnglists contribution. */
19997 struct loclists_rnglists_header header
;
19998 read_loclists_rnglists_header (&header
, section
,
19999 (sect_offset
) (rnglist_base
- rnglist_header_size
));
20001 /* Verify the rnglist index is valid. */
20002 if (rnglist_index
>= header
.offset_entry_count
)
20003 error (_("DW_FORM_rnglistx index pointing outside of "
20004 ".debug_rnglists offset array [in module %s]"),
20005 objfile_name (objfile
));
20007 /* Validate that reading won't go beyond the end of the section. */
20008 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
20009 error (_("Reading DW_FORM_rnglistx index beyond end of"
20010 ".debug_rnglists section [in module %s]"),
20011 objfile_name (objfile
));
20013 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20015 if (cu
->header
.offset_size
== 4)
20016 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
20018 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
20021 /* Process the attributes that had to be skipped in the first round. These
20022 attributes are the ones that need str_offsets_base or addr_base attributes.
20023 They could not have been processed in the first round, because at the time
20024 the values of str_offsets_base or addr_base may not have been known. */
20026 read_attribute_reprocess (const struct die_reader_specs
*reader
,
20027 struct attribute
*attr
, dwarf_tag tag
)
20029 struct dwarf2_cu
*cu
= reader
->cu
;
20030 switch (attr
->form
)
20032 case DW_FORM_addrx
:
20033 case DW_FORM_GNU_addr_index
:
20034 attr
->set_address (read_addr_index (cu
,
20035 attr
->as_unsigned_reprocess ()));
20037 case DW_FORM_loclistx
:
20039 sect_offset loclists_sect_off
20040 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
20042 attr
->set_unsigned (to_underlying (loclists_sect_off
));
20045 case DW_FORM_rnglistx
:
20047 sect_offset rnglists_sect_off
20048 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
20050 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
20054 case DW_FORM_strx1
:
20055 case DW_FORM_strx2
:
20056 case DW_FORM_strx3
:
20057 case DW_FORM_strx4
:
20058 case DW_FORM_GNU_str_index
:
20060 unsigned int str_index
= attr
->as_unsigned_reprocess ();
20061 gdb_assert (!attr
->canonical_string_p ());
20062 if (reader
->dwo_file
!= NULL
)
20063 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
20066 attr
->set_string_noncanonical (read_stub_str_index (cu
,
20071 gdb_assert_not_reached (_("Unexpected DWARF form."));
20075 /* Read an attribute value described by an attribute form. */
20077 static const gdb_byte
*
20078 read_attribute_value (const struct die_reader_specs
*reader
,
20079 struct attribute
*attr
, unsigned form
,
20080 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
20082 struct dwarf2_cu
*cu
= reader
->cu
;
20083 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20084 struct objfile
*objfile
= per_objfile
->objfile
;
20085 bfd
*abfd
= reader
->abfd
;
20086 struct comp_unit_head
*cu_header
= &cu
->header
;
20087 unsigned int bytes_read
;
20088 struct dwarf_block
*blk
;
20090 attr
->form
= (enum dwarf_form
) form
;
20093 case DW_FORM_ref_addr
:
20094 if (cu_header
->version
== 2)
20095 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
20098 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20100 info_ptr
+= bytes_read
;
20102 case DW_FORM_GNU_ref_alt
:
20103 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20105 info_ptr
+= bytes_read
;
20109 struct gdbarch
*gdbarch
= objfile
->arch ();
20110 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
20111 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
20112 attr
->set_address (addr
);
20113 info_ptr
+= bytes_read
;
20116 case DW_FORM_block2
:
20117 blk
= dwarf_alloc_block (cu
);
20118 blk
->size
= read_2_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_block4
:
20125 blk
= dwarf_alloc_block (cu
);
20126 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20128 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20129 info_ptr
+= blk
->size
;
20130 attr
->set_block (blk
);
20132 case DW_FORM_data2
:
20133 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20136 case DW_FORM_data4
:
20137 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20140 case DW_FORM_data8
:
20141 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20144 case DW_FORM_data16
:
20145 blk
= dwarf_alloc_block (cu
);
20147 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20149 attr
->set_block (blk
);
20151 case DW_FORM_sec_offset
:
20152 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20154 info_ptr
+= bytes_read
;
20156 case DW_FORM_loclistx
:
20158 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20160 info_ptr
+= bytes_read
;
20163 case DW_FORM_string
:
20164 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20166 info_ptr
+= bytes_read
;
20169 if (!cu
->per_cu
->is_dwz
)
20171 attr
->set_string_noncanonical
20172 (read_indirect_string (per_objfile
,
20173 abfd
, info_ptr
, cu_header
,
20175 info_ptr
+= bytes_read
;
20179 case DW_FORM_line_strp
:
20180 if (!cu
->per_cu
->is_dwz
)
20182 attr
->set_string_noncanonical
20183 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20185 info_ptr
+= bytes_read
;
20189 case DW_FORM_GNU_strp_alt
:
20191 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20192 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20195 attr
->set_string_noncanonical
20196 (dwz
->read_string (objfile
, str_offset
));
20197 info_ptr
+= bytes_read
;
20200 case DW_FORM_exprloc
:
20201 case DW_FORM_block
:
20202 blk
= dwarf_alloc_block (cu
);
20203 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20204 info_ptr
+= bytes_read
;
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_block1
:
20210 blk
= dwarf_alloc_block (cu
);
20211 blk
->size
= read_1_byte (abfd
, info_ptr
);
20213 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20214 info_ptr
+= blk
->size
;
20215 attr
->set_block (blk
);
20217 case DW_FORM_data1
:
20219 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20222 case DW_FORM_flag_present
:
20223 attr
->set_unsigned (1);
20225 case DW_FORM_sdata
:
20226 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20227 info_ptr
+= bytes_read
;
20229 case DW_FORM_rnglistx
:
20231 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20233 info_ptr
+= bytes_read
;
20236 case DW_FORM_udata
:
20237 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20238 info_ptr
+= bytes_read
;
20241 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20242 + read_1_byte (abfd
, info_ptr
)));
20246 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20247 + read_2_bytes (abfd
, info_ptr
)));
20251 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20252 + read_4_bytes (abfd
, info_ptr
)));
20256 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20257 + read_8_bytes (abfd
, info_ptr
)));
20260 case DW_FORM_ref_sig8
:
20261 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20264 case DW_FORM_ref_udata
:
20265 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20266 + read_unsigned_leb128 (abfd
, info_ptr
,
20268 info_ptr
+= bytes_read
;
20270 case DW_FORM_indirect
:
20271 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20272 info_ptr
+= bytes_read
;
20273 if (form
== DW_FORM_implicit_const
)
20275 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20276 info_ptr
+= bytes_read
;
20278 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20281 case DW_FORM_implicit_const
:
20282 attr
->set_signed (implicit_const
);
20284 case DW_FORM_addrx
:
20285 case DW_FORM_GNU_addr_index
:
20286 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20288 info_ptr
+= bytes_read
;
20291 case DW_FORM_strx1
:
20292 case DW_FORM_strx2
:
20293 case DW_FORM_strx3
:
20294 case DW_FORM_strx4
:
20295 case DW_FORM_GNU_str_index
:
20297 ULONGEST str_index
;
20298 if (form
== DW_FORM_strx1
)
20300 str_index
= read_1_byte (abfd
, info_ptr
);
20303 else if (form
== DW_FORM_strx2
)
20305 str_index
= read_2_bytes (abfd
, info_ptr
);
20308 else if (form
== DW_FORM_strx3
)
20310 str_index
= read_3_bytes (abfd
, info_ptr
);
20313 else if (form
== DW_FORM_strx4
)
20315 str_index
= read_4_bytes (abfd
, info_ptr
);
20320 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20321 info_ptr
+= bytes_read
;
20323 attr
->set_unsigned_reprocess (str_index
);
20327 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20328 dwarf_form_name (form
),
20329 bfd_get_filename (abfd
));
20333 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20334 attr
->form
= DW_FORM_GNU_ref_alt
;
20336 /* We have seen instances where the compiler tried to emit a byte
20337 size attribute of -1 which ended up being encoded as an unsigned
20338 0xffffffff. Although 0xffffffff is technically a valid size value,
20339 an object of this size seems pretty unlikely so we can relatively
20340 safely treat these cases as if the size attribute was invalid and
20341 treat them as zero by default. */
20342 if (attr
->name
== DW_AT_byte_size
20343 && form
== DW_FORM_data4
20344 && attr
->as_unsigned () >= 0xffffffff)
20347 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20348 hex_string (attr
->as_unsigned ()));
20349 attr
->set_unsigned (0);
20355 /* Read an attribute described by an abbreviated attribute. */
20357 static const gdb_byte
*
20358 read_attribute (const struct die_reader_specs
*reader
,
20359 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20360 const gdb_byte
*info_ptr
)
20362 attr
->name
= abbrev
->name
;
20363 attr
->string_is_canonical
= 0;
20364 attr
->requires_reprocessing
= 0;
20365 return read_attribute_value (reader
, attr
, abbrev
->form
,
20366 abbrev
->implicit_const
, info_ptr
);
20369 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20371 static const char *
20372 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20373 LONGEST str_offset
)
20375 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20376 str_offset
, "DW_FORM_strp");
20379 /* Return pointer to string at .debug_str offset as read from BUF.
20380 BUF is assumed to be in a compilation unit described by CU_HEADER.
20381 Return *BYTES_READ_PTR count of bytes read from BUF. */
20383 static const char *
20384 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20385 const gdb_byte
*buf
,
20386 const struct comp_unit_head
*cu_header
,
20387 unsigned int *bytes_read_ptr
)
20389 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20391 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20397 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20398 const struct comp_unit_head
*cu_header
,
20399 unsigned int *bytes_read_ptr
)
20401 bfd
*abfd
= objfile
->obfd
;
20402 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20404 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20407 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20408 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20409 ADDR_SIZE is the size of addresses from the CU header. */
20412 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20413 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20415 struct objfile
*objfile
= per_objfile
->objfile
;
20416 bfd
*abfd
= objfile
->obfd
;
20417 const gdb_byte
*info_ptr
;
20418 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20420 per_objfile
->per_bfd
->addr
.read (objfile
);
20421 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20422 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20423 objfile_name (objfile
));
20424 if (addr_base_or_zero
+ addr_index
* addr_size
20425 >= per_objfile
->per_bfd
->addr
.size
)
20426 error (_("DW_FORM_addr_index pointing outside of "
20427 ".debug_addr section [in module %s]"),
20428 objfile_name (objfile
));
20429 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20430 + addr_index
* addr_size
);
20431 if (addr_size
== 4)
20432 return bfd_get_32 (abfd
, info_ptr
);
20434 return bfd_get_64 (abfd
, info_ptr
);
20437 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20440 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20442 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20443 cu
->addr_base
, cu
->header
.addr_size
);
20446 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20449 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20450 unsigned int *bytes_read
)
20452 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20453 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20455 return read_addr_index (cu
, addr_index
);
20461 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20462 dwarf2_per_objfile
*per_objfile
,
20463 unsigned int addr_index
)
20465 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20466 gdb::optional
<ULONGEST
> addr_base
;
20469 /* We need addr_base and addr_size.
20470 If we don't have PER_CU->cu, we have to get it.
20471 Nasty, but the alternative is storing the needed info in PER_CU,
20472 which at this point doesn't seem justified: it's not clear how frequently
20473 it would get used and it would increase the size of every PER_CU.
20474 Entry points like dwarf2_per_cu_addr_size do a similar thing
20475 so we're not in uncharted territory here.
20476 Alas we need to be a bit more complicated as addr_base is contained
20479 We don't need to read the entire CU(/TU).
20480 We just need the header and top level die.
20482 IWBN to use the aging mechanism to let us lazily later discard the CU.
20483 For now we skip this optimization. */
20487 addr_base
= cu
->addr_base
;
20488 addr_size
= cu
->header
.addr_size
;
20492 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20493 addr_base
= reader
.cu
->addr_base
;
20494 addr_size
= reader
.cu
->header
.addr_size
;
20497 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20500 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20501 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20504 static const char *
20505 read_str_index (struct dwarf2_cu
*cu
,
20506 struct dwarf2_section_info
*str_section
,
20507 struct dwarf2_section_info
*str_offsets_section
,
20508 ULONGEST str_offsets_base
, ULONGEST str_index
)
20510 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20511 struct objfile
*objfile
= per_objfile
->objfile
;
20512 const char *objf_name
= objfile_name (objfile
);
20513 bfd
*abfd
= objfile
->obfd
;
20514 const gdb_byte
*info_ptr
;
20515 ULONGEST str_offset
;
20516 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20518 str_section
->read (objfile
);
20519 str_offsets_section
->read (objfile
);
20520 if (str_section
->buffer
== NULL
)
20521 error (_("%s used without %s section"
20522 " in CU at offset %s [in module %s]"),
20523 form_name
, str_section
->get_name (),
20524 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20525 if (str_offsets_section
->buffer
== NULL
)
20526 error (_("%s used without %s section"
20527 " in CU at offset %s [in module %s]"),
20528 form_name
, str_section
->get_name (),
20529 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20530 info_ptr
= (str_offsets_section
->buffer
20532 + str_index
* cu
->header
.offset_size
);
20533 if (cu
->header
.offset_size
== 4)
20534 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20536 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20537 if (str_offset
>= str_section
->size
)
20538 error (_("Offset from %s pointing outside of"
20539 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20540 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20541 return (const char *) (str_section
->buffer
+ str_offset
);
20544 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20546 static const char *
20547 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20549 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20550 ? reader
->cu
->header
.addr_size
: 0;
20551 return read_str_index (reader
->cu
,
20552 &reader
->dwo_file
->sections
.str
,
20553 &reader
->dwo_file
->sections
.str_offsets
,
20554 str_offsets_base
, str_index
);
20557 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20559 static const char *
20560 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20562 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20563 const char *objf_name
= objfile_name (objfile
);
20564 static const char form_name
[] = "DW_FORM_GNU_str_index";
20565 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20567 if (!cu
->str_offsets_base
.has_value ())
20568 error (_("%s used in Fission stub without %s"
20569 " in CU at offset 0x%lx [in module %s]"),
20570 form_name
, str_offsets_attr_name
,
20571 (long) cu
->header
.offset_size
, objf_name
);
20573 return read_str_index (cu
,
20574 &cu
->per_objfile
->per_bfd
->str
,
20575 &cu
->per_objfile
->per_bfd
->str_offsets
,
20576 *cu
->str_offsets_base
, str_index
);
20579 /* Return the length of an LEB128 number in BUF. */
20582 leb128_size (const gdb_byte
*buf
)
20584 const gdb_byte
*begin
= buf
;
20590 if ((byte
& 128) == 0)
20591 return buf
- begin
;
20596 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20605 cu
->language
= language_c
;
20608 case DW_LANG_C_plus_plus
:
20609 case DW_LANG_C_plus_plus_11
:
20610 case DW_LANG_C_plus_plus_14
:
20611 cu
->language
= language_cplus
;
20614 cu
->language
= language_d
;
20616 case DW_LANG_Fortran77
:
20617 case DW_LANG_Fortran90
:
20618 case DW_LANG_Fortran95
:
20619 case DW_LANG_Fortran03
:
20620 case DW_LANG_Fortran08
:
20621 cu
->language
= language_fortran
;
20624 cu
->language
= language_go
;
20626 case DW_LANG_Mips_Assembler
:
20627 cu
->language
= language_asm
;
20629 case DW_LANG_Ada83
:
20630 case DW_LANG_Ada95
:
20631 cu
->language
= language_ada
;
20633 case DW_LANG_Modula2
:
20634 cu
->language
= language_m2
;
20636 case DW_LANG_Pascal83
:
20637 cu
->language
= language_pascal
;
20640 cu
->language
= language_objc
;
20643 case DW_LANG_Rust_old
:
20644 cu
->language
= language_rust
;
20646 case DW_LANG_Cobol74
:
20647 case DW_LANG_Cobol85
:
20649 cu
->language
= language_minimal
;
20652 cu
->language_defn
= language_def (cu
->language
);
20655 /* Return the named attribute or NULL if not there. */
20657 static struct attribute
*
20658 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20663 struct attribute
*spec
= NULL
;
20665 for (i
= 0; i
< die
->num_attrs
; ++i
)
20667 if (die
->attrs
[i
].name
== name
)
20668 return &die
->attrs
[i
];
20669 if (die
->attrs
[i
].name
== DW_AT_specification
20670 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20671 spec
= &die
->attrs
[i
];
20677 die
= follow_die_ref (die
, spec
, &cu
);
20683 /* Return the string associated with a string-typed attribute, or NULL if it
20684 is either not found or is of an incorrect type. */
20686 static const char *
20687 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20689 struct attribute
*attr
;
20690 const char *str
= NULL
;
20692 attr
= dwarf2_attr (die
, name
, cu
);
20696 str
= attr
->as_string ();
20697 if (str
== nullptr)
20698 complaint (_("string type expected for attribute %s for "
20699 "DIE at %s in module %s"),
20700 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20701 objfile_name (cu
->per_objfile
->objfile
));
20707 /* Return the dwo name or NULL if not present. If present, it is in either
20708 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20709 static const char *
20710 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20712 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20713 if (dwo_name
== nullptr)
20714 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20718 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20719 and holds a non-zero value. This function should only be used for
20720 DW_FORM_flag or DW_FORM_flag_present attributes. */
20723 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20725 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20727 return attr
!= nullptr && attr
->as_boolean ();
20731 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20733 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20734 which value is non-zero. However, we have to be careful with
20735 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20736 (via dwarf2_flag_true_p) follows this attribute. So we may
20737 end up accidently finding a declaration attribute that belongs
20738 to a different DIE referenced by the specification attribute,
20739 even though the given DIE does not have a declaration attribute. */
20740 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20741 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20744 /* Return the die giving the specification for DIE, if there is
20745 one. *SPEC_CU is the CU containing DIE on input, and the CU
20746 containing the return value on output. If there is no
20747 specification, but there is an abstract origin, that is
20750 static struct die_info
*
20751 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20753 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20756 if (spec_attr
== NULL
)
20757 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20759 if (spec_attr
== NULL
)
20762 return follow_die_ref (die
, spec_attr
, spec_cu
);
20765 /* Stub for free_line_header to match void * callback types. */
20768 free_line_header_voidp (void *arg
)
20770 struct line_header
*lh
= (struct line_header
*) arg
;
20775 /* A convenience function to find the proper .debug_line section for a CU. */
20777 static struct dwarf2_section_info
*
20778 get_debug_line_section (struct dwarf2_cu
*cu
)
20780 struct dwarf2_section_info
*section
;
20781 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20783 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20785 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20786 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20787 else if (cu
->per_cu
->is_dwz
)
20789 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20791 section
= &dwz
->line
;
20794 section
= &per_objfile
->per_bfd
->line
;
20799 /* Read the statement program header starting at OFFSET in
20800 .debug_line, or .debug_line.dwo. Return a pointer
20801 to a struct line_header, allocated using xmalloc.
20802 Returns NULL if there is a problem reading the header, e.g., if it
20803 has a version we don't understand.
20805 NOTE: the strings in the include directory and file name tables of
20806 the returned object point into the dwarf line section buffer,
20807 and must not be freed. */
20809 static line_header_up
20810 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20812 struct dwarf2_section_info
*section
;
20813 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20815 section
= get_debug_line_section (cu
);
20816 section
->read (per_objfile
->objfile
);
20817 if (section
->buffer
== NULL
)
20819 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20820 complaint (_("missing .debug_line.dwo section"));
20822 complaint (_("missing .debug_line section"));
20826 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
20827 per_objfile
, section
, &cu
->header
);
20830 /* Subroutine of dwarf_decode_lines to simplify it.
20831 Return the file name of the psymtab for the given file_entry.
20832 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20833 If space for the result is malloc'd, *NAME_HOLDER will be set.
20834 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20836 static const char *
20837 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20838 const dwarf2_psymtab
*pst
,
20839 const char *comp_dir
,
20840 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20842 const char *include_name
= fe
.name
;
20843 const char *include_name_to_compare
= include_name
;
20844 const char *pst_filename
;
20847 const char *dir_name
= fe
.include_dir (lh
);
20849 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20850 if (!IS_ABSOLUTE_PATH (include_name
)
20851 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20853 /* Avoid creating a duplicate psymtab for PST.
20854 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20855 Before we do the comparison, however, we need to account
20856 for DIR_NAME and COMP_DIR.
20857 First prepend dir_name (if non-NULL). If we still don't
20858 have an absolute path prepend comp_dir (if non-NULL).
20859 However, the directory we record in the include-file's
20860 psymtab does not contain COMP_DIR (to match the
20861 corresponding symtab(s)).
20866 bash$ gcc -g ./hello.c
20867 include_name = "hello.c"
20869 DW_AT_comp_dir = comp_dir = "/tmp"
20870 DW_AT_name = "./hello.c"
20874 if (dir_name
!= NULL
)
20876 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20877 include_name
, (char *) NULL
));
20878 include_name
= name_holder
->get ();
20879 include_name_to_compare
= include_name
;
20881 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20883 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20884 include_name
, (char *) NULL
));
20885 include_name_to_compare
= hold_compare
.get ();
20889 pst_filename
= pst
->filename
;
20890 gdb::unique_xmalloc_ptr
<char> copied_name
;
20891 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20893 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20894 pst_filename
, (char *) NULL
));
20895 pst_filename
= copied_name
.get ();
20898 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20902 return include_name
;
20905 /* State machine to track the state of the line number program. */
20907 class lnp_state_machine
20910 /* Initialize a machine state for the start of a line number
20912 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20913 bool record_lines_p
);
20915 file_entry
*current_file ()
20917 /* lh->file_names is 0-based, but the file name numbers in the
20918 statement program are 1-based. */
20919 return m_line_header
->file_name_at (m_file
);
20922 /* Record the line in the state machine. END_SEQUENCE is true if
20923 we're processing the end of a sequence. */
20924 void record_line (bool end_sequence
);
20926 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
20927 nop-out rest of the lines in this sequence. */
20928 void check_line_address (struct dwarf2_cu
*cu
,
20929 const gdb_byte
*line_ptr
,
20930 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20932 void handle_set_discriminator (unsigned int discriminator
)
20934 m_discriminator
= discriminator
;
20935 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20938 /* Handle DW_LNE_set_address. */
20939 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20942 address
+= baseaddr
;
20943 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20946 /* Handle DW_LNS_advance_pc. */
20947 void handle_advance_pc (CORE_ADDR adjust
);
20949 /* Handle a special opcode. */
20950 void handle_special_opcode (unsigned char op_code
);
20952 /* Handle DW_LNS_advance_line. */
20953 void handle_advance_line (int line_delta
)
20955 advance_line (line_delta
);
20958 /* Handle DW_LNS_set_file. */
20959 void handle_set_file (file_name_index file
);
20961 /* Handle DW_LNS_negate_stmt. */
20962 void handle_negate_stmt ()
20964 m_is_stmt
= !m_is_stmt
;
20967 /* Handle DW_LNS_const_add_pc. */
20968 void handle_const_add_pc ();
20970 /* Handle DW_LNS_fixed_advance_pc. */
20971 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20973 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20977 /* Handle DW_LNS_copy. */
20978 void handle_copy ()
20980 record_line (false);
20981 m_discriminator
= 0;
20984 /* Handle DW_LNE_end_sequence. */
20985 void handle_end_sequence ()
20987 m_currently_recording_lines
= true;
20991 /* Advance the line by LINE_DELTA. */
20992 void advance_line (int line_delta
)
20994 m_line
+= line_delta
;
20996 if (line_delta
!= 0)
20997 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21000 struct dwarf2_cu
*m_cu
;
21002 gdbarch
*m_gdbarch
;
21004 /* True if we're recording lines.
21005 Otherwise we're building partial symtabs and are just interested in
21006 finding include files mentioned by the line number program. */
21007 bool m_record_lines_p
;
21009 /* The line number header. */
21010 line_header
*m_line_header
;
21012 /* These are part of the standard DWARF line number state machine,
21013 and initialized according to the DWARF spec. */
21015 unsigned char m_op_index
= 0;
21016 /* The line table index of the current file. */
21017 file_name_index m_file
= 1;
21018 unsigned int m_line
= 1;
21020 /* These are initialized in the constructor. */
21022 CORE_ADDR m_address
;
21024 unsigned int m_discriminator
;
21026 /* Additional bits of state we need to track. */
21028 /* The last file that we called dwarf2_start_subfile for.
21029 This is only used for TLLs. */
21030 unsigned int m_last_file
= 0;
21031 /* The last file a line number was recorded for. */
21032 struct subfile
*m_last_subfile
= NULL
;
21034 /* The address of the last line entry. */
21035 CORE_ADDR m_last_address
;
21037 /* Set to true when a previous line at the same address (using
21038 m_last_address) had m_is_stmt true. This is reset to false when a
21039 line entry at a new address (m_address different to m_last_address) is
21041 bool m_stmt_at_address
= false;
21043 /* When true, record the lines we decode. */
21044 bool m_currently_recording_lines
= false;
21046 /* The last line number that was recorded, used to coalesce
21047 consecutive entries for the same line. This can happen, for
21048 example, when discriminators are present. PR 17276. */
21049 unsigned int m_last_line
= 0;
21050 bool m_line_has_non_zero_discriminator
= false;
21054 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21056 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21057 / m_line_header
->maximum_ops_per_instruction
)
21058 * m_line_header
->minimum_instruction_length
);
21059 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21060 m_op_index
= ((m_op_index
+ adjust
)
21061 % m_line_header
->maximum_ops_per_instruction
);
21065 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21067 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21068 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
21069 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
21070 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
21071 / m_line_header
->maximum_ops_per_instruction
)
21072 * m_line_header
->minimum_instruction_length
);
21073 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21074 m_op_index
= ((m_op_index
+ adj_opcode_d
)
21075 % m_line_header
->maximum_ops_per_instruction
);
21077 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
21078 advance_line (line_delta
);
21079 record_line (false);
21080 m_discriminator
= 0;
21084 lnp_state_machine::handle_set_file (file_name_index file
)
21088 const file_entry
*fe
= current_file ();
21090 dwarf2_debug_line_missing_file_complaint ();
21091 else if (m_record_lines_p
)
21093 const char *dir
= fe
->include_dir (m_line_header
);
21095 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21096 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21097 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21102 lnp_state_machine::handle_const_add_pc ()
21105 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21108 = (((m_op_index
+ adjust
)
21109 / m_line_header
->maximum_ops_per_instruction
)
21110 * m_line_header
->minimum_instruction_length
);
21112 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21113 m_op_index
= ((m_op_index
+ adjust
)
21114 % m_line_header
->maximum_ops_per_instruction
);
21117 /* Return non-zero if we should add LINE to the line number table.
21118 LINE is the line to add, LAST_LINE is the last line that was added,
21119 LAST_SUBFILE is the subfile for LAST_LINE.
21120 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21121 had a non-zero discriminator.
21123 We have to be careful in the presence of discriminators.
21124 E.g., for this line:
21126 for (i = 0; i < 100000; i++);
21128 clang can emit four line number entries for that one line,
21129 each with a different discriminator.
21130 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21132 However, we want gdb to coalesce all four entries into one.
21133 Otherwise the user could stepi into the middle of the line and
21134 gdb would get confused about whether the pc really was in the
21135 middle of the line.
21137 Things are further complicated by the fact that two consecutive
21138 line number entries for the same line is a heuristic used by gcc
21139 to denote the end of the prologue. So we can't just discard duplicate
21140 entries, we have to be selective about it. The heuristic we use is
21141 that we only collapse consecutive entries for the same line if at least
21142 one of those entries has a non-zero discriminator. PR 17276.
21144 Note: Addresses in the line number state machine can never go backwards
21145 within one sequence, thus this coalescing is ok. */
21148 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21149 unsigned int line
, unsigned int last_line
,
21150 int line_has_non_zero_discriminator
,
21151 struct subfile
*last_subfile
)
21153 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21155 if (line
!= last_line
)
21157 /* Same line for the same file that we've seen already.
21158 As a last check, for pr 17276, only record the line if the line
21159 has never had a non-zero discriminator. */
21160 if (!line_has_non_zero_discriminator
)
21165 /* Use the CU's builder to record line number LINE beginning at
21166 address ADDRESS in the line table of subfile SUBFILE. */
21169 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21170 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
21171 struct dwarf2_cu
*cu
)
21173 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21175 if (dwarf_line_debug
)
21177 fprintf_unfiltered (gdb_stdlog
,
21178 "Recording line %u, file %s, address %s\n",
21179 line
, lbasename (subfile
->name
),
21180 paddress (gdbarch
, address
));
21184 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21187 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21188 Mark the end of a set of line number records.
21189 The arguments are the same as for dwarf_record_line_1.
21190 If SUBFILE is NULL the request is ignored. */
21193 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21194 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21196 if (subfile
== NULL
)
21199 if (dwarf_line_debug
)
21201 fprintf_unfiltered (gdb_stdlog
,
21202 "Finishing current line, file %s, address %s\n",
21203 lbasename (subfile
->name
),
21204 paddress (gdbarch
, address
));
21207 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21211 lnp_state_machine::record_line (bool end_sequence
)
21213 if (dwarf_line_debug
)
21215 fprintf_unfiltered (gdb_stdlog
,
21216 "Processing actual line %u: file %u,"
21217 " address %s, is_stmt %u, discrim %u%s\n",
21219 paddress (m_gdbarch
, m_address
),
21220 m_is_stmt
, m_discriminator
,
21221 (end_sequence
? "\t(end sequence)" : ""));
21224 file_entry
*fe
= current_file ();
21227 dwarf2_debug_line_missing_file_complaint ();
21228 /* For now we ignore lines not starting on an instruction boundary.
21229 But not when processing end_sequence for compatibility with the
21230 previous version of the code. */
21231 else if (m_op_index
== 0 || end_sequence
)
21233 fe
->included_p
= 1;
21234 if (m_record_lines_p
)
21236 /* When we switch files we insert an end maker in the first file,
21237 switch to the second file and add a new line entry. The
21238 problem is that the end marker inserted in the first file will
21239 discard any previous line entries at the same address. If the
21240 line entries in the first file are marked as is-stmt, while
21241 the new line in the second file is non-stmt, then this means
21242 the end marker will discard is-stmt lines so we can have a
21243 non-stmt line. This means that there are less addresses at
21244 which the user can insert a breakpoint.
21246 To improve this we track the last address in m_last_address,
21247 and whether we have seen an is-stmt at this address. Then
21248 when switching files, if we have seen a stmt at the current
21249 address, and we are switching to create a non-stmt line, then
21250 discard the new line. */
21252 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21253 bool ignore_this_line
21254 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21255 && !m_is_stmt
&& m_stmt_at_address
)
21256 || (!end_sequence
&& m_line
== 0));
21258 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21260 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21261 m_currently_recording_lines
? m_cu
: nullptr);
21264 if (!end_sequence
&& !ignore_this_line
)
21266 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21268 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21269 m_line_has_non_zero_discriminator
,
21272 buildsym_compunit
*builder
= m_cu
->get_builder ();
21273 dwarf_record_line_1 (m_gdbarch
,
21274 builder
->get_current_subfile (),
21275 m_line
, m_address
, is_stmt
,
21276 m_currently_recording_lines
? m_cu
: nullptr);
21278 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21279 m_last_line
= m_line
;
21284 /* Track whether we have seen any m_is_stmt true at m_address in case we
21285 have multiple line table entries all at m_address. */
21286 if (m_last_address
!= m_address
)
21288 m_stmt_at_address
= false;
21289 m_last_address
= m_address
;
21291 m_stmt_at_address
|= m_is_stmt
;
21294 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21295 line_header
*lh
, bool record_lines_p
)
21299 m_record_lines_p
= record_lines_p
;
21300 m_line_header
= lh
;
21302 m_currently_recording_lines
= true;
21304 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21305 was a line entry for it so that the backend has a chance to adjust it
21306 and also record it in case it needs it. This is currently used by MIPS
21307 code, cf. `mips_adjust_dwarf2_line'. */
21308 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21309 m_is_stmt
= lh
->default_is_stmt
;
21310 m_discriminator
= 0;
21312 m_last_address
= m_address
;
21313 m_stmt_at_address
= false;
21317 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21318 const gdb_byte
*line_ptr
,
21319 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21321 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21322 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21323 located at 0x0. In this case, additionally check that if
21324 ADDRESS < UNRELOCATED_LOWPC. */
21326 if ((address
== 0 && address
< unrelocated_lowpc
)
21327 || address
== (CORE_ADDR
) -1)
21329 /* This line table is for a function which has been
21330 GCd by the linker. Ignore it. PR gdb/12528 */
21332 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21333 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21335 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21336 line_offset
, objfile_name (objfile
));
21337 m_currently_recording_lines
= false;
21338 /* Note: m_currently_recording_lines is left as false until we see
21339 DW_LNE_end_sequence. */
21343 /* Subroutine of dwarf_decode_lines to simplify it.
21344 Process the line number information in LH.
21345 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21346 program in order to set included_p for every referenced header. */
21349 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21350 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21352 const gdb_byte
*line_ptr
, *extended_end
;
21353 const gdb_byte
*line_end
;
21354 unsigned int bytes_read
, extended_len
;
21355 unsigned char op_code
, extended_op
;
21356 CORE_ADDR baseaddr
;
21357 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21358 bfd
*abfd
= objfile
->obfd
;
21359 struct gdbarch
*gdbarch
= objfile
->arch ();
21360 /* True if we're recording line info (as opposed to building partial
21361 symtabs and just interested in finding include files mentioned by
21362 the line number program). */
21363 bool record_lines_p
= !decode_for_pst_p
;
21365 baseaddr
= objfile
->text_section_offset ();
21367 line_ptr
= lh
->statement_program_start
;
21368 line_end
= lh
->statement_program_end
;
21370 /* Read the statement sequences until there's nothing left. */
21371 while (line_ptr
< line_end
)
21373 /* The DWARF line number program state machine. Reset the state
21374 machine at the start of each sequence. */
21375 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21376 bool end_sequence
= false;
21378 if (record_lines_p
)
21380 /* Start a subfile for the current file of the state
21382 const file_entry
*fe
= state_machine
.current_file ();
21385 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21388 /* Decode the table. */
21389 while (line_ptr
< line_end
&& !end_sequence
)
21391 op_code
= read_1_byte (abfd
, line_ptr
);
21394 if (op_code
>= lh
->opcode_base
)
21396 /* Special opcode. */
21397 state_machine
.handle_special_opcode (op_code
);
21399 else switch (op_code
)
21401 case DW_LNS_extended_op
:
21402 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21404 line_ptr
+= bytes_read
;
21405 extended_end
= line_ptr
+ extended_len
;
21406 extended_op
= read_1_byte (abfd
, line_ptr
);
21408 if (DW_LNE_lo_user
<= extended_op
21409 && extended_op
<= DW_LNE_hi_user
)
21411 /* Vendor extension, ignore. */
21412 line_ptr
= extended_end
;
21415 switch (extended_op
)
21417 case DW_LNE_end_sequence
:
21418 state_machine
.handle_end_sequence ();
21419 end_sequence
= true;
21421 case DW_LNE_set_address
:
21424 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21425 line_ptr
+= bytes_read
;
21427 state_machine
.check_line_address (cu
, line_ptr
,
21428 lowpc
- baseaddr
, address
);
21429 state_machine
.handle_set_address (baseaddr
, address
);
21432 case DW_LNE_define_file
:
21434 const char *cur_file
;
21435 unsigned int mod_time
, length
;
21438 cur_file
= read_direct_string (abfd
, line_ptr
,
21440 line_ptr
+= bytes_read
;
21441 dindex
= (dir_index
)
21442 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21443 line_ptr
+= bytes_read
;
21445 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21446 line_ptr
+= bytes_read
;
21448 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21449 line_ptr
+= bytes_read
;
21450 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21453 case DW_LNE_set_discriminator
:
21455 /* The discriminator is not interesting to the
21456 debugger; just ignore it. We still need to
21457 check its value though:
21458 if there are consecutive entries for the same
21459 (non-prologue) line we want to coalesce them.
21462 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21463 line_ptr
+= bytes_read
;
21465 state_machine
.handle_set_discriminator (discr
);
21469 complaint (_("mangled .debug_line section"));
21472 /* Make sure that we parsed the extended op correctly. If e.g.
21473 we expected a different address size than the producer used,
21474 we may have read the wrong number of bytes. */
21475 if (line_ptr
!= extended_end
)
21477 complaint (_("mangled .debug_line section"));
21482 state_machine
.handle_copy ();
21484 case DW_LNS_advance_pc
:
21487 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21488 line_ptr
+= bytes_read
;
21490 state_machine
.handle_advance_pc (adjust
);
21493 case DW_LNS_advance_line
:
21496 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21497 line_ptr
+= bytes_read
;
21499 state_machine
.handle_advance_line (line_delta
);
21502 case DW_LNS_set_file
:
21504 file_name_index file
21505 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21507 line_ptr
+= bytes_read
;
21509 state_machine
.handle_set_file (file
);
21512 case DW_LNS_set_column
:
21513 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21514 line_ptr
+= bytes_read
;
21516 case DW_LNS_negate_stmt
:
21517 state_machine
.handle_negate_stmt ();
21519 case DW_LNS_set_basic_block
:
21521 /* Add to the address register of the state machine the
21522 address increment value corresponding to special opcode
21523 255. I.e., this value is scaled by the minimum
21524 instruction length since special opcode 255 would have
21525 scaled the increment. */
21526 case DW_LNS_const_add_pc
:
21527 state_machine
.handle_const_add_pc ();
21529 case DW_LNS_fixed_advance_pc
:
21531 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21534 state_machine
.handle_fixed_advance_pc (addr_adj
);
21539 /* Unknown standard opcode, ignore it. */
21542 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21544 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21545 line_ptr
+= bytes_read
;
21552 dwarf2_debug_line_missing_end_sequence_complaint ();
21554 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21555 in which case we still finish recording the last line). */
21556 state_machine
.record_line (true);
21560 /* Decode the Line Number Program (LNP) for the given line_header
21561 structure and CU. The actual information extracted and the type
21562 of structures created from the LNP depends on the value of PST.
21564 1. If PST is NULL, then this procedure uses the data from the program
21565 to create all necessary symbol tables, and their linetables.
21567 2. If PST is not NULL, this procedure reads the program to determine
21568 the list of files included by the unit represented by PST, and
21569 builds all the associated partial symbol tables.
21571 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21572 It is used for relative paths in the line table.
21573 NOTE: When processing partial symtabs (pst != NULL),
21574 comp_dir == pst->dirname.
21576 NOTE: It is important that psymtabs have the same file name (via strcmp)
21577 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21578 symtab we don't use it in the name of the psymtabs we create.
21579 E.g. expand_line_sal requires this when finding psymtabs to expand.
21580 A good testcase for this is mb-inline.exp.
21582 LOWPC is the lowest address in CU (or 0 if not known).
21584 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21585 for its PC<->lines mapping information. Otherwise only the filename
21586 table is read in. */
21589 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21590 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21591 CORE_ADDR lowpc
, int decode_mapping
)
21593 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21594 const int decode_for_pst_p
= (pst
!= NULL
);
21596 if (decode_mapping
)
21597 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21599 if (decode_for_pst_p
)
21601 /* Now that we're done scanning the Line Header Program, we can
21602 create the psymtab of each included file. */
21603 for (auto &file_entry
: lh
->file_names ())
21604 if (file_entry
.included_p
== 1)
21606 gdb::unique_xmalloc_ptr
<char> name_holder
;
21607 const char *include_name
=
21608 psymtab_include_file_name (lh
, file_entry
, pst
,
21609 comp_dir
, &name_holder
);
21610 if (include_name
!= NULL
)
21611 dwarf2_create_include_psymtab
21612 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
21613 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
21619 /* Make sure a symtab is created for every file, even files
21620 which contain only variables (i.e. no code with associated
21622 buildsym_compunit
*builder
= cu
->get_builder ();
21623 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21625 for (auto &fe
: lh
->file_names ())
21627 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21628 if (builder
->get_current_subfile ()->symtab
== NULL
)
21630 builder
->get_current_subfile ()->symtab
21631 = allocate_symtab (cust
,
21632 builder
->get_current_subfile ()->name
);
21634 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21639 /* Start a subfile for DWARF. FILENAME is the name of the file and
21640 DIRNAME the name of the source directory which contains FILENAME
21641 or NULL if not known.
21642 This routine tries to keep line numbers from identical absolute and
21643 relative file names in a common subfile.
21645 Using the `list' example from the GDB testsuite, which resides in
21646 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21647 of /srcdir/list0.c yields the following debugging information for list0.c:
21649 DW_AT_name: /srcdir/list0.c
21650 DW_AT_comp_dir: /compdir
21651 files.files[0].name: list0.h
21652 files.files[0].dir: /srcdir
21653 files.files[1].name: list0.c
21654 files.files[1].dir: /srcdir
21656 The line number information for list0.c has to end up in a single
21657 subfile, so that `break /srcdir/list0.c:1' works as expected.
21658 start_subfile will ensure that this happens provided that we pass the
21659 concatenation of files.files[1].dir and files.files[1].name as the
21663 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21664 const char *dirname
)
21666 gdb::unique_xmalloc_ptr
<char> copy
;
21668 /* In order not to lose the line information directory,
21669 we concatenate it to the filename when it makes sense.
21670 Note that the Dwarf3 standard says (speaking of filenames in line
21671 information): ``The directory index is ignored for file names
21672 that represent full path names''. Thus ignoring dirname in the
21673 `else' branch below isn't an issue. */
21675 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21677 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21678 filename
= copy
.get ();
21681 cu
->get_builder ()->start_subfile (filename
);
21684 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21685 buildsym_compunit constructor. */
21687 struct compunit_symtab
*
21688 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21691 gdb_assert (m_builder
== nullptr);
21693 m_builder
.reset (new struct buildsym_compunit
21694 (this->per_objfile
->objfile
,
21695 name
, comp_dir
, language
, low_pc
));
21697 list_in_scope
= get_builder ()->get_file_symbols ();
21699 get_builder ()->record_debugformat ("DWARF 2");
21700 get_builder ()->record_producer (producer
);
21702 processing_has_namespace_info
= false;
21704 return get_builder ()->get_compunit_symtab ();
21708 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21709 struct dwarf2_cu
*cu
)
21711 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21712 struct comp_unit_head
*cu_header
= &cu
->header
;
21714 /* NOTE drow/2003-01-30: There used to be a comment and some special
21715 code here to turn a symbol with DW_AT_external and a
21716 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21717 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21718 with some versions of binutils) where shared libraries could have
21719 relocations against symbols in their debug information - the
21720 minimal symbol would have the right address, but the debug info
21721 would not. It's no longer necessary, because we will explicitly
21722 apply relocations when we read in the debug information now. */
21724 /* A DW_AT_location attribute with no contents indicates that a
21725 variable has been optimized away. */
21726 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
21728 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21732 /* Handle one degenerate form of location expression specially, to
21733 preserve GDB's previous behavior when section offsets are
21734 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21735 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21737 if (attr
->form_is_block ())
21739 struct dwarf_block
*block
= attr
->as_block ();
21741 if ((block
->data
[0] == DW_OP_addr
21742 && block
->size
== 1 + cu_header
->addr_size
)
21743 || ((block
->data
[0] == DW_OP_GNU_addr_index
21744 || block
->data
[0] == DW_OP_addrx
)
21746 == 1 + leb128_size (&block
->data
[1]))))
21748 unsigned int dummy
;
21750 if (block
->data
[0] == DW_OP_addr
)
21751 SET_SYMBOL_VALUE_ADDRESS
21752 (sym
, cu
->header
.read_address (objfile
->obfd
,
21756 SET_SYMBOL_VALUE_ADDRESS
21757 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
21759 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21760 fixup_symbol_section (sym
, objfile
);
21761 SET_SYMBOL_VALUE_ADDRESS
21763 SYMBOL_VALUE_ADDRESS (sym
)
21764 + objfile
->section_offsets
[sym
->section_index ()]);
21769 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21770 expression evaluator, and use LOC_COMPUTED only when necessary
21771 (i.e. when the value of a register or memory location is
21772 referenced, or a thread-local block, etc.). Then again, it might
21773 not be worthwhile. I'm assuming that it isn't unless performance
21774 or memory numbers show me otherwise. */
21776 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21778 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21779 cu
->has_loclist
= true;
21782 /* Given a pointer to a DWARF information entry, figure out if we need
21783 to make a symbol table entry for it, and if so, create a new entry
21784 and return a pointer to it.
21785 If TYPE is NULL, determine symbol type from the die, otherwise
21786 used the passed type.
21787 If SPACE is not NULL, use it to hold the new symbol. If it is
21788 NULL, allocate a new symbol on the objfile's obstack. */
21790 static struct symbol
*
21791 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21792 struct symbol
*space
)
21794 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21795 struct objfile
*objfile
= per_objfile
->objfile
;
21796 struct gdbarch
*gdbarch
= objfile
->arch ();
21797 struct symbol
*sym
= NULL
;
21799 struct attribute
*attr
= NULL
;
21800 struct attribute
*attr2
= NULL
;
21801 CORE_ADDR baseaddr
;
21802 struct pending
**list_to_add
= NULL
;
21804 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21806 baseaddr
= objfile
->text_section_offset ();
21808 name
= dwarf2_name (die
, cu
);
21811 int suppress_add
= 0;
21816 sym
= new (&objfile
->objfile_obstack
) symbol
;
21817 OBJSTAT (objfile
, n_syms
++);
21819 /* Cache this symbol's name and the name's demangled form (if any). */
21820 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21821 /* Fortran does not have mangling standard and the mangling does differ
21822 between gfortran, iFort etc. */
21823 const char *physname
21824 = (cu
->language
== language_fortran
21825 ? dwarf2_full_name (name
, die
, cu
)
21826 : dwarf2_physname (name
, die
, cu
));
21827 const char *linkagename
= dw2_linkage_name (die
, cu
);
21829 if (linkagename
== nullptr || cu
->language
== language_ada
)
21830 sym
->set_linkage_name (physname
);
21833 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
21834 sym
->set_linkage_name (linkagename
);
21837 /* Default assumptions.
21838 Use the passed type or decode it from the die. */
21839 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21840 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21842 SYMBOL_TYPE (sym
) = type
;
21844 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21845 attr
= dwarf2_attr (die
,
21846 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21848 if (attr
!= nullptr)
21849 SYMBOL_LINE (sym
) = attr
->constant_value (0);
21851 attr
= dwarf2_attr (die
,
21852 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21854 if (attr
!= nullptr && attr
->is_nonnegative ())
21856 file_name_index file_index
21857 = (file_name_index
) attr
->as_nonnegative ();
21858 struct file_entry
*fe
;
21860 if (cu
->line_header
!= NULL
)
21861 fe
= cu
->line_header
->file_name_at (file_index
);
21866 complaint (_("file index out of range"));
21868 symbol_set_symtab (sym
, fe
->symtab
);
21874 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21875 if (attr
!= nullptr)
21879 addr
= attr
->as_address ();
21880 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21881 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21882 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21885 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21886 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21887 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21888 add_symbol_to_list (sym
, cu
->list_in_scope
);
21890 case DW_TAG_subprogram
:
21891 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21893 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21894 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21895 if ((attr2
!= nullptr && attr2
->as_boolean ())
21896 || cu
->language
== language_ada
21897 || cu
->language
== language_fortran
)
21899 /* Subprograms marked external are stored as a global symbol.
21900 Ada and Fortran subprograms, whether marked external or
21901 not, are always stored as a global symbol, because we want
21902 to be able to access them globally. For instance, we want
21903 to be able to break on a nested subprogram without having
21904 to specify the context. */
21905 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21909 list_to_add
= cu
->list_in_scope
;
21912 case DW_TAG_inlined_subroutine
:
21913 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21915 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21916 SYMBOL_INLINED (sym
) = 1;
21917 list_to_add
= cu
->list_in_scope
;
21919 case DW_TAG_template_value_param
:
21921 /* Fall through. */
21922 case DW_TAG_constant
:
21923 case DW_TAG_variable
:
21924 case DW_TAG_member
:
21925 /* Compilation with minimal debug info may result in
21926 variables with missing type entries. Change the
21927 misleading `void' type to something sensible. */
21928 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
21929 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21931 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21932 /* In the case of DW_TAG_member, we should only be called for
21933 static const members. */
21934 if (die
->tag
== DW_TAG_member
)
21936 /* dwarf2_add_field uses die_is_declaration,
21937 so we do the same. */
21938 gdb_assert (die_is_declaration (die
, cu
));
21941 if (attr
!= nullptr)
21943 dwarf2_const_value (attr
, sym
, cu
);
21944 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21947 if (attr2
!= nullptr && attr2
->as_boolean ())
21948 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21950 list_to_add
= cu
->list_in_scope
;
21954 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21955 if (attr
!= nullptr)
21957 var_decode_location (attr
, sym
, cu
);
21958 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21960 /* Fortran explicitly imports any global symbols to the local
21961 scope by DW_TAG_common_block. */
21962 if (cu
->language
== language_fortran
&& die
->parent
21963 && die
->parent
->tag
== DW_TAG_common_block
)
21966 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21967 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21968 && !per_objfile
->per_bfd
->has_section_at_zero
)
21970 /* When a static variable is eliminated by the linker,
21971 the corresponding debug information is not stripped
21972 out, but the variable address is set to null;
21973 do not add such variables into symbol table. */
21975 else if (attr2
!= nullptr && attr2
->as_boolean ())
21977 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21978 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21979 && per_objfile
->per_bfd
->can_copy
)
21981 /* A global static variable might be subject to
21982 copy relocation. We first check for a local
21983 minsym, though, because maybe the symbol was
21984 marked hidden, in which case this would not
21986 bound_minimal_symbol found
21987 = (lookup_minimal_symbol_linkage
21988 (sym
->linkage_name (), objfile
));
21989 if (found
.minsym
!= nullptr)
21990 sym
->maybe_copied
= 1;
21993 /* A variable with DW_AT_external is never static,
21994 but it may be block-scoped. */
21996 = ((cu
->list_in_scope
21997 == cu
->get_builder ()->get_file_symbols ())
21998 ? cu
->get_builder ()->get_global_symbols ()
21999 : cu
->list_in_scope
);
22002 list_to_add
= cu
->list_in_scope
;
22006 /* We do not know the address of this symbol.
22007 If it is an external symbol and we have type information
22008 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22009 The address of the variable will then be determined from
22010 the minimal symbol table whenever the variable is
22012 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22014 /* Fortran explicitly imports any global symbols to the local
22015 scope by DW_TAG_common_block. */
22016 if (cu
->language
== language_fortran
&& die
->parent
22017 && die
->parent
->tag
== DW_TAG_common_block
)
22019 /* SYMBOL_CLASS doesn't matter here because
22020 read_common_block is going to reset it. */
22022 list_to_add
= cu
->list_in_scope
;
22024 else if (attr2
!= nullptr && attr2
->as_boolean ()
22025 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22027 /* A variable with DW_AT_external is never static, but it
22028 may be block-scoped. */
22030 = ((cu
->list_in_scope
22031 == cu
->get_builder ()->get_file_symbols ())
22032 ? cu
->get_builder ()->get_global_symbols ()
22033 : cu
->list_in_scope
);
22035 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22037 else if (!die_is_declaration (die
, cu
))
22039 /* Use the default LOC_OPTIMIZED_OUT class. */
22040 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22042 list_to_add
= cu
->list_in_scope
;
22046 case DW_TAG_formal_parameter
:
22048 /* If we are inside a function, mark this as an argument. If
22049 not, we might be looking at an argument to an inlined function
22050 when we do not have enough information to show inlined frames;
22051 pretend it's a local variable in that case so that the user can
22053 struct context_stack
*curr
22054 = cu
->get_builder ()->get_current_context_stack ();
22055 if (curr
!= nullptr && curr
->name
!= nullptr)
22056 SYMBOL_IS_ARGUMENT (sym
) = 1;
22057 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22058 if (attr
!= nullptr)
22060 var_decode_location (attr
, sym
, cu
);
22062 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22063 if (attr
!= nullptr)
22065 dwarf2_const_value (attr
, sym
, cu
);
22068 list_to_add
= cu
->list_in_scope
;
22071 case DW_TAG_unspecified_parameters
:
22072 /* From varargs functions; gdb doesn't seem to have any
22073 interest in this information, so just ignore it for now.
22076 case DW_TAG_template_type_param
:
22078 /* Fall through. */
22079 case DW_TAG_class_type
:
22080 case DW_TAG_interface_type
:
22081 case DW_TAG_structure_type
:
22082 case DW_TAG_union_type
:
22083 case DW_TAG_set_type
:
22084 case DW_TAG_enumeration_type
:
22085 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22086 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22089 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22090 really ever be static objects: otherwise, if you try
22091 to, say, break of a class's method and you're in a file
22092 which doesn't mention that class, it won't work unless
22093 the check for all static symbols in lookup_symbol_aux
22094 saves you. See the OtherFileClass tests in
22095 gdb.c++/namespace.exp. */
22099 buildsym_compunit
*builder
= cu
->get_builder ();
22101 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22102 && cu
->language
== language_cplus
22103 ? builder
->get_global_symbols ()
22104 : cu
->list_in_scope
);
22106 /* The semantics of C++ state that "struct foo {
22107 ... }" also defines a typedef for "foo". */
22108 if (cu
->language
== language_cplus
22109 || cu
->language
== language_ada
22110 || cu
->language
== language_d
22111 || cu
->language
== language_rust
)
22113 /* The symbol's name is already allocated along
22114 with this objfile, so we don't need to
22115 duplicate it for the type. */
22116 if (SYMBOL_TYPE (sym
)->name () == 0)
22117 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
22122 case DW_TAG_typedef
:
22123 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22124 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22125 list_to_add
= cu
->list_in_scope
;
22127 case DW_TAG_array_type
:
22128 case DW_TAG_base_type
:
22129 case DW_TAG_subrange_type
:
22130 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22131 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22132 list_to_add
= cu
->list_in_scope
;
22134 case DW_TAG_enumerator
:
22135 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22136 if (attr
!= nullptr)
22138 dwarf2_const_value (attr
, sym
, cu
);
22141 /* NOTE: carlton/2003-11-10: See comment above in the
22142 DW_TAG_class_type, etc. block. */
22145 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22146 && cu
->language
== language_cplus
22147 ? cu
->get_builder ()->get_global_symbols ()
22148 : cu
->list_in_scope
);
22151 case DW_TAG_imported_declaration
:
22152 case DW_TAG_namespace
:
22153 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22154 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22156 case DW_TAG_module
:
22157 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22158 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22159 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22161 case DW_TAG_common_block
:
22162 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22163 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22164 add_symbol_to_list (sym
, cu
->list_in_scope
);
22167 /* Not a tag we recognize. Hopefully we aren't processing
22168 trash data, but since we must specifically ignore things
22169 we don't recognize, there is nothing else we should do at
22171 complaint (_("unsupported tag: '%s'"),
22172 dwarf_tag_name (die
->tag
));
22178 sym
->hash_next
= objfile
->template_symbols
;
22179 objfile
->template_symbols
= sym
;
22180 list_to_add
= NULL
;
22183 if (list_to_add
!= NULL
)
22184 add_symbol_to_list (sym
, list_to_add
);
22186 /* For the benefit of old versions of GCC, check for anonymous
22187 namespaces based on the demangled name. */
22188 if (!cu
->processing_has_namespace_info
22189 && cu
->language
== language_cplus
)
22190 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22195 /* Given an attr with a DW_FORM_dataN value in host byte order,
22196 zero-extend it as appropriate for the symbol's type. The DWARF
22197 standard (v4) is not entirely clear about the meaning of using
22198 DW_FORM_dataN for a constant with a signed type, where the type is
22199 wider than the data. The conclusion of a discussion on the DWARF
22200 list was that this is unspecified. We choose to always zero-extend
22201 because that is the interpretation long in use by GCC. */
22204 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22205 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22207 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22208 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22209 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22210 LONGEST l
= attr
->constant_value (0);
22212 if (bits
< sizeof (*value
) * 8)
22214 l
&= ((LONGEST
) 1 << bits
) - 1;
22217 else if (bits
== sizeof (*value
) * 8)
22221 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22222 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22229 /* Read a constant value from an attribute. Either set *VALUE, or if
22230 the value does not fit in *VALUE, set *BYTES - either already
22231 allocated on the objfile obstack, or newly allocated on OBSTACK,
22232 or, set *BATON, if we translated the constant to a location
22236 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22237 const char *name
, struct obstack
*obstack
,
22238 struct dwarf2_cu
*cu
,
22239 LONGEST
*value
, const gdb_byte
**bytes
,
22240 struct dwarf2_locexpr_baton
**baton
)
22242 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22243 struct objfile
*objfile
= per_objfile
->objfile
;
22244 struct comp_unit_head
*cu_header
= &cu
->header
;
22245 struct dwarf_block
*blk
;
22246 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22247 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22253 switch (attr
->form
)
22256 case DW_FORM_addrx
:
22257 case DW_FORM_GNU_addr_index
:
22261 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22262 dwarf2_const_value_length_mismatch_complaint (name
,
22263 cu_header
->addr_size
,
22264 TYPE_LENGTH (type
));
22265 /* Symbols of this form are reasonably rare, so we just
22266 piggyback on the existing location code rather than writing
22267 a new implementation of symbol_computed_ops. */
22268 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22269 (*baton
)->per_objfile
= per_objfile
;
22270 (*baton
)->per_cu
= cu
->per_cu
;
22271 gdb_assert ((*baton
)->per_cu
);
22273 (*baton
)->size
= 2 + cu_header
->addr_size
;
22274 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22275 (*baton
)->data
= data
;
22277 data
[0] = DW_OP_addr
;
22278 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22279 byte_order
, attr
->as_address ());
22280 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22283 case DW_FORM_string
:
22286 case DW_FORM_GNU_str_index
:
22287 case DW_FORM_GNU_strp_alt
:
22288 /* The string is already allocated on the objfile obstack, point
22290 *bytes
= (const gdb_byte
*) attr
->as_string ();
22292 case DW_FORM_block1
:
22293 case DW_FORM_block2
:
22294 case DW_FORM_block4
:
22295 case DW_FORM_block
:
22296 case DW_FORM_exprloc
:
22297 case DW_FORM_data16
:
22298 blk
= attr
->as_block ();
22299 if (TYPE_LENGTH (type
) != blk
->size
)
22300 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22301 TYPE_LENGTH (type
));
22302 *bytes
= blk
->data
;
22305 /* The DW_AT_const_value attributes are supposed to carry the
22306 symbol's value "represented as it would be on the target
22307 architecture." By the time we get here, it's already been
22308 converted to host endianness, so we just need to sign- or
22309 zero-extend it as appropriate. */
22310 case DW_FORM_data1
:
22311 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22313 case DW_FORM_data2
:
22314 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22316 case DW_FORM_data4
:
22317 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22319 case DW_FORM_data8
:
22320 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22323 case DW_FORM_sdata
:
22324 case DW_FORM_implicit_const
:
22325 *value
= attr
->as_signed ();
22328 case DW_FORM_udata
:
22329 *value
= attr
->as_unsigned ();
22333 complaint (_("unsupported const value attribute form: '%s'"),
22334 dwarf_form_name (attr
->form
));
22341 /* Copy constant value from an attribute to a symbol. */
22344 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22345 struct dwarf2_cu
*cu
)
22347 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22349 const gdb_byte
*bytes
;
22350 struct dwarf2_locexpr_baton
*baton
;
22352 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22353 sym
->print_name (),
22354 &objfile
->objfile_obstack
, cu
,
22355 &value
, &bytes
, &baton
);
22359 SYMBOL_LOCATION_BATON (sym
) = baton
;
22360 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22362 else if (bytes
!= NULL
)
22364 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22365 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22369 SYMBOL_VALUE (sym
) = value
;
22370 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22374 /* Return the type of the die in question using its DW_AT_type attribute. */
22376 static struct type
*
22377 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22379 struct attribute
*type_attr
;
22381 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22384 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22385 /* A missing DW_AT_type represents a void type. */
22386 return objfile_type (objfile
)->builtin_void
;
22389 return lookup_die_type (die
, type_attr
, cu
);
22392 /* True iff CU's producer generates GNAT Ada auxiliary information
22393 that allows to find parallel types through that information instead
22394 of having to do expensive parallel lookups by type name. */
22397 need_gnat_info (struct dwarf2_cu
*cu
)
22399 /* Assume that the Ada compiler was GNAT, which always produces
22400 the auxiliary information. */
22401 return (cu
->language
== language_ada
);
22404 /* Return the auxiliary type of the die in question using its
22405 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22406 attribute is not present. */
22408 static struct type
*
22409 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22411 struct attribute
*type_attr
;
22413 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22417 return lookup_die_type (die
, type_attr
, cu
);
22420 /* If DIE has a descriptive_type attribute, then set the TYPE's
22421 descriptive type accordingly. */
22424 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22425 struct dwarf2_cu
*cu
)
22427 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22429 if (descriptive_type
)
22431 ALLOCATE_GNAT_AUX_TYPE (type
);
22432 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22436 /* Return the containing type of the die in question using its
22437 DW_AT_containing_type attribute. */
22439 static struct type
*
22440 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22442 struct attribute
*type_attr
;
22443 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22445 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22447 error (_("Dwarf Error: Problem turning containing type into gdb type "
22448 "[in module %s]"), objfile_name (objfile
));
22450 return lookup_die_type (die
, type_attr
, cu
);
22453 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22455 static struct type
*
22456 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22458 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22459 struct objfile
*objfile
= per_objfile
->objfile
;
22462 std::string message
22463 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22464 objfile_name (objfile
),
22465 sect_offset_str (cu
->header
.sect_off
),
22466 sect_offset_str (die
->sect_off
));
22467 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22469 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22472 /* Look up the type of DIE in CU using its type attribute ATTR.
22473 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22474 DW_AT_containing_type.
22475 If there is no type substitute an error marker. */
22477 static struct type
*
22478 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22479 struct dwarf2_cu
*cu
)
22481 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22482 struct objfile
*objfile
= per_objfile
->objfile
;
22483 struct type
*this_type
;
22485 gdb_assert (attr
->name
== DW_AT_type
22486 || attr
->name
== DW_AT_GNAT_descriptive_type
22487 || attr
->name
== DW_AT_containing_type
);
22489 /* First see if we have it cached. */
22491 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22493 struct dwarf2_per_cu_data
*per_cu
;
22494 sect_offset sect_off
= attr
->get_ref_die_offset ();
22496 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22497 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22499 else if (attr
->form_is_ref ())
22501 sect_offset sect_off
= attr
->get_ref_die_offset ();
22503 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22505 else if (attr
->form
== DW_FORM_ref_sig8
)
22507 ULONGEST signature
= attr
->as_signature ();
22509 return get_signatured_type (die
, signature
, cu
);
22513 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22514 " at %s [in module %s]"),
22515 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22516 objfile_name (objfile
));
22517 return build_error_marker_type (cu
, die
);
22520 /* If not cached we need to read it in. */
22522 if (this_type
== NULL
)
22524 struct die_info
*type_die
= NULL
;
22525 struct dwarf2_cu
*type_cu
= cu
;
22527 if (attr
->form_is_ref ())
22528 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22529 if (type_die
== NULL
)
22530 return build_error_marker_type (cu
, die
);
22531 /* If we find the type now, it's probably because the type came
22532 from an inter-CU reference and the type's CU got expanded before
22534 this_type
= read_type_die (type_die
, type_cu
);
22537 /* If we still don't have a type use an error marker. */
22539 if (this_type
== NULL
)
22540 return build_error_marker_type (cu
, die
);
22545 /* Return the type in DIE, CU.
22546 Returns NULL for invalid types.
22548 This first does a lookup in die_type_hash,
22549 and only reads the die in if necessary.
22551 NOTE: This can be called when reading in partial or full symbols. */
22553 static struct type
*
22554 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22556 struct type
*this_type
;
22558 this_type
= get_die_type (die
, cu
);
22562 return read_type_die_1 (die
, cu
);
22565 /* Read the type in DIE, CU.
22566 Returns NULL for invalid types. */
22568 static struct type
*
22569 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22571 struct type
*this_type
= NULL
;
22575 case DW_TAG_class_type
:
22576 case DW_TAG_interface_type
:
22577 case DW_TAG_structure_type
:
22578 case DW_TAG_union_type
:
22579 this_type
= read_structure_type (die
, cu
);
22581 case DW_TAG_enumeration_type
:
22582 this_type
= read_enumeration_type (die
, cu
);
22584 case DW_TAG_subprogram
:
22585 case DW_TAG_subroutine_type
:
22586 case DW_TAG_inlined_subroutine
:
22587 this_type
= read_subroutine_type (die
, cu
);
22589 case DW_TAG_array_type
:
22590 this_type
= read_array_type (die
, cu
);
22592 case DW_TAG_set_type
:
22593 this_type
= read_set_type (die
, cu
);
22595 case DW_TAG_pointer_type
:
22596 this_type
= read_tag_pointer_type (die
, cu
);
22598 case DW_TAG_ptr_to_member_type
:
22599 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22601 case DW_TAG_reference_type
:
22602 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22604 case DW_TAG_rvalue_reference_type
:
22605 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22607 case DW_TAG_const_type
:
22608 this_type
= read_tag_const_type (die
, cu
);
22610 case DW_TAG_volatile_type
:
22611 this_type
= read_tag_volatile_type (die
, cu
);
22613 case DW_TAG_restrict_type
:
22614 this_type
= read_tag_restrict_type (die
, cu
);
22616 case DW_TAG_string_type
:
22617 this_type
= read_tag_string_type (die
, cu
);
22619 case DW_TAG_typedef
:
22620 this_type
= read_typedef (die
, cu
);
22622 case DW_TAG_subrange_type
:
22623 this_type
= read_subrange_type (die
, cu
);
22625 case DW_TAG_base_type
:
22626 this_type
= read_base_type (die
, cu
);
22628 case DW_TAG_unspecified_type
:
22629 this_type
= read_unspecified_type (die
, cu
);
22631 case DW_TAG_namespace
:
22632 this_type
= read_namespace_type (die
, cu
);
22634 case DW_TAG_module
:
22635 this_type
= read_module_type (die
, cu
);
22637 case DW_TAG_atomic_type
:
22638 this_type
= read_tag_atomic_type (die
, cu
);
22641 complaint (_("unexpected tag in read_type_die: '%s'"),
22642 dwarf_tag_name (die
->tag
));
22649 /* See if we can figure out if the class lives in a namespace. We do
22650 this by looking for a member function; its demangled name will
22651 contain namespace info, if there is any.
22652 Return the computed name or NULL.
22653 Space for the result is allocated on the objfile's obstack.
22654 This is the full-die version of guess_partial_die_structure_name.
22655 In this case we know DIE has no useful parent. */
22657 static const char *
22658 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22660 struct die_info
*spec_die
;
22661 struct dwarf2_cu
*spec_cu
;
22662 struct die_info
*child
;
22663 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22666 spec_die
= die_specification (die
, &spec_cu
);
22667 if (spec_die
!= NULL
)
22673 for (child
= die
->child
;
22675 child
= child
->sibling
)
22677 if (child
->tag
== DW_TAG_subprogram
)
22679 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22681 if (linkage_name
!= NULL
)
22683 gdb::unique_xmalloc_ptr
<char> actual_name
22684 (cu
->language_defn
->class_name_from_physname (linkage_name
));
22685 const char *name
= NULL
;
22687 if (actual_name
!= NULL
)
22689 const char *die_name
= dwarf2_name (die
, cu
);
22691 if (die_name
!= NULL
22692 && strcmp (die_name
, actual_name
.get ()) != 0)
22694 /* Strip off the class name from the full name.
22695 We want the prefix. */
22696 int die_name_len
= strlen (die_name
);
22697 int actual_name_len
= strlen (actual_name
.get ());
22698 const char *ptr
= actual_name
.get ();
22700 /* Test for '::' as a sanity check. */
22701 if (actual_name_len
> die_name_len
+ 2
22702 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22703 name
= obstack_strndup (
22704 &objfile
->per_bfd
->storage_obstack
,
22705 ptr
, actual_name_len
- die_name_len
- 2);
22716 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22717 prefix part in such case. See
22718 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22720 static const char *
22721 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22723 struct attribute
*attr
;
22726 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22727 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22730 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22733 attr
= dw2_linkage_name_attr (die
, cu
);
22734 const char *attr_name
= attr
->as_string ();
22735 if (attr
== NULL
|| attr_name
== NULL
)
22738 /* dwarf2_name had to be already called. */
22739 gdb_assert (attr
->canonical_string_p ());
22741 /* Strip the base name, keep any leading namespaces/classes. */
22742 base
= strrchr (attr_name
, ':');
22743 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
22746 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22747 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22749 &base
[-1] - attr_name
);
22752 /* Return the name of the namespace/class that DIE is defined within,
22753 or "" if we can't tell. The caller should not xfree the result.
22755 For example, if we're within the method foo() in the following
22765 then determine_prefix on foo's die will return "N::C". */
22767 static const char *
22768 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22770 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22771 struct die_info
*parent
, *spec_die
;
22772 struct dwarf2_cu
*spec_cu
;
22773 struct type
*parent_type
;
22774 const char *retval
;
22776 if (cu
->language
!= language_cplus
22777 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22778 && cu
->language
!= language_rust
)
22781 retval
= anonymous_struct_prefix (die
, cu
);
22785 /* We have to be careful in the presence of DW_AT_specification.
22786 For example, with GCC 3.4, given the code
22790 // Definition of N::foo.
22794 then we'll have a tree of DIEs like this:
22796 1: DW_TAG_compile_unit
22797 2: DW_TAG_namespace // N
22798 3: DW_TAG_subprogram // declaration of N::foo
22799 4: DW_TAG_subprogram // definition of N::foo
22800 DW_AT_specification // refers to die #3
22802 Thus, when processing die #4, we have to pretend that we're in
22803 the context of its DW_AT_specification, namely the contex of die
22806 spec_die
= die_specification (die
, &spec_cu
);
22807 if (spec_die
== NULL
)
22808 parent
= die
->parent
;
22811 parent
= spec_die
->parent
;
22815 if (parent
== NULL
)
22817 else if (parent
->building_fullname
)
22820 const char *parent_name
;
22822 /* It has been seen on RealView 2.2 built binaries,
22823 DW_TAG_template_type_param types actually _defined_ as
22824 children of the parent class:
22827 template class <class Enum> Class{};
22828 Class<enum E> class_e;
22830 1: DW_TAG_class_type (Class)
22831 2: DW_TAG_enumeration_type (E)
22832 3: DW_TAG_enumerator (enum1:0)
22833 3: DW_TAG_enumerator (enum2:1)
22835 2: DW_TAG_template_type_param
22836 DW_AT_type DW_FORM_ref_udata (E)
22838 Besides being broken debug info, it can put GDB into an
22839 infinite loop. Consider:
22841 When we're building the full name for Class<E>, we'll start
22842 at Class, and go look over its template type parameters,
22843 finding E. We'll then try to build the full name of E, and
22844 reach here. We're now trying to build the full name of E,
22845 and look over the parent DIE for containing scope. In the
22846 broken case, if we followed the parent DIE of E, we'd again
22847 find Class, and once again go look at its template type
22848 arguments, etc., etc. Simply don't consider such parent die
22849 as source-level parent of this die (it can't be, the language
22850 doesn't allow it), and break the loop here. */
22851 name
= dwarf2_name (die
, cu
);
22852 parent_name
= dwarf2_name (parent
, cu
);
22853 complaint (_("template param type '%s' defined within parent '%s'"),
22854 name
? name
: "<unknown>",
22855 parent_name
? parent_name
: "<unknown>");
22859 switch (parent
->tag
)
22861 case DW_TAG_namespace
:
22862 parent_type
= read_type_die (parent
, cu
);
22863 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22864 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22865 Work around this problem here. */
22866 if (cu
->language
== language_cplus
22867 && strcmp (parent_type
->name (), "::") == 0)
22869 /* We give a name to even anonymous namespaces. */
22870 return parent_type
->name ();
22871 case DW_TAG_class_type
:
22872 case DW_TAG_interface_type
:
22873 case DW_TAG_structure_type
:
22874 case DW_TAG_union_type
:
22875 case DW_TAG_module
:
22876 parent_type
= read_type_die (parent
, cu
);
22877 if (parent_type
->name () != NULL
)
22878 return parent_type
->name ();
22880 /* An anonymous structure is only allowed non-static data
22881 members; no typedefs, no member functions, et cetera.
22882 So it does not need a prefix. */
22884 case DW_TAG_compile_unit
:
22885 case DW_TAG_partial_unit
:
22886 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22887 if (cu
->language
== language_cplus
22888 && !per_objfile
->per_bfd
->types
.empty ()
22889 && die
->child
!= NULL
22890 && (die
->tag
== DW_TAG_class_type
22891 || die
->tag
== DW_TAG_structure_type
22892 || die
->tag
== DW_TAG_union_type
))
22894 const char *name
= guess_full_die_structure_name (die
, cu
);
22899 case DW_TAG_subprogram
:
22900 /* Nested subroutines in Fortran get a prefix with the name
22901 of the parent's subroutine. */
22902 if (cu
->language
== language_fortran
)
22904 if ((die
->tag
== DW_TAG_subprogram
)
22905 && (dwarf2_name (parent
, cu
) != NULL
))
22906 return dwarf2_name (parent
, cu
);
22908 return determine_prefix (parent
, cu
);
22909 case DW_TAG_enumeration_type
:
22910 parent_type
= read_type_die (parent
, cu
);
22911 if (parent_type
->is_declared_class ())
22913 if (parent_type
->name () != NULL
)
22914 return parent_type
->name ();
22917 /* Fall through. */
22919 return determine_prefix (parent
, cu
);
22923 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22924 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22925 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22926 an obconcat, otherwise allocate storage for the result. The CU argument is
22927 used to determine the language and hence, the appropriate separator. */
22929 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22932 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22933 int physname
, struct dwarf2_cu
*cu
)
22935 const char *lead
= "";
22938 if (suffix
== NULL
|| suffix
[0] == '\0'
22939 || prefix
== NULL
|| prefix
[0] == '\0')
22941 else if (cu
->language
== language_d
)
22943 /* For D, the 'main' function could be defined in any module, but it
22944 should never be prefixed. */
22945 if (strcmp (suffix
, "D main") == 0)
22953 else if (cu
->language
== language_fortran
&& physname
)
22955 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22956 DW_AT_MIPS_linkage_name is preferred and used instead. */
22964 if (prefix
== NULL
)
22966 if (suffix
== NULL
)
22973 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22975 strcpy (retval
, lead
);
22976 strcat (retval
, prefix
);
22977 strcat (retval
, sep
);
22978 strcat (retval
, suffix
);
22983 /* We have an obstack. */
22984 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22988 /* Get name of a die, return NULL if not found. */
22990 static const char *
22991 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22992 struct objfile
*objfile
)
22994 if (name
&& cu
->language
== language_cplus
)
22996 gdb::unique_xmalloc_ptr
<char> canon_name
22997 = cp_canonicalize_string (name
);
22999 if (canon_name
!= nullptr)
23000 name
= objfile
->intern (canon_name
.get ());
23006 /* Get name of a die, return NULL if not found.
23007 Anonymous namespaces are converted to their magic string. */
23009 static const char *
23010 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23012 struct attribute
*attr
;
23013 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23015 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23016 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23017 if (attr_name
== nullptr
23018 && die
->tag
!= DW_TAG_namespace
23019 && die
->tag
!= DW_TAG_class_type
23020 && die
->tag
!= DW_TAG_interface_type
23021 && die
->tag
!= DW_TAG_structure_type
23022 && die
->tag
!= DW_TAG_union_type
)
23027 case DW_TAG_compile_unit
:
23028 case DW_TAG_partial_unit
:
23029 /* Compilation units have a DW_AT_name that is a filename, not
23030 a source language identifier. */
23031 case DW_TAG_enumeration_type
:
23032 case DW_TAG_enumerator
:
23033 /* These tags always have simple identifiers already; no need
23034 to canonicalize them. */
23037 case DW_TAG_namespace
:
23038 if (attr_name
!= nullptr)
23040 return CP_ANONYMOUS_NAMESPACE_STR
;
23042 case DW_TAG_class_type
:
23043 case DW_TAG_interface_type
:
23044 case DW_TAG_structure_type
:
23045 case DW_TAG_union_type
:
23046 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23047 structures or unions. These were of the form "._%d" in GCC 4.1,
23048 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23049 and GCC 4.4. We work around this problem by ignoring these. */
23050 if (attr_name
!= nullptr
23051 && (startswith (attr_name
, "._")
23052 || startswith (attr_name
, "<anonymous")))
23055 /* GCC might emit a nameless typedef that has a linkage name. See
23056 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23057 if (!attr
|| attr_name
== NULL
)
23059 attr
= dw2_linkage_name_attr (die
, cu
);
23060 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23061 if (attr
== NULL
|| attr_name
== NULL
)
23064 /* Avoid demangling attr_name the second time on a second
23065 call for the same DIE. */
23066 if (!attr
->canonical_string_p ())
23068 gdb::unique_xmalloc_ptr
<char> demangled
23069 (gdb_demangle (attr_name
, DMGL_TYPES
));
23070 if (demangled
== nullptr)
23073 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
23074 attr_name
= attr
->as_string ();
23077 /* Strip any leading namespaces/classes, keep only the
23078 base name. DW_AT_name for named DIEs does not
23079 contain the prefixes. */
23080 const char *base
= strrchr (attr_name
, ':');
23081 if (base
&& base
> attr_name
&& base
[-1] == ':')
23092 if (!attr
->canonical_string_p ())
23093 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
23095 return attr
->as_string ();
23098 /* Return the die that this die in an extension of, or NULL if there
23099 is none. *EXT_CU is the CU containing DIE on input, and the CU
23100 containing the return value on output. */
23102 static struct die_info
*
23103 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23105 struct attribute
*attr
;
23107 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23111 return follow_die_ref (die
, attr
, ext_cu
);
23115 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23119 print_spaces (indent
, f
);
23120 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23121 dwarf_tag_name (die
->tag
), die
->abbrev
,
23122 sect_offset_str (die
->sect_off
));
23124 if (die
->parent
!= NULL
)
23126 print_spaces (indent
, f
);
23127 fprintf_unfiltered (f
, " parent at offset: %s\n",
23128 sect_offset_str (die
->parent
->sect_off
));
23131 print_spaces (indent
, f
);
23132 fprintf_unfiltered (f
, " has children: %s\n",
23133 dwarf_bool_name (die
->child
!= NULL
));
23135 print_spaces (indent
, f
);
23136 fprintf_unfiltered (f
, " attributes:\n");
23138 for (i
= 0; i
< die
->num_attrs
; ++i
)
23140 print_spaces (indent
, f
);
23141 fprintf_unfiltered (f
, " %s (%s) ",
23142 dwarf_attr_name (die
->attrs
[i
].name
),
23143 dwarf_form_name (die
->attrs
[i
].form
));
23145 switch (die
->attrs
[i
].form
)
23148 case DW_FORM_addrx
:
23149 case DW_FORM_GNU_addr_index
:
23150 fprintf_unfiltered (f
, "address: ");
23151 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
23153 case DW_FORM_block2
:
23154 case DW_FORM_block4
:
23155 case DW_FORM_block
:
23156 case DW_FORM_block1
:
23157 fprintf_unfiltered (f
, "block: size %s",
23158 pulongest (die
->attrs
[i
].as_block ()->size
));
23160 case DW_FORM_exprloc
:
23161 fprintf_unfiltered (f
, "expression: size %s",
23162 pulongest (die
->attrs
[i
].as_block ()->size
));
23164 case DW_FORM_data16
:
23165 fprintf_unfiltered (f
, "constant of 16 bytes");
23167 case DW_FORM_ref_addr
:
23168 fprintf_unfiltered (f
, "ref address: ");
23169 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23171 case DW_FORM_GNU_ref_alt
:
23172 fprintf_unfiltered (f
, "alt ref address: ");
23173 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23179 case DW_FORM_ref_udata
:
23180 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23181 (long) (die
->attrs
[i
].as_unsigned ()));
23183 case DW_FORM_data1
:
23184 case DW_FORM_data2
:
23185 case DW_FORM_data4
:
23186 case DW_FORM_data8
:
23187 case DW_FORM_udata
:
23188 fprintf_unfiltered (f
, "constant: %s",
23189 pulongest (die
->attrs
[i
].as_unsigned ()));
23191 case DW_FORM_sec_offset
:
23192 fprintf_unfiltered (f
, "section offset: %s",
23193 pulongest (die
->attrs
[i
].as_unsigned ()));
23195 case DW_FORM_ref_sig8
:
23196 fprintf_unfiltered (f
, "signature: %s",
23197 hex_string (die
->attrs
[i
].as_signature ()));
23199 case DW_FORM_string
:
23201 case DW_FORM_line_strp
:
23203 case DW_FORM_GNU_str_index
:
23204 case DW_FORM_GNU_strp_alt
:
23205 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23206 die
->attrs
[i
].as_string ()
23207 ? die
->attrs
[i
].as_string () : "",
23208 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23211 if (die
->attrs
[i
].as_boolean ())
23212 fprintf_unfiltered (f
, "flag: TRUE");
23214 fprintf_unfiltered (f
, "flag: FALSE");
23216 case DW_FORM_flag_present
:
23217 fprintf_unfiltered (f
, "flag: TRUE");
23219 case DW_FORM_indirect
:
23220 /* The reader will have reduced the indirect form to
23221 the "base form" so this form should not occur. */
23222 fprintf_unfiltered (f
,
23223 "unexpected attribute form: DW_FORM_indirect");
23225 case DW_FORM_sdata
:
23226 case DW_FORM_implicit_const
:
23227 fprintf_unfiltered (f
, "constant: %s",
23228 plongest (die
->attrs
[i
].as_signed ()));
23231 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23232 die
->attrs
[i
].form
);
23235 fprintf_unfiltered (f
, "\n");
23240 dump_die_for_error (struct die_info
*die
)
23242 dump_die_shallow (gdb_stderr
, 0, die
);
23246 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23248 int indent
= level
* 4;
23250 gdb_assert (die
!= NULL
);
23252 if (level
>= max_level
)
23255 dump_die_shallow (f
, indent
, die
);
23257 if (die
->child
!= NULL
)
23259 print_spaces (indent
, f
);
23260 fprintf_unfiltered (f
, " Children:");
23261 if (level
+ 1 < max_level
)
23263 fprintf_unfiltered (f
, "\n");
23264 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23268 fprintf_unfiltered (f
,
23269 " [not printed, max nesting level reached]\n");
23273 if (die
->sibling
!= NULL
&& level
> 0)
23275 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23279 /* This is called from the pdie macro in gdbinit.in.
23280 It's not static so gcc will keep a copy callable from gdb. */
23283 dump_die (struct die_info
*die
, int max_level
)
23285 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23289 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23293 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23294 to_underlying (die
->sect_off
),
23300 /* Follow reference or signature attribute ATTR of SRC_DIE.
23301 On entry *REF_CU is the CU of SRC_DIE.
23302 On exit *REF_CU is the CU of the result. */
23304 static struct die_info
*
23305 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23306 struct dwarf2_cu
**ref_cu
)
23308 struct die_info
*die
;
23310 if (attr
->form_is_ref ())
23311 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23312 else if (attr
->form
== DW_FORM_ref_sig8
)
23313 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23316 dump_die_for_error (src_die
);
23317 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23318 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23324 /* Follow reference OFFSET.
23325 On entry *REF_CU is the CU of the source die referencing OFFSET.
23326 On exit *REF_CU is the CU of the result.
23327 Returns NULL if OFFSET is invalid. */
23329 static struct die_info
*
23330 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23331 struct dwarf2_cu
**ref_cu
)
23333 struct die_info temp_die
;
23334 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23335 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23337 gdb_assert (cu
->per_cu
!= NULL
);
23341 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23342 "source CU contains target offset: %d",
23343 sect_offset_str (cu
->per_cu
->sect_off
),
23344 sect_offset_str (sect_off
),
23345 cu
->header
.offset_in_cu_p (sect_off
));
23347 if (cu
->per_cu
->is_debug_types
)
23349 /* .debug_types CUs cannot reference anything outside their CU.
23350 If they need to, they have to reference a signatured type via
23351 DW_FORM_ref_sig8. */
23352 if (!cu
->header
.offset_in_cu_p (sect_off
))
23355 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23356 || !cu
->header
.offset_in_cu_p (sect_off
))
23358 struct dwarf2_per_cu_data
*per_cu
;
23360 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23363 dwarf_read_debug_printf_v ("target CU offset: %s, "
23364 "target CU DIEs loaded: %d",
23365 sect_offset_str (per_cu
->sect_off
),
23366 per_objfile
->get_cu (per_cu
) != nullptr);
23368 /* If necessary, add it to the queue and load its DIEs.
23370 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23371 it doesn't mean they are currently loaded. Since we require them
23372 to be loaded, we must check for ourselves. */
23373 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
)
23374 || per_objfile
->get_cu (per_cu
) == nullptr)
23375 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23376 false, cu
->language
);
23378 target_cu
= per_objfile
->get_cu (per_cu
);
23379 gdb_assert (target_cu
!= nullptr);
23381 else if (cu
->dies
== NULL
)
23383 /* We're loading full DIEs during partial symbol reading. */
23384 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23385 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23389 *ref_cu
= target_cu
;
23390 temp_die
.sect_off
= sect_off
;
23392 if (target_cu
!= cu
)
23393 target_cu
->ancestor
= cu
;
23395 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23397 to_underlying (sect_off
));
23400 /* Follow reference attribute ATTR of SRC_DIE.
23401 On entry *REF_CU is the CU of SRC_DIE.
23402 On exit *REF_CU is the CU of the result. */
23404 static struct die_info
*
23405 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23406 struct dwarf2_cu
**ref_cu
)
23408 sect_offset sect_off
= attr
->get_ref_die_offset ();
23409 struct dwarf2_cu
*cu
= *ref_cu
;
23410 struct die_info
*die
;
23412 die
= follow_die_offset (sect_off
,
23413 (attr
->form
== DW_FORM_GNU_ref_alt
23414 || cu
->per_cu
->is_dwz
),
23417 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23418 "at %s [in module %s]"),
23419 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23420 objfile_name (cu
->per_objfile
->objfile
));
23427 struct dwarf2_locexpr_baton
23428 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23429 dwarf2_per_cu_data
*per_cu
,
23430 dwarf2_per_objfile
*per_objfile
,
23431 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23432 bool resolve_abstract_p
)
23434 struct die_info
*die
;
23435 struct attribute
*attr
;
23436 struct dwarf2_locexpr_baton retval
;
23437 struct objfile
*objfile
= per_objfile
->objfile
;
23439 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23441 cu
= load_cu (per_cu
, per_objfile
, false);
23445 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23446 Instead just throw an error, not much else we can do. */
23447 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23448 sect_offset_str (sect_off
), objfile_name (objfile
));
23451 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23453 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23454 sect_offset_str (sect_off
), objfile_name (objfile
));
23456 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23457 if (!attr
&& resolve_abstract_p
23458 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23459 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23461 CORE_ADDR pc
= get_frame_pc ();
23462 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23463 struct gdbarch
*gdbarch
= objfile
->arch ();
23465 for (const auto &cand_off
23466 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23468 struct dwarf2_cu
*cand_cu
= cu
;
23469 struct die_info
*cand
23470 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23473 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23476 CORE_ADDR pc_low
, pc_high
;
23477 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23478 if (pc_low
== ((CORE_ADDR
) -1))
23480 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23481 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23482 if (!(pc_low
<= pc
&& pc
< pc_high
))
23486 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23493 /* DWARF: "If there is no such attribute, then there is no effect.".
23494 DATA is ignored if SIZE is 0. */
23496 retval
.data
= NULL
;
23499 else if (attr
->form_is_section_offset ())
23501 struct dwarf2_loclist_baton loclist_baton
;
23502 CORE_ADDR pc
= get_frame_pc ();
23505 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23507 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23509 retval
.size
= size
;
23513 if (!attr
->form_is_block ())
23514 error (_("Dwarf Error: DIE at %s referenced in module %s "
23515 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23516 sect_offset_str (sect_off
), objfile_name (objfile
));
23518 struct dwarf_block
*block
= attr
->as_block ();
23519 retval
.data
= block
->data
;
23520 retval
.size
= block
->size
;
23522 retval
.per_objfile
= per_objfile
;
23523 retval
.per_cu
= cu
->per_cu
;
23525 per_objfile
->age_comp_units ();
23532 struct dwarf2_locexpr_baton
23533 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23534 dwarf2_per_cu_data
*per_cu
,
23535 dwarf2_per_objfile
*per_objfile
,
23536 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23538 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23540 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23544 /* Write a constant of a given type as target-ordered bytes into
23547 static const gdb_byte
*
23548 write_constant_as_bytes (struct obstack
*obstack
,
23549 enum bfd_endian byte_order
,
23556 *len
= TYPE_LENGTH (type
);
23557 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23558 store_unsigned_integer (result
, *len
, byte_order
, value
);
23566 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23567 dwarf2_per_cu_data
*per_cu
,
23568 dwarf2_per_objfile
*per_objfile
,
23572 struct die_info
*die
;
23573 struct attribute
*attr
;
23574 const gdb_byte
*result
= NULL
;
23577 enum bfd_endian byte_order
;
23578 struct objfile
*objfile
= per_objfile
->objfile
;
23580 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23582 cu
= load_cu (per_cu
, per_objfile
, false);
23586 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23587 Instead just throw an error, not much else we can do. */
23588 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23589 sect_offset_str (sect_off
), objfile_name (objfile
));
23592 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23594 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23595 sect_offset_str (sect_off
), objfile_name (objfile
));
23597 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23601 byte_order
= (bfd_big_endian (objfile
->obfd
)
23602 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23604 switch (attr
->form
)
23607 case DW_FORM_addrx
:
23608 case DW_FORM_GNU_addr_index
:
23612 *len
= cu
->header
.addr_size
;
23613 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23614 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23618 case DW_FORM_string
:
23621 case DW_FORM_GNU_str_index
:
23622 case DW_FORM_GNU_strp_alt
:
23623 /* The string is already allocated on the objfile obstack, point
23626 const char *attr_name
= attr
->as_string ();
23627 result
= (const gdb_byte
*) attr_name
;
23628 *len
= strlen (attr_name
);
23631 case DW_FORM_block1
:
23632 case DW_FORM_block2
:
23633 case DW_FORM_block4
:
23634 case DW_FORM_block
:
23635 case DW_FORM_exprloc
:
23636 case DW_FORM_data16
:
23638 struct dwarf_block
*block
= attr
->as_block ();
23639 result
= block
->data
;
23640 *len
= block
->size
;
23644 /* The DW_AT_const_value attributes are supposed to carry the
23645 symbol's value "represented as it would be on the target
23646 architecture." By the time we get here, it's already been
23647 converted to host endianness, so we just need to sign- or
23648 zero-extend it as appropriate. */
23649 case DW_FORM_data1
:
23650 type
= die_type (die
, cu
);
23651 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23652 if (result
== NULL
)
23653 result
= write_constant_as_bytes (obstack
, byte_order
,
23656 case DW_FORM_data2
:
23657 type
= die_type (die
, cu
);
23658 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23659 if (result
== NULL
)
23660 result
= write_constant_as_bytes (obstack
, byte_order
,
23663 case DW_FORM_data4
:
23664 type
= die_type (die
, cu
);
23665 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23666 if (result
== NULL
)
23667 result
= write_constant_as_bytes (obstack
, byte_order
,
23670 case DW_FORM_data8
:
23671 type
= die_type (die
, cu
);
23672 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23673 if (result
== NULL
)
23674 result
= write_constant_as_bytes (obstack
, byte_order
,
23678 case DW_FORM_sdata
:
23679 case DW_FORM_implicit_const
:
23680 type
= die_type (die
, cu
);
23681 result
= write_constant_as_bytes (obstack
, byte_order
,
23682 type
, attr
->as_signed (), len
);
23685 case DW_FORM_udata
:
23686 type
= die_type (die
, cu
);
23687 result
= write_constant_as_bytes (obstack
, byte_order
,
23688 type
, attr
->as_unsigned (), len
);
23692 complaint (_("unsupported const value attribute form: '%s'"),
23693 dwarf_form_name (attr
->form
));
23703 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23704 dwarf2_per_cu_data
*per_cu
,
23705 dwarf2_per_objfile
*per_objfile
)
23707 struct die_info
*die
;
23709 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23711 cu
= load_cu (per_cu
, per_objfile
, false);
23716 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23720 return die_type (die
, cu
);
23726 dwarf2_get_die_type (cu_offset die_offset
,
23727 dwarf2_per_cu_data
*per_cu
,
23728 dwarf2_per_objfile
*per_objfile
)
23730 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23731 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
23734 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23735 On entry *REF_CU is the CU of SRC_DIE.
23736 On exit *REF_CU is the CU of the result.
23737 Returns NULL if the referenced DIE isn't found. */
23739 static struct die_info
*
23740 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23741 struct dwarf2_cu
**ref_cu
)
23743 struct die_info temp_die
;
23744 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23745 struct die_info
*die
;
23746 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
23749 /* While it might be nice to assert sig_type->type == NULL here,
23750 we can get here for DW_AT_imported_declaration where we need
23751 the DIE not the type. */
23753 /* If necessary, add it to the queue and load its DIEs.
23755 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23756 it doesn't mean they are currently loaded. Since we require them
23757 to be loaded, we must check for ourselves. */
23758 if (maybe_queue_comp_unit (*ref_cu
, sig_type
, per_objfile
,
23760 || per_objfile
->get_cu (sig_type
) == nullptr)
23761 read_signatured_type (sig_type
, per_objfile
);
23763 sig_cu
= per_objfile
->get_cu (sig_type
);
23764 gdb_assert (sig_cu
!= NULL
);
23765 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23766 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23767 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23768 to_underlying (temp_die
.sect_off
));
23771 /* For .gdb_index version 7 keep track of included TUs.
23772 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23773 if (per_objfile
->per_bfd
->index_table
!= NULL
23774 && per_objfile
->per_bfd
->index_table
->version
<= 7)
23776 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23781 sig_cu
->ancestor
= cu
;
23789 /* Follow signatured type referenced by ATTR in SRC_DIE.
23790 On entry *REF_CU is the CU of SRC_DIE.
23791 On exit *REF_CU is the CU of the result.
23792 The result is the DIE of the type.
23793 If the referenced type cannot be found an error is thrown. */
23795 static struct die_info
*
23796 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23797 struct dwarf2_cu
**ref_cu
)
23799 ULONGEST signature
= attr
->as_signature ();
23800 struct signatured_type
*sig_type
;
23801 struct die_info
*die
;
23803 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23805 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23806 /* sig_type will be NULL if the signatured type is missing from
23808 if (sig_type
== NULL
)
23810 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23811 " from DIE at %s [in module %s]"),
23812 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23813 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23816 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23819 dump_die_for_error (src_die
);
23820 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23821 " from DIE at %s [in module %s]"),
23822 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23823 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23829 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23830 reading in and processing the type unit if necessary. */
23832 static struct type
*
23833 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23834 struct dwarf2_cu
*cu
)
23836 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23837 struct signatured_type
*sig_type
;
23838 struct dwarf2_cu
*type_cu
;
23839 struct die_info
*type_die
;
23842 sig_type
= lookup_signatured_type (cu
, signature
);
23843 /* sig_type will be NULL if the signatured type is missing from
23845 if (sig_type
== NULL
)
23847 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23848 " from DIE at %s [in module %s]"),
23849 hex_string (signature
), sect_offset_str (die
->sect_off
),
23850 objfile_name (per_objfile
->objfile
));
23851 return build_error_marker_type (cu
, die
);
23854 /* If we already know the type we're done. */
23855 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
23856 if (type
!= nullptr)
23860 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23861 if (type_die
!= NULL
)
23863 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23864 is created. This is important, for example, because for c++ classes
23865 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23866 type
= read_type_die (type_die
, type_cu
);
23869 complaint (_("Dwarf Error: Cannot build signatured type %s"
23870 " referenced from DIE at %s [in module %s]"),
23871 hex_string (signature
), sect_offset_str (die
->sect_off
),
23872 objfile_name (per_objfile
->objfile
));
23873 type
= build_error_marker_type (cu
, die
);
23878 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23879 " from DIE at %s [in module %s]"),
23880 hex_string (signature
), sect_offset_str (die
->sect_off
),
23881 objfile_name (per_objfile
->objfile
));
23882 type
= build_error_marker_type (cu
, die
);
23885 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
23890 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23891 reading in and processing the type unit if necessary. */
23893 static struct type
*
23894 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23895 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23897 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23898 if (attr
->form_is_ref ())
23900 struct dwarf2_cu
*type_cu
= cu
;
23901 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23903 return read_type_die (type_die
, type_cu
);
23905 else if (attr
->form
== DW_FORM_ref_sig8
)
23907 return get_signatured_type (die
, attr
->as_signature (), cu
);
23911 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23913 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23914 " at %s [in module %s]"),
23915 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23916 objfile_name (per_objfile
->objfile
));
23917 return build_error_marker_type (cu
, die
);
23921 /* Load the DIEs associated with type unit PER_CU into memory. */
23924 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
23925 dwarf2_per_objfile
*per_objfile
)
23927 struct signatured_type
*sig_type
;
23929 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23930 gdb_assert (! per_cu
->type_unit_group_p ());
23932 /* We have the per_cu, but we need the signatured_type.
23933 Fortunately this is an easy translation. */
23934 gdb_assert (per_cu
->is_debug_types
);
23935 sig_type
= (struct signatured_type
*) per_cu
;
23937 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
23939 read_signatured_type (sig_type
, per_objfile
);
23941 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
23944 /* Read in a signatured type and build its CU and DIEs.
23945 If the type is a stub for the real type in a DWO file,
23946 read in the real type from the DWO file as well. */
23949 read_signatured_type (signatured_type
*sig_type
,
23950 dwarf2_per_objfile
*per_objfile
)
23952 gdb_assert (sig_type
->is_debug_types
);
23953 gdb_assert (per_objfile
->get_cu (sig_type
) == nullptr);
23955 cutu_reader
reader (sig_type
, per_objfile
, nullptr, nullptr, false);
23957 if (!reader
.dummy_p
)
23959 struct dwarf2_cu
*cu
= reader
.cu
;
23960 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23962 gdb_assert (cu
->die_hash
== NULL
);
23964 htab_create_alloc_ex (cu
->header
.length
/ 12,
23968 &cu
->comp_unit_obstack
,
23969 hashtab_obstack_allocate
,
23970 dummy_obstack_deallocate
);
23972 if (reader
.comp_unit_die
->has_children
)
23973 reader
.comp_unit_die
->child
23974 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23975 reader
.comp_unit_die
);
23976 cu
->dies
= reader
.comp_unit_die
;
23977 /* comp_unit_die is not stored in die_hash, no need. */
23979 /* We try not to read any attributes in this function, because
23980 not all CUs needed for references have been loaded yet, and
23981 symbol table processing isn't initialized. But we have to
23982 set the CU language, or we won't be able to build types
23983 correctly. Similarly, if we do not read the producer, we can
23984 not apply producer-specific interpretation. */
23985 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23990 sig_type
->tu_read
= 1;
23993 /* Decode simple location descriptions.
23994 Given a pointer to a dwarf block that defines a location, compute
23995 the location and return the value. If COMPUTED is non-null, it is
23996 set to true to indicate that decoding was successful, and false
23997 otherwise. If COMPUTED is null, then this function may emit a
24001 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
24003 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
24005 size_t size
= blk
->size
;
24006 const gdb_byte
*data
= blk
->data
;
24007 CORE_ADDR stack
[64];
24009 unsigned int bytes_read
, unsnd
;
24012 if (computed
!= nullptr)
24018 stack
[++stacki
] = 0;
24057 stack
[++stacki
] = op
- DW_OP_lit0
;
24092 stack
[++stacki
] = op
- DW_OP_reg0
;
24095 if (computed
== nullptr)
24096 dwarf2_complex_location_expr_complaint ();
24103 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24105 stack
[++stacki
] = unsnd
;
24108 if (computed
== nullptr)
24109 dwarf2_complex_location_expr_complaint ();
24116 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
24121 case DW_OP_const1u
:
24122 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24126 case DW_OP_const1s
:
24127 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24131 case DW_OP_const2u
:
24132 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24136 case DW_OP_const2s
:
24137 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24141 case DW_OP_const4u
:
24142 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24146 case DW_OP_const4s
:
24147 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24151 case DW_OP_const8u
:
24152 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24157 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24163 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24168 stack
[stacki
+ 1] = stack
[stacki
];
24173 stack
[stacki
- 1] += stack
[stacki
];
24177 case DW_OP_plus_uconst
:
24178 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24184 stack
[stacki
- 1] -= stack
[stacki
];
24189 /* If we're not the last op, then we definitely can't encode
24190 this using GDB's address_class enum. This is valid for partial
24191 global symbols, although the variable's address will be bogus
24195 if (computed
== nullptr)
24196 dwarf2_complex_location_expr_complaint ();
24202 case DW_OP_GNU_push_tls_address
:
24203 case DW_OP_form_tls_address
:
24204 /* The top of the stack has the offset from the beginning
24205 of the thread control block at which the variable is located. */
24206 /* Nothing should follow this operator, so the top of stack would
24208 /* This is valid for partial global symbols, but the variable's
24209 address will be bogus in the psymtab. Make it always at least
24210 non-zero to not look as a variable garbage collected by linker
24211 which have DW_OP_addr 0. */
24214 if (computed
== nullptr)
24215 dwarf2_complex_location_expr_complaint ();
24222 case DW_OP_GNU_uninit
:
24223 if (computed
!= nullptr)
24228 case DW_OP_GNU_addr_index
:
24229 case DW_OP_GNU_const_index
:
24230 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24236 if (computed
== nullptr)
24238 const char *name
= get_DW_OP_name (op
);
24241 complaint (_("unsupported stack op: '%s'"),
24244 complaint (_("unsupported stack op: '%02x'"),
24248 return (stack
[stacki
]);
24251 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24252 outside of the allocated space. Also enforce minimum>0. */
24253 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24255 if (computed
== nullptr)
24256 complaint (_("location description stack overflow"));
24262 if (computed
== nullptr)
24263 complaint (_("location description stack underflow"));
24268 if (computed
!= nullptr)
24270 return (stack
[stacki
]);
24273 /* memory allocation interface */
24275 static struct dwarf_block
*
24276 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24278 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24281 static struct die_info
*
24282 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24284 struct die_info
*die
;
24285 size_t size
= sizeof (struct die_info
);
24288 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24290 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24291 memset (die
, 0, sizeof (struct die_info
));
24297 /* Macro support. */
24299 /* An overload of dwarf_decode_macros that finds the correct section
24300 and ensures it is read in before calling the other overload. */
24303 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24304 int section_is_gnu
)
24306 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24307 struct objfile
*objfile
= per_objfile
->objfile
;
24308 const struct line_header
*lh
= cu
->line_header
;
24309 unsigned int offset_size
= cu
->header
.offset_size
;
24310 struct dwarf2_section_info
*section
;
24311 const char *section_name
;
24313 if (cu
->dwo_unit
!= nullptr)
24315 if (section_is_gnu
)
24317 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24318 section_name
= ".debug_macro.dwo";
24322 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24323 section_name
= ".debug_macinfo.dwo";
24328 if (section_is_gnu
)
24330 section
= &per_objfile
->per_bfd
->macro
;
24331 section_name
= ".debug_macro";
24335 section
= &per_objfile
->per_bfd
->macinfo
;
24336 section_name
= ".debug_macinfo";
24340 section
->read (objfile
);
24341 if (section
->buffer
== nullptr)
24343 complaint (_("missing %s section"), section_name
);
24347 buildsym_compunit
*builder
= cu
->get_builder ();
24349 struct dwarf2_section_info
*str_offsets_section
;
24350 struct dwarf2_section_info
*str_section
;
24351 ULONGEST str_offsets_base
;
24353 if (cu
->dwo_unit
!= nullptr)
24355 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24356 ->sections
.str_offsets
;
24357 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24358 str_offsets_base
= cu
->header
.addr_size
;
24362 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24363 str_section
= &per_objfile
->per_bfd
->str
;
24364 str_offsets_base
= *cu
->str_offsets_base
;
24367 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24368 offset_size
, offset
, str_section
, str_offsets_section
,
24369 str_offsets_base
, section_is_gnu
);
24372 /* Return the .debug_loc section to use for CU.
24373 For DWO files use .debug_loc.dwo. */
24375 static struct dwarf2_section_info
*
24376 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24378 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24382 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24384 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24386 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24387 : &per_objfile
->per_bfd
->loc
);
24390 /* Return the .debug_rnglists section to use for CU. */
24391 static struct dwarf2_section_info
*
24392 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24394 if (cu
->header
.version
< 5)
24395 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24396 cu
->header
.version
);
24397 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24399 /* Make sure we read the .debug_rnglists section from the file that
24400 contains the DW_AT_ranges attribute we are reading. Normally that
24401 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24402 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24404 if (cu
->dwo_unit
!= nullptr
24405 && tag
!= DW_TAG_compile_unit
24406 && tag
!= DW_TAG_skeleton_unit
)
24408 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24410 if (sections
->rnglists
.size
> 0)
24411 return §ions
->rnglists
;
24413 error (_(".debug_rnglists section is missing from .dwo file."));
24415 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24418 /* A helper function that fills in a dwarf2_loclist_baton. */
24421 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24422 struct dwarf2_loclist_baton
*baton
,
24423 const struct attribute
*attr
)
24425 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24426 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24428 section
->read (per_objfile
->objfile
);
24430 baton
->per_objfile
= per_objfile
;
24431 baton
->per_cu
= cu
->per_cu
;
24432 gdb_assert (baton
->per_cu
);
24433 /* We don't know how long the location list is, but make sure we
24434 don't run off the edge of the section. */
24435 baton
->size
= section
->size
- attr
->as_unsigned ();
24436 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24437 if (cu
->base_address
.has_value ())
24438 baton
->base_address
= *cu
->base_address
;
24440 baton
->base_address
= 0;
24441 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24445 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24446 struct dwarf2_cu
*cu
, int is_block
)
24448 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24449 struct objfile
*objfile
= per_objfile
->objfile
;
24450 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24452 if (attr
->form_is_section_offset ()
24453 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24454 the section. If so, fall through to the complaint in the
24456 && attr
->as_unsigned () < section
->get_size (objfile
))
24458 struct dwarf2_loclist_baton
*baton
;
24460 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24462 fill_in_loclist_baton (cu
, baton
, attr
);
24464 if (!cu
->base_address
.has_value ())
24465 complaint (_("Location list used without "
24466 "specifying the CU base address."));
24468 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24469 ? dwarf2_loclist_block_index
24470 : dwarf2_loclist_index
);
24471 SYMBOL_LOCATION_BATON (sym
) = baton
;
24475 struct dwarf2_locexpr_baton
*baton
;
24477 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24478 baton
->per_objfile
= per_objfile
;
24479 baton
->per_cu
= cu
->per_cu
;
24480 gdb_assert (baton
->per_cu
);
24482 if (attr
->form_is_block ())
24484 /* Note that we're just copying the block's data pointer
24485 here, not the actual data. We're still pointing into the
24486 info_buffer for SYM's objfile; right now we never release
24487 that buffer, but when we do clean up properly this may
24489 struct dwarf_block
*block
= attr
->as_block ();
24490 baton
->size
= block
->size
;
24491 baton
->data
= block
->data
;
24495 dwarf2_invalid_attrib_class_complaint ("location description",
24496 sym
->natural_name ());
24500 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24501 ? dwarf2_locexpr_block_index
24502 : dwarf2_locexpr_index
);
24503 SYMBOL_LOCATION_BATON (sym
) = baton
;
24509 const comp_unit_head
*
24510 dwarf2_per_cu_data::get_header () const
24512 if (!m_header_read_in
)
24514 const gdb_byte
*info_ptr
24515 = this->section
->buffer
+ to_underlying (this->sect_off
);
24517 memset (&m_header
, 0, sizeof (m_header
));
24519 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24520 rcuh_kind::COMPILE
);
24522 m_header_read_in
= true;
24531 dwarf2_per_cu_data::addr_size () const
24533 return this->get_header ()->addr_size
;
24539 dwarf2_per_cu_data::offset_size () const
24541 return this->get_header ()->offset_size
;
24547 dwarf2_per_cu_data::ref_addr_size () const
24549 const comp_unit_head
*header
= this->get_header ();
24551 if (header
->version
== 2)
24552 return header
->addr_size
;
24554 return header
->offset_size
;
24560 dwarf2_cu::addr_type () const
24562 struct objfile
*objfile
= this->per_objfile
->objfile
;
24563 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24564 struct type
*addr_type
= lookup_pointer_type (void_type
);
24565 int addr_size
= this->per_cu
->addr_size ();
24567 if (TYPE_LENGTH (addr_type
) == addr_size
)
24570 addr_type
= addr_sized_int_type (addr_type
->is_unsigned ());
24574 /* A helper function for dwarf2_find_containing_comp_unit that returns
24575 the index of the result, and that searches a vector. It will
24576 return a result even if the offset in question does not actually
24577 occur in any CU. This is separate so that it can be unit
24581 dwarf2_find_containing_comp_unit
24582 (sect_offset sect_off
,
24583 unsigned int offset_in_dwz
,
24584 const std::vector
<std::unique_ptr
<dwarf2_per_cu_data
>> &all_comp_units
)
24589 high
= all_comp_units
.size () - 1;
24592 struct dwarf2_per_cu_data
*mid_cu
;
24593 int mid
= low
+ (high
- low
) / 2;
24595 mid_cu
= all_comp_units
[mid
].get ();
24596 if (mid_cu
->is_dwz
> offset_in_dwz
24597 || (mid_cu
->is_dwz
== offset_in_dwz
24598 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24603 gdb_assert (low
== high
);
24607 /* Locate the .debug_info compilation unit from CU's objfile which contains
24608 the DIE at OFFSET. Raises an error on failure. */
24610 static struct dwarf2_per_cu_data
*
24611 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24612 unsigned int offset_in_dwz
,
24613 dwarf2_per_objfile
*per_objfile
)
24615 int low
= dwarf2_find_containing_comp_unit
24616 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24617 dwarf2_per_cu_data
*this_cu
24618 = per_objfile
->per_bfd
->all_comp_units
[low
].get ();
24620 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24622 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24623 error (_("Dwarf Error: could not find partial DIE containing "
24624 "offset %s [in module %s]"),
24625 sect_offset_str (sect_off
),
24626 bfd_get_filename (per_objfile
->objfile
->obfd
));
24628 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24630 return per_objfile
->per_bfd
->all_comp_units
[low
- 1].get ();
24634 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24635 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24636 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24637 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
24644 namespace selftests
{
24645 namespace find_containing_comp_unit
{
24650 std::unique_ptr
<dwarf2_per_cu_data
> one (new dwarf2_per_cu_data
);
24651 dwarf2_per_cu_data
*one_ptr
= one
.get ();
24652 std::unique_ptr
<dwarf2_per_cu_data
> two (new dwarf2_per_cu_data
);
24653 dwarf2_per_cu_data
*two_ptr
= two
.get ();
24654 std::unique_ptr
<dwarf2_per_cu_data
> three (new dwarf2_per_cu_data
);
24655 dwarf2_per_cu_data
*three_ptr
= three
.get ();
24656 std::unique_ptr
<dwarf2_per_cu_data
> four (new dwarf2_per_cu_data
);
24657 dwarf2_per_cu_data
*four_ptr
= four
.get ();
24660 two
->sect_off
= sect_offset (one
->length
);
24665 four
->sect_off
= sect_offset (three
->length
);
24669 std::vector
<std::unique_ptr
<dwarf2_per_cu_data
>> units
;
24670 units
.push_back (std::move (one
));
24671 units
.push_back (std::move (two
));
24672 units
.push_back (std::move (three
));
24673 units
.push_back (std::move (four
));
24677 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
24678 SELF_CHECK (units
[result
].get () == one_ptr
);
24679 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
24680 SELF_CHECK (units
[result
].get () == one_ptr
);
24681 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
24682 SELF_CHECK (units
[result
].get () == two_ptr
);
24684 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
24685 SELF_CHECK (units
[result
].get () == three_ptr
);
24686 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
24687 SELF_CHECK (units
[result
].get () == three_ptr
);
24688 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
24689 SELF_CHECK (units
[result
].get () == four_ptr
);
24695 #endif /* GDB_SELF_TEST */
24697 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
24699 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
24700 dwarf2_per_objfile
*per_objfile
)
24702 per_objfile (per_objfile
),
24704 has_loclist (false),
24705 checked_producer (false),
24706 producer_is_gxx_lt_4_6 (false),
24707 producer_is_gcc_lt_4_3 (false),
24708 producer_is_icc (false),
24709 producer_is_icc_lt_14 (false),
24710 producer_is_codewarrior (false),
24711 processing_has_namespace_info (false)
24715 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
24718 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
24719 enum language pretend_language
)
24721 struct attribute
*attr
;
24723 /* Set the language we're debugging. */
24724 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
24725 if (attr
!= nullptr)
24726 set_cu_language (attr
->constant_value (0), cu
);
24729 cu
->language
= pretend_language
;
24730 cu
->language_defn
= language_def (cu
->language
);
24733 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
24739 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
24741 auto it
= m_dwarf2_cus
.find (per_cu
);
24742 if (it
== m_dwarf2_cus
.end ())
24751 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
24753 gdb_assert (this->get_cu (per_cu
) == nullptr);
24755 m_dwarf2_cus
[per_cu
] = cu
;
24761 dwarf2_per_objfile::age_comp_units ()
24763 dwarf_read_debug_printf_v ("running");
24765 /* This is not expected to be called in the middle of CU expansion. There is
24766 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
24767 loaded in memory. Calling age_comp_units while the queue is in use could
24768 make us free the DIEs for a CU that is in the queue and therefore break
24770 gdb_assert (!this->per_bfd
->queue
.has_value ());
24772 /* Start by clearing all marks. */
24773 for (auto pair
: m_dwarf2_cus
)
24774 pair
.second
->mark
= false;
24776 /* Traverse all CUs, mark them and their dependencies if used recently
24778 for (auto pair
: m_dwarf2_cus
)
24780 dwarf2_cu
*cu
= pair
.second
;
24783 if (cu
->last_used
<= dwarf_max_cache_age
)
24787 /* Delete all CUs still not marked. */
24788 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
24790 dwarf2_cu
*cu
= it
->second
;
24794 dwarf_read_debug_printf_v ("deleting old CU %s",
24795 sect_offset_str (cu
->per_cu
->sect_off
));
24797 it
= m_dwarf2_cus
.erase (it
);
24807 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
24809 auto it
= m_dwarf2_cus
.find (per_cu
);
24810 if (it
== m_dwarf2_cus
.end ())
24815 m_dwarf2_cus
.erase (it
);
24818 dwarf2_per_objfile::~dwarf2_per_objfile ()
24823 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
24824 We store these in a hash table separate from the DIEs, and preserve them
24825 when the DIEs are flushed out of cache.
24827 The CU "per_cu" pointer is needed because offset alone is not enough to
24828 uniquely identify the type. A file may have multiple .debug_types sections,
24829 or the type may come from a DWO file. Furthermore, while it's more logical
24830 to use per_cu->section+offset, with Fission the section with the data is in
24831 the DWO file but we don't know that section at the point we need it.
24832 We have to use something in dwarf2_per_cu_data (or the pointer to it)
24833 because we can enter the lookup routine, get_die_type_at_offset, from
24834 outside this file, and thus won't necessarily have PER_CU->cu.
24835 Fortunately, PER_CU is stable for the life of the objfile. */
24837 struct dwarf2_per_cu_offset_and_type
24839 const struct dwarf2_per_cu_data
*per_cu
;
24840 sect_offset sect_off
;
24844 /* Hash function for a dwarf2_per_cu_offset_and_type. */
24847 per_cu_offset_and_type_hash (const void *item
)
24849 const struct dwarf2_per_cu_offset_and_type
*ofs
24850 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
24852 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
24855 /* Equality function for a dwarf2_per_cu_offset_and_type. */
24858 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
24860 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
24861 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
24862 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
24863 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
24865 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
24866 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
24869 /* Set the type associated with DIE to TYPE. Save it in CU's hash
24870 table if necessary. For convenience, return TYPE.
24872 The DIEs reading must have careful ordering to:
24873 * Not cause infinite loops trying to read in DIEs as a prerequisite for
24874 reading current DIE.
24875 * Not trying to dereference contents of still incompletely read in types
24876 while reading in other DIEs.
24877 * Enable referencing still incompletely read in types just by a pointer to
24878 the type without accessing its fields.
24880 Therefore caller should follow these rules:
24881 * Try to fetch any prerequisite types we may need to build this DIE type
24882 before building the type and calling set_die_type.
24883 * After building type call set_die_type for current DIE as soon as
24884 possible before fetching more types to complete the current type.
24885 * Make the type as complete as possible before fetching more types. */
24887 static struct type
*
24888 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
24889 bool skip_data_location
)
24891 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24892 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
24893 struct objfile
*objfile
= per_objfile
->objfile
;
24894 struct attribute
*attr
;
24895 struct dynamic_prop prop
;
24897 /* For Ada types, make sure that the gnat-specific data is always
24898 initialized (if not already set). There are a few types where
24899 we should not be doing so, because the type-specific area is
24900 already used to hold some other piece of info (eg: TYPE_CODE_FLT
24901 where the type-specific area is used to store the floatformat).
24902 But this is not a problem, because the gnat-specific information
24903 is actually not needed for these types. */
24904 if (need_gnat_info (cu
)
24905 && type
->code () != TYPE_CODE_FUNC
24906 && type
->code () != TYPE_CODE_FLT
24907 && type
->code () != TYPE_CODE_METHODPTR
24908 && type
->code () != TYPE_CODE_MEMBERPTR
24909 && type
->code () != TYPE_CODE_METHOD
24910 && type
->code () != TYPE_CODE_FIXED_POINT
24911 && !HAVE_GNAT_AUX_INFO (type
))
24912 INIT_GNAT_SPECIFIC (type
);
24914 /* Read DW_AT_allocated and set in type. */
24915 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
24918 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24919 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24920 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
24923 /* Read DW_AT_associated and set in type. */
24924 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
24927 struct type
*prop_type
= cu
->addr_sized_int_type (false);
24928 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
24929 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
24932 /* Read DW_AT_data_location and set in type. */
24933 if (!skip_data_location
)
24935 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
24936 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
24937 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
24940 if (per_objfile
->die_type_hash
== NULL
)
24941 per_objfile
->die_type_hash
24942 = htab_up (htab_create_alloc (127,
24943 per_cu_offset_and_type_hash
,
24944 per_cu_offset_and_type_eq
,
24945 NULL
, xcalloc
, xfree
));
24947 ofs
.per_cu
= cu
->per_cu
;
24948 ofs
.sect_off
= die
->sect_off
;
24950 slot
= (struct dwarf2_per_cu_offset_and_type
**)
24951 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
24953 complaint (_("A problem internal to GDB: DIE %s has type already set"),
24954 sect_offset_str (die
->sect_off
));
24955 *slot
= XOBNEW (&objfile
->objfile_obstack
,
24956 struct dwarf2_per_cu_offset_and_type
);
24961 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
24962 or return NULL if the die does not have a saved type. */
24964 static struct type
*
24965 get_die_type_at_offset (sect_offset sect_off
,
24966 dwarf2_per_cu_data
*per_cu
,
24967 dwarf2_per_objfile
*per_objfile
)
24969 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
24971 if (per_objfile
->die_type_hash
== NULL
)
24974 ofs
.per_cu
= per_cu
;
24975 ofs
.sect_off
= sect_off
;
24976 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
24977 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
24984 /* Look up the type for DIE in CU in die_type_hash,
24985 or return NULL if DIE does not have a saved type. */
24987 static struct type
*
24988 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
24990 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
24993 /* Add a dependence relationship from CU to REF_PER_CU. */
24996 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
24997 struct dwarf2_per_cu_data
*ref_per_cu
)
25001 if (cu
->dependencies
== NULL
)
25003 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25004 NULL
, &cu
->comp_unit_obstack
,
25005 hashtab_obstack_allocate
,
25006 dummy_obstack_deallocate
);
25008 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25010 *slot
= ref_per_cu
;
25013 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25014 Set the mark field in every compilation unit in the
25015 cache that we must keep because we are keeping CU.
25017 DATA is the dwarf2_per_objfile object in which to look up CUs. */
25020 dwarf2_mark_helper (void **slot
, void *data
)
25022 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
25023 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
25024 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
25026 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25027 reading of the chain. As such dependencies remain valid it is not much
25028 useful to track and undo them during QUIT cleanups. */
25037 if (cu
->dependencies
!= nullptr)
25038 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
25043 /* Set the mark field in CU and in every other compilation unit in the
25044 cache that we must keep because we are keeping CU. */
25047 dwarf2_mark (struct dwarf2_cu
*cu
)
25054 if (cu
->dependencies
!= nullptr)
25055 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
25058 /* Trivial hash function for partial_die_info: the hash value of a DIE
25059 is its offset in .debug_info for this objfile. */
25062 partial_die_hash (const void *item
)
25064 const struct partial_die_info
*part_die
25065 = (const struct partial_die_info
*) item
;
25067 return to_underlying (part_die
->sect_off
);
25070 /* Trivial comparison function for partial_die_info structures: two DIEs
25071 are equal if they have the same offset. */
25074 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25076 const struct partial_die_info
*part_die_lhs
25077 = (const struct partial_die_info
*) item_lhs
;
25078 const struct partial_die_info
*part_die_rhs
25079 = (const struct partial_die_info
*) item_rhs
;
25081 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25084 struct cmd_list_element
*set_dwarf_cmdlist
;
25085 struct cmd_list_element
*show_dwarf_cmdlist
;
25088 show_check_physname (struct ui_file
*file
, int from_tty
,
25089 struct cmd_list_element
*c
, const char *value
)
25091 fprintf_filtered (file
,
25092 _("Whether to check \"physname\" is %s.\n"),
25096 void _initialize_dwarf2_read ();
25098 _initialize_dwarf2_read ()
25100 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
25101 Set DWARF specific variables.\n\
25102 Configure DWARF variables such as the cache size."),
25103 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25104 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25106 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
25107 Show DWARF specific variables.\n\
25108 Show DWARF variables such as the cache size."),
25109 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25110 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25112 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25113 &dwarf_max_cache_age
, _("\
25114 Set the upper bound on the age of cached DWARF compilation units."), _("\
25115 Show the upper bound on the age of cached DWARF compilation units."), _("\
25116 A higher limit means that cached compilation units will be stored\n\
25117 in memory longer, and more total memory will be used. Zero disables\n\
25118 caching, which can slow down startup."),
25120 show_dwarf_max_cache_age
,
25121 &set_dwarf_cmdlist
,
25122 &show_dwarf_cmdlist
);
25124 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25125 Set debugging of the DWARF reader."), _("\
25126 Show debugging of the DWARF reader."), _("\
25127 When enabled (non-zero), debugging messages are printed during DWARF\n\
25128 reading and symtab expansion. A value of 1 (one) provides basic\n\
25129 information. A value greater than 1 provides more verbose information."),
25132 &setdebuglist
, &showdebuglist
);
25134 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25135 Set debugging of the DWARF DIE reader."), _("\
25136 Show debugging of the DWARF DIE reader."), _("\
25137 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25138 The value is the maximum depth to print."),
25141 &setdebuglist
, &showdebuglist
);
25143 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25144 Set debugging of the dwarf line reader."), _("\
25145 Show debugging of the dwarf line reader."), _("\
25146 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25147 A value of 1 (one) provides basic information.\n\
25148 A value greater than 1 provides more verbose information."),
25151 &setdebuglist
, &showdebuglist
);
25153 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25154 Set cross-checking of \"physname\" code against demangler."), _("\
25155 Show cross-checking of \"physname\" code against demangler."), _("\
25156 When enabled, GDB's internal \"physname\" code is checked against\n\
25158 NULL
, show_check_physname
,
25159 &setdebuglist
, &showdebuglist
);
25161 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25162 no_class
, &use_deprecated_index_sections
, _("\
25163 Set whether to use deprecated gdb_index sections."), _("\
25164 Show whether to use deprecated gdb_index sections."), _("\
25165 When enabled, deprecated .gdb_index sections are used anyway.\n\
25166 Normally they are ignored either because of a missing feature or\n\
25167 performance issue.\n\
25168 Warning: This option must be enabled before gdb reads the file."),
25171 &setlist
, &showlist
);
25173 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25174 &dwarf2_locexpr_funcs
);
25175 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25176 &dwarf2_loclist_funcs
);
25178 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25179 &dwarf2_block_frame_base_locexpr_funcs
);
25180 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25181 &dwarf2_block_frame_base_loclist_funcs
);
25184 selftests::register_test ("dw2_expand_symtabs_matching",
25185 selftests::dw2_expand_symtabs_matching::run_test
);
25186 selftests::register_test ("dwarf2_find_containing_comp_unit",
25187 selftests::find_containing_comp_unit::run_test
);