1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2021 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2/read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf2/attribute.h"
35 #include "dwarf2/comp-unit.h"
36 #include "dwarf2/index-cache.h"
37 #include "dwarf2/index-common.h"
38 #include "dwarf2/leb.h"
39 #include "dwarf2/line-header.h"
40 #include "dwarf2/dwz.h"
41 #include "dwarf2/macro.h"
42 #include "dwarf2/die.h"
43 #include "dwarf2/sect-names.h"
44 #include "dwarf2/stringify.h"
45 #include "dwarf2/public.h"
54 #include "gdb-demangle.h"
55 #include "filenames.h" /* for DOSish file names */
57 #include "complaints.h"
58 #include "dwarf2/expr.h"
59 #include "dwarf2/loc.h"
60 #include "cp-support.h"
66 #include "typeprint.h"
71 #include "gdbcore.h" /* for gnutarget */
72 #include "gdb/gdb-index.h"
77 #include "namespace.h"
78 #include "gdbsupport/function-view.h"
79 #include "gdbsupport/gdb_optional.h"
80 #include "gdbsupport/underlying.h"
81 #include "gdbsupport/hash_enum.h"
82 #include "filename-seen-cache.h"
86 #include <unordered_map>
87 #include "gdbsupport/selftest.h"
88 #include "rust-lang.h"
89 #include "gdbsupport/pathstuff.h"
90 #include "count-one-bits.h"
92 /* When == 1, print basic high level tracing messages.
93 When > 1, be more verbose.
94 This is in contrast to the low level DIE reading of dwarf_die_debug. */
95 static unsigned int dwarf_read_debug
= 0;
97 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 1. */
99 #define dwarf_read_debug_printf(fmt, ...) \
100 debug_prefixed_printf_cond (dwarf_read_debug >= 1, "dwarf-read", fmt, \
103 /* Print a "dwarf-read" debug statement if dwarf_read_debug is >= 2. */
105 #define dwarf_read_debug_printf_v(fmt, ...) \
106 debug_prefixed_printf_cond (dwarf_read_debug >= 2, "dwarf-read", fmt, \
109 /* When non-zero, dump DIEs after they are read in. */
110 static unsigned int dwarf_die_debug
= 0;
112 /* When non-zero, dump line number entries as they are read in. */
113 unsigned int dwarf_line_debug
= 0;
115 /* When true, cross-check physname against demangler. */
116 static bool check_physname
= false;
118 /* When true, do not reject deprecated .gdb_index sections. */
119 static bool use_deprecated_index_sections
= false;
121 /* This is used to store the data that is always per objfile. */
122 static const objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
124 /* These are used to store the dwarf2_per_bfd objects.
126 objfiles having the same BFD, which doesn't require relocations, are going to
127 share a dwarf2_per_bfd object, which is held in the _bfd_data_key version.
129 Other objfiles are not going to share a dwarf2_per_bfd with any other
130 objfiles, so they'll have their own version kept in the _objfile_data_key
132 static const struct bfd_key
<dwarf2_per_bfd
> dwarf2_per_bfd_bfd_data_key
;
133 static const struct objfile_key
<dwarf2_per_bfd
> dwarf2_per_bfd_objfile_data_key
;
135 /* The "aclass" indices for various kinds of computed DWARF symbols. */
137 static int dwarf2_locexpr_index
;
138 static int dwarf2_loclist_index
;
139 static int dwarf2_locexpr_block_index
;
140 static int dwarf2_loclist_block_index
;
142 /* Size of .debug_loclists section header for 32-bit DWARF format. */
143 #define LOCLIST_HEADER_SIZE32 12
145 /* Size of .debug_loclists section header for 64-bit DWARF format. */
146 #define LOCLIST_HEADER_SIZE64 20
148 /* Size of .debug_rnglists section header for 32-bit DWARF format. */
149 #define RNGLIST_HEADER_SIZE32 12
151 /* Size of .debug_rnglists section header for 64-bit DWARF format. */
152 #define RNGLIST_HEADER_SIZE64 20
154 /* An index into a (C++) symbol name component in a symbol name as
155 recorded in the mapped_index's symbol table. For each C++ symbol
156 in the symbol table, we record one entry for the start of each
157 component in the symbol in a table of name components, and then
158 sort the table, in order to be able to binary search symbol names,
159 ignoring leading namespaces, both completion and regular look up.
160 For example, for symbol "A::B::C", we'll have an entry that points
161 to "A::B::C", another that points to "B::C", and another for "C".
162 Note that function symbols in GDB index have no parameter
163 information, just the function/method names. You can convert a
164 name_component to a "const char *" using the
165 'mapped_index::symbol_name_at(offset_type)' method. */
167 struct name_component
169 /* Offset in the symbol name where the component starts. Stored as
170 a (32-bit) offset instead of a pointer to save memory and improve
171 locality on 64-bit architectures. */
172 offset_type name_offset
;
174 /* The symbol's index in the symbol and constant pool tables of a
179 /* Base class containing bits shared by both .gdb_index and
180 .debug_name indexes. */
182 struct mapped_index_base
184 mapped_index_base () = default;
185 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
187 /* The name_component table (a sorted vector). See name_component's
188 description above. */
189 std::vector
<name_component
> name_components
;
191 /* How NAME_COMPONENTS is sorted. */
192 enum case_sensitivity name_components_casing
;
194 /* Return the number of names in the symbol table. */
195 virtual size_t symbol_name_count () const = 0;
197 /* Get the name of the symbol at IDX in the symbol table. */
198 virtual const char *symbol_name_at
199 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const = 0;
201 /* Return whether the name at IDX in the symbol table should be
203 virtual bool symbol_name_slot_invalid (offset_type idx
) const
208 /* Build the symbol name component sorted vector, if we haven't
210 void build_name_components (dwarf2_per_objfile
*per_objfile
);
212 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
213 possible matches for LN_NO_PARAMS in the name component
215 std::pair
<std::vector
<name_component
>::const_iterator
,
216 std::vector
<name_component
>::const_iterator
>
217 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
219 dwarf2_per_objfile
*per_objfile
) const;
221 /* Prevent deleting/destroying via a base class pointer. */
223 ~mapped_index_base() = default;
226 /* A description of the mapped index. The file format is described in
227 a comment by the code that writes the index. */
228 struct mapped_index final
: public mapped_index_base
230 /* A slot/bucket in the symbol table hash. */
231 struct symbol_table_slot
233 const offset_type name
;
234 const offset_type vec
;
237 /* Index data format version. */
240 /* The address table data. */
241 gdb::array_view
<const gdb_byte
> address_table
;
243 /* The symbol table, implemented as a hash table. */
244 gdb::array_view
<symbol_table_slot
> symbol_table
;
246 /* A pointer to the constant pool. */
247 const char *constant_pool
= nullptr;
249 bool symbol_name_slot_invalid (offset_type idx
) const override
251 const auto &bucket
= this->symbol_table
[idx
];
252 return bucket
.name
== 0 && bucket
.vec
== 0;
255 /* Convenience method to get at the name of the symbol at IDX in the
257 const char *symbol_name_at
258 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
259 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
261 size_t symbol_name_count () const override
262 { return this->symbol_table
.size (); }
265 /* A description of the mapped .debug_names.
266 Uninitialized map has CU_COUNT 0. */
267 struct mapped_debug_names final
: public mapped_index_base
269 bfd_endian dwarf5_byte_order
;
270 bool dwarf5_is_dwarf64
;
271 bool augmentation_is_gdb
;
273 uint32_t cu_count
= 0;
274 uint32_t tu_count
, bucket_count
, name_count
;
275 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
276 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
277 const gdb_byte
*name_table_string_offs_reordered
;
278 const gdb_byte
*name_table_entry_offs_reordered
;
279 const gdb_byte
*entry_pool
;
286 /* Attribute name DW_IDX_*. */
289 /* Attribute form DW_FORM_*. */
292 /* Value if FORM is DW_FORM_implicit_const. */
293 LONGEST implicit_const
;
295 std::vector
<attr
> attr_vec
;
298 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
300 const char *namei_to_name
301 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
303 /* Implementation of the mapped_index_base virtual interface, for
304 the name_components cache. */
306 const char *symbol_name_at
307 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
308 { return namei_to_name (idx
, per_objfile
); }
310 size_t symbol_name_count () const override
311 { return this->name_count
; }
314 /* See dwarf2read.h. */
317 get_dwarf2_per_objfile (struct objfile
*objfile
)
319 return dwarf2_objfile_data_key
.get (objfile
);
322 /* Default names of the debugging sections. */
324 /* Note that if the debugging section has been compressed, it might
325 have a name like .zdebug_info. */
327 const struct dwarf2_debug_sections dwarf2_elf_names
=
329 { ".debug_info", ".zdebug_info" },
330 { ".debug_abbrev", ".zdebug_abbrev" },
331 { ".debug_line", ".zdebug_line" },
332 { ".debug_loc", ".zdebug_loc" },
333 { ".debug_loclists", ".zdebug_loclists" },
334 { ".debug_macinfo", ".zdebug_macinfo" },
335 { ".debug_macro", ".zdebug_macro" },
336 { ".debug_str", ".zdebug_str" },
337 { ".debug_str_offsets", ".zdebug_str_offsets" },
338 { ".debug_line_str", ".zdebug_line_str" },
339 { ".debug_ranges", ".zdebug_ranges" },
340 { ".debug_rnglists", ".zdebug_rnglists" },
341 { ".debug_types", ".zdebug_types" },
342 { ".debug_addr", ".zdebug_addr" },
343 { ".debug_frame", ".zdebug_frame" },
344 { ".eh_frame", NULL
},
345 { ".gdb_index", ".zgdb_index" },
346 { ".debug_names", ".zdebug_names" },
347 { ".debug_aranges", ".zdebug_aranges" },
351 /* List of DWO/DWP sections. */
353 static const struct dwop_section_names
355 struct dwarf2_section_names abbrev_dwo
;
356 struct dwarf2_section_names info_dwo
;
357 struct dwarf2_section_names line_dwo
;
358 struct dwarf2_section_names loc_dwo
;
359 struct dwarf2_section_names loclists_dwo
;
360 struct dwarf2_section_names macinfo_dwo
;
361 struct dwarf2_section_names macro_dwo
;
362 struct dwarf2_section_names rnglists_dwo
;
363 struct dwarf2_section_names str_dwo
;
364 struct dwarf2_section_names str_offsets_dwo
;
365 struct dwarf2_section_names types_dwo
;
366 struct dwarf2_section_names cu_index
;
367 struct dwarf2_section_names tu_index
;
371 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
372 { ".debug_info.dwo", ".zdebug_info.dwo" },
373 { ".debug_line.dwo", ".zdebug_line.dwo" },
374 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
375 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
376 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
377 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
378 { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo" },
379 { ".debug_str.dwo", ".zdebug_str.dwo" },
380 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
381 { ".debug_types.dwo", ".zdebug_types.dwo" },
382 { ".debug_cu_index", ".zdebug_cu_index" },
383 { ".debug_tu_index", ".zdebug_tu_index" },
386 /* local data types */
388 /* The location list and range list sections (.debug_loclists & .debug_rnglists)
389 begin with a header, which contains the following information. */
390 struct loclists_rnglists_header
392 /* A 4-byte or 12-byte length containing the length of the
393 set of entries for this compilation unit, not including the
394 length field itself. */
397 /* A 2-byte version identifier. */
400 /* A 1-byte unsigned integer containing the size in bytes of an address on
401 the target system. */
402 unsigned char addr_size
;
404 /* A 1-byte unsigned integer containing the size in bytes of a segment selector
405 on the target system. */
406 unsigned char segment_collector_size
;
408 /* A 4-byte count of the number of offsets that follow the header. */
409 unsigned int offset_entry_count
;
412 /* Type used for delaying computation of method physnames.
413 See comments for compute_delayed_physnames. */
414 struct delayed_method_info
416 /* The type to which the method is attached, i.e., its parent class. */
419 /* The index of the method in the type's function fieldlists. */
422 /* The index of the method in the fieldlist. */
425 /* The name of the DIE. */
428 /* The DIE associated with this method. */
429 struct die_info
*die
;
432 /* Internal state when decoding a particular compilation unit. */
435 explicit dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
436 dwarf2_per_objfile
*per_objfile
);
438 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
440 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
441 Create the set of symtabs used by this TU, or if this TU is sharing
442 symtabs with another TU and the symtabs have already been created
443 then restore those symtabs in the line header.
444 We don't need the pc/line-number mapping for type units. */
445 void setup_type_unit_groups (struct die_info
*die
);
447 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
448 buildsym_compunit constructor. */
449 struct compunit_symtab
*start_symtab (const char *name
,
450 const char *comp_dir
,
453 /* Reset the builder. */
454 void reset_builder () { m_builder
.reset (); }
456 /* Return a type that is a generic pointer type, the size of which
457 matches the address size given in the compilation unit header for
459 struct type
*addr_type () const;
461 /* Find an integer type the same size as the address size given in
462 the compilation unit header for this CU. UNSIGNED_P controls if
463 the integer is unsigned or not. */
464 struct type
*addr_sized_int_type (bool unsigned_p
) const;
466 /* The header of the compilation unit. */
467 struct comp_unit_head header
{};
469 /* Base address of this compilation unit. */
470 gdb::optional
<CORE_ADDR
> base_address
;
472 /* The language we are debugging. */
473 enum language language
= language_unknown
;
474 const struct language_defn
*language_defn
= nullptr;
476 const char *producer
= nullptr;
479 /* The symtab builder for this CU. This is only non-NULL when full
480 symbols are being read. */
481 std::unique_ptr
<buildsym_compunit
> m_builder
;
484 /* The generic symbol table building routines have separate lists for
485 file scope symbols and all all other scopes (local scopes). So
486 we need to select the right one to pass to add_symbol_to_list().
487 We do it by keeping a pointer to the correct list in list_in_scope.
489 FIXME: The original dwarf code just treated the file scope as the
490 first local scope, and all other local scopes as nested local
491 scopes, and worked fine. Check to see if we really need to
492 distinguish these in buildsym.c. */
493 struct pending
**list_in_scope
= nullptr;
495 /* Hash table holding all the loaded partial DIEs
496 with partial_die->offset.SECT_OFF as hash. */
497 htab_t partial_dies
= nullptr;
499 /* Storage for things with the same lifetime as this read-in compilation
500 unit, including partial DIEs. */
501 auto_obstack comp_unit_obstack
;
503 /* Backlink to our per_cu entry. */
504 struct dwarf2_per_cu_data
*per_cu
;
506 /* The dwarf2_per_objfile that owns this. */
507 dwarf2_per_objfile
*per_objfile
;
509 /* How many compilation units ago was this CU last referenced? */
512 /* A hash table of DIE cu_offset for following references with
513 die_info->offset.sect_off as hash. */
514 htab_t die_hash
= nullptr;
516 /* Full DIEs if read in. */
517 struct die_info
*dies
= nullptr;
519 /* A set of pointers to dwarf2_per_cu_data objects for compilation
520 units referenced by this one. Only set during full symbol processing;
521 partial symbol tables do not have dependencies. */
522 htab_t dependencies
= nullptr;
524 /* Header data from the line table, during full symbol processing. */
525 struct line_header
*line_header
= nullptr;
526 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
527 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
528 this is the DW_TAG_compile_unit die for this CU. We'll hold on
529 to the line header as long as this DIE is being processed. See
530 process_die_scope. */
531 die_info
*line_header_die_owner
= nullptr;
533 /* A list of methods which need to have physnames computed
534 after all type information has been read. */
535 std::vector
<delayed_method_info
> method_list
;
537 /* To be copied to symtab->call_site_htab. */
538 htab_t call_site_htab
= nullptr;
540 /* Non-NULL if this CU came from a DWO file.
541 There is an invariant here that is important to remember:
542 Except for attributes copied from the top level DIE in the "main"
543 (or "stub") file in preparation for reading the DWO file
544 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
545 Either there isn't a DWO file (in which case this is NULL and the point
546 is moot), or there is and either we're not going to read it (in which
547 case this is NULL) or there is and we are reading it (in which case this
549 struct dwo_unit
*dwo_unit
= nullptr;
551 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
552 Note this value comes from the Fission stub CU/TU's DIE. */
553 gdb::optional
<ULONGEST
> addr_base
;
555 /* The DW_AT_GNU_ranges_base attribute, if present.
557 This is only relevant in the context of pre-DWARF 5 split units. In this
558 context, there is a .debug_ranges section in the linked executable,
559 containing all the ranges data for all the compilation units. Each
560 skeleton/stub unit has (if needed) a DW_AT_GNU_ranges_base attribute that
561 indicates the base of its contribution to that section. The DW_AT_ranges
562 attributes in the split-unit are of the form DW_FORM_sec_offset and point
563 into the .debug_ranges section of the linked file. However, they are not
564 "true" DW_FORM_sec_offset, because they are relative to the base of their
565 compilation unit's contribution, rather than relative to the beginning of
566 the section. The DW_AT_GNU_ranges_base value must be added to it to make
567 it relative to the beginning of the section.
569 Note that the value is zero when we are not in a pre-DWARF 5 split-unit
570 case, so this value can be added without needing to know whether we are in
573 N.B. If a DW_AT_ranges attribute is found on the DW_TAG_compile_unit in the
574 skeleton/stub, it must not have the base added, as it already points to the
575 right place. And since the DW_TAG_compile_unit DIE in the split-unit can't
576 have a DW_AT_ranges attribute, we can use the
578 die->tag != DW_AT_compile_unit
580 to determine whether the base should be added or not. */
581 ULONGEST gnu_ranges_base
= 0;
583 /* The DW_AT_rnglists_base attribute, if present.
585 This is used when processing attributes of form DW_FORM_rnglistx in
586 non-split units. Attributes of this form found in a split unit don't
587 use it, as split-unit files have their own non-shared .debug_rnglists.dwo
589 ULONGEST rnglists_base
= 0;
591 /* The DW_AT_loclists_base attribute if present. */
592 ULONGEST loclist_base
= 0;
594 /* When reading debug info generated by older versions of rustc, we
595 have to rewrite some union types to be struct types with a
596 variant part. This rewriting must be done after the CU is fully
597 read in, because otherwise at the point of rewriting some struct
598 type might not have been fully processed. So, we keep a list of
599 all such types here and process them after expansion. */
600 std::vector
<struct type
*> rust_unions
;
602 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
603 files, the value is implicitly zero. For DWARF 5 version DWO files, the
604 value is often implicit and is the size of the header of
605 .debug_str_offsets section (8 or 4, depending on the address size). */
606 gdb::optional
<ULONGEST
> str_offsets_base
;
608 /* Mark used when releasing cached dies. */
611 /* This CU references .debug_loc. See the symtab->locations_valid field.
612 This test is imperfect as there may exist optimized debug code not using
613 any location list and still facing inlining issues if handled as
614 unoptimized code. For a future better test see GCC PR other/32998. */
615 bool has_loclist
: 1;
617 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
618 if all the producer_is_* fields are valid. This information is cached
619 because profiling CU expansion showed excessive time spent in
620 producer_is_gxx_lt_4_6. */
621 bool checked_producer
: 1;
622 bool producer_is_gxx_lt_4_6
: 1;
623 bool producer_is_gcc_lt_4_3
: 1;
624 bool producer_is_icc
: 1;
625 bool producer_is_icc_lt_14
: 1;
626 bool producer_is_codewarrior
: 1;
628 /* When true, the file that we're processing is known to have
629 debugging info for C++ namespaces. GCC 3.3.x did not produce
630 this information, but later versions do. */
632 bool processing_has_namespace_info
: 1;
634 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
636 /* If this CU was inherited by another CU (via specification,
637 abstract_origin, etc), this is the ancestor CU. */
640 /* Get the buildsym_compunit for this CU. */
641 buildsym_compunit
*get_builder ()
643 /* If this CU has a builder associated with it, use that. */
644 if (m_builder
!= nullptr)
645 return m_builder
.get ();
647 /* Otherwise, search ancestors for a valid builder. */
648 if (ancestor
!= nullptr)
649 return ancestor
->get_builder ();
655 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
656 This includes type_unit_group and quick_file_names. */
658 struct stmt_list_hash
660 /* The DWO unit this table is from or NULL if there is none. */
661 struct dwo_unit
*dwo_unit
;
663 /* Offset in .debug_line or .debug_line.dwo. */
664 sect_offset line_sect_off
;
667 /* Each element of dwarf2_per_bfd->type_unit_groups is a pointer to
668 an object of this type. This contains elements of type unit groups
669 that can be shared across objfiles. The non-shareable parts are in
670 type_unit_group_unshareable. */
672 struct type_unit_group
674 /* dwarf2read.c's main "handle" on a TU symtab.
675 To simplify things we create an artificial CU that "includes" all the
676 type units using this stmt_list so that the rest of the code still has
677 a "per_cu" handle on the symtab. */
678 struct dwarf2_per_cu_data per_cu
;
680 /* The TUs that share this DW_AT_stmt_list entry.
681 This is added to while parsing type units to build partial symtabs,
682 and is deleted afterwards and not used again. */
683 std::vector
<signatured_type
*> *tus
;
685 /* The data used to construct the hash key. */
686 struct stmt_list_hash hash
;
689 /* These sections are what may appear in a (real or virtual) DWO file. */
693 struct dwarf2_section_info abbrev
;
694 struct dwarf2_section_info line
;
695 struct dwarf2_section_info loc
;
696 struct dwarf2_section_info loclists
;
697 struct dwarf2_section_info macinfo
;
698 struct dwarf2_section_info macro
;
699 struct dwarf2_section_info rnglists
;
700 struct dwarf2_section_info str
;
701 struct dwarf2_section_info str_offsets
;
702 /* In the case of a virtual DWO file, these two are unused. */
703 struct dwarf2_section_info info
;
704 std::vector
<dwarf2_section_info
> types
;
707 /* CUs/TUs in DWP/DWO files. */
711 /* Backlink to the containing struct dwo_file. */
712 struct dwo_file
*dwo_file
;
714 /* The "id" that distinguishes this CU/TU.
715 .debug_info calls this "dwo_id", .debug_types calls this "signature".
716 Since signatures came first, we stick with it for consistency. */
719 /* The section this CU/TU lives in, in the DWO file. */
720 struct dwarf2_section_info
*section
;
722 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
723 sect_offset sect_off
;
726 /* For types, offset in the type's DIE of the type defined by this TU. */
727 cu_offset type_offset_in_tu
;
730 /* include/dwarf2.h defines the DWP section codes.
731 It defines a max value but it doesn't define a min value, which we
732 use for error checking, so provide one. */
734 enum dwp_v2_section_ids
739 /* Data for one DWO file.
741 This includes virtual DWO files (a virtual DWO file is a DWO file as it
742 appears in a DWP file). DWP files don't really have DWO files per se -
743 comdat folding of types "loses" the DWO file they came from, and from
744 a high level view DWP files appear to contain a mass of random types.
745 However, to maintain consistency with the non-DWP case we pretend DWP
746 files contain virtual DWO files, and we assign each TU with one virtual
747 DWO file (generally based on the line and abbrev section offsets -
748 a heuristic that seems to work in practice). */
752 dwo_file () = default;
753 DISABLE_COPY_AND_ASSIGN (dwo_file
);
755 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
756 For virtual DWO files the name is constructed from the section offsets
757 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
758 from related CU+TUs. */
759 const char *dwo_name
= nullptr;
761 /* The DW_AT_comp_dir attribute. */
762 const char *comp_dir
= nullptr;
764 /* The bfd, when the file is open. Otherwise this is NULL.
765 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
766 gdb_bfd_ref_ptr dbfd
;
768 /* The sections that make up this DWO file.
769 Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
770 sections (for lack of a better name). */
771 struct dwo_sections sections
{};
773 /* The CUs in the file.
774 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
775 an extension to handle LLVM's Link Time Optimization output (where
776 multiple source files may be compiled into a single object/dwo pair). */
779 /* Table of TUs in the file.
780 Each element is a struct dwo_unit. */
784 /* These sections are what may appear in a DWP file. */
788 /* These are used by all DWP versions (1, 2 and 5). */
789 struct dwarf2_section_info str
;
790 struct dwarf2_section_info cu_index
;
791 struct dwarf2_section_info tu_index
;
793 /* These are only used by DWP version 2 and version 5 files.
794 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
795 sections are referenced by section number, and are not recorded here.
796 In DWP version 2 or 5 there is at most one copy of all these sections,
797 each section being (effectively) comprised of the concatenation of all of
798 the individual sections that exist in the version 1 format.
799 To keep the code simple we treat each of these concatenated pieces as a
800 section itself (a virtual section?). */
801 struct dwarf2_section_info abbrev
;
802 struct dwarf2_section_info info
;
803 struct dwarf2_section_info line
;
804 struct dwarf2_section_info loc
;
805 struct dwarf2_section_info loclists
;
806 struct dwarf2_section_info macinfo
;
807 struct dwarf2_section_info macro
;
808 struct dwarf2_section_info rnglists
;
809 struct dwarf2_section_info str_offsets
;
810 struct dwarf2_section_info types
;
813 /* These sections are what may appear in a virtual DWO file in DWP version 1.
814 A virtual DWO file is a DWO file as it appears in a DWP file. */
816 struct virtual_v1_dwo_sections
818 struct dwarf2_section_info abbrev
;
819 struct dwarf2_section_info line
;
820 struct dwarf2_section_info loc
;
821 struct dwarf2_section_info macinfo
;
822 struct dwarf2_section_info macro
;
823 struct dwarf2_section_info str_offsets
;
824 /* Each DWP hash table entry records one CU or one TU.
825 That is recorded here, and copied to dwo_unit.section. */
826 struct dwarf2_section_info info_or_types
;
829 /* Similar to virtual_v1_dwo_sections, but for DWP version 2 or 5.
830 In version 2, the sections of the DWO files are concatenated together
831 and stored in one section of that name. Thus each ELF section contains
832 several "virtual" sections. */
834 struct virtual_v2_or_v5_dwo_sections
836 bfd_size_type abbrev_offset
;
837 bfd_size_type abbrev_size
;
839 bfd_size_type line_offset
;
840 bfd_size_type line_size
;
842 bfd_size_type loc_offset
;
843 bfd_size_type loc_size
;
845 bfd_size_type loclists_offset
;
846 bfd_size_type loclists_size
;
848 bfd_size_type macinfo_offset
;
849 bfd_size_type macinfo_size
;
851 bfd_size_type macro_offset
;
852 bfd_size_type macro_size
;
854 bfd_size_type rnglists_offset
;
855 bfd_size_type rnglists_size
;
857 bfd_size_type str_offsets_offset
;
858 bfd_size_type str_offsets_size
;
860 /* Each DWP hash table entry records one CU or one TU.
861 That is recorded here, and copied to dwo_unit.section. */
862 bfd_size_type info_or_types_offset
;
863 bfd_size_type info_or_types_size
;
866 /* Contents of DWP hash tables. */
868 struct dwp_hash_table
870 uint32_t version
, nr_columns
;
871 uint32_t nr_units
, nr_slots
;
872 const gdb_byte
*hash_table
, *unit_table
;
877 const gdb_byte
*indices
;
881 /* This is indexed by column number and gives the id of the section
883 #define MAX_NR_V2_DWO_SECTIONS \
884 (1 /* .debug_info or .debug_types */ \
885 + 1 /* .debug_abbrev */ \
886 + 1 /* .debug_line */ \
887 + 1 /* .debug_loc */ \
888 + 1 /* .debug_str_offsets */ \
889 + 1 /* .debug_macro or .debug_macinfo */)
890 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
891 const gdb_byte
*offsets
;
892 const gdb_byte
*sizes
;
896 /* This is indexed by column number and gives the id of the section
898 #define MAX_NR_V5_DWO_SECTIONS \
899 (1 /* .debug_info */ \
900 + 1 /* .debug_abbrev */ \
901 + 1 /* .debug_line */ \
902 + 1 /* .debug_loclists */ \
903 + 1 /* .debug_str_offsets */ \
904 + 1 /* .debug_macro */ \
905 + 1 /* .debug_rnglists */)
906 int section_ids
[MAX_NR_V5_DWO_SECTIONS
];
907 const gdb_byte
*offsets
;
908 const gdb_byte
*sizes
;
913 /* Data for one DWP file. */
917 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
919 dbfd (std::move (abfd
))
923 /* Name of the file. */
926 /* File format version. */
930 gdb_bfd_ref_ptr dbfd
;
932 /* Section info for this file. */
933 struct dwp_sections sections
{};
935 /* Table of CUs in the file. */
936 const struct dwp_hash_table
*cus
= nullptr;
938 /* Table of TUs in the file. */
939 const struct dwp_hash_table
*tus
= nullptr;
941 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
945 /* Table to map ELF section numbers to their sections.
946 This is only needed for the DWP V1 file format. */
947 unsigned int num_sections
= 0;
948 asection
**elf_sections
= nullptr;
951 /* Struct used to pass misc. parameters to read_die_and_children, et
952 al. which are used for both .debug_info and .debug_types dies.
953 All parameters here are unchanging for the life of the call. This
954 struct exists to abstract away the constant parameters of die reading. */
956 struct die_reader_specs
958 /* The bfd of die_section. */
961 /* The CU of the DIE we are parsing. */
962 struct dwarf2_cu
*cu
;
964 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
965 struct dwo_file
*dwo_file
;
967 /* The section the die comes from.
968 This is either .debug_info or .debug_types, or the .dwo variants. */
969 struct dwarf2_section_info
*die_section
;
971 /* die_section->buffer. */
972 const gdb_byte
*buffer
;
974 /* The end of the buffer. */
975 const gdb_byte
*buffer_end
;
977 /* The abbreviation table to use when reading the DIEs. */
978 struct abbrev_table
*abbrev_table
;
981 /* A subclass of die_reader_specs that holds storage and has complex
982 constructor and destructor behavior. */
984 class cutu_reader
: public die_reader_specs
988 cutu_reader (dwarf2_per_cu_data
*this_cu
,
989 dwarf2_per_objfile
*per_objfile
,
990 struct abbrev_table
*abbrev_table
,
991 dwarf2_cu
*existing_cu
,
994 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
995 dwarf2_per_objfile
*per_objfile
,
996 struct dwarf2_cu
*parent_cu
= nullptr,
997 struct dwo_file
*dwo_file
= nullptr);
999 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
1001 const gdb_byte
*info_ptr
= nullptr;
1002 struct die_info
*comp_unit_die
= nullptr;
1003 bool dummy_p
= false;
1005 /* Release the new CU, putting it on the chain. This cannot be done
1010 void init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
1011 dwarf2_per_objfile
*per_objfile
,
1012 dwarf2_cu
*existing_cu
);
1014 struct dwarf2_per_cu_data
*m_this_cu
;
1015 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
1017 /* The ordinary abbreviation table. */
1018 abbrev_table_up m_abbrev_table_holder
;
1020 /* The DWO abbreviation table. */
1021 abbrev_table_up m_dwo_abbrev_table
;
1024 /* When we construct a partial symbol table entry we only
1025 need this much information. */
1026 struct partial_die_info
: public allocate_on_obstack
1028 partial_die_info (sect_offset sect_off
, const struct abbrev_info
*abbrev
);
1030 /* Disable assign but still keep copy ctor, which is needed
1031 load_partial_dies. */
1032 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1034 /* Adjust the partial die before generating a symbol for it. This
1035 function may set the is_external flag or change the DIE's
1037 void fixup (struct dwarf2_cu
*cu
);
1039 /* Read a minimal amount of information into the minimal die
1041 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1042 const struct abbrev_info
&abbrev
,
1043 const gdb_byte
*info_ptr
);
1045 /* Compute the name of this partial DIE. This memoizes the
1046 result, so it is safe to call multiple times. */
1047 const char *name (dwarf2_cu
*cu
);
1049 /* Offset of this DIE. */
1050 const sect_offset sect_off
;
1052 /* DWARF-2 tag for this DIE. */
1053 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1055 /* Assorted flags describing the data found in this DIE. */
1056 const unsigned int has_children
: 1;
1058 unsigned int is_external
: 1;
1059 unsigned int is_declaration
: 1;
1060 unsigned int has_type
: 1;
1061 unsigned int has_specification
: 1;
1062 unsigned int has_pc_info
: 1;
1063 unsigned int may_be_inlined
: 1;
1065 /* This DIE has been marked DW_AT_main_subprogram. */
1066 unsigned int main_subprogram
: 1;
1068 /* Flag set if the SCOPE field of this structure has been
1070 unsigned int scope_set
: 1;
1072 /* Flag set if the DIE has a byte_size attribute. */
1073 unsigned int has_byte_size
: 1;
1075 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1076 unsigned int has_const_value
: 1;
1078 /* Flag set if any of the DIE's children are template arguments. */
1079 unsigned int has_template_arguments
: 1;
1081 /* Flag set if fixup has been called on this die. */
1082 unsigned int fixup_called
: 1;
1084 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1085 unsigned int is_dwz
: 1;
1087 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1088 unsigned int spec_is_dwz
: 1;
1090 unsigned int canonical_name
: 1;
1092 /* The name of this DIE. Normally the value of DW_AT_name, but
1093 sometimes a default name for unnamed DIEs. */
1094 const char *raw_name
= nullptr;
1096 /* The linkage name, if present. */
1097 const char *linkage_name
= nullptr;
1099 /* The scope to prepend to our children. This is generally
1100 allocated on the comp_unit_obstack, so will disappear
1101 when this compilation unit leaves the cache. */
1102 const char *scope
= nullptr;
1104 /* Some data associated with the partial DIE. The tag determines
1105 which field is live. */
1108 /* The location description associated with this DIE, if any. */
1109 struct dwarf_block
*locdesc
;
1110 /* The offset of an import, for DW_TAG_imported_unit. */
1111 sect_offset sect_off
;
1114 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1115 CORE_ADDR lowpc
= 0;
1116 CORE_ADDR highpc
= 0;
1118 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1119 DW_AT_sibling, if any. */
1120 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1121 could return DW_AT_sibling values to its caller load_partial_dies. */
1122 const gdb_byte
*sibling
= nullptr;
1124 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1125 DW_AT_specification (or DW_AT_abstract_origin or
1126 DW_AT_extension). */
1127 sect_offset spec_offset
{};
1129 /* Pointers to this DIE's parent, first child, and next sibling,
1131 struct partial_die_info
*die_parent
= nullptr;
1132 struct partial_die_info
*die_child
= nullptr;
1133 struct partial_die_info
*die_sibling
= nullptr;
1135 friend struct partial_die_info
*
1136 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1139 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1140 partial_die_info (sect_offset sect_off
)
1141 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1145 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1147 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1152 has_specification
= 0;
1155 main_subprogram
= 0;
1158 has_const_value
= 0;
1159 has_template_arguments
= 0;
1167 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1168 but this would require a corresponding change in unpack_field_as_long
1170 static int bits_per_byte
= 8;
1172 struct variant_part_builder
;
1174 /* When reading a variant, we track a bit more information about the
1175 field, and store it in an object of this type. */
1177 struct variant_field
1179 int first_field
= -1;
1180 int last_field
= -1;
1182 /* A variant can contain other variant parts. */
1183 std::vector
<variant_part_builder
> variant_parts
;
1185 /* If we see a DW_TAG_variant, then this will be set if this is the
1187 bool default_branch
= false;
1188 /* If we see a DW_AT_discr_value, then this will be the discriminant
1190 ULONGEST discriminant_value
= 0;
1191 /* If we see a DW_AT_discr_list, then this is a pointer to the list
1193 struct dwarf_block
*discr_list_data
= nullptr;
1196 /* This represents a DW_TAG_variant_part. */
1198 struct variant_part_builder
1200 /* The offset of the discriminant field. */
1201 sect_offset discriminant_offset
{};
1203 /* Variants that are direct children of this variant part. */
1204 std::vector
<variant_field
> variants
;
1206 /* True if we're currently reading a variant. */
1207 bool processing_variant
= false;
1212 int accessibility
= 0;
1214 /* Variant parts need to find the discriminant, which is a DIE
1215 reference. We track the section offset of each field to make
1218 struct field field
{};
1223 const char *name
= nullptr;
1224 std::vector
<struct fn_field
> fnfields
;
1227 /* The routines that read and process dies for a C struct or C++ class
1228 pass lists of data member fields and lists of member function fields
1229 in an instance of a field_info structure, as defined below. */
1232 /* List of data member and baseclasses fields. */
1233 std::vector
<struct nextfield
> fields
;
1234 std::vector
<struct nextfield
> baseclasses
;
1236 /* Set if the accessibility of one of the fields is not public. */
1237 bool non_public_fields
= false;
1239 /* Member function fieldlist array, contains name of possibly overloaded
1240 member function, number of overloaded member functions and a pointer
1241 to the head of the member function field chain. */
1242 std::vector
<struct fnfieldlist
> fnfieldlists
;
1244 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1245 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1246 std::vector
<struct decl_field
> typedef_field_list
;
1248 /* Nested types defined by this class and the number of elements in this
1250 std::vector
<struct decl_field
> nested_types_list
;
1252 /* If non-null, this is the variant part we are currently
1254 variant_part_builder
*current_variant_part
= nullptr;
1255 /* This holds all the top-level variant parts attached to the type
1257 std::vector
<variant_part_builder
> variant_parts
;
1259 /* Return the total number of fields (including baseclasses). */
1260 int nfields () const
1262 return fields
.size () + baseclasses
.size ();
1266 /* Loaded secondary compilation units are kept in memory until they
1267 have not been referenced for the processing of this many
1268 compilation units. Set this to zero to disable caching. Cache
1269 sizes of up to at least twenty will improve startup time for
1270 typical inter-CU-reference binaries, at an obvious memory cost. */
1271 static int dwarf_max_cache_age
= 5;
1273 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1274 struct cmd_list_element
*c
, const char *value
)
1276 fprintf_filtered (file
, _("The upper bound on the age of cached "
1277 "DWARF compilation units is %s.\n"),
1281 /* local function prototypes */
1283 static void dwarf2_find_base_address (struct die_info
*die
,
1284 struct dwarf2_cu
*cu
);
1286 static dwarf2_psymtab
*create_partial_symtab
1287 (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
1290 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1291 const gdb_byte
*info_ptr
,
1292 struct die_info
*type_unit_die
);
1294 static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
);
1296 static void scan_partial_symbols (struct partial_die_info
*,
1297 CORE_ADDR
*, CORE_ADDR
*,
1298 int, struct dwarf2_cu
*);
1300 static void add_partial_symbol (struct partial_die_info
*,
1301 struct dwarf2_cu
*);
1303 static void add_partial_namespace (struct partial_die_info
*pdi
,
1304 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1305 int set_addrmap
, struct dwarf2_cu
*cu
);
1307 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1308 CORE_ADDR
*highpc
, int set_addrmap
,
1309 struct dwarf2_cu
*cu
);
1311 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1312 struct dwarf2_cu
*cu
);
1314 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1315 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1316 int need_pc
, struct dwarf2_cu
*cu
);
1318 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1320 static struct partial_die_info
*load_partial_dies
1321 (const struct die_reader_specs
*, const gdb_byte
*, int);
1323 /* A pair of partial_die_info and compilation unit. */
1324 struct cu_partial_die_info
1326 /* The compilation unit of the partial_die_info. */
1327 struct dwarf2_cu
*cu
;
1328 /* A partial_die_info. */
1329 struct partial_die_info
*pdi
;
1331 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1337 cu_partial_die_info () = delete;
1340 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1341 struct dwarf2_cu
*);
1343 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1345 const struct attr_abbrev
*,
1348 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1349 struct attribute
*attr
, dwarf_tag tag
);
1351 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1353 static sect_offset
read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
1354 dwarf2_section_info
*, sect_offset
);
1356 static const char *read_indirect_string
1357 (dwarf2_per_objfile
*per_objfile
, bfd
*, const gdb_byte
*,
1358 const struct comp_unit_head
*, unsigned int *);
1360 static const char *read_indirect_string_at_offset
1361 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
1363 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1367 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1368 ULONGEST str_index
);
1370 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1371 ULONGEST str_index
);
1373 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1375 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1376 struct dwarf2_cu
*);
1378 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1379 struct dwarf2_cu
*cu
);
1381 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1383 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1384 struct dwarf2_cu
*cu
);
1386 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1388 static struct die_info
*die_specification (struct die_info
*die
,
1389 struct dwarf2_cu
**);
1391 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1392 struct dwarf2_cu
*cu
);
1394 static void dwarf_decode_lines (struct line_header
*, const char *,
1395 struct dwarf2_cu
*, dwarf2_psymtab
*,
1396 CORE_ADDR
, int decode_mapping
);
1398 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1401 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1402 struct dwarf2_cu
*, struct symbol
* = NULL
);
1404 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1405 struct dwarf2_cu
*);
1407 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1410 struct obstack
*obstack
,
1411 struct dwarf2_cu
*cu
, LONGEST
*value
,
1412 const gdb_byte
**bytes
,
1413 struct dwarf2_locexpr_baton
**baton
);
1415 static struct type
*read_subrange_index_type (struct die_info
*die
,
1416 struct dwarf2_cu
*cu
);
1418 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1420 static int need_gnat_info (struct dwarf2_cu
*);
1422 static struct type
*die_descriptive_type (struct die_info
*,
1423 struct dwarf2_cu
*);
1425 static void set_descriptive_type (struct type
*, struct die_info
*,
1426 struct dwarf2_cu
*);
1428 static struct type
*die_containing_type (struct die_info
*,
1429 struct dwarf2_cu
*);
1431 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1432 struct dwarf2_cu
*);
1434 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1436 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1438 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1440 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1441 const char *suffix
, int physname
,
1442 struct dwarf2_cu
*cu
);
1444 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1446 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1448 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1450 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1452 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1454 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1456 /* Return the .debug_loclists section to use for cu. */
1457 static struct dwarf2_section_info
*cu_debug_loc_section (struct dwarf2_cu
*cu
);
1459 /* Return the .debug_rnglists section to use for cu. */
1460 static struct dwarf2_section_info
*cu_debug_rnglists_section
1461 (struct dwarf2_cu
*cu
, dwarf_tag tag
);
1463 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1464 values. Keep the items ordered with increasing constraints compliance. */
1467 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1468 PC_BOUNDS_NOT_PRESENT
,
1470 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1471 were present but they do not form a valid range of PC addresses. */
1474 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1477 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1481 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1482 CORE_ADDR
*, CORE_ADDR
*,
1486 static void get_scope_pc_bounds (struct die_info
*,
1487 CORE_ADDR
*, CORE_ADDR
*,
1488 struct dwarf2_cu
*);
1490 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1491 CORE_ADDR
, struct dwarf2_cu
*);
1493 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1494 struct dwarf2_cu
*);
1496 static void dwarf2_attach_fields_to_type (struct field_info
*,
1497 struct type
*, struct dwarf2_cu
*);
1499 static void dwarf2_add_member_fn (struct field_info
*,
1500 struct die_info
*, struct type
*,
1501 struct dwarf2_cu
*);
1503 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1505 struct dwarf2_cu
*);
1507 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1509 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1511 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1513 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1515 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1517 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1519 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1521 static struct type
*read_module_type (struct die_info
*die
,
1522 struct dwarf2_cu
*cu
);
1524 static const char *namespace_name (struct die_info
*die
,
1525 int *is_anonymous
, struct dwarf2_cu
*);
1527 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1529 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*,
1532 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1533 struct dwarf2_cu
*);
1535 static struct die_info
*read_die_and_siblings_1
1536 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1539 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1540 const gdb_byte
*info_ptr
,
1541 const gdb_byte
**new_info_ptr
,
1542 struct die_info
*parent
);
1544 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1545 struct die_info
**, const gdb_byte
*,
1548 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1549 struct die_info
**, const gdb_byte
*);
1551 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1553 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1556 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1558 static const char *dwarf2_full_name (const char *name
,
1559 struct die_info
*die
,
1560 struct dwarf2_cu
*cu
);
1562 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1563 struct dwarf2_cu
*cu
);
1565 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1566 struct dwarf2_cu
**);
1568 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1570 static void dump_die_for_error (struct die_info
*);
1572 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1575 /*static*/ void dump_die (struct die_info
*, int max_level
);
1577 static void store_in_ref_table (struct die_info
*,
1578 struct dwarf2_cu
*);
1580 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1581 const struct attribute
*,
1582 struct dwarf2_cu
**);
1584 static struct die_info
*follow_die_ref (struct die_info
*,
1585 const struct attribute
*,
1586 struct dwarf2_cu
**);
1588 static struct die_info
*follow_die_sig (struct die_info
*,
1589 const struct attribute
*,
1590 struct dwarf2_cu
**);
1592 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1593 struct dwarf2_cu
*);
1595 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1596 const struct attribute
*,
1597 struct dwarf2_cu
*);
1599 static void load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
1600 dwarf2_per_objfile
*per_objfile
);
1602 static void read_signatured_type (signatured_type
*sig_type
,
1603 dwarf2_per_objfile
*per_objfile
);
1605 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1606 struct die_info
*die
, struct dwarf2_cu
*cu
,
1607 struct dynamic_prop
*prop
, struct type
*type
);
1609 /* memory allocation interface */
1611 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1613 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1615 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1617 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1618 struct dwarf2_loclist_baton
*baton
,
1619 const struct attribute
*attr
);
1621 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1623 struct dwarf2_cu
*cu
,
1626 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1627 const gdb_byte
*info_ptr
,
1628 const struct abbrev_info
*abbrev
);
1630 static hashval_t
partial_die_hash (const void *item
);
1632 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1634 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1635 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1636 dwarf2_per_objfile
*per_objfile
);
1638 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1639 struct die_info
*comp_unit_die
,
1640 enum language pretend_language
);
1642 static struct type
*set_die_type (struct die_info
*, struct type
*,
1643 struct dwarf2_cu
*, bool = false);
1645 static void create_all_comp_units (dwarf2_per_objfile
*per_objfile
);
1647 static int create_all_type_units (dwarf2_per_objfile
*per_objfile
);
1649 static void load_full_comp_unit (dwarf2_per_cu_data
*per_cu
,
1650 dwarf2_per_objfile
*per_objfile
,
1651 dwarf2_cu
*existing_cu
,
1653 enum language pretend_language
);
1655 static void process_full_comp_unit (dwarf2_cu
*cu
,
1656 enum language pretend_language
);
1658 static void process_full_type_unit (dwarf2_cu
*cu
,
1659 enum language pretend_language
);
1661 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1662 struct dwarf2_per_cu_data
*);
1664 static void dwarf2_mark (struct dwarf2_cu
*);
1666 static struct type
*get_die_type_at_offset (sect_offset
,
1667 dwarf2_per_cu_data
*per_cu
,
1668 dwarf2_per_objfile
*per_objfile
);
1670 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1672 static void queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
1673 dwarf2_per_objfile
*per_objfile
,
1674 enum language pretend_language
);
1676 static void process_queue (dwarf2_per_objfile
*per_objfile
);
1678 /* Class, the destructor of which frees all allocated queue entries. This
1679 will only have work to do if an error was thrown while processing the
1680 dwarf. If no error was thrown then the queue entries should have all
1681 been processed, and freed, as we went along. */
1683 class dwarf2_queue_guard
1686 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1687 : m_per_objfile (per_objfile
)
1689 gdb_assert (!m_per_objfile
->per_bfd
->queue
.has_value ());
1691 m_per_objfile
->per_bfd
->queue
.emplace ();
1694 /* Free any entries remaining on the queue. There should only be
1695 entries left if we hit an error while processing the dwarf. */
1696 ~dwarf2_queue_guard ()
1698 gdb_assert (m_per_objfile
->per_bfd
->queue
.has_value ());
1700 m_per_objfile
->per_bfd
->queue
.reset ();
1703 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1706 dwarf2_per_objfile
*m_per_objfile
;
1709 dwarf2_queue_item::~dwarf2_queue_item ()
1711 /* Anything still marked queued is likely to be in an
1712 inconsistent state, so discard it. */
1715 per_objfile
->remove_cu (per_cu
);
1720 /* The return type of find_file_and_directory. Note, the enclosed
1721 string pointers are only valid while this object is valid. */
1723 struct file_and_directory
1725 /* The filename. This is never NULL. */
1728 /* The compilation directory. NULL if not known. If we needed to
1729 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1730 points directly to the DW_AT_comp_dir string attribute owned by
1731 the obstack that owns the DIE. */
1732 const char *comp_dir
;
1734 /* If we needed to build a new string for comp_dir, this is what
1735 owns the storage. */
1736 std::string comp_dir_storage
;
1739 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1740 struct dwarf2_cu
*cu
);
1742 static htab_up
allocate_signatured_type_table ();
1744 static htab_up
allocate_dwo_unit_table ();
1746 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1747 (dwarf2_per_objfile
*per_objfile
, struct dwp_file
*dwp_file
,
1748 const char *comp_dir
, ULONGEST signature
, int is_debug_types
);
1750 static struct dwp_file
*get_dwp_file (dwarf2_per_objfile
*per_objfile
);
1752 static struct dwo_unit
*lookup_dwo_comp_unit
1753 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
1754 ULONGEST signature
);
1756 static struct dwo_unit
*lookup_dwo_type_unit
1757 (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
);
1759 static void queue_and_load_all_dwo_tus (dwarf2_cu
*cu
);
1761 /* A unique pointer to a dwo_file. */
1763 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1765 static void process_cu_includes (dwarf2_per_objfile
*per_objfile
);
1767 static void check_producer (struct dwarf2_cu
*cu
);
1769 static void free_line_header_voidp (void *arg
);
1771 /* Various complaints about symbol reading that don't abort the process. */
1774 dwarf2_debug_line_missing_file_complaint (void)
1776 complaint (_(".debug_line section has line data without a file"));
1780 dwarf2_debug_line_missing_end_sequence_complaint (void)
1782 complaint (_(".debug_line section has line "
1783 "program sequence without an end"));
1787 dwarf2_complex_location_expr_complaint (void)
1789 complaint (_("location expression too complex"));
1793 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1796 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1801 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1803 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1807 /* Hash function for line_header_hash. */
1810 line_header_hash (const struct line_header
*ofs
)
1812 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1815 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1818 line_header_hash_voidp (const void *item
)
1820 const struct line_header
*ofs
= (const struct line_header
*) item
;
1822 return line_header_hash (ofs
);
1825 /* Equality function for line_header_hash. */
1828 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1830 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1831 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1833 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1834 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1839 /* See declaration. */
1841 dwarf2_per_bfd::dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
,
1844 can_copy (can_copy_
)
1847 names
= &dwarf2_elf_names
;
1849 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1850 locate_sections (obfd
, sec
, *names
);
1853 dwarf2_per_bfd::~dwarf2_per_bfd ()
1855 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1856 per_cu
->imported_symtabs_free ();
1858 for (signatured_type
*sig_type
: all_type_units
)
1859 sig_type
->per_cu
.imported_symtabs_free ();
1861 /* Everything else should be on this->obstack. */
1867 dwarf2_per_objfile::remove_all_cus ()
1869 gdb_assert (!this->per_bfd
->queue
.has_value ());
1871 for (auto pair
: m_dwarf2_cus
)
1874 m_dwarf2_cus
.clear ();
1877 /* A helper class that calls free_cached_comp_units on
1880 class free_cached_comp_units
1884 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1885 : m_per_objfile (per_objfile
)
1889 ~free_cached_comp_units ()
1891 m_per_objfile
->remove_all_cus ();
1894 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1898 dwarf2_per_objfile
*m_per_objfile
;
1904 dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const
1906 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1908 return this->m_symtabs
[per_cu
->index
] != nullptr;
1914 dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data
*per_cu
) const
1916 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1918 return this->m_symtabs
[per_cu
->index
];
1924 dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data
*per_cu
,
1925 compunit_symtab
*symtab
)
1927 gdb_assert (per_cu
->index
< this->m_symtabs
.size ());
1928 gdb_assert (this->m_symtabs
[per_cu
->index
] == nullptr);
1930 this->m_symtabs
[per_cu
->index
] = symtab
;
1933 /* Try to locate the sections we need for DWARF 2 debugging
1934 information and return true if we have enough to do something.
1935 NAMES points to the dwarf2 section names, or is NULL if the standard
1936 ELF names are used. CAN_COPY is true for formats where symbol
1937 interposition is possible and so symbol values must follow copy
1938 relocation rules. */
1941 dwarf2_has_info (struct objfile
*objfile
,
1942 const struct dwarf2_debug_sections
*names
,
1945 if (objfile
->flags
& OBJF_READNEVER
)
1948 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1950 if (per_objfile
== NULL
)
1952 dwarf2_per_bfd
*per_bfd
;
1954 /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD
1955 doesn't require relocations. */
1956 if (!gdb_bfd_requires_relocations (objfile
->obfd
))
1958 /* See if one has been created for this BFD yet. */
1959 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1961 if (per_bfd
== nullptr)
1963 /* No, create it now. */
1964 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1965 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1970 /* No sharing possible, create one specifically for this objfile. */
1971 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1972 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1975 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1978 return (!per_objfile
->per_bfd
->info
.is_virtual
1979 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1980 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1981 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1984 /* See declaration. */
1987 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1988 const dwarf2_debug_sections
&names
)
1990 flagword aflag
= bfd_section_flags (sectp
);
1992 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1995 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1996 > bfd_get_file_size (abfd
))
1998 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1999 warning (_("Discarding section %s which has a section size (%s"
2000 ") larger than the file size [in module %s]"),
2001 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2002 bfd_get_filename (abfd
));
2004 else if (names
.info
.matches (sectp
->name
))
2006 this->info
.s
.section
= sectp
;
2007 this->info
.size
= bfd_section_size (sectp
);
2009 else if (names
.abbrev
.matches (sectp
->name
))
2011 this->abbrev
.s
.section
= sectp
;
2012 this->abbrev
.size
= bfd_section_size (sectp
);
2014 else if (names
.line
.matches (sectp
->name
))
2016 this->line
.s
.section
= sectp
;
2017 this->line
.size
= bfd_section_size (sectp
);
2019 else if (names
.loc
.matches (sectp
->name
))
2021 this->loc
.s
.section
= sectp
;
2022 this->loc
.size
= bfd_section_size (sectp
);
2024 else if (names
.loclists
.matches (sectp
->name
))
2026 this->loclists
.s
.section
= sectp
;
2027 this->loclists
.size
= bfd_section_size (sectp
);
2029 else if (names
.macinfo
.matches (sectp
->name
))
2031 this->macinfo
.s
.section
= sectp
;
2032 this->macinfo
.size
= bfd_section_size (sectp
);
2034 else if (names
.macro
.matches (sectp
->name
))
2036 this->macro
.s
.section
= sectp
;
2037 this->macro
.size
= bfd_section_size (sectp
);
2039 else if (names
.str
.matches (sectp
->name
))
2041 this->str
.s
.section
= sectp
;
2042 this->str
.size
= bfd_section_size (sectp
);
2044 else if (names
.str_offsets
.matches (sectp
->name
))
2046 this->str_offsets
.s
.section
= sectp
;
2047 this->str_offsets
.size
= bfd_section_size (sectp
);
2049 else if (names
.line_str
.matches (sectp
->name
))
2051 this->line_str
.s
.section
= sectp
;
2052 this->line_str
.size
= bfd_section_size (sectp
);
2054 else if (names
.addr
.matches (sectp
->name
))
2056 this->addr
.s
.section
= sectp
;
2057 this->addr
.size
= bfd_section_size (sectp
);
2059 else if (names
.frame
.matches (sectp
->name
))
2061 this->frame
.s
.section
= sectp
;
2062 this->frame
.size
= bfd_section_size (sectp
);
2064 else if (names
.eh_frame
.matches (sectp
->name
))
2066 this->eh_frame
.s
.section
= sectp
;
2067 this->eh_frame
.size
= bfd_section_size (sectp
);
2069 else if (names
.ranges
.matches (sectp
->name
))
2071 this->ranges
.s
.section
= sectp
;
2072 this->ranges
.size
= bfd_section_size (sectp
);
2074 else if (names
.rnglists
.matches (sectp
->name
))
2076 this->rnglists
.s
.section
= sectp
;
2077 this->rnglists
.size
= bfd_section_size (sectp
);
2079 else if (names
.types
.matches (sectp
->name
))
2081 struct dwarf2_section_info type_section
;
2083 memset (&type_section
, 0, sizeof (type_section
));
2084 type_section
.s
.section
= sectp
;
2085 type_section
.size
= bfd_section_size (sectp
);
2087 this->types
.push_back (type_section
);
2089 else if (names
.gdb_index
.matches (sectp
->name
))
2091 this->gdb_index
.s
.section
= sectp
;
2092 this->gdb_index
.size
= bfd_section_size (sectp
);
2094 else if (names
.debug_names
.matches (sectp
->name
))
2096 this->debug_names
.s
.section
= sectp
;
2097 this->debug_names
.size
= bfd_section_size (sectp
);
2099 else if (names
.debug_aranges
.matches (sectp
->name
))
2101 this->debug_aranges
.s
.section
= sectp
;
2102 this->debug_aranges
.size
= bfd_section_size (sectp
);
2105 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2106 && bfd_section_vma (sectp
) == 0)
2107 this->has_section_at_zero
= true;
2110 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2114 dwarf2_get_section_info (struct objfile
*objfile
,
2115 enum dwarf2_section_enum sect
,
2116 asection
**sectp
, const gdb_byte
**bufp
,
2117 bfd_size_type
*sizep
)
2119 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2120 struct dwarf2_section_info
*info
;
2122 /* We may see an objfile without any DWARF, in which case we just
2124 if (per_objfile
== NULL
)
2133 case DWARF2_DEBUG_FRAME
:
2134 info
= &per_objfile
->per_bfd
->frame
;
2136 case DWARF2_EH_FRAME
:
2137 info
= &per_objfile
->per_bfd
->eh_frame
;
2140 gdb_assert_not_reached ("unexpected section");
2143 info
->read (objfile
);
2145 *sectp
= info
->get_bfd_section ();
2146 *bufp
= info
->buffer
;
2147 *sizep
= info
->size
;
2151 /* DWARF quick_symbol_functions support. */
2153 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2154 unique line tables, so we maintain a separate table of all .debug_line
2155 derived entries to support the sharing.
2156 All the quick functions need is the list of file names. We discard the
2157 line_header when we're done and don't need to record it here. */
2158 struct quick_file_names
2160 /* The data used to construct the hash key. */
2161 struct stmt_list_hash hash
;
2163 /* The number of entries in file_names, real_names. */
2164 unsigned int num_file_names
;
2166 /* The file names from the line table, after being run through
2168 const char **file_names
;
2170 /* The file names from the line table after being run through
2171 gdb_realpath. These are computed lazily. */
2172 const char **real_names
;
2175 /* When using the index (and thus not using psymtabs), each CU has an
2176 object of this type. This is used to hold information needed by
2177 the various "quick" methods. */
2178 struct dwarf2_per_cu_quick_data
2180 /* The file table. This can be NULL if there was no file table
2181 or it's currently not read in.
2182 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2183 struct quick_file_names
*file_names
;
2185 /* A temporary mark bit used when iterating over all CUs in
2186 expand_symtabs_matching. */
2187 unsigned int mark
: 1;
2189 /* True if we've tried to read the file table and found there isn't one.
2190 There will be no point in trying to read it again next time. */
2191 unsigned int no_file_data
: 1;
2194 struct dwarf2_base_index_functions
: public quick_symbol_functions
2196 bool has_symbols (struct objfile
*objfile
) override
;
2198 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
2200 void forget_cached_source_info (struct objfile
*objfile
) override
;
2202 bool map_symtabs_matching_filename
2203 (struct objfile
*objfile
, const char *name
, const char *real_path
,
2204 gdb::function_view
<bool (symtab
*)> callback
) override
;
2206 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
2209 bool *symbol_found_p
) override
2211 *symbol_found_p
= false;
2212 return language_unknown
;
2215 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
2217 void expand_all_symtabs (struct objfile
*objfile
) override
;
2219 void expand_symtabs_with_fullname (struct objfile
*objfile
,
2220 const char *fullname
) override
;
2222 struct compunit_symtab
*find_pc_sect_compunit_symtab
2223 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
2224 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
2226 struct compunit_symtab
*find_compunit_symtab_by_address
2227 (struct objfile
*objfile
, CORE_ADDR address
) override
2232 void map_symbol_filenames (struct objfile
*objfile
,
2233 symbol_filename_ftype
*fun
, void *data
,
2234 int need_fullname
) override
;
2237 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
2239 struct compunit_symtab
*lookup_symbol (struct objfile
*objfile
,
2240 block_enum block_index
,
2242 domain_enum domain
) override
;
2244 void dump (struct objfile
*objfile
) override
;
2246 void expand_symtabs_for_function (struct objfile
*objfile
,
2247 const char *func_name
) override
;
2249 void map_matching_symbols
2251 const lookup_name_info
&lookup_name
,
2254 gdb::function_view
<symbol_found_callback_ftype
> callback
,
2255 symbol_compare_ftype
*ordered_compare
) override
;
2257 void expand_symtabs_matching
2258 (struct objfile
*objfile
,
2259 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2260 const lookup_name_info
*lookup_name
,
2261 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2262 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2263 enum search_domain kind
) override
;
2266 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
2268 struct compunit_symtab
*lookup_symbol (struct objfile
*objfile
,
2269 block_enum block_index
,
2271 domain_enum domain
) override
;
2273 void dump (struct objfile
*objfile
) override
;
2275 void expand_symtabs_for_function (struct objfile
*objfile
,
2276 const char *func_name
) override
;
2278 void map_matching_symbols
2280 const lookup_name_info
&lookup_name
,
2283 gdb::function_view
<symbol_found_callback_ftype
> callback
,
2284 symbol_compare_ftype
*ordered_compare
) override
;
2286 void expand_symtabs_matching
2287 (struct objfile
*objfile
,
2288 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2289 const lookup_name_info
*lookup_name
,
2290 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2291 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2292 enum search_domain kind
) override
;
2295 quick_symbol_functions_up
2296 make_dwarf_gdb_index ()
2298 return quick_symbol_functions_up (new dwarf2_gdb_index
);
2301 quick_symbol_functions_up
2302 make_dwarf_debug_names ()
2304 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
2307 /* Utility hash function for a stmt_list_hash. */
2310 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2314 if (stmt_list_hash
->dwo_unit
!= NULL
)
2315 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2316 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2320 /* Utility equality function for a stmt_list_hash. */
2323 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2324 const struct stmt_list_hash
*rhs
)
2326 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2328 if (lhs
->dwo_unit
!= NULL
2329 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2332 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2335 /* Hash function for a quick_file_names. */
2338 hash_file_name_entry (const void *e
)
2340 const struct quick_file_names
*file_data
2341 = (const struct quick_file_names
*) e
;
2343 return hash_stmt_list_entry (&file_data
->hash
);
2346 /* Equality function for a quick_file_names. */
2349 eq_file_name_entry (const void *a
, const void *b
)
2351 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2352 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2354 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2357 /* Delete function for a quick_file_names. */
2360 delete_file_name_entry (void *e
)
2362 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2365 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2367 xfree ((void*) file_data
->file_names
[i
]);
2368 if (file_data
->real_names
)
2369 xfree ((void*) file_data
->real_names
[i
]);
2372 /* The space for the struct itself lives on the obstack, so we don't
2376 /* Create a quick_file_names hash table. */
2379 create_quick_file_names_table (unsigned int nr_initial_entries
)
2381 return htab_up (htab_create_alloc (nr_initial_entries
,
2382 hash_file_name_entry
, eq_file_name_entry
,
2383 delete_file_name_entry
, xcalloc
, xfree
));
2386 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2387 function is unrelated to symtabs, symtab would have to be created afterwards.
2388 You should call age_cached_comp_units after processing the CU. */
2391 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2394 if (per_cu
->is_debug_types
)
2395 load_full_type_unit (per_cu
, per_objfile
);
2397 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2398 skip_partial
, language_minimal
);
2400 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2402 return nullptr; /* Dummy CU. */
2404 dwarf2_find_base_address (cu
->dies
, cu
);
2409 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2412 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2413 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2415 /* Skip type_unit_groups, reading the type units they contain
2416 is handled elsewhere. */
2417 if (per_cu
->type_unit_group_p ())
2421 /* The destructor of dwarf2_queue_guard frees any entries left on
2422 the queue. After this point we're guaranteed to leave this function
2423 with the dwarf queue empty. */
2424 dwarf2_queue_guard
q_guard (per_objfile
);
2426 if (!per_objfile
->symtab_set_p (per_cu
))
2428 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2429 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2431 /* If we just loaded a CU from a DWO, and we're working with an index
2432 that may badly handle TUs, load all the TUs in that DWO as well.
2433 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2434 if (!per_cu
->is_debug_types
2436 && cu
->dwo_unit
!= NULL
2437 && per_objfile
->per_bfd
->index_table
!= NULL
2438 && per_objfile
->per_bfd
->index_table
->version
<= 7
2439 /* DWP files aren't supported yet. */
2440 && get_dwp_file (per_objfile
) == NULL
)
2441 queue_and_load_all_dwo_tus (cu
);
2444 process_queue (per_objfile
);
2447 /* Age the cache, releasing compilation units that have not
2448 been used recently. */
2449 per_objfile
->age_comp_units ();
2452 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2453 the per-objfile for which this symtab is instantiated.
2455 Returns the resulting symbol table. */
2457 static struct compunit_symtab
*
2458 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2459 dwarf2_per_objfile
*per_objfile
,
2462 gdb_assert (per_objfile
->per_bfd
->using_index
);
2464 if (!per_objfile
->symtab_set_p (per_cu
))
2466 free_cached_comp_units
freer (per_objfile
);
2467 scoped_restore decrementer
= increment_reading_symtab ();
2468 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2469 process_cu_includes (per_objfile
);
2472 return per_objfile
->get_symtab (per_cu
);
2475 /* See declaration. */
2477 dwarf2_per_cu_data
*
2478 dwarf2_per_bfd::get_cutu (int index
)
2480 if (index
>= this->all_comp_units
.size ())
2482 index
-= this->all_comp_units
.size ();
2483 gdb_assert (index
< this->all_type_units
.size ());
2484 return &this->all_type_units
[index
]->per_cu
;
2487 return this->all_comp_units
[index
];
2490 /* See declaration. */
2492 dwarf2_per_cu_data
*
2493 dwarf2_per_bfd::get_cu (int index
)
2495 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2497 return this->all_comp_units
[index
];
2500 /* See declaration. */
2503 dwarf2_per_bfd::get_tu (int index
)
2505 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2507 return this->all_type_units
[index
];
2512 dwarf2_per_cu_data
*
2513 dwarf2_per_bfd::allocate_per_cu ()
2515 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2516 result
->per_bfd
= this;
2517 result
->index
= m_num_psymtabs
++;
2524 dwarf2_per_bfd::allocate_signatured_type ()
2526 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2527 result
->per_cu
.per_bfd
= this;
2528 result
->per_cu
.index
= m_num_psymtabs
++;
2532 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2533 obstack, and constructed with the specified field values. */
2535 static dwarf2_per_cu_data
*
2536 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2537 struct dwarf2_section_info
*section
,
2539 sect_offset sect_off
, ULONGEST length
)
2541 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2542 the_cu
->sect_off
= sect_off
;
2543 the_cu
->length
= length
;
2544 the_cu
->section
= section
;
2545 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2546 struct dwarf2_per_cu_quick_data
);
2547 the_cu
->is_dwz
= is_dwz
;
2551 /* A helper for create_cus_from_index that handles a given list of
2555 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2556 const gdb_byte
*cu_list
, offset_type n_elements
,
2557 struct dwarf2_section_info
*section
,
2560 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2562 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2564 sect_offset sect_off
2565 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2566 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2569 dwarf2_per_cu_data
*per_cu
2570 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2572 per_bfd
->all_comp_units
.push_back (per_cu
);
2576 /* Read the CU list from the mapped index, and use it to create all
2577 the CU objects for PER_BFD. */
2580 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2581 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2582 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2584 gdb_assert (per_bfd
->all_comp_units
.empty ());
2585 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2587 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2590 if (dwz_elements
== 0)
2593 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2594 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2598 /* Create the signatured type hash table from the index. */
2601 create_signatured_type_table_from_index
2602 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2603 const gdb_byte
*bytes
, offset_type elements
)
2605 gdb_assert (per_bfd
->all_type_units
.empty ());
2606 per_bfd
->all_type_units
.reserve (elements
/ 3);
2608 htab_up sig_types_hash
= allocate_signatured_type_table ();
2610 for (offset_type i
= 0; i
< elements
; i
+= 3)
2612 struct signatured_type
*sig_type
;
2615 cu_offset type_offset_in_tu
;
2617 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2618 sect_offset sect_off
2619 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2621 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2623 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2626 sig_type
= per_bfd
->allocate_signatured_type ();
2627 sig_type
->signature
= signature
;
2628 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2629 sig_type
->per_cu
.is_debug_types
= 1;
2630 sig_type
->per_cu
.section
= section
;
2631 sig_type
->per_cu
.sect_off
= sect_off
;
2632 sig_type
->per_cu
.v
.quick
2633 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2634 struct dwarf2_per_cu_quick_data
);
2636 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2639 per_bfd
->all_type_units
.push_back (sig_type
);
2642 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2645 /* Create the signatured type hash table from .debug_names. */
2648 create_signatured_type_table_from_debug_names
2649 (dwarf2_per_objfile
*per_objfile
,
2650 const mapped_debug_names
&map
,
2651 struct dwarf2_section_info
*section
,
2652 struct dwarf2_section_info
*abbrev_section
)
2654 struct objfile
*objfile
= per_objfile
->objfile
;
2656 section
->read (objfile
);
2657 abbrev_section
->read (objfile
);
2659 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
2660 per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2662 htab_up sig_types_hash
= allocate_signatured_type_table ();
2664 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2666 struct signatured_type
*sig_type
;
2669 sect_offset sect_off
2670 = (sect_offset
) (extract_unsigned_integer
2671 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2673 map
.dwarf5_byte_order
));
2675 comp_unit_head cu_header
;
2676 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2678 section
->buffer
+ to_underlying (sect_off
),
2681 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2682 sig_type
->signature
= cu_header
.signature
;
2683 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2684 sig_type
->per_cu
.is_debug_types
= 1;
2685 sig_type
->per_cu
.section
= section
;
2686 sig_type
->per_cu
.sect_off
= sect_off
;
2687 sig_type
->per_cu
.v
.quick
2688 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2689 struct dwarf2_per_cu_quick_data
);
2691 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2694 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2697 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2700 /* Read the address map data from the mapped index, and use it to
2701 populate the psymtabs_addrmap. */
2704 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2705 struct mapped_index
*index
)
2707 struct objfile
*objfile
= per_objfile
->objfile
;
2708 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2709 struct gdbarch
*gdbarch
= objfile
->arch ();
2710 const gdb_byte
*iter
, *end
;
2711 struct addrmap
*mutable_map
;
2714 auto_obstack temp_obstack
;
2716 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2718 iter
= index
->address_table
.data ();
2719 end
= iter
+ index
->address_table
.size ();
2721 baseaddr
= objfile
->text_section_offset ();
2725 ULONGEST hi
, lo
, cu_index
;
2726 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2728 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2730 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2735 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2736 hex_string (lo
), hex_string (hi
));
2740 if (cu_index
>= per_bfd
->all_comp_units
.size ())
2742 complaint (_(".gdb_index address table has invalid CU number %u"),
2743 (unsigned) cu_index
);
2747 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2748 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2749 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2750 per_bfd
->get_cu (cu_index
));
2753 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2757 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2758 populate the psymtabs_addrmap. */
2761 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2762 struct dwarf2_section_info
*section
)
2764 struct objfile
*objfile
= per_objfile
->objfile
;
2765 bfd
*abfd
= objfile
->obfd
;
2766 struct gdbarch
*gdbarch
= objfile
->arch ();
2767 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2768 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
2770 auto_obstack temp_obstack
;
2771 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2773 std::unordered_map
<sect_offset
,
2774 dwarf2_per_cu_data
*,
2775 gdb::hash_enum
<sect_offset
>>
2776 debug_info_offset_to_per_cu
;
2777 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
2779 const auto insertpair
2780 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2781 if (!insertpair
.second
)
2783 warning (_("Section .debug_aranges in %s has duplicate "
2784 "debug_info_offset %s, ignoring .debug_aranges."),
2785 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2790 section
->read (objfile
);
2792 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2794 const gdb_byte
*addr
= section
->buffer
;
2796 while (addr
< section
->buffer
+ section
->size
)
2798 const gdb_byte
*const entry_addr
= addr
;
2799 unsigned int bytes_read
;
2801 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2805 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2806 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2807 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2808 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2810 warning (_("Section .debug_aranges in %s entry at offset %s "
2811 "length %s exceeds section length %s, "
2812 "ignoring .debug_aranges."),
2813 objfile_name (objfile
),
2814 plongest (entry_addr
- section
->buffer
),
2815 plongest (bytes_read
+ entry_length
),
2816 pulongest (section
->size
));
2820 /* The version number. */
2821 const uint16_t version
= read_2_bytes (abfd
, addr
);
2825 warning (_("Section .debug_aranges in %s entry at offset %s "
2826 "has unsupported version %d, ignoring .debug_aranges."),
2827 objfile_name (objfile
),
2828 plongest (entry_addr
- section
->buffer
), version
);
2832 const uint64_t debug_info_offset
2833 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2834 addr
+= offset_size
;
2835 const auto per_cu_it
2836 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2837 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2839 warning (_("Section .debug_aranges in %s entry at offset %s "
2840 "debug_info_offset %s does not exists, "
2841 "ignoring .debug_aranges."),
2842 objfile_name (objfile
),
2843 plongest (entry_addr
- section
->buffer
),
2844 pulongest (debug_info_offset
));
2847 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2849 const uint8_t address_size
= *addr
++;
2850 if (address_size
< 1 || address_size
> 8)
2852 warning (_("Section .debug_aranges in %s entry at offset %s "
2853 "address_size %u is invalid, ignoring .debug_aranges."),
2854 objfile_name (objfile
),
2855 plongest (entry_addr
- section
->buffer
), address_size
);
2859 const uint8_t segment_selector_size
= *addr
++;
2860 if (segment_selector_size
!= 0)
2862 warning (_("Section .debug_aranges in %s entry at offset %s "
2863 "segment_selector_size %u is not supported, "
2864 "ignoring .debug_aranges."),
2865 objfile_name (objfile
),
2866 plongest (entry_addr
- section
->buffer
),
2867 segment_selector_size
);
2871 /* Must pad to an alignment boundary that is twice the address
2872 size. It is undocumented by the DWARF standard but GCC does
2874 for (size_t padding
= ((-(addr
- section
->buffer
))
2875 & (2 * address_size
- 1));
2876 padding
> 0; padding
--)
2879 warning (_("Section .debug_aranges in %s entry at offset %s "
2880 "padding is not zero, ignoring .debug_aranges."),
2881 objfile_name (objfile
),
2882 plongest (entry_addr
- section
->buffer
));
2888 if (addr
+ 2 * address_size
> entry_end
)
2890 warning (_("Section .debug_aranges in %s entry at offset %s "
2891 "address list is not properly terminated, "
2892 "ignoring .debug_aranges."),
2893 objfile_name (objfile
),
2894 plongest (entry_addr
- section
->buffer
));
2897 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2899 addr
+= address_size
;
2900 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2902 addr
+= address_size
;
2903 if (start
== 0 && length
== 0)
2905 if (start
== 0 && !per_bfd
->has_section_at_zero
)
2907 /* Symbol was eliminated due to a COMDAT group. */
2910 ULONGEST end
= start
+ length
;
2911 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2913 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2915 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2919 per_bfd
->index_addrmap
= addrmap_create_fixed (mutable_map
,
2923 /* Find a slot in the mapped index INDEX for the object named NAME.
2924 If NAME is found, set *VEC_OUT to point to the CU vector in the
2925 constant pool and return true. If NAME cannot be found, return
2929 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2930 offset_type
**vec_out
)
2933 offset_type slot
, step
;
2934 int (*cmp
) (const char *, const char *);
2936 gdb::unique_xmalloc_ptr
<char> without_params
;
2937 if (current_language
->la_language
== language_cplus
2938 || current_language
->la_language
== language_fortran
2939 || current_language
->la_language
== language_d
)
2941 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2944 if (strchr (name
, '(') != NULL
)
2946 without_params
= cp_remove_params (name
);
2948 if (without_params
!= NULL
)
2949 name
= without_params
.get ();
2953 /* Index version 4 did not support case insensitive searches. But the
2954 indices for case insensitive languages are built in lowercase, therefore
2955 simulate our NAME being searched is also lowercased. */
2956 hash
= mapped_index_string_hash ((index
->version
== 4
2957 && case_sensitivity
== case_sensitive_off
2958 ? 5 : index
->version
),
2961 slot
= hash
& (index
->symbol_table
.size () - 1);
2962 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2963 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2969 const auto &bucket
= index
->symbol_table
[slot
];
2970 if (bucket
.name
== 0 && bucket
.vec
== 0)
2973 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2974 if (!cmp (name
, str
))
2976 *vec_out
= (offset_type
*) (index
->constant_pool
2977 + MAYBE_SWAP (bucket
.vec
));
2981 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2985 /* A helper function that reads the .gdb_index from BUFFER and fills
2986 in MAP. FILENAME is the name of the file containing the data;
2987 it is used for error reporting. DEPRECATED_OK is true if it is
2988 ok to use deprecated sections.
2990 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2991 out parameters that are filled in with information about the CU and
2992 TU lists in the section.
2994 Returns true if all went well, false otherwise. */
2997 read_gdb_index_from_buffer (const char *filename
,
2999 gdb::array_view
<const gdb_byte
> buffer
,
3000 struct mapped_index
*map
,
3001 const gdb_byte
**cu_list
,
3002 offset_type
*cu_list_elements
,
3003 const gdb_byte
**types_list
,
3004 offset_type
*types_list_elements
)
3006 const gdb_byte
*addr
= &buffer
[0];
3008 /* Version check. */
3009 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3010 /* Versions earlier than 3 emitted every copy of a psymbol. This
3011 causes the index to behave very poorly for certain requests. Version 3
3012 contained incomplete addrmap. So, it seems better to just ignore such
3016 static int warning_printed
= 0;
3017 if (!warning_printed
)
3019 warning (_("Skipping obsolete .gdb_index section in %s."),
3021 warning_printed
= 1;
3025 /* Index version 4 uses a different hash function than index version
3028 Versions earlier than 6 did not emit psymbols for inlined
3029 functions. Using these files will cause GDB not to be able to
3030 set breakpoints on inlined functions by name, so we ignore these
3031 indices unless the user has done
3032 "set use-deprecated-index-sections on". */
3033 if (version
< 6 && !deprecated_ok
)
3035 static int warning_printed
= 0;
3036 if (!warning_printed
)
3039 Skipping deprecated .gdb_index section in %s.\n\
3040 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3041 to use the section anyway."),
3043 warning_printed
= 1;
3047 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3048 of the TU (for symbols coming from TUs),
3049 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3050 Plus gold-generated indices can have duplicate entries for global symbols,
3051 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3052 These are just performance bugs, and we can't distinguish gdb-generated
3053 indices from gold-generated ones, so issue no warning here. */
3055 /* Indexes with higher version than the one supported by GDB may be no
3056 longer backward compatible. */
3060 map
->version
= version
;
3062 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3065 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3066 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3070 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3071 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3072 - MAYBE_SWAP (metadata
[i
]))
3076 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3077 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3079 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3082 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3083 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3085 = gdb::array_view
<mapped_index::symbol_table_slot
>
3086 ((mapped_index::symbol_table_slot
*) symbol_table
,
3087 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3090 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3095 /* Callback types for dwarf2_read_gdb_index. */
3097 typedef gdb::function_view
3098 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3099 get_gdb_index_contents_ftype
;
3100 typedef gdb::function_view
3101 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3102 get_gdb_index_contents_dwz_ftype
;
3104 /* Read .gdb_index. If everything went ok, initialize the "quick"
3105 elements of all the CUs and return 1. Otherwise, return 0. */
3108 dwarf2_read_gdb_index
3109 (dwarf2_per_objfile
*per_objfile
,
3110 get_gdb_index_contents_ftype get_gdb_index_contents
,
3111 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3113 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3114 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3115 struct dwz_file
*dwz
;
3116 struct objfile
*objfile
= per_objfile
->objfile
;
3117 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3119 gdb::array_view
<const gdb_byte
> main_index_contents
3120 = get_gdb_index_contents (objfile
, per_bfd
);
3122 if (main_index_contents
.empty ())
3125 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3126 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3127 use_deprecated_index_sections
,
3128 main_index_contents
, map
.get (), &cu_list
,
3129 &cu_list_elements
, &types_list
,
3130 &types_list_elements
))
3133 /* Don't use the index if it's empty. */
3134 if (map
->symbol_table
.empty ())
3137 /* If there is a .dwz file, read it so we can get its CU list as
3139 dwz
= dwarf2_get_dwz_file (per_bfd
);
3142 struct mapped_index dwz_map
;
3143 const gdb_byte
*dwz_types_ignore
;
3144 offset_type dwz_types_elements_ignore
;
3146 gdb::array_view
<const gdb_byte
> dwz_index_content
3147 = get_gdb_index_contents_dwz (objfile
, dwz
);
3149 if (dwz_index_content
.empty ())
3152 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3153 1, dwz_index_content
, &dwz_map
,
3154 &dwz_list
, &dwz_list_elements
,
3156 &dwz_types_elements_ignore
))
3158 warning (_("could not read '.gdb_index' section from %s; skipping"),
3159 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3164 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
3167 if (types_list_elements
)
3169 /* We can only handle a single .debug_types when we have an
3171 if (per_bfd
->types
.size () != 1)
3174 dwarf2_section_info
*section
= &per_bfd
->types
[0];
3176 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
3177 types_list_elements
);
3180 create_addrmap_from_index (per_objfile
, map
.get ());
3182 per_bfd
->index_table
= std::move (map
);
3183 per_bfd
->using_index
= 1;
3184 per_bfd
->quick_file_names_table
=
3185 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
3190 /* die_reader_func for dw2_get_file_names. */
3193 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3194 struct die_info
*comp_unit_die
)
3196 struct dwarf2_cu
*cu
= reader
->cu
;
3197 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3198 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3199 struct dwarf2_per_cu_data
*lh_cu
;
3200 struct attribute
*attr
;
3202 struct quick_file_names
*qfn
;
3204 gdb_assert (! this_cu
->is_debug_types
);
3206 /* Our callers never want to match partial units -- instead they
3207 will match the enclosing full CU. */
3208 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3210 this_cu
->v
.quick
->no_file_data
= 1;
3218 sect_offset line_offset
{};
3220 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3221 if (attr
!= nullptr && attr
->form_is_unsigned ())
3223 struct quick_file_names find_entry
;
3225 line_offset
= (sect_offset
) attr
->as_unsigned ();
3227 /* We may have already read in this line header (TU line header sharing).
3228 If we have we're done. */
3229 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3230 find_entry
.hash
.line_sect_off
= line_offset
;
3231 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3232 &find_entry
, INSERT
);
3235 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3239 lh
= dwarf_decode_line_header (line_offset
, cu
);
3243 lh_cu
->v
.quick
->no_file_data
= 1;
3247 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3248 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3249 qfn
->hash
.line_sect_off
= line_offset
;
3250 gdb_assert (slot
!= NULL
);
3253 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3256 if (strcmp (fnd
.name
, "<unknown>") != 0)
3259 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3261 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3262 qfn
->num_file_names
);
3264 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3265 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3266 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3267 fnd
.comp_dir
).release ();
3268 qfn
->real_names
= NULL
;
3270 lh_cu
->v
.quick
->file_names
= qfn
;
3273 /* A helper for the "quick" functions which attempts to read the line
3274 table for THIS_CU. */
3276 static struct quick_file_names
*
3277 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3278 dwarf2_per_objfile
*per_objfile
)
3280 /* This should never be called for TUs. */
3281 gdb_assert (! this_cu
->is_debug_types
);
3282 /* Nor type unit groups. */
3283 gdb_assert (! this_cu
->type_unit_group_p ());
3285 if (this_cu
->v
.quick
->file_names
!= NULL
)
3286 return this_cu
->v
.quick
->file_names
;
3287 /* If we know there is no line data, no point in looking again. */
3288 if (this_cu
->v
.quick
->no_file_data
)
3291 cutu_reader
reader (this_cu
, per_objfile
);
3292 if (!reader
.dummy_p
)
3293 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
3295 if (this_cu
->v
.quick
->no_file_data
)
3297 return this_cu
->v
.quick
->file_names
;
3300 /* A helper for the "quick" functions which computes and caches the
3301 real path for a given file name from the line table. */
3304 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3305 struct quick_file_names
*qfn
, int index
)
3307 if (qfn
->real_names
== NULL
)
3308 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3309 qfn
->num_file_names
, const char *);
3311 if (qfn
->real_names
[index
] == NULL
)
3312 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3314 return qfn
->real_names
[index
];
3318 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3320 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3321 dwarf2_per_cu_data
*dwarf_cu
= per_objfile
->per_bfd
->all_comp_units
.back ();
3322 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3327 return compunit_primary_filetab (cust
);
3330 /* Traversal function for dw2_forget_cached_source_info. */
3333 dw2_free_cached_file_names (void **slot
, void *info
)
3335 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3337 if (file_data
->real_names
)
3341 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3343 xfree ((void*) file_data
->real_names
[i
]);
3344 file_data
->real_names
[i
] = NULL
;
3352 dwarf2_base_index_functions::forget_cached_source_info
3353 (struct objfile
*objfile
)
3355 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3357 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3358 dw2_free_cached_file_names
, NULL
);
3361 /* Helper function for dw2_map_symtabs_matching_filename that expands
3362 the symtabs and calls the iterator. */
3365 dw2_map_expand_apply (struct objfile
*objfile
,
3366 struct dwarf2_per_cu_data
*per_cu
,
3367 const char *name
, const char *real_path
,
3368 gdb::function_view
<bool (symtab
*)> callback
)
3370 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3372 /* Don't visit already-expanded CUs. */
3373 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3374 if (per_objfile
->symtab_set_p (per_cu
))
3377 /* This may expand more than one symtab, and we want to iterate over
3379 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3381 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3382 last_made
, callback
);
3385 /* Implementation of the map_symtabs_matching_filename method. */
3388 dwarf2_base_index_functions::map_symtabs_matching_filename
3389 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3390 gdb::function_view
<bool (symtab
*)> callback
)
3392 const char *name_basename
= lbasename (name
);
3393 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3395 /* The rule is CUs specify all the files, including those used by
3396 any TU, so there's no need to scan TUs here. */
3398 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3400 /* We only need to look at symtabs not already expanded. */
3401 if (per_objfile
->symtab_set_p (per_cu
))
3404 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3405 if (file_data
== NULL
)
3408 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3410 const char *this_name
= file_data
->file_names
[j
];
3411 const char *this_real_name
;
3413 if (compare_filenames_for_search (this_name
, name
))
3415 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3421 /* Before we invoke realpath, which can get expensive when many
3422 files are involved, do a quick comparison of the basenames. */
3423 if (! basenames_may_differ
3424 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3427 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3428 if (compare_filenames_for_search (this_real_name
, name
))
3430 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3436 if (real_path
!= NULL
)
3438 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3439 gdb_assert (IS_ABSOLUTE_PATH (name
));
3440 if (this_real_name
!= NULL
3441 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3443 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3455 /* Struct used to manage iterating over all CUs looking for a symbol. */
3457 struct dw2_symtab_iterator
3459 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3460 dwarf2_per_objfile
*per_objfile
;
3461 /* If set, only look for symbols that match that block. Valid values are
3462 GLOBAL_BLOCK and STATIC_BLOCK. */
3463 gdb::optional
<block_enum
> block_index
;
3464 /* The kind of symbol we're looking for. */
3466 /* The list of CUs from the index entry of the symbol,
3467 or NULL if not found. */
3469 /* The next element in VEC to look at. */
3471 /* The number of elements in VEC, or zero if there is no match. */
3473 /* Have we seen a global version of the symbol?
3474 If so we can ignore all further global instances.
3475 This is to work around gold/15646, inefficient gold-generated
3480 /* Initialize the index symtab iterator ITER, common part. */
3483 dw2_symtab_iter_init_common (struct dw2_symtab_iterator
*iter
,
3484 dwarf2_per_objfile
*per_objfile
,
3485 gdb::optional
<block_enum
> block_index
,
3488 iter
->per_objfile
= per_objfile
;
3489 iter
->block_index
= block_index
;
3490 iter
->domain
= domain
;
3492 iter
->global_seen
= 0;
3497 /* Initialize the index symtab iterator ITER, const char *NAME variant. */
3500 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3501 dwarf2_per_objfile
*per_objfile
,
3502 gdb::optional
<block_enum
> block_index
,
3506 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3508 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3509 /* index is NULL if OBJF_READNOW. */
3513 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3514 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3517 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3520 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3521 dwarf2_per_objfile
*per_objfile
,
3522 gdb::optional
<block_enum
> block_index
,
3523 domain_enum domain
, offset_type namei
)
3525 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3527 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3528 /* index is NULL if OBJF_READNOW. */
3532 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3533 const auto &bucket
= index
->symbol_table
[namei
];
3535 iter
->vec
= (offset_type
*) (index
->constant_pool
3536 + MAYBE_SWAP (bucket
.vec
));
3537 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3540 /* Return the next matching CU or NULL if there are no more. */
3542 static struct dwarf2_per_cu_data
*
3543 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3545 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3547 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3549 offset_type cu_index_and_attrs
=
3550 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3551 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3552 gdb_index_symbol_kind symbol_kind
=
3553 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3554 /* Only check the symbol attributes if they're present.
3555 Indices prior to version 7 don't record them,
3556 and indices >= 7 may elide them for certain symbols
3557 (gold does this). */
3559 (per_objfile
->per_bfd
->index_table
->version
>= 7
3560 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3562 /* Don't crash on bad data. */
3563 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
3564 + per_objfile
->per_bfd
->all_type_units
.size ()))
3566 complaint (_(".gdb_index entry has bad CU index"
3567 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3571 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
3573 /* Skip if already read in. */
3574 if (per_objfile
->symtab_set_p (per_cu
))
3577 /* Check static vs global. */
3580 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3582 if (iter
->block_index
.has_value ())
3584 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3586 if (is_static
!= want_static
)
3590 /* Work around gold/15646. */
3592 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3594 if (iter
->global_seen
)
3597 iter
->global_seen
= 1;
3601 /* Only check the symbol's kind if it has one. */
3604 switch (iter
->domain
)
3607 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3608 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3609 /* Some types are also in VAR_DOMAIN. */
3610 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3614 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3618 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3622 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3637 struct compunit_symtab
*
3638 dwarf2_gdb_index::lookup_symbol (struct objfile
*objfile
,
3639 block_enum block_index
,
3640 const char *name
, domain_enum domain
)
3642 struct compunit_symtab
*stab_best
= NULL
;
3643 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3645 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3647 struct dw2_symtab_iterator iter
;
3648 struct dwarf2_per_cu_data
*per_cu
;
3650 dw2_symtab_iter_init (&iter
, per_objfile
, block_index
, domain
, name
);
3652 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3654 struct symbol
*sym
, *with_opaque
= NULL
;
3655 struct compunit_symtab
*stab
3656 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3657 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3658 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3660 sym
= block_find_symbol (block
, name
, domain
,
3661 block_find_non_opaque_type_preferred
,
3664 /* Some caution must be observed with overloaded functions
3665 and methods, since the index will not contain any overload
3666 information (but NAME might contain it). */
3669 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3671 if (with_opaque
!= NULL
3672 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3675 /* Keep looking through other CUs. */
3682 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
,
3688 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3689 int total
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3690 + per_objfile
->per_bfd
->all_type_units
.size ());
3693 for (int i
= 0; i
< total
; ++i
)
3695 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3697 if (!per_objfile
->symtab_set_p (per_cu
))
3700 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3701 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3704 /* This dumps minimal information about the index.
3705 It is called via "mt print objfiles".
3706 One use is to verify .gdb_index has been loaded by the
3707 gdb.dwarf2/gdb-index.exp testcase. */
3710 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3712 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3714 gdb_assert (per_objfile
->per_bfd
->using_index
);
3715 printf_filtered (".gdb_index:");
3716 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3718 printf_filtered (" version %d\n",
3719 per_objfile
->per_bfd
->index_table
->version
);
3722 printf_filtered (" faked for \"readnow\"\n");
3723 printf_filtered ("\n");
3727 dwarf2_gdb_index::expand_symtabs_for_function (struct objfile
*objfile
,
3728 const char *func_name
)
3730 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3732 struct dw2_symtab_iterator iter
;
3733 struct dwarf2_per_cu_data
*per_cu
;
3735 dw2_symtab_iter_init (&iter
, per_objfile
, {}, VAR_DOMAIN
, func_name
);
3737 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3738 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3743 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3745 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3746 int total_units
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3747 + per_objfile
->per_bfd
->all_type_units
.size ());
3749 for (int i
= 0; i
< total_units
; ++i
)
3751 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3753 /* We don't want to directly expand a partial CU, because if we
3754 read it with the wrong language, then assertion failures can
3755 be triggered later on. See PR symtab/23010. So, tell
3756 dw2_instantiate_symtab to skip partial CUs -- any important
3757 partial CU will be read via DW_TAG_imported_unit anyway. */
3758 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3763 dwarf2_base_index_functions::expand_symtabs_with_fullname
3764 (struct objfile
*objfile
, const char *fullname
)
3766 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3768 /* We don't need to consider type units here.
3769 This is only called for examining code, e.g. expand_line_sal.
3770 There can be an order of magnitude (or more) more type units
3771 than comp units, and we avoid them if we can. */
3773 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3775 /* We only need to look at symtabs not already expanded. */
3776 if (per_objfile
->symtab_set_p (per_cu
))
3779 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3780 if (file_data
== NULL
)
3783 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3785 const char *this_fullname
= file_data
->file_names
[j
];
3787 if (filename_cmp (this_fullname
, fullname
) == 0)
3789 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3797 dw2_expand_symtabs_matching_symbol
3798 (mapped_index_base
&index
,
3799 const lookup_name_info
&lookup_name_in
,
3800 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3801 enum search_domain kind
,
3802 gdb::function_view
<bool (offset_type
)> match_callback
,
3803 dwarf2_per_objfile
*per_objfile
);
3806 dw2_expand_symtabs_matching_one
3807 (dwarf2_per_cu_data
*per_cu
,
3808 dwarf2_per_objfile
*per_objfile
,
3809 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3810 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3813 dw2_map_matching_symbols
3814 (struct objfile
*objfile
,
3815 const lookup_name_info
&name
, domain_enum domain
,
3817 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3818 symbol_compare_ftype
*ordered_compare
)
3821 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3823 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3825 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3827 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3829 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3830 auto matcher
= [&] (const char *symname
)
3832 if (ordered_compare
== nullptr)
3834 return ordered_compare (symname
, match_name
) == 0;
3837 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3838 [&] (offset_type namei
)
3840 struct dw2_symtab_iterator iter
;
3841 struct dwarf2_per_cu_data
*per_cu
;
3843 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3845 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3846 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3853 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3854 proceed assuming all symtabs have been read in. */
3857 for (compunit_symtab
*cust
: objfile
->compunits ())
3859 const struct block
*block
;
3863 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3864 if (!iterate_over_symbols_terminated (block
, name
,
3871 dwarf2_gdb_index::map_matching_symbols
3872 (struct objfile
*objfile
,
3873 const lookup_name_info
&name
, domain_enum domain
,
3875 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3876 symbol_compare_ftype
*ordered_compare
)
3878 dw2_map_matching_symbols (objfile
, name
, domain
, global
, callback
,
3882 /* Starting from a search name, return the string that finds the upper
3883 bound of all strings that start with SEARCH_NAME in a sorted name
3884 list. Returns the empty string to indicate that the upper bound is
3885 the end of the list. */
3888 make_sort_after_prefix_name (const char *search_name
)
3890 /* When looking to complete "func", we find the upper bound of all
3891 symbols that start with "func" by looking for where we'd insert
3892 the closest string that would follow "func" in lexicographical
3893 order. Usually, that's "func"-with-last-character-incremented,
3894 i.e. "fund". Mind non-ASCII characters, though. Usually those
3895 will be UTF-8 multi-byte sequences, but we can't be certain.
3896 Especially mind the 0xff character, which is a valid character in
3897 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3898 rule out compilers allowing it in identifiers. Note that
3899 conveniently, strcmp/strcasecmp are specified to compare
3900 characters interpreted as unsigned char. So what we do is treat
3901 the whole string as a base 256 number composed of a sequence of
3902 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3903 to 0, and carries 1 to the following more-significant position.
3904 If the very first character in SEARCH_NAME ends up incremented
3905 and carries/overflows, then the upper bound is the end of the
3906 list. The string after the empty string is also the empty
3909 Some examples of this operation:
3911 SEARCH_NAME => "+1" RESULT
3915 "\xff" "a" "\xff" => "\xff" "b"
3920 Then, with these symbols for example:
3926 completing "func" looks for symbols between "func" and
3927 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3928 which finds "func" and "func1", but not "fund".
3932 funcÿ (Latin1 'ÿ' [0xff])
3936 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3937 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3941 ÿÿ (Latin1 'ÿ' [0xff])
3944 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3945 the end of the list.
3947 std::string after
= search_name
;
3948 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3950 if (!after
.empty ())
3951 after
.back () = (unsigned char) after
.back () + 1;
3955 /* See declaration. */
3957 std::pair
<std::vector
<name_component
>::const_iterator
,
3958 std::vector
<name_component
>::const_iterator
>
3959 mapped_index_base::find_name_components_bounds
3960 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3961 dwarf2_per_objfile
*per_objfile
) const
3964 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3966 const char *lang_name
3967 = lookup_name_without_params
.language_lookup_name (lang
);
3969 /* Comparison function object for lower_bound that matches against a
3970 given symbol name. */
3971 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3974 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3975 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3976 return name_cmp (elem_name
, name
) < 0;
3979 /* Comparison function object for upper_bound that matches against a
3980 given symbol name. */
3981 auto lookup_compare_upper
= [&] (const char *name
,
3982 const name_component
&elem
)
3984 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3985 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3986 return name_cmp (name
, elem_name
) < 0;
3989 auto begin
= this->name_components
.begin ();
3990 auto end
= this->name_components
.end ();
3992 /* Find the lower bound. */
3995 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3998 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4001 /* Find the upper bound. */
4004 if (lookup_name_without_params
.completion_mode ())
4006 /* In completion mode, we want UPPER to point past all
4007 symbols names that have the same prefix. I.e., with
4008 these symbols, and completing "func":
4010 function << lower bound
4012 other_function << upper bound
4014 We find the upper bound by looking for the insertion
4015 point of "func"-with-last-character-incremented,
4017 std::string after
= make_sort_after_prefix_name (lang_name
);
4020 return std::lower_bound (lower
, end
, after
.c_str (),
4021 lookup_compare_lower
);
4024 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4027 return {lower
, upper
};
4030 /* See declaration. */
4033 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
4035 if (!this->name_components
.empty ())
4038 this->name_components_casing
= case_sensitivity
;
4040 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4042 /* The code below only knows how to break apart components of C++
4043 symbol names (and other languages that use '::' as
4044 namespace/module separator) and Ada symbol names. */
4045 auto count
= this->symbol_name_count ();
4046 for (offset_type idx
= 0; idx
< count
; idx
++)
4048 if (this->symbol_name_slot_invalid (idx
))
4051 const char *name
= this->symbol_name_at (idx
, per_objfile
);
4053 /* Add each name component to the name component table. */
4054 unsigned int previous_len
= 0;
4056 if (strstr (name
, "::") != nullptr)
4058 for (unsigned int current_len
= cp_find_first_component (name
);
4059 name
[current_len
] != '\0';
4060 current_len
+= cp_find_first_component (name
+ current_len
))
4062 gdb_assert (name
[current_len
] == ':');
4063 this->name_components
.push_back ({previous_len
, idx
});
4064 /* Skip the '::'. */
4066 previous_len
= current_len
;
4071 /* Handle the Ada encoded (aka mangled) form here. */
4072 for (const char *iter
= strstr (name
, "__");
4074 iter
= strstr (iter
, "__"))
4076 this->name_components
.push_back ({previous_len
, idx
});
4078 previous_len
= iter
- name
;
4082 this->name_components
.push_back ({previous_len
, idx
});
4085 /* Sort name_components elements by name. */
4086 auto name_comp_compare
= [&] (const name_component
&left
,
4087 const name_component
&right
)
4089 const char *left_qualified
4090 = this->symbol_name_at (left
.idx
, per_objfile
);
4091 const char *right_qualified
4092 = this->symbol_name_at (right
.idx
, per_objfile
);
4094 const char *left_name
= left_qualified
+ left
.name_offset
;
4095 const char *right_name
= right_qualified
+ right
.name_offset
;
4097 return name_cmp (left_name
, right_name
) < 0;
4100 std::sort (this->name_components
.begin (),
4101 this->name_components
.end (),
4105 /* Helper for dw2_expand_symtabs_matching that works with a
4106 mapped_index_base instead of the containing objfile. This is split
4107 to a separate function in order to be able to unit test the
4108 name_components matching using a mock mapped_index_base. For each
4109 symbol name that matches, calls MATCH_CALLBACK, passing it the
4110 symbol's index in the mapped_index_base symbol table. */
4113 dw2_expand_symtabs_matching_symbol
4114 (mapped_index_base
&index
,
4115 const lookup_name_info
&lookup_name_in
,
4116 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4117 enum search_domain kind
,
4118 gdb::function_view
<bool (offset_type
)> match_callback
,
4119 dwarf2_per_objfile
*per_objfile
)
4121 lookup_name_info lookup_name_without_params
4122 = lookup_name_in
.make_ignore_params ();
4124 /* Build the symbol name component sorted vector, if we haven't
4126 index
.build_name_components (per_objfile
);
4128 /* The same symbol may appear more than once in the range though.
4129 E.g., if we're looking for symbols that complete "w", and we have
4130 a symbol named "w1::w2", we'll find the two name components for
4131 that same symbol in the range. To be sure we only call the
4132 callback once per symbol, we first collect the symbol name
4133 indexes that matched in a temporary vector and ignore
4135 std::vector
<offset_type
> matches
;
4137 struct name_and_matcher
4139 symbol_name_matcher_ftype
*matcher
;
4142 bool operator== (const name_and_matcher
&other
) const
4144 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4148 /* A vector holding all the different symbol name matchers, for all
4150 std::vector
<name_and_matcher
> matchers
;
4152 for (int i
= 0; i
< nr_languages
; i
++)
4154 enum language lang_e
= (enum language
) i
;
4156 const language_defn
*lang
= language_def (lang_e
);
4157 symbol_name_matcher_ftype
*name_matcher
4158 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
4160 name_and_matcher key
{
4162 lookup_name_without_params
.language_lookup_name (lang_e
)
4165 /* Don't insert the same comparison routine more than once.
4166 Note that we do this linear walk. This is not a problem in
4167 practice because the number of supported languages is
4169 if (std::find (matchers
.begin (), matchers
.end (), key
)
4172 matchers
.push_back (std::move (key
));
4175 = index
.find_name_components_bounds (lookup_name_without_params
,
4176 lang_e
, per_objfile
);
4178 /* Now for each symbol name in range, check to see if we have a name
4179 match, and if so, call the MATCH_CALLBACK callback. */
4181 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4183 const char *qualified
4184 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4186 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4187 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4190 matches
.push_back (bounds
.first
->idx
);
4194 std::sort (matches
.begin (), matches
.end ());
4196 /* Finally call the callback, once per match. */
4198 for (offset_type idx
: matches
)
4202 if (!match_callback (idx
))
4208 /* Above we use a type wider than idx's for 'prev', since 0 and
4209 (offset_type)-1 are both possible values. */
4210 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4215 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4217 /* A mock .gdb_index/.debug_names-like name index table, enough to
4218 exercise dw2_expand_symtabs_matching_symbol, which works with the
4219 mapped_index_base interface. Builds an index from the symbol list
4220 passed as parameter to the constructor. */
4221 class mock_mapped_index
: public mapped_index_base
4224 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4225 : m_symbol_table (symbols
)
4228 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4230 /* Return the number of names in the symbol table. */
4231 size_t symbol_name_count () const override
4233 return m_symbol_table
.size ();
4236 /* Get the name of the symbol at IDX in the symbol table. */
4237 const char *symbol_name_at
4238 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4240 return m_symbol_table
[idx
];
4244 gdb::array_view
<const char *> m_symbol_table
;
4247 /* Convenience function that converts a NULL pointer to a "<null>"
4248 string, to pass to print routines. */
4251 string_or_null (const char *str
)
4253 return str
!= NULL
? str
: "<null>";
4256 /* Check if a lookup_name_info built from
4257 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4258 index. EXPECTED_LIST is the list of expected matches, in expected
4259 matching order. If no match expected, then an empty list is
4260 specified. Returns true on success. On failure prints a warning
4261 indicating the file:line that failed, and returns false. */
4264 check_match (const char *file
, int line
,
4265 mock_mapped_index
&mock_index
,
4266 const char *name
, symbol_name_match_type match_type
,
4267 bool completion_mode
,
4268 std::initializer_list
<const char *> expected_list
,
4269 dwarf2_per_objfile
*per_objfile
)
4271 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4273 bool matched
= true;
4275 auto mismatch
= [&] (const char *expected_str
,
4278 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4279 "expected=\"%s\", got=\"%s\"\n"),
4281 (match_type
== symbol_name_match_type::FULL
4283 name
, string_or_null (expected_str
), string_or_null (got
));
4287 auto expected_it
= expected_list
.begin ();
4288 auto expected_end
= expected_list
.end ();
4290 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4292 [&] (offset_type idx
)
4294 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4295 const char *expected_str
4296 = expected_it
== expected_end
? NULL
: *expected_it
++;
4298 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4299 mismatch (expected_str
, matched_name
);
4303 const char *expected_str
4304 = expected_it
== expected_end
? NULL
: *expected_it
++;
4305 if (expected_str
!= NULL
)
4306 mismatch (expected_str
, NULL
);
4311 /* The symbols added to the mock mapped_index for testing (in
4313 static const char *test_symbols
[] = {
4322 "ns2::tmpl<int>::foo2",
4323 "(anonymous namespace)::A::B::C",
4325 /* These are used to check that the increment-last-char in the
4326 matching algorithm for completion doesn't match "t1_fund" when
4327 completing "t1_func". */
4333 /* A UTF-8 name with multi-byte sequences to make sure that
4334 cp-name-parser understands this as a single identifier ("função"
4335 is "function" in PT). */
4338 /* \377 (0xff) is Latin1 'ÿ'. */
4341 /* \377 (0xff) is Latin1 'ÿ'. */
4345 /* A name with all sorts of complications. Starts with "z" to make
4346 it easier for the completion tests below. */
4347 #define Z_SYM_NAME \
4348 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4349 "::tuple<(anonymous namespace)::ui*, " \
4350 "std::default_delete<(anonymous namespace)::ui>, void>"
4355 /* Returns true if the mapped_index_base::find_name_component_bounds
4356 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4357 in completion mode. */
4360 check_find_bounds_finds (mapped_index_base
&index
,
4361 const char *search_name
,
4362 gdb::array_view
<const char *> expected_syms
,
4363 dwarf2_per_objfile
*per_objfile
)
4365 lookup_name_info
lookup_name (search_name
,
4366 symbol_name_match_type::FULL
, true);
4368 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4372 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4373 if (distance
!= expected_syms
.size ())
4376 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4378 auto nc_elem
= bounds
.first
+ exp_elem
;
4379 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4380 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4387 /* Test the lower-level mapped_index::find_name_component_bounds
4391 test_mapped_index_find_name_component_bounds ()
4393 mock_mapped_index
mock_index (test_symbols
);
4395 mock_index
.build_name_components (NULL
/* per_objfile */);
4397 /* Test the lower-level mapped_index::find_name_component_bounds
4398 method in completion mode. */
4400 static const char *expected_syms
[] = {
4405 SELF_CHECK (check_find_bounds_finds
4406 (mock_index
, "t1_func", expected_syms
,
4407 NULL
/* per_objfile */));
4410 /* Check that the increment-last-char in the name matching algorithm
4411 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4413 static const char *expected_syms1
[] = {
4417 SELF_CHECK (check_find_bounds_finds
4418 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4420 static const char *expected_syms2
[] = {
4423 SELF_CHECK (check_find_bounds_finds
4424 (mock_index
, "\377\377", expected_syms2
,
4425 NULL
/* per_objfile */));
4429 /* Test dw2_expand_symtabs_matching_symbol. */
4432 test_dw2_expand_symtabs_matching_symbol ()
4434 mock_mapped_index
mock_index (test_symbols
);
4436 /* We let all tests run until the end even if some fails, for debug
4438 bool any_mismatch
= false;
4440 /* Create the expected symbols list (an initializer_list). Needed
4441 because lists have commas, and we need to pass them to CHECK,
4442 which is a macro. */
4443 #define EXPECT(...) { __VA_ARGS__ }
4445 /* Wrapper for check_match that passes down the current
4446 __FILE__/__LINE__. */
4447 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4448 any_mismatch |= !check_match (__FILE__, __LINE__, \
4450 NAME, MATCH_TYPE, COMPLETION_MODE, \
4451 EXPECTED_LIST, NULL)
4453 /* Identity checks. */
4454 for (const char *sym
: test_symbols
)
4456 /* Should be able to match all existing symbols. */
4457 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4460 /* Should be able to match all existing symbols with
4462 std::string with_params
= std::string (sym
) + "(int)";
4463 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4466 /* Should be able to match all existing symbols with
4467 parameters and qualifiers. */
4468 with_params
= std::string (sym
) + " ( int ) const";
4469 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4472 /* This should really find sym, but cp-name-parser.y doesn't
4473 know about lvalue/rvalue qualifiers yet. */
4474 with_params
= std::string (sym
) + " ( int ) &&";
4475 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4479 /* Check that the name matching algorithm for completion doesn't get
4480 confused with Latin1 'ÿ' / 0xff. */
4482 static const char str
[] = "\377";
4483 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4484 EXPECT ("\377", "\377\377123"));
4487 /* Check that the increment-last-char in the matching algorithm for
4488 completion doesn't match "t1_fund" when completing "t1_func". */
4490 static const char str
[] = "t1_func";
4491 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4492 EXPECT ("t1_func", "t1_func1"));
4495 /* Check that completion mode works at each prefix of the expected
4498 static const char str
[] = "function(int)";
4499 size_t len
= strlen (str
);
4502 for (size_t i
= 1; i
< len
; i
++)
4504 lookup
.assign (str
, i
);
4505 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4506 EXPECT ("function"));
4510 /* While "w" is a prefix of both components, the match function
4511 should still only be called once. */
4513 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4515 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4519 /* Same, with a "complicated" symbol. */
4521 static const char str
[] = Z_SYM_NAME
;
4522 size_t len
= strlen (str
);
4525 for (size_t i
= 1; i
< len
; i
++)
4527 lookup
.assign (str
, i
);
4528 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4529 EXPECT (Z_SYM_NAME
));
4533 /* In FULL mode, an incomplete symbol doesn't match. */
4535 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4539 /* A complete symbol with parameters matches any overload, since the
4540 index has no overload info. */
4542 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4543 EXPECT ("std::zfunction", "std::zfunction2"));
4544 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4545 EXPECT ("std::zfunction", "std::zfunction2"));
4546 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4547 EXPECT ("std::zfunction", "std::zfunction2"));
4550 /* Check that whitespace is ignored appropriately. A symbol with a
4551 template argument list. */
4553 static const char expected
[] = "ns::foo<int>";
4554 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4556 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4560 /* Check that whitespace is ignored appropriately. A symbol with a
4561 template argument list that includes a pointer. */
4563 static const char expected
[] = "ns::foo<char*>";
4564 /* Try both completion and non-completion modes. */
4565 static const bool completion_mode
[2] = {false, true};
4566 for (size_t i
= 0; i
< 2; i
++)
4568 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4569 completion_mode
[i
], EXPECT (expected
));
4570 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4571 completion_mode
[i
], EXPECT (expected
));
4573 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4574 completion_mode
[i
], EXPECT (expected
));
4575 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4576 completion_mode
[i
], EXPECT (expected
));
4581 /* Check method qualifiers are ignored. */
4582 static const char expected
[] = "ns::foo<char*>";
4583 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4584 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4585 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4586 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4587 CHECK_MATCH ("foo < char * > ( int ) const",
4588 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4589 CHECK_MATCH ("foo < char * > ( int ) &&",
4590 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4593 /* Test lookup names that don't match anything. */
4595 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4598 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4602 /* Some wild matching tests, exercising "(anonymous namespace)",
4603 which should not be confused with a parameter list. */
4605 static const char *syms
[] = {
4609 "A :: B :: C ( int )",
4614 for (const char *s
: syms
)
4616 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4617 EXPECT ("(anonymous namespace)::A::B::C"));
4622 static const char expected
[] = "ns2::tmpl<int>::foo2";
4623 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4625 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4629 SELF_CHECK (!any_mismatch
);
4638 test_mapped_index_find_name_component_bounds ();
4639 test_dw2_expand_symtabs_matching_symbol ();
4642 }} // namespace selftests::dw2_expand_symtabs_matching
4644 #endif /* GDB_SELF_TEST */
4646 /* If FILE_MATCHER is NULL or if PER_CU has
4647 dwarf2_per_cu_quick_data::MARK set (see
4648 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4649 EXPANSION_NOTIFY on it. */
4652 dw2_expand_symtabs_matching_one
4653 (dwarf2_per_cu_data
*per_cu
,
4654 dwarf2_per_objfile
*per_objfile
,
4655 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4656 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4658 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4660 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4662 compunit_symtab
*symtab
4663 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4664 gdb_assert (symtab
!= nullptr);
4666 if (expansion_notify
!= NULL
&& symtab_was_null
)
4667 expansion_notify (symtab
);
4671 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4672 matched, to expand corresponding CUs that were marked. IDX is the
4673 index of the symbol name that matched. */
4676 dw2_expand_marked_cus
4677 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4678 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4679 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4682 offset_type
*vec
, vec_len
, vec_idx
;
4683 bool global_seen
= false;
4684 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4686 vec
= (offset_type
*) (index
.constant_pool
4687 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4688 vec_len
= MAYBE_SWAP (vec
[0]);
4689 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4691 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4692 /* This value is only valid for index versions >= 7. */
4693 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4694 gdb_index_symbol_kind symbol_kind
=
4695 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4696 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4697 /* Only check the symbol attributes if they're present.
4698 Indices prior to version 7 don't record them,
4699 and indices >= 7 may elide them for certain symbols
4700 (gold does this). */
4703 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4705 /* Work around gold/15646. */
4708 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4716 /* Only check the symbol's kind if it has one. */
4721 case VARIABLES_DOMAIN
:
4722 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4725 case FUNCTIONS_DOMAIN
:
4726 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4730 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4733 case MODULES_DOMAIN
:
4734 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4742 /* Don't crash on bad data. */
4743 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
4744 + per_objfile
->per_bfd
->all_type_units
.size ()))
4746 complaint (_(".gdb_index entry has bad CU index"
4747 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4751 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
4752 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4757 /* If FILE_MATCHER is non-NULL, set all the
4758 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4759 that match FILE_MATCHER. */
4762 dw_expand_symtabs_matching_file_matcher
4763 (dwarf2_per_objfile
*per_objfile
,
4764 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4766 if (file_matcher
== NULL
)
4769 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4771 NULL
, xcalloc
, xfree
));
4772 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4774 NULL
, xcalloc
, xfree
));
4776 /* The rule is CUs specify all the files, including those used by
4777 any TU, so there's no need to scan TUs here. */
4779 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4783 per_cu
->v
.quick
->mark
= 0;
4785 /* We only need to look at symtabs not already expanded. */
4786 if (per_objfile
->symtab_set_p (per_cu
))
4789 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4790 if (file_data
== NULL
)
4793 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4795 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4797 per_cu
->v
.quick
->mark
= 1;
4801 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4803 const char *this_real_name
;
4805 if (file_matcher (file_data
->file_names
[j
], false))
4807 per_cu
->v
.quick
->mark
= 1;
4811 /* Before we invoke realpath, which can get expensive when many
4812 files are involved, do a quick comparison of the basenames. */
4813 if (!basenames_may_differ
4814 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4818 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4819 if (file_matcher (this_real_name
, false))
4821 per_cu
->v
.quick
->mark
= 1;
4826 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4827 ? visited_found
.get ()
4828 : visited_not_found
.get (),
4835 dw2_expand_symtabs_matching
4836 (struct objfile
*objfile
,
4837 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4838 const lookup_name_info
*lookup_name
,
4839 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4840 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4841 enum search_domain kind
)
4843 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4845 /* index_table is NULL if OBJF_READNOW. */
4846 if (!per_objfile
->per_bfd
->index_table
)
4849 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4851 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4853 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4857 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4858 file_matcher
, expansion_notify
);
4863 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4865 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4867 kind
, [&] (offset_type idx
)
4869 dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
, expansion_notify
,
4876 dwarf2_gdb_index::expand_symtabs_matching
4877 (struct objfile
*objfile
,
4878 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4879 const lookup_name_info
*lookup_name
,
4880 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4881 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4882 enum search_domain kind
)
4884 dw2_expand_symtabs_matching (objfile
, file_matcher
, lookup_name
,
4885 symbol_matcher
, expansion_notify
, kind
);
4888 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4891 static struct compunit_symtab
*
4892 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4897 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4898 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4901 if (cust
->includes
== NULL
)
4904 for (i
= 0; cust
->includes
[i
]; ++i
)
4906 struct compunit_symtab
*s
= cust
->includes
[i
];
4908 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4916 struct compunit_symtab
*
4917 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4918 (struct objfile
*objfile
,
4919 struct bound_minimal_symbol msymbol
,
4921 struct obj_section
*section
,
4924 struct dwarf2_per_cu_data
*data
;
4925 struct compunit_symtab
*result
;
4927 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4928 if (per_objfile
->per_bfd
->index_addrmap
== nullptr)
4931 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4932 data
= ((struct dwarf2_per_cu_data
*)
4933 addrmap_find (per_objfile
->per_bfd
->index_addrmap
,
4938 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
4939 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4940 paddress (objfile
->arch (), pc
));
4942 result
= recursively_find_pc_sect_compunit_symtab
4943 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
4945 gdb_assert (result
!= NULL
);
4950 dwarf2_base_index_functions::map_symbol_filenames (struct objfile
*objfile
,
4951 symbol_filename_ftype
*fun
,
4955 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4957 if (!per_objfile
->per_bfd
->filenames_cache
)
4959 per_objfile
->per_bfd
->filenames_cache
.emplace ();
4961 htab_up
visited (htab_create_alloc (10,
4962 htab_hash_pointer
, htab_eq_pointer
,
4963 NULL
, xcalloc
, xfree
));
4965 /* The rule is CUs specify all the files, including those used
4966 by any TU, so there's no need to scan TUs here. We can
4967 ignore file names coming from already-expanded CUs. */
4969 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4971 if (per_objfile
->symtab_set_p (per_cu
))
4973 void **slot
= htab_find_slot (visited
.get (),
4974 per_cu
->v
.quick
->file_names
,
4977 *slot
= per_cu
->v
.quick
->file_names
;
4981 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4983 /* We only need to look at symtabs not already expanded. */
4984 if (per_objfile
->symtab_set_p (per_cu
))
4987 quick_file_names
*file_data
4988 = dw2_get_file_names (per_cu
, per_objfile
);
4989 if (file_data
== NULL
)
4992 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4995 /* Already visited. */
5000 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5002 const char *filename
= file_data
->file_names
[j
];
5003 per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
5008 per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
5010 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5013 this_real_name
= gdb_realpath (filename
);
5014 (*fun
) (filename
, this_real_name
.get (), data
);
5019 dwarf2_base_index_functions::has_symbols (struct objfile
*objfile
)
5024 /* DWARF-5 debug_names reader. */
5026 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5027 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5029 /* A helper function that reads the .debug_names section in SECTION
5030 and fills in MAP. FILENAME is the name of the file containing the
5031 section; it is used for error reporting.
5033 Returns true if all went well, false otherwise. */
5036 read_debug_names_from_section (struct objfile
*objfile
,
5037 const char *filename
,
5038 struct dwarf2_section_info
*section
,
5039 mapped_debug_names
&map
)
5041 if (section
->empty ())
5044 /* Older elfutils strip versions could keep the section in the main
5045 executable while splitting it for the separate debug info file. */
5046 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5049 section
->read (objfile
);
5051 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
5053 const gdb_byte
*addr
= section
->buffer
;
5055 bfd
*const abfd
= section
->get_bfd_owner ();
5057 unsigned int bytes_read
;
5058 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5061 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5062 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5063 if (bytes_read
+ length
!= section
->size
)
5065 /* There may be multiple per-CU indices. */
5066 warning (_("Section .debug_names in %s length %s does not match "
5067 "section length %s, ignoring .debug_names."),
5068 filename
, plongest (bytes_read
+ length
),
5069 pulongest (section
->size
));
5073 /* The version number. */
5074 uint16_t version
= read_2_bytes (abfd
, addr
);
5078 warning (_("Section .debug_names in %s has unsupported version %d, "
5079 "ignoring .debug_names."),
5085 uint16_t padding
= read_2_bytes (abfd
, addr
);
5089 warning (_("Section .debug_names in %s has unsupported padding %d, "
5090 "ignoring .debug_names."),
5095 /* comp_unit_count - The number of CUs in the CU list. */
5096 map
.cu_count
= read_4_bytes (abfd
, addr
);
5099 /* local_type_unit_count - The number of TUs in the local TU
5101 map
.tu_count
= read_4_bytes (abfd
, addr
);
5104 /* foreign_type_unit_count - The number of TUs in the foreign TU
5106 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5108 if (foreign_tu_count
!= 0)
5110 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5111 "ignoring .debug_names."),
5112 filename
, static_cast<unsigned long> (foreign_tu_count
));
5116 /* bucket_count - The number of hash buckets in the hash lookup
5118 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5121 /* name_count - The number of unique names in the index. */
5122 map
.name_count
= read_4_bytes (abfd
, addr
);
5125 /* abbrev_table_size - The size in bytes of the abbreviations
5127 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5130 /* augmentation_string_size - The size in bytes of the augmentation
5131 string. This value is rounded up to a multiple of 4. */
5132 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5134 map
.augmentation_is_gdb
= ((augmentation_string_size
5135 == sizeof (dwarf5_augmentation
))
5136 && memcmp (addr
, dwarf5_augmentation
,
5137 sizeof (dwarf5_augmentation
)) == 0);
5138 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5139 addr
+= augmentation_string_size
;
5142 map
.cu_table_reordered
= addr
;
5143 addr
+= map
.cu_count
* map
.offset_size
;
5145 /* List of Local TUs */
5146 map
.tu_table_reordered
= addr
;
5147 addr
+= map
.tu_count
* map
.offset_size
;
5149 /* Hash Lookup Table */
5150 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5151 addr
+= map
.bucket_count
* 4;
5152 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5153 addr
+= map
.name_count
* 4;
5156 map
.name_table_string_offs_reordered
= addr
;
5157 addr
+= map
.name_count
* map
.offset_size
;
5158 map
.name_table_entry_offs_reordered
= addr
;
5159 addr
+= map
.name_count
* map
.offset_size
;
5161 const gdb_byte
*abbrev_table_start
= addr
;
5164 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5169 const auto insertpair
5170 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5171 if (!insertpair
.second
)
5173 warning (_("Section .debug_names in %s has duplicate index %s, "
5174 "ignoring .debug_names."),
5175 filename
, pulongest (index_num
));
5178 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5179 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5184 mapped_debug_names::index_val::attr attr
;
5185 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5187 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5189 if (attr
.form
== DW_FORM_implicit_const
)
5191 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5195 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5197 indexval
.attr_vec
.push_back (std::move (attr
));
5200 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5202 warning (_("Section .debug_names in %s has abbreviation_table "
5203 "of size %s vs. written as %u, ignoring .debug_names."),
5204 filename
, plongest (addr
- abbrev_table_start
),
5208 map
.entry_pool
= addr
;
5213 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5217 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5218 const mapped_debug_names
&map
,
5219 dwarf2_section_info
§ion
,
5222 if (!map
.augmentation_is_gdb
)
5224 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5226 sect_offset sect_off
5227 = (sect_offset
) (extract_unsigned_integer
5228 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5230 map
.dwarf5_byte_order
));
5231 /* We don't know the length of the CU, because the CU list in a
5232 .debug_names index can be incomplete, so we can't use the start
5233 of the next CU as end of this CU. We create the CUs here with
5234 length 0, and in cutu_reader::cutu_reader we'll fill in the
5236 dwarf2_per_cu_data
*per_cu
5237 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5239 per_bfd
->all_comp_units
.push_back (per_cu
);
5244 sect_offset sect_off_prev
;
5245 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5247 sect_offset sect_off_next
;
5248 if (i
< map
.cu_count
)
5251 = (sect_offset
) (extract_unsigned_integer
5252 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5254 map
.dwarf5_byte_order
));
5257 sect_off_next
= (sect_offset
) section
.size
;
5260 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5261 dwarf2_per_cu_data
*per_cu
5262 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5263 sect_off_prev
, length
);
5264 per_bfd
->all_comp_units
.push_back (per_cu
);
5266 sect_off_prev
= sect_off_next
;
5270 /* Read the CU list from the mapped index, and use it to create all
5271 the CU objects for this dwarf2_per_objfile. */
5274 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5275 const mapped_debug_names
&map
,
5276 const mapped_debug_names
&dwz_map
)
5278 gdb_assert (per_bfd
->all_comp_units
.empty ());
5279 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5281 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5282 false /* is_dwz */);
5284 if (dwz_map
.cu_count
== 0)
5287 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5288 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5292 /* Read .debug_names. If everything went ok, initialize the "quick"
5293 elements of all the CUs and return true. Otherwise, return false. */
5296 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
5298 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5299 mapped_debug_names dwz_map
;
5300 struct objfile
*objfile
= per_objfile
->objfile
;
5301 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5303 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5304 &per_objfile
->per_bfd
->debug_names
, *map
))
5307 /* Don't use the index if it's empty. */
5308 if (map
->name_count
== 0)
5311 /* If there is a .dwz file, read it so we can get its CU list as
5313 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5316 if (!read_debug_names_from_section (objfile
,
5317 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5318 &dwz
->debug_names
, dwz_map
))
5320 warning (_("could not read '.debug_names' section from %s; skipping"),
5321 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5326 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
5328 if (map
->tu_count
!= 0)
5330 /* We can only handle a single .debug_types when we have an
5332 if (per_bfd
->types
.size () != 1)
5335 dwarf2_section_info
*section
= &per_bfd
->types
[0];
5337 create_signatured_type_table_from_debug_names
5338 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
5341 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
5343 per_bfd
->debug_names_table
= std::move (map
);
5344 per_bfd
->using_index
= 1;
5345 per_bfd
->quick_file_names_table
=
5346 create_quick_file_names_table (per_objfile
->per_bfd
->all_comp_units
.size ());
5351 /* Type used to manage iterating over all CUs looking for a symbol for
5354 class dw2_debug_names_iterator
5357 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5358 gdb::optional
<block_enum
> block_index
,
5360 const char *name
, dwarf2_per_objfile
*per_objfile
)
5361 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5362 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5363 m_per_objfile (per_objfile
)
5366 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5367 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5370 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5371 m_per_objfile (per_objfile
)
5374 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5375 block_enum block_index
, domain_enum domain
,
5376 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5377 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5378 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5379 m_per_objfile (per_objfile
)
5382 /* Return the next matching CU or NULL if there are no more. */
5383 dwarf2_per_cu_data
*next ();
5386 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5388 dwarf2_per_objfile
*per_objfile
);
5389 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5391 dwarf2_per_objfile
*per_objfile
);
5393 /* The internalized form of .debug_names. */
5394 const mapped_debug_names
&m_map
;
5396 /* If set, only look for symbols that match that block. Valid values are
5397 GLOBAL_BLOCK and STATIC_BLOCK. */
5398 const gdb::optional
<block_enum
> m_block_index
;
5400 /* The kind of symbol we're looking for. */
5401 const domain_enum m_domain
= UNDEF_DOMAIN
;
5402 const search_domain m_search
= ALL_DOMAIN
;
5404 /* The list of CUs from the index entry of the symbol, or NULL if
5406 const gdb_byte
*m_addr
;
5408 dwarf2_per_objfile
*m_per_objfile
;
5412 mapped_debug_names::namei_to_name
5413 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5415 const ULONGEST namei_string_offs
5416 = extract_unsigned_integer ((name_table_string_offs_reordered
5417 + namei
* offset_size
),
5420 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5423 /* Find a slot in .debug_names for the object named NAME. If NAME is
5424 found, return pointer to its pool data. If NAME cannot be found,
5428 dw2_debug_names_iterator::find_vec_in_debug_names
5429 (const mapped_debug_names
&map
, const char *name
,
5430 dwarf2_per_objfile
*per_objfile
)
5432 int (*cmp
) (const char *, const char *);
5434 gdb::unique_xmalloc_ptr
<char> without_params
;
5435 if (current_language
->la_language
== language_cplus
5436 || current_language
->la_language
== language_fortran
5437 || current_language
->la_language
== language_d
)
5439 /* NAME is already canonical. Drop any qualifiers as
5440 .debug_names does not contain any. */
5442 if (strchr (name
, '(') != NULL
)
5444 without_params
= cp_remove_params (name
);
5445 if (without_params
!= NULL
)
5446 name
= without_params
.get ();
5450 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5452 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5454 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5455 (map
.bucket_table_reordered
5456 + (full_hash
% map
.bucket_count
)), 4,
5457 map
.dwarf5_byte_order
);
5461 if (namei
>= map
.name_count
)
5463 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5465 namei
, map
.name_count
,
5466 objfile_name (per_objfile
->objfile
));
5472 const uint32_t namei_full_hash
5473 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5474 (map
.hash_table_reordered
+ namei
), 4,
5475 map
.dwarf5_byte_order
);
5476 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5479 if (full_hash
== namei_full_hash
)
5481 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5483 #if 0 /* An expensive sanity check. */
5484 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5486 complaint (_("Wrong .debug_names hash for string at index %u "
5488 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5493 if (cmp (namei_string
, name
) == 0)
5495 const ULONGEST namei_entry_offs
5496 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5497 + namei
* map
.offset_size
),
5498 map
.offset_size
, map
.dwarf5_byte_order
);
5499 return map
.entry_pool
+ namei_entry_offs
;
5504 if (namei
>= map
.name_count
)
5510 dw2_debug_names_iterator::find_vec_in_debug_names
5511 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5513 if (namei
>= map
.name_count
)
5515 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5517 namei
, map
.name_count
,
5518 objfile_name (per_objfile
->objfile
));
5522 const ULONGEST namei_entry_offs
5523 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5524 + namei
* map
.offset_size
),
5525 map
.offset_size
, map
.dwarf5_byte_order
);
5526 return map
.entry_pool
+ namei_entry_offs
;
5529 /* See dw2_debug_names_iterator. */
5531 dwarf2_per_cu_data
*
5532 dw2_debug_names_iterator::next ()
5537 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5538 struct objfile
*objfile
= m_per_objfile
->objfile
;
5539 bfd
*const abfd
= objfile
->obfd
;
5543 unsigned int bytes_read
;
5544 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5545 m_addr
+= bytes_read
;
5549 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5550 if (indexval_it
== m_map
.abbrev_map
.cend ())
5552 complaint (_("Wrong .debug_names undefined abbrev code %s "
5554 pulongest (abbrev
), objfile_name (objfile
));
5557 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5558 enum class symbol_linkage
{
5562 } symbol_linkage_
= symbol_linkage::unknown
;
5563 dwarf2_per_cu_data
*per_cu
= NULL
;
5564 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5569 case DW_FORM_implicit_const
:
5570 ull
= attr
.implicit_const
;
5572 case DW_FORM_flag_present
:
5576 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5577 m_addr
+= bytes_read
;
5580 ull
= read_4_bytes (abfd
, m_addr
);
5584 ull
= read_8_bytes (abfd
, m_addr
);
5587 case DW_FORM_ref_sig8
:
5588 ull
= read_8_bytes (abfd
, m_addr
);
5592 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5593 dwarf_form_name (attr
.form
),
5594 objfile_name (objfile
));
5597 switch (attr
.dw_idx
)
5599 case DW_IDX_compile_unit
:
5600 /* Don't crash on bad data. */
5601 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5603 complaint (_(".debug_names entry has bad CU index %s"
5606 objfile_name (objfile
));
5609 per_cu
= per_bfd
->get_cutu (ull
);
5611 case DW_IDX_type_unit
:
5612 /* Don't crash on bad data. */
5613 if (ull
>= per_bfd
->all_type_units
.size ())
5615 complaint (_(".debug_names entry has bad TU index %s"
5618 objfile_name (objfile
));
5621 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5623 case DW_IDX_die_offset
:
5624 /* In a per-CU index (as opposed to a per-module index), index
5625 entries without CU attribute implicitly refer to the single CU. */
5627 per_cu
= per_bfd
->get_cu (0);
5629 case DW_IDX_GNU_internal
:
5630 if (!m_map
.augmentation_is_gdb
)
5632 symbol_linkage_
= symbol_linkage::static_
;
5634 case DW_IDX_GNU_external
:
5635 if (!m_map
.augmentation_is_gdb
)
5637 symbol_linkage_
= symbol_linkage::extern_
;
5642 /* Skip if already read in. */
5643 if (m_per_objfile
->symtab_set_p (per_cu
))
5646 /* Check static vs global. */
5647 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5649 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5650 const bool symbol_is_static
=
5651 symbol_linkage_
== symbol_linkage::static_
;
5652 if (want_static
!= symbol_is_static
)
5656 /* Match dw2_symtab_iter_next, symbol_kind
5657 and debug_names::psymbol_tag. */
5661 switch (indexval
.dwarf_tag
)
5663 case DW_TAG_variable
:
5664 case DW_TAG_subprogram
:
5665 /* Some types are also in VAR_DOMAIN. */
5666 case DW_TAG_typedef
:
5667 case DW_TAG_structure_type
:
5674 switch (indexval
.dwarf_tag
)
5676 case DW_TAG_typedef
:
5677 case DW_TAG_structure_type
:
5684 switch (indexval
.dwarf_tag
)
5687 case DW_TAG_variable
:
5694 switch (indexval
.dwarf_tag
)
5706 /* Match dw2_expand_symtabs_matching, symbol_kind and
5707 debug_names::psymbol_tag. */
5710 case VARIABLES_DOMAIN
:
5711 switch (indexval
.dwarf_tag
)
5713 case DW_TAG_variable
:
5719 case FUNCTIONS_DOMAIN
:
5720 switch (indexval
.dwarf_tag
)
5722 case DW_TAG_subprogram
:
5729 switch (indexval
.dwarf_tag
)
5731 case DW_TAG_typedef
:
5732 case DW_TAG_structure_type
:
5738 case MODULES_DOMAIN
:
5739 switch (indexval
.dwarf_tag
)
5753 struct compunit_symtab
*
5754 dwarf2_debug_names_index::lookup_symbol
5755 (struct objfile
*objfile
, block_enum block_index
,
5756 const char *name
, domain_enum domain
)
5758 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5760 const auto &mapp
= per_objfile
->per_bfd
->debug_names_table
;
5763 /* index is NULL if OBJF_READNOW. */
5766 const auto &map
= *mapp
;
5768 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
, per_objfile
);
5770 struct compunit_symtab
*stab_best
= NULL
;
5771 struct dwarf2_per_cu_data
*per_cu
;
5772 while ((per_cu
= iter
.next ()) != NULL
)
5774 struct symbol
*sym
, *with_opaque
= NULL
;
5775 compunit_symtab
*stab
5776 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5777 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5778 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5780 sym
= block_find_symbol (block
, name
, domain
,
5781 block_find_non_opaque_type_preferred
,
5784 /* Some caution must be observed with overloaded functions and
5785 methods, since the index will not contain any overload
5786 information (but NAME might contain it). */
5789 && strcmp_iw (sym
->search_name (), name
) == 0)
5791 if (with_opaque
!= NULL
5792 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5795 /* Keep looking through other CUs. */
5801 /* This dumps minimal information about .debug_names. It is called
5802 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5803 uses this to verify that .debug_names has been loaded. */
5806 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5808 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5810 gdb_assert (per_objfile
->per_bfd
->using_index
);
5811 printf_filtered (".debug_names:");
5812 if (per_objfile
->per_bfd
->debug_names_table
)
5813 printf_filtered (" exists\n");
5815 printf_filtered (" faked for \"readnow\"\n");
5816 printf_filtered ("\n");
5820 dwarf2_debug_names_index::expand_symtabs_for_function
5821 (struct objfile
*objfile
, const char *func_name
)
5823 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5825 /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5826 if (per_objfile
->per_bfd
->debug_names_table
)
5828 const mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5830 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5833 struct dwarf2_per_cu_data
*per_cu
;
5834 while ((per_cu
= iter
.next ()) != NULL
)
5835 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5840 dwarf2_debug_names_index::map_matching_symbols
5841 (struct objfile
*objfile
,
5842 const lookup_name_info
&name
, domain_enum domain
,
5844 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5845 symbol_compare_ftype
*ordered_compare
)
5847 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5849 /* debug_names_table is NULL if OBJF_READNOW. */
5850 if (!per_objfile
->per_bfd
->debug_names_table
)
5853 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5854 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5856 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5857 auto matcher
= [&] (const char *symname
)
5859 if (ordered_compare
== nullptr)
5861 return ordered_compare (symname
, match_name
) == 0;
5864 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5865 [&] (offset_type namei
)
5867 /* The name was matched, now expand corresponding CUs that were
5869 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5872 struct dwarf2_per_cu_data
*per_cu
;
5873 while ((per_cu
= iter
.next ()) != NULL
)
5874 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5879 /* It's a shame we couldn't do this inside the
5880 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5881 that have already been expanded. Instead, this loop matches what
5882 the psymtab code does. */
5883 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5885 compunit_symtab
*symtab
= per_objfile
->get_symtab (per_cu
);
5886 if (symtab
!= nullptr)
5888 const struct block
*block
5889 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5890 if (!iterate_over_symbols_terminated (block
, name
,
5898 dwarf2_debug_names_index::expand_symtabs_matching
5899 (struct objfile
*objfile
,
5900 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5901 const lookup_name_info
*lookup_name
,
5902 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5903 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5904 enum search_domain kind
)
5906 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5908 /* debug_names_table is NULL if OBJF_READNOW. */
5909 if (!per_objfile
->per_bfd
->debug_names_table
)
5912 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5914 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5916 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5920 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5926 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5928 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5930 kind
, [&] (offset_type namei
)
5932 /* The name was matched, now expand corresponding CUs that were
5934 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
);
5936 struct dwarf2_per_cu_data
*per_cu
;
5937 while ((per_cu
= iter
.next ()) != NULL
)
5938 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5944 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5945 to either a dwarf2_per_bfd or dwz_file object. */
5947 template <typename T
>
5948 static gdb::array_view
<const gdb_byte
>
5949 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5951 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5953 if (section
->empty ())
5956 /* Older elfutils strip versions could keep the section in the main
5957 executable while splitting it for the separate debug info file. */
5958 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5961 section
->read (obj
);
5963 /* dwarf2_section_info::size is a bfd_size_type, while
5964 gdb::array_view works with size_t. On 32-bit hosts, with
5965 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5966 is 32-bit. So we need an explicit narrowing conversion here.
5967 This is fine, because it's impossible to allocate or mmap an
5968 array/buffer larger than what size_t can represent. */
5969 return gdb::make_array_view (section
->buffer
, section
->size
);
5972 /* Lookup the index cache for the contents of the index associated to
5975 static gdb::array_view
<const gdb_byte
>
5976 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5978 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5979 if (build_id
== nullptr)
5982 return global_index_cache
.lookup_gdb_index (build_id
,
5983 &dwarf2_per_bfd
->index_cache_res
);
5986 /* Same as the above, but for DWZ. */
5988 static gdb::array_view
<const gdb_byte
>
5989 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5991 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5992 if (build_id
== nullptr)
5995 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5998 /* See symfile.h. */
6001 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6003 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6004 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6006 dwarf_read_debug_printf ("called");
6008 /* If we're about to read full symbols, don't bother with the
6009 indices. In this case we also don't care if some other debug
6010 format is making psymtabs, because they are all about to be
6012 if ((objfile
->flags
& OBJF_READNOW
))
6014 dwarf_read_debug_printf ("readnow requested");
6016 /* When using READNOW, the using_index flag (set below) indicates that
6017 PER_BFD was already initialized, when we loaded some other objfile. */
6018 if (per_bfd
->using_index
)
6020 dwarf_read_debug_printf ("using_index already set");
6021 *index_kind
= dw_index_kind::GDB_INDEX
;
6022 per_objfile
->resize_symtabs ();
6026 per_bfd
->using_index
= 1;
6027 create_all_comp_units (per_objfile
);
6028 create_all_type_units (per_objfile
);
6029 per_bfd
->quick_file_names_table
6030 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
6031 per_objfile
->resize_symtabs ();
6033 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
6034 + per_bfd
->all_type_units
.size ()); ++i
)
6036 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
6038 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6039 struct dwarf2_per_cu_quick_data
);
6042 /* Return 1 so that gdb sees the "quick" functions. However,
6043 these functions will be no-ops because we will have expanded
6045 *index_kind
= dw_index_kind::GDB_INDEX
;
6049 /* Was a debug names index already read when we processed an objfile sharing
6051 if (per_bfd
->debug_names_table
!= nullptr)
6053 dwarf_read_debug_printf ("re-using shared debug names table");
6054 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6055 per_objfile
->resize_symtabs ();
6059 /* Was a GDB index already read when we processed an objfile sharing
6061 if (per_bfd
->index_table
!= nullptr)
6063 dwarf_read_debug_printf ("re-using shared index table");
6064 *index_kind
= dw_index_kind::GDB_INDEX
;
6065 per_objfile
->resize_symtabs ();
6069 /* There might already be partial symtabs built for this BFD. This happens
6070 when loading the same binary twice with the index-cache enabled. If so,
6071 don't try to read an index. The objfile / per_objfile initialization will
6072 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
6074 if (per_bfd
->partial_symtabs
!= nullptr)
6076 dwarf_read_debug_printf ("re-using shared partial symtabs");
6080 if (dwarf2_read_debug_names (per_objfile
))
6082 dwarf_read_debug_printf ("found debug names");
6083 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6084 per_objfile
->resize_symtabs ();
6088 if (dwarf2_read_gdb_index (per_objfile
,
6089 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
6090 get_gdb_index_contents_from_section
<dwz_file
>))
6092 dwarf_read_debug_printf ("found gdb index from file");
6093 *index_kind
= dw_index_kind::GDB_INDEX
;
6094 per_objfile
->resize_symtabs ();
6098 /* ... otherwise, try to find the index in the index cache. */
6099 if (dwarf2_read_gdb_index (per_objfile
,
6100 get_gdb_index_contents_from_cache
,
6101 get_gdb_index_contents_from_cache_dwz
))
6103 dwarf_read_debug_printf ("found gdb index from cache");
6104 global_index_cache
.hit ();
6105 *index_kind
= dw_index_kind::GDB_INDEX
;
6106 per_objfile
->resize_symtabs ();
6110 global_index_cache
.miss ();
6116 /* Build a partial symbol table. */
6119 dwarf2_build_psymtabs (struct objfile
*objfile
, psymbol_functions
*psf
)
6121 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6122 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6124 if (per_bfd
->partial_symtabs
!= nullptr)
6126 /* Partial symbols were already read, so now we can simply
6130 psf
= new psymbol_functions (per_bfd
->partial_symtabs
);
6131 objfile
->qf
.emplace_front (psf
);
6134 psf
->set_partial_symtabs (per_bfd
->partial_symtabs
);
6135 per_objfile
->resize_symtabs ();
6141 psf
= new psymbol_functions
;
6142 objfile
->qf
.emplace_front (psf
);
6144 const std::shared_ptr
<psymtab_storage
> &partial_symtabs
6145 = psf
->get_partial_symtabs ();
6147 /* Set the local reference to partial symtabs, so that we don't try
6148 to read them again if reading another objfile with the same BFD.
6149 If we can't in fact share, this won't make a difference anyway as
6150 the dwarf2_per_bfd object won't be shared. */
6151 per_bfd
->partial_symtabs
= partial_symtabs
;
6155 /* This isn't really ideal: all the data we allocate on the
6156 objfile's obstack is still uselessly kept around. However,
6157 freeing it seems unsafe. */
6158 psymtab_discarder
psymtabs (partial_symtabs
.get ());
6159 dwarf2_build_psymtabs_hard (per_objfile
);
6162 per_objfile
->resize_symtabs ();
6164 /* (maybe) store an index in the cache. */
6165 global_index_cache
.store (per_objfile
);
6167 catch (const gdb_exception_error
&except
)
6169 exception_print (gdb_stderr
, except
);
6173 /* Find the base address of the compilation unit for range lists and
6174 location lists. It will normally be specified by DW_AT_low_pc.
6175 In DWARF-3 draft 4, the base address could be overridden by
6176 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6177 compilation units with discontinuous ranges. */
6180 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6182 struct attribute
*attr
;
6184 cu
->base_address
.reset ();
6186 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6187 if (attr
!= nullptr)
6188 cu
->base_address
= attr
->as_address ();
6191 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6192 if (attr
!= nullptr)
6193 cu
->base_address
= attr
->as_address ();
6197 /* Helper function that returns the proper abbrev section for
6200 static struct dwarf2_section_info
*
6201 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6203 struct dwarf2_section_info
*abbrev
;
6204 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6206 if (this_cu
->is_dwz
)
6207 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
6209 abbrev
= &per_bfd
->abbrev
;
6214 /* Fetch the abbreviation table offset from a comp or type unit header. */
6217 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
6218 struct dwarf2_section_info
*section
,
6219 sect_offset sect_off
)
6221 bfd
*abfd
= section
->get_bfd_owner ();
6222 const gdb_byte
*info_ptr
;
6223 unsigned int initial_length_size
, offset_size
;
6226 section
->read (per_objfile
->objfile
);
6227 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6228 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6229 offset_size
= initial_length_size
== 4 ? 4 : 8;
6230 info_ptr
+= initial_length_size
;
6232 version
= read_2_bytes (abfd
, info_ptr
);
6236 /* Skip unit type and address size. */
6240 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6243 /* A partial symtab that is used only for include files. */
6244 struct dwarf2_include_psymtab
: public partial_symtab
6246 dwarf2_include_psymtab (const char *filename
,
6247 psymtab_storage
*partial_symtabs
,
6248 struct objfile
*objfile
)
6249 : partial_symtab (filename
, partial_symtabs
, objfile
)
6253 void read_symtab (struct objfile
*objfile
) override
6255 /* It's an include file, no symbols to read for it.
6256 Everything is in the includer symtab. */
6258 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6259 expansion of the includer psymtab. We use the dependencies[0] field to
6260 model the includer. But if we go the regular route of calling
6261 expand_psymtab here, and having expand_psymtab call expand_dependencies
6262 to expand the includer, we'll only use expand_psymtab on the includer
6263 (making it a non-toplevel psymtab), while if we expand the includer via
6264 another path, we'll use read_symtab (making it a toplevel psymtab).
6265 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6266 psymtab, and trigger read_symtab on the includer here directly. */
6267 includer ()->read_symtab (objfile
);
6270 void expand_psymtab (struct objfile
*objfile
) override
6272 /* This is not called by read_symtab, and should not be called by any
6273 expand_dependencies. */
6277 bool readin_p (struct objfile
*objfile
) const override
6279 return includer ()->readin_p (objfile
);
6282 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6288 partial_symtab
*includer () const
6290 /* An include psymtab has exactly one dependency: the psymtab that
6292 gdb_assert (this->number_of_dependencies
== 1);
6293 return this->dependencies
[0];
6297 /* Allocate a new partial symtab for file named NAME and mark this new
6298 partial symtab as being an include of PST. */
6301 dwarf2_create_include_psymtab (dwarf2_per_bfd
*per_bfd
,
6303 dwarf2_psymtab
*pst
,
6304 psymtab_storage
*partial_symtabs
,
6305 struct objfile
*objfile
)
6307 dwarf2_include_psymtab
*subpst
6308 = new dwarf2_include_psymtab (name
, partial_symtabs
, objfile
);
6310 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6311 subpst
->dirname
= pst
->dirname
;
6313 subpst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (1);
6314 subpst
->dependencies
[0] = pst
;
6315 subpst
->number_of_dependencies
= 1;
6318 /* Read the Line Number Program data and extract the list of files
6319 included by the source file represented by PST. Build an include
6320 partial symtab for each of these included files. */
6323 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6324 struct die_info
*die
,
6325 dwarf2_psymtab
*pst
)
6328 struct attribute
*attr
;
6330 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6331 if (attr
!= nullptr && attr
->form_is_unsigned ())
6332 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
6334 return; /* No linetable, so no includes. */
6336 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6337 that we pass in the raw text_low here; that is ok because we're
6338 only decoding the line table to make include partial symtabs, and
6339 so the addresses aren't really used. */
6340 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6341 pst
->raw_text_low (), 1);
6345 hash_signatured_type (const void *item
)
6347 const struct signatured_type
*sig_type
6348 = (const struct signatured_type
*) item
;
6350 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6351 return sig_type
->signature
;
6355 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6357 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6358 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6360 return lhs
->signature
== rhs
->signature
;
6363 /* Allocate a hash table for signatured types. */
6366 allocate_signatured_type_table ()
6368 return htab_up (htab_create_alloc (41,
6369 hash_signatured_type
,
6371 NULL
, xcalloc
, xfree
));
6374 /* A helper function to add a signatured type CU to a table. */
6377 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6379 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6380 std::vector
<signatured_type
*> *all_type_units
6381 = (std::vector
<signatured_type
*> *) datum
;
6383 all_type_units
->push_back (sigt
);
6388 /* A helper for create_debug_types_hash_table. Read types from SECTION
6389 and fill them into TYPES_HTAB. It will process only type units,
6390 therefore DW_UT_type. */
6393 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6394 struct dwo_file
*dwo_file
,
6395 dwarf2_section_info
*section
, htab_up
&types_htab
,
6396 rcuh_kind section_kind
)
6398 struct objfile
*objfile
= per_objfile
->objfile
;
6399 struct dwarf2_section_info
*abbrev_section
;
6401 const gdb_byte
*info_ptr
, *end_ptr
;
6403 abbrev_section
= (dwo_file
!= NULL
6404 ? &dwo_file
->sections
.abbrev
6405 : &per_objfile
->per_bfd
->abbrev
);
6407 dwarf_read_debug_printf ("Reading %s for %s",
6408 section
->get_name (),
6409 abbrev_section
->get_file_name ());
6411 section
->read (objfile
);
6412 info_ptr
= section
->buffer
;
6414 if (info_ptr
== NULL
)
6417 /* We can't set abfd until now because the section may be empty or
6418 not present, in which case the bfd is unknown. */
6419 abfd
= section
->get_bfd_owner ();
6421 /* We don't use cutu_reader here because we don't need to read
6422 any dies: the signature is in the header. */
6424 end_ptr
= info_ptr
+ section
->size
;
6425 while (info_ptr
< end_ptr
)
6427 struct signatured_type
*sig_type
;
6428 struct dwo_unit
*dwo_tu
;
6430 const gdb_byte
*ptr
= info_ptr
;
6431 struct comp_unit_head header
;
6432 unsigned int length
;
6434 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6436 /* Initialize it due to a false compiler warning. */
6437 header
.signature
= -1;
6438 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6440 /* We need to read the type's signature in order to build the hash
6441 table, but we don't need anything else just yet. */
6443 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6444 abbrev_section
, ptr
, section_kind
);
6446 length
= header
.get_length ();
6448 /* Skip dummy type units. */
6449 if (ptr
>= info_ptr
+ length
6450 || peek_abbrev_code (abfd
, ptr
) == 0
6451 || (header
.unit_type
!= DW_UT_type
6452 && header
.unit_type
!= DW_UT_split_type
))
6458 if (types_htab
== NULL
)
6461 types_htab
= allocate_dwo_unit_table ();
6463 types_htab
= allocate_signatured_type_table ();
6469 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6470 dwo_tu
->dwo_file
= dwo_file
;
6471 dwo_tu
->signature
= header
.signature
;
6472 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6473 dwo_tu
->section
= section
;
6474 dwo_tu
->sect_off
= sect_off
;
6475 dwo_tu
->length
= length
;
6479 /* N.B.: type_offset is not usable if this type uses a DWO file.
6480 The real type_offset is in the DWO file. */
6482 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6483 sig_type
->signature
= header
.signature
;
6484 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6485 sig_type
->per_cu
.is_debug_types
= 1;
6486 sig_type
->per_cu
.section
= section
;
6487 sig_type
->per_cu
.sect_off
= sect_off
;
6488 sig_type
->per_cu
.length
= length
;
6491 slot
= htab_find_slot (types_htab
.get (),
6492 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6494 gdb_assert (slot
!= NULL
);
6497 sect_offset dup_sect_off
;
6501 const struct dwo_unit
*dup_tu
6502 = (const struct dwo_unit
*) *slot
;
6504 dup_sect_off
= dup_tu
->sect_off
;
6508 const struct signatured_type
*dup_tu
6509 = (const struct signatured_type
*) *slot
;
6511 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6514 complaint (_("debug type entry at offset %s is duplicate to"
6515 " the entry at offset %s, signature %s"),
6516 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6517 hex_string (header
.signature
));
6519 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6521 dwarf_read_debug_printf_v (" offset %s, signature %s",
6522 sect_offset_str (sect_off
),
6523 hex_string (header
.signature
));
6529 /* Create the hash table of all entries in the .debug_types
6530 (or .debug_types.dwo) section(s).
6531 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6532 otherwise it is NULL.
6534 The result is a pointer to the hash table or NULL if there are no types.
6536 Note: This function processes DWO files only, not DWP files. */
6539 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6540 struct dwo_file
*dwo_file
,
6541 gdb::array_view
<dwarf2_section_info
> type_sections
,
6542 htab_up
&types_htab
)
6544 for (dwarf2_section_info
§ion
: type_sections
)
6545 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6549 /* Create the hash table of all entries in the .debug_types section,
6550 and initialize all_type_units.
6551 The result is zero if there is an error (e.g. missing .debug_types section),
6552 otherwise non-zero. */
6555 create_all_type_units (dwarf2_per_objfile
*per_objfile
)
6559 create_debug_type_hash_table (per_objfile
, NULL
, &per_objfile
->per_bfd
->info
,
6560 types_htab
, rcuh_kind::COMPILE
);
6561 create_debug_types_hash_table (per_objfile
, NULL
, per_objfile
->per_bfd
->types
,
6563 if (types_htab
== NULL
)
6565 per_objfile
->per_bfd
->signatured_types
= NULL
;
6569 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6571 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
6572 per_objfile
->per_bfd
->all_type_units
.reserve
6573 (htab_elements (per_objfile
->per_bfd
->signatured_types
.get ()));
6575 htab_traverse_noresize (per_objfile
->per_bfd
->signatured_types
.get (),
6576 add_signatured_type_cu_to_table
,
6577 &per_objfile
->per_bfd
->all_type_units
);
6582 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6583 If SLOT is non-NULL, it is the entry to use in the hash table.
6584 Otherwise we find one. */
6586 static struct signatured_type
*
6587 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6589 if (per_objfile
->per_bfd
->all_type_units
.size ()
6590 == per_objfile
->per_bfd
->all_type_units
.capacity ())
6591 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6593 signatured_type
*sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6595 per_objfile
->resize_symtabs ();
6597 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6598 sig_type
->signature
= sig
;
6599 sig_type
->per_cu
.is_debug_types
= 1;
6600 if (per_objfile
->per_bfd
->using_index
)
6602 sig_type
->per_cu
.v
.quick
=
6603 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6604 struct dwarf2_per_cu_quick_data
);
6609 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6612 gdb_assert (*slot
== NULL
);
6614 /* The rest of sig_type must be filled in by the caller. */
6618 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6619 Fill in SIG_ENTRY with DWO_ENTRY. */
6622 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6623 struct signatured_type
*sig_entry
,
6624 struct dwo_unit
*dwo_entry
)
6626 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6628 /* Make sure we're not clobbering something we don't expect to. */
6629 gdb_assert (! sig_entry
->per_cu
.queued
);
6630 gdb_assert (per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6631 if (per_bfd
->using_index
)
6633 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6634 gdb_assert (!per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6637 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6638 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6639 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6640 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6641 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6643 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6644 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6645 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6646 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6647 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6648 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6649 sig_entry
->dwo_unit
= dwo_entry
;
6652 /* Subroutine of lookup_signatured_type.
6653 If we haven't read the TU yet, create the signatured_type data structure
6654 for a TU to be read in directly from a DWO file, bypassing the stub.
6655 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6656 using .gdb_index, then when reading a CU we want to stay in the DWO file
6657 containing that CU. Otherwise we could end up reading several other DWO
6658 files (due to comdat folding) to process the transitive closure of all the
6659 mentioned TUs, and that can be slow. The current DWO file will have every
6660 type signature that it needs.
6661 We only do this for .gdb_index because in the psymtab case we already have
6662 to read all the DWOs to build the type unit groups. */
6664 static struct signatured_type
*
6665 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6667 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6668 struct dwo_file
*dwo_file
;
6669 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6670 struct signatured_type find_sig_entry
, *sig_entry
;
6673 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6675 /* If TU skeletons have been removed then we may not have read in any
6677 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6678 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6680 /* We only ever need to read in one copy of a signatured type.
6681 Use the global signatured_types array to do our own comdat-folding
6682 of types. If this is the first time we're reading this TU, and
6683 the TU has an entry in .gdb_index, replace the recorded data from
6684 .gdb_index with this TU. */
6686 find_sig_entry
.signature
= sig
;
6687 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6688 &find_sig_entry
, INSERT
);
6689 sig_entry
= (struct signatured_type
*) *slot
;
6691 /* We can get here with the TU already read, *or* in the process of being
6692 read. Don't reassign the global entry to point to this DWO if that's
6693 the case. Also note that if the TU is already being read, it may not
6694 have come from a DWO, the program may be a mix of Fission-compiled
6695 code and non-Fission-compiled code. */
6697 /* Have we already tried to read this TU?
6698 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6699 needn't exist in the global table yet). */
6700 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6703 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6704 dwo_unit of the TU itself. */
6705 dwo_file
= cu
->dwo_unit
->dwo_file
;
6707 /* Ok, this is the first time we're reading this TU. */
6708 if (dwo_file
->tus
== NULL
)
6710 find_dwo_entry
.signature
= sig
;
6711 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6713 if (dwo_entry
== NULL
)
6716 /* If the global table doesn't have an entry for this TU, add one. */
6717 if (sig_entry
== NULL
)
6718 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6720 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6721 sig_entry
->per_cu
.tu_read
= 1;
6725 /* Subroutine of lookup_signatured_type.
6726 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6727 then try the DWP file. If the TU stub (skeleton) has been removed then
6728 it won't be in .gdb_index. */
6730 static struct signatured_type
*
6731 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6733 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6734 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6735 struct dwo_unit
*dwo_entry
;
6736 struct signatured_type find_sig_entry
, *sig_entry
;
6739 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6740 gdb_assert (dwp_file
!= NULL
);
6742 /* If TU skeletons have been removed then we may not have read in any
6744 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6745 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6747 find_sig_entry
.signature
= sig
;
6748 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6749 &find_sig_entry
, INSERT
);
6750 sig_entry
= (struct signatured_type
*) *slot
;
6752 /* Have we already tried to read this TU?
6753 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6754 needn't exist in the global table yet). */
6755 if (sig_entry
!= NULL
)
6758 if (dwp_file
->tus
== NULL
)
6760 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6761 1 /* is_debug_types */);
6762 if (dwo_entry
== NULL
)
6765 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6766 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6771 /* Lookup a signature based type for DW_FORM_ref_sig8.
6772 Returns NULL if signature SIG is not present in the table.
6773 It is up to the caller to complain about this. */
6775 static struct signatured_type
*
6776 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6778 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6780 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6782 /* We're in a DWO/DWP file, and we're using .gdb_index.
6783 These cases require special processing. */
6784 if (get_dwp_file (per_objfile
) == NULL
)
6785 return lookup_dwo_signatured_type (cu
, sig
);
6787 return lookup_dwp_signatured_type (cu
, sig
);
6791 struct signatured_type find_entry
, *entry
;
6793 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6795 find_entry
.signature
= sig
;
6796 entry
= ((struct signatured_type
*)
6797 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6803 /* Low level DIE reading support. */
6805 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6808 init_cu_die_reader (struct die_reader_specs
*reader
,
6809 struct dwarf2_cu
*cu
,
6810 struct dwarf2_section_info
*section
,
6811 struct dwo_file
*dwo_file
,
6812 struct abbrev_table
*abbrev_table
)
6814 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6815 reader
->abfd
= section
->get_bfd_owner ();
6817 reader
->dwo_file
= dwo_file
;
6818 reader
->die_section
= section
;
6819 reader
->buffer
= section
->buffer
;
6820 reader
->buffer_end
= section
->buffer
+ section
->size
;
6821 reader
->abbrev_table
= abbrev_table
;
6824 /* Subroutine of cutu_reader to simplify it.
6825 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6826 There's just a lot of work to do, and cutu_reader is big enough
6829 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6830 from it to the DIE in the DWO. If NULL we are skipping the stub.
6831 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6832 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6833 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6834 STUB_COMP_DIR may be non-NULL.
6835 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6836 are filled in with the info of the DIE from the DWO file.
6837 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6838 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6839 kept around for at least as long as *RESULT_READER.
6841 The result is non-zero if a valid (non-dummy) DIE was found. */
6844 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6845 struct dwo_unit
*dwo_unit
,
6846 struct die_info
*stub_comp_unit_die
,
6847 const char *stub_comp_dir
,
6848 struct die_reader_specs
*result_reader
,
6849 const gdb_byte
**result_info_ptr
,
6850 struct die_info
**result_comp_unit_die
,
6851 abbrev_table_up
*result_dwo_abbrev_table
)
6853 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6854 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6855 struct objfile
*objfile
= per_objfile
->objfile
;
6857 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6858 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6859 int i
,num_extra_attrs
;
6860 struct dwarf2_section_info
*dwo_abbrev_section
;
6861 struct die_info
*comp_unit_die
;
6863 /* At most one of these may be provided. */
6864 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6866 /* These attributes aren't processed until later:
6867 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6868 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6869 referenced later. However, these attributes are found in the stub
6870 which we won't have later. In order to not impose this complication
6871 on the rest of the code, we read them here and copy them to the
6880 if (stub_comp_unit_die
!= NULL
)
6882 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6884 if (!per_cu
->is_debug_types
)
6885 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6886 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6887 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6888 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6889 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6891 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6893 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6894 We need the value before we can process DW_AT_ranges values from the
6896 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6898 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6899 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6900 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6901 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6903 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6905 else if (stub_comp_dir
!= NULL
)
6907 /* Reconstruct the comp_dir attribute to simplify the code below. */
6908 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6909 comp_dir
->name
= DW_AT_comp_dir
;
6910 comp_dir
->form
= DW_FORM_string
;
6911 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6914 /* Set up for reading the DWO CU/TU. */
6915 cu
->dwo_unit
= dwo_unit
;
6916 dwarf2_section_info
*section
= dwo_unit
->section
;
6917 section
->read (objfile
);
6918 abfd
= section
->get_bfd_owner ();
6919 begin_info_ptr
= info_ptr
= (section
->buffer
6920 + to_underlying (dwo_unit
->sect_off
));
6921 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6923 if (per_cu
->is_debug_types
)
6925 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6927 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6928 section
, dwo_abbrev_section
,
6929 info_ptr
, rcuh_kind::TYPE
);
6930 /* This is not an assert because it can be caused by bad debug info. */
6931 if (sig_type
->signature
!= cu
->header
.signature
)
6933 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6934 " TU at offset %s [in module %s]"),
6935 hex_string (sig_type
->signature
),
6936 hex_string (cu
->header
.signature
),
6937 sect_offset_str (dwo_unit
->sect_off
),
6938 bfd_get_filename (abfd
));
6940 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6941 /* For DWOs coming from DWP files, we don't know the CU length
6942 nor the type's offset in the TU until now. */
6943 dwo_unit
->length
= cu
->header
.get_length ();
6944 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6946 /* Establish the type offset that can be used to lookup the type.
6947 For DWO files, we don't know it until now. */
6948 sig_type
->type_offset_in_section
6949 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6953 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6954 section
, dwo_abbrev_section
,
6955 info_ptr
, rcuh_kind::COMPILE
);
6956 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6957 /* For DWOs coming from DWP files, we don't know the CU length
6959 dwo_unit
->length
= cu
->header
.get_length ();
6962 dwo_abbrev_section
->read (objfile
);
6963 *result_dwo_abbrev_table
6964 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6965 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6966 result_dwo_abbrev_table
->get ());
6968 /* Read in the die, but leave space to copy over the attributes
6969 from the stub. This has the benefit of simplifying the rest of
6970 the code - all the work to maintain the illusion of a single
6971 DW_TAG_{compile,type}_unit DIE is done here. */
6972 num_extra_attrs
= ((stmt_list
!= NULL
)
6976 + (comp_dir
!= NULL
));
6977 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6980 /* Copy over the attributes from the stub to the DIE we just read in. */
6981 comp_unit_die
= *result_comp_unit_die
;
6982 i
= comp_unit_die
->num_attrs
;
6983 if (stmt_list
!= NULL
)
6984 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6986 comp_unit_die
->attrs
[i
++] = *low_pc
;
6987 if (high_pc
!= NULL
)
6988 comp_unit_die
->attrs
[i
++] = *high_pc
;
6990 comp_unit_die
->attrs
[i
++] = *ranges
;
6991 if (comp_dir
!= NULL
)
6992 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6993 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6995 if (dwarf_die_debug
)
6997 fprintf_unfiltered (gdb_stdlog
,
6998 "Read die from %s@0x%x of %s:\n",
6999 section
->get_name (),
7000 (unsigned) (begin_info_ptr
- section
->buffer
),
7001 bfd_get_filename (abfd
));
7002 dump_die (comp_unit_die
, dwarf_die_debug
);
7005 /* Skip dummy compilation units. */
7006 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7007 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7010 *result_info_ptr
= info_ptr
;
7014 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7015 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7016 signature is part of the header. */
7017 static gdb::optional
<ULONGEST
>
7018 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7020 if (cu
->header
.version
>= 5)
7021 return cu
->header
.signature
;
7022 struct attribute
*attr
;
7023 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7024 if (attr
== nullptr || !attr
->form_is_unsigned ())
7025 return gdb::optional
<ULONGEST
> ();
7026 return attr
->as_unsigned ();
7029 /* Subroutine of cutu_reader to simplify it.
7030 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7031 Returns NULL if the specified DWO unit cannot be found. */
7033 static struct dwo_unit
*
7034 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
7036 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7037 struct dwo_unit
*dwo_unit
;
7038 const char *comp_dir
;
7040 gdb_assert (cu
!= NULL
);
7042 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7043 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7044 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7046 if (per_cu
->is_debug_types
)
7047 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
7050 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7052 if (!signature
.has_value ())
7053 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7055 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
7057 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
7063 /* Subroutine of cutu_reader to simplify it.
7064 See it for a description of the parameters.
7065 Read a TU directly from a DWO file, bypassing the stub. */
7068 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
7069 dwarf2_per_objfile
*per_objfile
,
7070 dwarf2_cu
*existing_cu
)
7072 struct signatured_type
*sig_type
;
7074 /* Verify we can do the following downcast, and that we have the
7076 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7077 sig_type
= (struct signatured_type
*) this_cu
;
7078 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7082 if (existing_cu
!= nullptr)
7085 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
7086 /* There's no need to do the rereading_dwo_cu handling that
7087 cutu_reader does since we don't read the stub. */
7091 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7092 in per_objfile yet. */
7093 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7094 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7095 cu
= m_new_cu
.get ();
7098 /* A future optimization, if needed, would be to use an existing
7099 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7100 could share abbrev tables. */
7102 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
7103 NULL
/* stub_comp_unit_die */,
7104 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7107 &m_dwo_abbrev_table
) == 0)
7114 /* Initialize a CU (or TU) and read its DIEs.
7115 If the CU defers to a DWO file, read the DWO file as well.
7117 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7118 Otherwise the table specified in the comp unit header is read in and used.
7119 This is an optimization for when we already have the abbrev table.
7121 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7124 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7125 dwarf2_per_objfile
*per_objfile
,
7126 struct abbrev_table
*abbrev_table
,
7127 dwarf2_cu
*existing_cu
,
7129 : die_reader_specs
{},
7132 struct objfile
*objfile
= per_objfile
->objfile
;
7133 struct dwarf2_section_info
*section
= this_cu
->section
;
7134 bfd
*abfd
= section
->get_bfd_owner ();
7135 const gdb_byte
*begin_info_ptr
;
7136 struct signatured_type
*sig_type
= NULL
;
7137 struct dwarf2_section_info
*abbrev_section
;
7138 /* Non-zero if CU currently points to a DWO file and we need to
7139 reread it. When this happens we need to reread the skeleton die
7140 before we can reread the DWO file (this only applies to CUs, not TUs). */
7141 int rereading_dwo_cu
= 0;
7143 if (dwarf_die_debug
)
7144 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7145 this_cu
->is_debug_types
? "type" : "comp",
7146 sect_offset_str (this_cu
->sect_off
));
7148 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7149 file (instead of going through the stub), short-circuit all of this. */
7150 if (this_cu
->reading_dwo_directly
)
7152 /* Narrow down the scope of possibilities to have to understand. */
7153 gdb_assert (this_cu
->is_debug_types
);
7154 gdb_assert (abbrev_table
== NULL
);
7155 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
7159 /* This is cheap if the section is already read in. */
7160 section
->read (objfile
);
7162 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7164 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7168 if (existing_cu
!= nullptr)
7171 /* If this CU is from a DWO file we need to start over, we need to
7172 refetch the attributes from the skeleton CU.
7173 This could be optimized by retrieving those attributes from when we
7174 were here the first time: the previous comp_unit_die was stored in
7175 comp_unit_obstack. But there's no data yet that we need this
7177 if (cu
->dwo_unit
!= NULL
)
7178 rereading_dwo_cu
= 1;
7182 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7183 in per_objfile yet. */
7184 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7185 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7186 cu
= m_new_cu
.get ();
7189 /* Get the header. */
7190 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7192 /* We already have the header, there's no need to read it in again. */
7193 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7197 if (this_cu
->is_debug_types
)
7199 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7200 section
, abbrev_section
,
7201 info_ptr
, rcuh_kind::TYPE
);
7203 /* Since per_cu is the first member of struct signatured_type,
7204 we can go from a pointer to one to a pointer to the other. */
7205 sig_type
= (struct signatured_type
*) this_cu
;
7206 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7207 gdb_assert (sig_type
->type_offset_in_tu
7208 == cu
->header
.type_cu_offset_in_tu
);
7209 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7211 /* LENGTH has not been set yet for type units if we're
7212 using .gdb_index. */
7213 this_cu
->length
= cu
->header
.get_length ();
7215 /* Establish the type offset that can be used to lookup the type. */
7216 sig_type
->type_offset_in_section
=
7217 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7219 this_cu
->dwarf_version
= cu
->header
.version
;
7223 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7224 section
, abbrev_section
,
7226 rcuh_kind::COMPILE
);
7228 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7229 if (this_cu
->length
== 0)
7230 this_cu
->length
= cu
->header
.get_length ();
7232 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7233 this_cu
->dwarf_version
= cu
->header
.version
;
7237 /* Skip dummy compilation units. */
7238 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7239 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7245 /* If we don't have them yet, read the abbrevs for this compilation unit.
7246 And if we need to read them now, make sure they're freed when we're
7248 if (abbrev_table
!= NULL
)
7249 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7252 abbrev_section
->read (objfile
);
7253 m_abbrev_table_holder
7254 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
7255 abbrev_table
= m_abbrev_table_holder
.get ();
7258 /* Read the top level CU/TU die. */
7259 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7260 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7262 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7268 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7269 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7270 table from the DWO file and pass the ownership over to us. It will be
7271 referenced from READER, so we must make sure to free it after we're done
7274 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7275 DWO CU, that this test will fail (the attribute will not be present). */
7276 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7277 if (dwo_name
!= nullptr)
7279 struct dwo_unit
*dwo_unit
;
7280 struct die_info
*dwo_comp_unit_die
;
7282 if (comp_unit_die
->has_children
)
7284 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7285 " has children (offset %s) [in module %s]"),
7286 sect_offset_str (this_cu
->sect_off
),
7287 bfd_get_filename (abfd
));
7289 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7290 if (dwo_unit
!= NULL
)
7292 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7293 comp_unit_die
, NULL
,
7296 &m_dwo_abbrev_table
) == 0)
7302 comp_unit_die
= dwo_comp_unit_die
;
7306 /* Yikes, we couldn't find the rest of the DIE, we only have
7307 the stub. A complaint has already been logged. There's
7308 not much more we can do except pass on the stub DIE to
7309 die_reader_func. We don't want to throw an error on bad
7316 cutu_reader::keep ()
7318 /* Done, clean up. */
7319 gdb_assert (!dummy_p
);
7320 if (m_new_cu
!= NULL
)
7322 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7324 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7325 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7329 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7330 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7331 assumed to have already done the lookup to find the DWO file).
7333 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7334 THIS_CU->is_debug_types, but nothing else.
7336 We fill in THIS_CU->length.
7338 THIS_CU->cu is always freed when done.
7339 This is done in order to not leave THIS_CU->cu in a state where we have
7340 to care whether it refers to the "main" CU or the DWO CU.
7342 When parent_cu is passed, it is used to provide a default value for
7343 str_offsets_base and addr_base from the parent. */
7345 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7346 dwarf2_per_objfile
*per_objfile
,
7347 struct dwarf2_cu
*parent_cu
,
7348 struct dwo_file
*dwo_file
)
7349 : die_reader_specs
{},
7352 struct objfile
*objfile
= per_objfile
->objfile
;
7353 struct dwarf2_section_info
*section
= this_cu
->section
;
7354 bfd
*abfd
= section
->get_bfd_owner ();
7355 struct dwarf2_section_info
*abbrev_section
;
7356 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7358 if (dwarf_die_debug
)
7359 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7360 this_cu
->is_debug_types
? "type" : "comp",
7361 sect_offset_str (this_cu
->sect_off
));
7363 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7365 abbrev_section
= (dwo_file
!= NULL
7366 ? &dwo_file
->sections
.abbrev
7367 : get_abbrev_section_for_cu (this_cu
));
7369 /* This is cheap if the section is already read in. */
7370 section
->read (objfile
);
7372 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7374 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7375 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
7376 section
, abbrev_section
, info_ptr
,
7377 (this_cu
->is_debug_types
7379 : rcuh_kind::COMPILE
));
7381 if (parent_cu
!= nullptr)
7383 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7384 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7386 this_cu
->length
= m_new_cu
->header
.get_length ();
7388 /* Skip dummy compilation units. */
7389 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7390 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7396 abbrev_section
->read (objfile
);
7397 m_abbrev_table_holder
7398 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
7400 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7401 m_abbrev_table_holder
.get ());
7402 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7406 /* Type Unit Groups.
7408 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7409 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7410 so that all types coming from the same compilation (.o file) are grouped
7411 together. A future step could be to put the types in the same symtab as
7412 the CU the types ultimately came from. */
7415 hash_type_unit_group (const void *item
)
7417 const struct type_unit_group
*tu_group
7418 = (const struct type_unit_group
*) item
;
7420 return hash_stmt_list_entry (&tu_group
->hash
);
7424 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7426 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7427 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7429 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7432 /* Allocate a hash table for type unit groups. */
7435 allocate_type_unit_groups_table ()
7437 return htab_up (htab_create_alloc (3,
7438 hash_type_unit_group
,
7440 NULL
, xcalloc
, xfree
));
7443 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7444 partial symtabs. We combine several TUs per psymtab to not let the size
7445 of any one psymtab grow too big. */
7446 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7447 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7449 /* Helper routine for get_type_unit_group.
7450 Create the type_unit_group object used to hold one or more TUs. */
7452 static struct type_unit_group
*
7453 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7455 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7456 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7457 struct dwarf2_per_cu_data
*per_cu
;
7458 struct type_unit_group
*tu_group
;
7460 tu_group
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, type_unit_group
);
7461 per_cu
= &tu_group
->per_cu
;
7462 per_cu
->per_bfd
= per_bfd
;
7464 if (per_bfd
->using_index
)
7466 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7467 struct dwarf2_per_cu_quick_data
);
7471 unsigned int line_offset
= to_underlying (line_offset_struct
);
7472 dwarf2_psymtab
*pst
;
7475 /* Give the symtab a useful name for debug purposes. */
7476 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7477 name
= string_printf ("<type_units_%d>",
7478 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7480 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7482 pst
= create_partial_symtab (per_cu
, per_objfile
, name
.c_str ());
7483 pst
->anonymous
= true;
7486 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7487 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7492 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7493 STMT_LIST is a DW_AT_stmt_list attribute. */
7495 static struct type_unit_group
*
7496 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7498 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7499 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7500 struct type_unit_group
*tu_group
;
7502 unsigned int line_offset
;
7503 struct type_unit_group type_unit_group_for_lookup
;
7505 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7506 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7508 /* Do we need to create a new group, or can we use an existing one? */
7510 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
7512 line_offset
= stmt_list
->as_unsigned ();
7513 ++tu_stats
->nr_symtab_sharers
;
7517 /* Ugh, no stmt_list. Rare, but we have to handle it.
7518 We can do various things here like create one group per TU or
7519 spread them over multiple groups to split up the expansion work.
7520 To avoid worst case scenarios (too many groups or too large groups)
7521 we, umm, group them in bunches. */
7522 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7523 | (tu_stats
->nr_stmt_less_type_units
7524 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7525 ++tu_stats
->nr_stmt_less_type_units
;
7528 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7529 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7530 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7531 &type_unit_group_for_lookup
, INSERT
);
7534 tu_group
= (struct type_unit_group
*) *slot
;
7535 gdb_assert (tu_group
!= NULL
);
7539 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7540 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7542 ++tu_stats
->nr_symtabs
;
7548 /* Partial symbol tables. */
7550 /* Create a psymtab named NAME and assign it to PER_CU.
7552 The caller must fill in the following details:
7553 dirname, textlow, texthigh. */
7555 static dwarf2_psymtab
*
7556 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7557 dwarf2_per_objfile
*per_objfile
,
7560 struct objfile
*objfile
= per_objfile
->objfile
;
7561 dwarf2_psymtab
*pst
;
7563 pst
= new dwarf2_psymtab (name
, per_objfile
->per_bfd
->partial_symtabs
.get (),
7566 pst
->psymtabs_addrmap_supported
= true;
7568 /* This is the glue that links PST into GDB's symbol API. */
7569 per_cu
->v
.psymtab
= pst
;
7574 /* DIE reader function for process_psymtab_comp_unit. */
7577 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7578 const gdb_byte
*info_ptr
,
7579 struct die_info
*comp_unit_die
,
7580 enum language pretend_language
)
7582 struct dwarf2_cu
*cu
= reader
->cu
;
7583 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7584 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7585 struct objfile
*objfile
= per_objfile
->objfile
;
7586 struct gdbarch
*gdbarch
= objfile
->arch ();
7587 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7589 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7590 dwarf2_psymtab
*pst
;
7591 enum pc_bounds_kind cu_bounds_kind
;
7592 const char *filename
;
7594 gdb_assert (! per_cu
->is_debug_types
);
7596 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7598 /* Allocate a new partial symbol table structure. */
7599 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7600 static const char artificial
[] = "<artificial>";
7601 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7602 if (filename
== NULL
)
7604 else if (strcmp (filename
, artificial
) == 0)
7606 debug_filename
.reset (concat (artificial
, "@",
7607 sect_offset_str (per_cu
->sect_off
),
7609 filename
= debug_filename
.get ();
7612 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7614 /* This must be done before calling dwarf2_build_include_psymtabs. */
7615 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7617 baseaddr
= objfile
->text_section_offset ();
7619 dwarf2_find_base_address (comp_unit_die
, cu
);
7621 /* Possibly set the default values of LOWPC and HIGHPC from
7623 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7624 &best_highpc
, cu
, pst
);
7625 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7628 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7631 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7633 /* Store the contiguous range if it is not empty; it can be
7634 empty for CUs with no code. */
7635 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
7639 /* Check if comp unit has_children.
7640 If so, read the rest of the partial symbols from this comp unit.
7641 If not, there's no more debug_info for this comp unit. */
7642 if (comp_unit_die
->has_children
)
7644 struct partial_die_info
*first_die
;
7645 CORE_ADDR lowpc
, highpc
;
7647 lowpc
= ((CORE_ADDR
) -1);
7648 highpc
= ((CORE_ADDR
) 0);
7650 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7652 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7653 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7655 /* If we didn't find a lowpc, set it to highpc to avoid
7656 complaints from `maint check'. */
7657 if (lowpc
== ((CORE_ADDR
) -1))
7660 /* If the compilation unit didn't have an explicit address range,
7661 then use the information extracted from its child dies. */
7662 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7665 best_highpc
= highpc
;
7668 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7669 best_lowpc
+ baseaddr
)
7671 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7672 best_highpc
+ baseaddr
)
7677 if (!cu
->per_cu
->imported_symtabs_empty ())
7680 int len
= cu
->per_cu
->imported_symtabs_size ();
7682 /* Fill in 'dependencies' here; we fill in 'users' in a
7684 pst
->number_of_dependencies
= len
;
7686 = per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7687 for (i
= 0; i
< len
; ++i
)
7689 pst
->dependencies
[i
]
7690 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7693 cu
->per_cu
->imported_symtabs_free ();
7696 /* Get the list of files included in the current compilation unit,
7697 and build a psymtab for each of them. */
7698 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7700 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7701 ", %d global, %d static syms",
7702 per_cu
->is_debug_types
? "type" : "comp",
7703 sect_offset_str (per_cu
->sect_off
),
7704 paddress (gdbarch
, pst
->text_low (objfile
)),
7705 paddress (gdbarch
, pst
->text_high (objfile
)),
7706 (int) pst
->global_psymbols
.size (),
7707 (int) pst
->static_psymbols
.size ());
7710 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7711 Process compilation unit THIS_CU for a psymtab. */
7714 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7715 dwarf2_per_objfile
*per_objfile
,
7716 bool want_partial_unit
,
7717 enum language pretend_language
)
7719 /* If this compilation unit was already read in, free the
7720 cached copy in order to read it in again. This is
7721 necessary because we skipped some symbols when we first
7722 read in the compilation unit (see load_partial_dies).
7723 This problem could be avoided, but the benefit is unclear. */
7724 per_objfile
->remove_cu (this_cu
);
7726 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7728 switch (reader
.comp_unit_die
->tag
)
7730 case DW_TAG_compile_unit
:
7731 this_cu
->unit_type
= DW_UT_compile
;
7733 case DW_TAG_partial_unit
:
7734 this_cu
->unit_type
= DW_UT_partial
;
7736 case DW_TAG_type_unit
:
7737 this_cu
->unit_type
= DW_UT_type
;
7747 else if (this_cu
->is_debug_types
)
7748 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7749 reader
.comp_unit_die
);
7750 else if (want_partial_unit
7751 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7752 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7753 reader
.comp_unit_die
,
7756 this_cu
->lang
= reader
.cu
->language
;
7758 /* Age out any secondary CUs. */
7759 per_objfile
->age_comp_units ();
7762 /* Reader function for build_type_psymtabs. */
7765 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7766 const gdb_byte
*info_ptr
,
7767 struct die_info
*type_unit_die
)
7769 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7770 struct dwarf2_cu
*cu
= reader
->cu
;
7771 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7772 struct signatured_type
*sig_type
;
7773 struct type_unit_group
*tu_group
;
7774 struct attribute
*attr
;
7775 struct partial_die_info
*first_die
;
7776 CORE_ADDR lowpc
, highpc
;
7777 dwarf2_psymtab
*pst
;
7779 gdb_assert (per_cu
->is_debug_types
);
7780 sig_type
= (struct signatured_type
*) per_cu
;
7782 if (! type_unit_die
->has_children
)
7785 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7786 tu_group
= get_type_unit_group (cu
, attr
);
7788 if (tu_group
->tus
== nullptr)
7789 tu_group
->tus
= new std::vector
<signatured_type
*>;
7790 tu_group
->tus
->push_back (sig_type
);
7792 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7793 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7794 pst
->anonymous
= true;
7796 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7798 lowpc
= (CORE_ADDR
) -1;
7799 highpc
= (CORE_ADDR
) 0;
7800 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7805 /* Struct used to sort TUs by their abbreviation table offset. */
7807 struct tu_abbrev_offset
7809 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7810 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7813 signatured_type
*sig_type
;
7814 sect_offset abbrev_offset
;
7817 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7820 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7821 const struct tu_abbrev_offset
&b
)
7823 return a
.abbrev_offset
< b
.abbrev_offset
;
7826 /* Efficiently read all the type units.
7827 This does the bulk of the work for build_type_psymtabs.
7829 The efficiency is because we sort TUs by the abbrev table they use and
7830 only read each abbrev table once. In one program there are 200K TUs
7831 sharing 8K abbrev tables.
7833 The main purpose of this function is to support building the
7834 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7835 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7836 can collapse the search space by grouping them by stmt_list.
7837 The savings can be significant, in the same program from above the 200K TUs
7838 share 8K stmt_list tables.
7840 FUNC is expected to call get_type_unit_group, which will create the
7841 struct type_unit_group if necessary and add it to
7842 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7845 build_type_psymtabs_1 (dwarf2_per_objfile
*per_objfile
)
7847 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7848 abbrev_table_up abbrev_table
;
7849 sect_offset abbrev_offset
;
7851 /* It's up to the caller to not call us multiple times. */
7852 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7854 if (per_objfile
->per_bfd
->all_type_units
.empty ())
7857 /* TUs typically share abbrev tables, and there can be way more TUs than
7858 abbrev tables. Sort by abbrev table to reduce the number of times we
7859 read each abbrev table in.
7860 Alternatives are to punt or to maintain a cache of abbrev tables.
7861 This is simpler and efficient enough for now.
7863 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7864 symtab to use). Typically TUs with the same abbrev offset have the same
7865 stmt_list value too so in practice this should work well.
7867 The basic algorithm here is:
7869 sort TUs by abbrev table
7870 for each TU with same abbrev table:
7871 read abbrev table if first user
7872 read TU top level DIE
7873 [IWBN if DWO skeletons had DW_AT_stmt_list]
7876 dwarf_read_debug_printf ("Building type unit groups ...");
7878 /* Sort in a separate table to maintain the order of all_type_units
7879 for .gdb_index: TU indices directly index all_type_units. */
7880 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7881 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
7883 for (signatured_type
*sig_type
: per_objfile
->per_bfd
->all_type_units
)
7884 sorted_by_abbrev
.emplace_back
7885 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->per_cu
.section
,
7886 sig_type
->per_cu
.sect_off
));
7888 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7889 sort_tu_by_abbrev_offset
);
7891 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7893 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7895 /* Switch to the next abbrev table if necessary. */
7896 if (abbrev_table
== NULL
7897 || tu
.abbrev_offset
!= abbrev_offset
)
7899 abbrev_offset
= tu
.abbrev_offset
;
7900 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7902 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7903 ++tu_stats
->nr_uniq_abbrev_tables
;
7906 cutu_reader
reader (&tu
.sig_type
->per_cu
, per_objfile
,
7907 abbrev_table
.get (), nullptr, false);
7908 if (!reader
.dummy_p
)
7909 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7910 reader
.comp_unit_die
);
7914 /* Print collected type unit statistics. */
7917 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7919 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7921 dwarf_read_debug_printf ("Type unit statistics:");
7922 dwarf_read_debug_printf (" %zu TUs",
7923 per_objfile
->per_bfd
->all_type_units
.size ());
7924 dwarf_read_debug_printf (" %d uniq abbrev tables",
7925 tu_stats
->nr_uniq_abbrev_tables
);
7926 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7927 tu_stats
->nr_symtabs
);
7928 dwarf_read_debug_printf (" %d symtab sharers",
7929 tu_stats
->nr_symtab_sharers
);
7930 dwarf_read_debug_printf (" %d type units without a stmt_list",
7931 tu_stats
->nr_stmt_less_type_units
);
7932 dwarf_read_debug_printf (" %d all_type_units reallocs",
7933 tu_stats
->nr_all_type_units_reallocs
);
7936 /* Traversal function for build_type_psymtabs. */
7939 build_type_psymtab_dependencies (void **slot
, void *info
)
7941 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7942 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7943 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7944 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7945 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7946 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7949 gdb_assert (len
> 0);
7950 gdb_assert (per_cu
->type_unit_group_p ());
7952 pst
->number_of_dependencies
= len
;
7953 pst
->dependencies
= per_bfd
->partial_symtabs
->allocate_dependencies (len
);
7954 for (i
= 0; i
< len
; ++i
)
7956 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7957 gdb_assert (iter
->per_cu
.is_debug_types
);
7958 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7959 iter
->type_unit_group
= tu_group
;
7962 delete tu_group
->tus
;
7963 tu_group
->tus
= nullptr;
7968 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7969 Build partial symbol tables for the .debug_types comp-units. */
7972 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7974 if (! create_all_type_units (per_objfile
))
7977 build_type_psymtabs_1 (per_objfile
);
7980 /* Traversal function for process_skeletonless_type_unit.
7981 Read a TU in a DWO file and build partial symbols for it. */
7984 process_skeletonless_type_unit (void **slot
, void *info
)
7986 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7987 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7988 struct signatured_type find_entry
, *entry
;
7990 /* If this TU doesn't exist in the global table, add it and read it in. */
7992 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7993 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7995 find_entry
.signature
= dwo_unit
->signature
;
7996 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7997 &find_entry
, INSERT
);
7998 /* If we've already seen this type there's nothing to do. What's happening
7999 is we're doing our own version of comdat-folding here. */
8003 /* This does the job that create_all_type_units would have done for
8005 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
8006 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
8009 /* This does the job that build_type_psymtabs_1 would have done. */
8010 cutu_reader
reader (&entry
->per_cu
, per_objfile
, nullptr, nullptr, false);
8011 if (!reader
.dummy_p
)
8012 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8013 reader
.comp_unit_die
);
8018 /* Traversal function for process_skeletonless_type_units. */
8021 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8023 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8025 if (dwo_file
->tus
!= NULL
)
8026 htab_traverse_noresize (dwo_file
->tus
.get (),
8027 process_skeletonless_type_unit
, info
);
8032 /* Scan all TUs of DWO files, verifying we've processed them.
8033 This is needed in case a TU was emitted without its skeleton.
8034 Note: This can't be done until we know what all the DWO files are. */
8037 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
8039 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8040 if (get_dwp_file (per_objfile
) == NULL
8041 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
8043 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
8044 process_dwo_file_for_skeletonless_type_units
,
8049 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8052 set_partial_user (dwarf2_per_objfile
*per_objfile
)
8054 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8056 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8061 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8063 /* Set the 'user' field only if it is not already set. */
8064 if (pst
->dependencies
[j
]->user
== NULL
)
8065 pst
->dependencies
[j
]->user
= pst
;
8070 /* Build the partial symbol table by doing a quick pass through the
8071 .debug_info and .debug_abbrev sections. */
8074 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
8076 struct objfile
*objfile
= per_objfile
->objfile
;
8077 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
8079 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
8080 objfile_name (objfile
));
8082 scoped_restore restore_reading_psyms
8083 = make_scoped_restore (&per_objfile
->per_bfd
->reading_partial_symbols
,
8086 per_bfd
->info
.read (objfile
);
8088 /* Any cached compilation units will be linked by the per-objfile
8089 read_in_chain. Make sure to free them when we're done. */
8090 free_cached_comp_units
freer (per_objfile
);
8092 build_type_psymtabs (per_objfile
);
8094 create_all_comp_units (per_objfile
);
8096 /* Create a temporary address map on a temporary obstack. We later
8097 copy this to the final obstack. */
8098 auto_obstack temp_obstack
;
8100 scoped_restore save_psymtabs_addrmap
8101 = make_scoped_restore (&per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8102 addrmap_create_mutable (&temp_obstack
));
8104 for (dwarf2_per_cu_data
*per_cu
: per_bfd
->all_comp_units
)
8106 if (per_cu
->v
.psymtab
!= NULL
)
8107 /* In case a forward DW_TAG_imported_unit has read the CU already. */
8109 process_psymtab_comp_unit (per_cu
, per_objfile
, false,
8113 /* This has to wait until we read the CUs, we need the list of DWOs. */
8114 process_skeletonless_type_units (per_objfile
);
8116 /* Now that all TUs have been processed we can fill in the dependencies. */
8117 if (per_bfd
->type_unit_groups
!= NULL
)
8119 htab_traverse_noresize (per_bfd
->type_unit_groups
.get (),
8120 build_type_psymtab_dependencies
, per_objfile
);
8123 if (dwarf_read_debug
> 0)
8124 print_tu_stats (per_objfile
);
8126 set_partial_user (per_objfile
);
8128 per_bfd
->partial_symtabs
->psymtabs_addrmap
8129 = addrmap_create_fixed (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8130 per_bfd
->partial_symtabs
->obstack ());
8131 /* At this point we want to keep the address map. */
8132 save_psymtabs_addrmap
.release ();
8134 dwarf_read_debug_printf ("Done building psymtabs of %s",
8135 objfile_name (objfile
));
8138 /* Load the partial DIEs for a secondary CU into memory.
8139 This is also used when rereading a primary CU with load_all_dies. */
8142 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8143 dwarf2_per_objfile
*per_objfile
,
8144 dwarf2_cu
*existing_cu
)
8146 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8148 if (!reader
.dummy_p
)
8150 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8153 /* Check if comp unit has_children.
8154 If so, read the rest of the partial symbols from this comp unit.
8155 If not, there's no more debug_info for this comp unit. */
8156 if (reader
.comp_unit_die
->has_children
)
8157 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8164 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
8165 struct dwarf2_section_info
*section
,
8166 struct dwarf2_section_info
*abbrev_section
,
8167 unsigned int is_dwz
)
8169 const gdb_byte
*info_ptr
;
8170 struct objfile
*objfile
= per_objfile
->objfile
;
8172 dwarf_read_debug_printf ("Reading %s for %s",
8173 section
->get_name (),
8174 section
->get_file_name ());
8176 section
->read (objfile
);
8178 info_ptr
= section
->buffer
;
8180 while (info_ptr
< section
->buffer
+ section
->size
)
8182 struct dwarf2_per_cu_data
*this_cu
;
8184 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8186 comp_unit_head cu_header
;
8187 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
8188 abbrev_section
, info_ptr
,
8189 rcuh_kind::COMPILE
);
8191 /* Save the compilation unit for later lookup. */
8192 if (cu_header
.unit_type
!= DW_UT_type
)
8193 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
8196 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
8197 sig_type
->signature
= cu_header
.signature
;
8198 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8199 this_cu
= &sig_type
->per_cu
;
8201 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8202 this_cu
->sect_off
= sect_off
;
8203 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8204 this_cu
->is_dwz
= is_dwz
;
8205 this_cu
->section
= section
;
8207 per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8209 info_ptr
= info_ptr
+ this_cu
->length
;
8213 /* Create a list of all compilation units in OBJFILE.
8214 This is only done for -readnow and building partial symtabs. */
8217 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
8219 gdb_assert (per_objfile
->per_bfd
->all_comp_units
.empty ());
8220 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
8221 &per_objfile
->per_bfd
->abbrev
, 0);
8223 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
8225 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1);
8228 /* Process all loaded DIEs for compilation unit CU, starting at
8229 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8230 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8231 DW_AT_ranges). See the comments of add_partial_subprogram on how
8232 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8235 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8236 CORE_ADDR
*highpc
, int set_addrmap
,
8237 struct dwarf2_cu
*cu
)
8239 struct partial_die_info
*pdi
;
8241 /* Now, march along the PDI's, descending into ones which have
8242 interesting children but skipping the children of the other ones,
8243 until we reach the end of the compilation unit. */
8251 /* Anonymous namespaces or modules have no name but have interesting
8252 children, so we need to look at them. Ditto for anonymous
8255 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8256 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8257 || pdi
->tag
== DW_TAG_imported_unit
8258 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8262 case DW_TAG_subprogram
:
8263 case DW_TAG_inlined_subroutine
:
8264 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8265 if (cu
->language
== language_cplus
)
8266 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8269 case DW_TAG_constant
:
8270 case DW_TAG_variable
:
8271 case DW_TAG_typedef
:
8272 case DW_TAG_union_type
:
8273 if (!pdi
->is_declaration
8274 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8276 add_partial_symbol (pdi
, cu
);
8279 case DW_TAG_class_type
:
8280 case DW_TAG_interface_type
:
8281 case DW_TAG_structure_type
:
8282 if (!pdi
->is_declaration
)
8284 add_partial_symbol (pdi
, cu
);
8286 if ((cu
->language
== language_rust
8287 || cu
->language
== language_cplus
) && pdi
->has_children
)
8288 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8291 case DW_TAG_enumeration_type
:
8292 if (!pdi
->is_declaration
)
8293 add_partial_enumeration (pdi
, cu
);
8295 case DW_TAG_base_type
:
8296 case DW_TAG_subrange_type
:
8297 /* File scope base type definitions are added to the partial
8299 add_partial_symbol (pdi
, cu
);
8301 case DW_TAG_namespace
:
8302 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8305 if (!pdi
->is_declaration
)
8306 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8308 case DW_TAG_imported_unit
:
8310 struct dwarf2_per_cu_data
*per_cu
;
8312 /* For now we don't handle imported units in type units. */
8313 if (cu
->per_cu
->is_debug_types
)
8315 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8316 " supported in type units [in module %s]"),
8317 objfile_name (cu
->per_objfile
->objfile
));
8320 per_cu
= dwarf2_find_containing_comp_unit
8321 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8323 /* Go read the partial unit, if needed. */
8324 if (per_cu
->v
.psymtab
== NULL
)
8325 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8328 cu
->per_cu
->imported_symtabs_push (per_cu
);
8331 case DW_TAG_imported_declaration
:
8332 add_partial_symbol (pdi
, cu
);
8339 /* If the die has a sibling, skip to the sibling. */
8341 pdi
= pdi
->die_sibling
;
8345 /* Functions used to compute the fully scoped name of a partial DIE.
8347 Normally, this is simple. For C++, the parent DIE's fully scoped
8348 name is concatenated with "::" and the partial DIE's name.
8349 Enumerators are an exception; they use the scope of their parent
8350 enumeration type, i.e. the name of the enumeration type is not
8351 prepended to the enumerator.
8353 There are two complexities. One is DW_AT_specification; in this
8354 case "parent" means the parent of the target of the specification,
8355 instead of the direct parent of the DIE. The other is compilers
8356 which do not emit DW_TAG_namespace; in this case we try to guess
8357 the fully qualified name of structure types from their members'
8358 linkage names. This must be done using the DIE's children rather
8359 than the children of any DW_AT_specification target. We only need
8360 to do this for structures at the top level, i.e. if the target of
8361 any DW_AT_specification (if any; otherwise the DIE itself) does not
8364 /* Compute the scope prefix associated with PDI's parent, in
8365 compilation unit CU. The result will be allocated on CU's
8366 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8367 field. NULL is returned if no prefix is necessary. */
8369 partial_die_parent_scope (struct partial_die_info
*pdi
,
8370 struct dwarf2_cu
*cu
)
8372 const char *grandparent_scope
;
8373 struct partial_die_info
*parent
, *real_pdi
;
8375 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8376 then this means the parent of the specification DIE. */
8379 while (real_pdi
->has_specification
)
8381 auto res
= find_partial_die (real_pdi
->spec_offset
,
8382 real_pdi
->spec_is_dwz
, cu
);
8387 parent
= real_pdi
->die_parent
;
8391 if (parent
->scope_set
)
8392 return parent
->scope
;
8396 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8398 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8399 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8400 Work around this problem here. */
8401 if (cu
->language
== language_cplus
8402 && parent
->tag
== DW_TAG_namespace
8403 && strcmp (parent
->name (cu
), "::") == 0
8404 && grandparent_scope
== NULL
)
8406 parent
->scope
= NULL
;
8407 parent
->scope_set
= 1;
8411 /* Nested subroutines in Fortran get a prefix. */
8412 if (pdi
->tag
== DW_TAG_enumerator
)
8413 /* Enumerators should not get the name of the enumeration as a prefix. */
8414 parent
->scope
= grandparent_scope
;
8415 else if (parent
->tag
== DW_TAG_namespace
8416 || parent
->tag
== DW_TAG_module
8417 || parent
->tag
== DW_TAG_structure_type
8418 || parent
->tag
== DW_TAG_class_type
8419 || parent
->tag
== DW_TAG_interface_type
8420 || parent
->tag
== DW_TAG_union_type
8421 || parent
->tag
== DW_TAG_enumeration_type
8422 || (cu
->language
== language_fortran
8423 && parent
->tag
== DW_TAG_subprogram
8424 && pdi
->tag
== DW_TAG_subprogram
))
8426 if (grandparent_scope
== NULL
)
8427 parent
->scope
= parent
->name (cu
);
8429 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8431 parent
->name (cu
), 0, cu
);
8435 /* FIXME drow/2004-04-01: What should we be doing with
8436 function-local names? For partial symbols, we should probably be
8438 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8439 dwarf_tag_name (parent
->tag
),
8440 sect_offset_str (pdi
->sect_off
));
8441 parent
->scope
= grandparent_scope
;
8444 parent
->scope_set
= 1;
8445 return parent
->scope
;
8448 /* Return the fully scoped name associated with PDI, from compilation unit
8449 CU. The result will be allocated with malloc. */
8451 static gdb::unique_xmalloc_ptr
<char>
8452 partial_die_full_name (struct partial_die_info
*pdi
,
8453 struct dwarf2_cu
*cu
)
8455 const char *parent_scope
;
8457 /* If this is a template instantiation, we can not work out the
8458 template arguments from partial DIEs. So, unfortunately, we have
8459 to go through the full DIEs. At least any work we do building
8460 types here will be reused if full symbols are loaded later. */
8461 if (pdi
->has_template_arguments
)
8465 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8467 struct die_info
*die
;
8468 struct attribute attr
;
8469 struct dwarf2_cu
*ref_cu
= cu
;
8471 /* DW_FORM_ref_addr is using section offset. */
8472 attr
.name
= (enum dwarf_attribute
) 0;
8473 attr
.form
= DW_FORM_ref_addr
;
8474 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8475 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8477 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8481 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8482 if (parent_scope
== NULL
)
8485 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8491 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8493 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8494 struct objfile
*objfile
= per_objfile
->objfile
;
8495 struct gdbarch
*gdbarch
= objfile
->arch ();
8497 const char *actual_name
= NULL
;
8500 baseaddr
= objfile
->text_section_offset ();
8502 gdb::unique_xmalloc_ptr
<char> built_actual_name
8503 = partial_die_full_name (pdi
, cu
);
8504 if (built_actual_name
!= NULL
)
8505 actual_name
= built_actual_name
.get ();
8507 if (actual_name
== NULL
)
8508 actual_name
= pdi
->name (cu
);
8510 partial_symbol psymbol
;
8511 memset (&psymbol
, 0, sizeof (psymbol
));
8512 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8513 psymbol
.ginfo
.set_section_index (-1);
8515 /* The code below indicates that the psymbol should be installed by
8517 gdb::optional
<psymbol_placement
> where
;
8521 case DW_TAG_inlined_subroutine
:
8522 case DW_TAG_subprogram
:
8523 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8525 if (pdi
->is_external
8526 || cu
->language
== language_ada
8527 || (cu
->language
== language_fortran
8528 && pdi
->die_parent
!= NULL
8529 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8531 /* Normally, only "external" DIEs are part of the global scope.
8532 But in Ada and Fortran, we want to be able to access nested
8533 procedures globally. So all Ada and Fortran subprograms are
8534 stored in the global scope. */
8535 where
= psymbol_placement::GLOBAL
;
8538 where
= psymbol_placement::STATIC
;
8540 psymbol
.domain
= VAR_DOMAIN
;
8541 psymbol
.aclass
= LOC_BLOCK
;
8542 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8543 psymbol
.ginfo
.value
.address
= addr
;
8545 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8546 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8548 case DW_TAG_constant
:
8549 psymbol
.domain
= VAR_DOMAIN
;
8550 psymbol
.aclass
= LOC_STATIC
;
8551 where
= (pdi
->is_external
8552 ? psymbol_placement::GLOBAL
8553 : psymbol_placement::STATIC
);
8555 case DW_TAG_variable
:
8557 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8561 && !per_objfile
->per_bfd
->has_section_at_zero
)
8563 /* A global or static variable may also have been stripped
8564 out by the linker if unused, in which case its address
8565 will be nullified; do not add such variables into partial
8566 symbol table then. */
8568 else if (pdi
->is_external
)
8571 Don't enter into the minimal symbol tables as there is
8572 a minimal symbol table entry from the ELF symbols already.
8573 Enter into partial symbol table if it has a location
8574 descriptor or a type.
8575 If the location descriptor is missing, new_symbol will create
8576 a LOC_UNRESOLVED symbol, the address of the variable will then
8577 be determined from the minimal symbol table whenever the variable
8579 The address for the partial symbol table entry is not
8580 used by GDB, but it comes in handy for debugging partial symbol
8583 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8585 psymbol
.domain
= VAR_DOMAIN
;
8586 psymbol
.aclass
= LOC_STATIC
;
8587 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8588 psymbol
.ginfo
.value
.address
= addr
;
8589 where
= psymbol_placement::GLOBAL
;
8594 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8596 /* Static Variable. Skip symbols whose value we cannot know (those
8597 without location descriptors or constant values). */
8598 if (!has_loc
&& !pdi
->has_const_value
)
8601 psymbol
.domain
= VAR_DOMAIN
;
8602 psymbol
.aclass
= LOC_STATIC
;
8603 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8605 psymbol
.ginfo
.value
.address
= addr
;
8606 where
= psymbol_placement::STATIC
;
8609 case DW_TAG_array_type
:
8610 case DW_TAG_typedef
:
8611 case DW_TAG_base_type
:
8612 case DW_TAG_subrange_type
:
8613 psymbol
.domain
= VAR_DOMAIN
;
8614 psymbol
.aclass
= LOC_TYPEDEF
;
8615 where
= psymbol_placement::STATIC
;
8617 case DW_TAG_imported_declaration
:
8618 case DW_TAG_namespace
:
8619 psymbol
.domain
= VAR_DOMAIN
;
8620 psymbol
.aclass
= LOC_TYPEDEF
;
8621 where
= psymbol_placement::GLOBAL
;
8624 /* With Fortran 77 there might be a "BLOCK DATA" module
8625 available without any name. If so, we skip the module as it
8626 doesn't bring any value. */
8627 if (actual_name
!= nullptr)
8629 psymbol
.domain
= MODULE_DOMAIN
;
8630 psymbol
.aclass
= LOC_TYPEDEF
;
8631 where
= psymbol_placement::GLOBAL
;
8634 case DW_TAG_class_type
:
8635 case DW_TAG_interface_type
:
8636 case DW_TAG_structure_type
:
8637 case DW_TAG_union_type
:
8638 case DW_TAG_enumeration_type
:
8639 /* Skip external references. The DWARF standard says in the section
8640 about "Structure, Union, and Class Type Entries": "An incomplete
8641 structure, union or class type is represented by a structure,
8642 union or class entry that does not have a byte size attribute
8643 and that has a DW_AT_declaration attribute." */
8644 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8647 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8648 static vs. global. */
8649 psymbol
.domain
= STRUCT_DOMAIN
;
8650 psymbol
.aclass
= LOC_TYPEDEF
;
8651 where
= (cu
->language
== language_cplus
8652 ? psymbol_placement::GLOBAL
8653 : psymbol_placement::STATIC
);
8655 case DW_TAG_enumerator
:
8656 psymbol
.domain
= VAR_DOMAIN
;
8657 psymbol
.aclass
= LOC_CONST
;
8658 where
= (cu
->language
== language_cplus
8659 ? psymbol_placement::GLOBAL
8660 : psymbol_placement::STATIC
);
8666 if (where
.has_value ())
8668 if (built_actual_name
!= nullptr)
8669 actual_name
= objfile
->intern (actual_name
);
8670 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8671 psymbol
.ginfo
.set_linkage_name (actual_name
);
8674 psymbol
.ginfo
.set_demangled_name (actual_name
,
8675 &objfile
->objfile_obstack
);
8676 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8678 cu
->per_cu
->v
.psymtab
->add_psymbol
8679 (psymbol
, *where
, per_objfile
->per_bfd
->partial_symtabs
.get (),
8684 /* Read a partial die corresponding to a namespace; also, add a symbol
8685 corresponding to that namespace to the symbol table. NAMESPACE is
8686 the name of the enclosing namespace. */
8689 add_partial_namespace (struct partial_die_info
*pdi
,
8690 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8691 int set_addrmap
, struct dwarf2_cu
*cu
)
8693 /* Add a symbol for the namespace. */
8695 add_partial_symbol (pdi
, cu
);
8697 /* Now scan partial symbols in that namespace. */
8699 if (pdi
->has_children
)
8700 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8703 /* Read a partial die corresponding to a Fortran module. */
8706 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8707 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8709 /* Add a symbol for the namespace. */
8711 add_partial_symbol (pdi
, cu
);
8713 /* Now scan partial symbols in that module. */
8715 if (pdi
->has_children
)
8716 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8719 /* Read a partial die corresponding to a subprogram or an inlined
8720 subprogram and create a partial symbol for that subprogram.
8721 When the CU language allows it, this routine also defines a partial
8722 symbol for each nested subprogram that this subprogram contains.
8723 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8724 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8726 PDI may also be a lexical block, in which case we simply search
8727 recursively for subprograms defined inside that lexical block.
8728 Again, this is only performed when the CU language allows this
8729 type of definitions. */
8732 add_partial_subprogram (struct partial_die_info
*pdi
,
8733 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8734 int set_addrmap
, struct dwarf2_cu
*cu
)
8736 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8738 if (pdi
->has_pc_info
)
8740 if (pdi
->lowpc
< *lowpc
)
8741 *lowpc
= pdi
->lowpc
;
8742 if (pdi
->highpc
> *highpc
)
8743 *highpc
= pdi
->highpc
;
8746 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8747 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
8748 struct gdbarch
*gdbarch
= objfile
->arch ();
8750 CORE_ADDR this_highpc
;
8751 CORE_ADDR this_lowpc
;
8753 baseaddr
= objfile
->text_section_offset ();
8755 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8756 pdi
->lowpc
+ baseaddr
)
8759 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8760 pdi
->highpc
+ baseaddr
)
8762 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
8763 this_lowpc
, this_highpc
- 1,
8764 cu
->per_cu
->v
.psymtab
);
8768 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8770 if (!pdi
->is_declaration
)
8771 /* Ignore subprogram DIEs that do not have a name, they are
8772 illegal. Do not emit a complaint at this point, we will
8773 do so when we convert this psymtab into a symtab. */
8775 add_partial_symbol (pdi
, cu
);
8779 if (! pdi
->has_children
)
8782 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8784 pdi
= pdi
->die_child
;
8788 if (pdi
->tag
== DW_TAG_subprogram
8789 || pdi
->tag
== DW_TAG_inlined_subroutine
8790 || pdi
->tag
== DW_TAG_lexical_block
)
8791 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8792 pdi
= pdi
->die_sibling
;
8797 /* Read a partial die corresponding to an enumeration type. */
8800 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8801 struct dwarf2_cu
*cu
)
8803 struct partial_die_info
*pdi
;
8805 if (enum_pdi
->name (cu
) != NULL
)
8806 add_partial_symbol (enum_pdi
, cu
);
8808 pdi
= enum_pdi
->die_child
;
8811 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8812 complaint (_("malformed enumerator DIE ignored"));
8814 add_partial_symbol (pdi
, cu
);
8815 pdi
= pdi
->die_sibling
;
8819 /* Return the initial uleb128 in the die at INFO_PTR. */
8822 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8824 unsigned int bytes_read
;
8826 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8829 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8830 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8832 Return the corresponding abbrev, or NULL if the number is zero (indicating
8833 an empty DIE). In either case *BYTES_READ will be set to the length of
8834 the initial number. */
8836 static const struct abbrev_info
*
8837 peek_die_abbrev (const die_reader_specs
&reader
,
8838 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8840 dwarf2_cu
*cu
= reader
.cu
;
8841 bfd
*abfd
= reader
.abfd
;
8842 unsigned int abbrev_number
8843 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8845 if (abbrev_number
== 0)
8848 const abbrev_info
*abbrev
8849 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8852 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8853 " at offset %s [in module %s]"),
8854 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8855 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8861 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8862 Returns a pointer to the end of a series of DIEs, terminated by an empty
8863 DIE. Any children of the skipped DIEs will also be skipped. */
8865 static const gdb_byte
*
8866 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8870 unsigned int bytes_read
;
8871 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8875 return info_ptr
+ bytes_read
;
8877 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8881 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8882 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8883 abbrev corresponding to that skipped uleb128 should be passed in
8884 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8887 static const gdb_byte
*
8888 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8889 const struct abbrev_info
*abbrev
)
8891 unsigned int bytes_read
;
8892 struct attribute attr
;
8893 bfd
*abfd
= reader
->abfd
;
8894 struct dwarf2_cu
*cu
= reader
->cu
;
8895 const gdb_byte
*buffer
= reader
->buffer
;
8896 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8897 unsigned int form
, i
;
8899 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8901 /* The only abbrev we care about is DW_AT_sibling. */
8902 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8904 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8905 if (attr
.form
== DW_FORM_ref_addr
)
8906 complaint (_("ignoring absolute DW_AT_sibling"));
8909 sect_offset off
= attr
.get_ref_die_offset ();
8910 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8912 if (sibling_ptr
< info_ptr
)
8913 complaint (_("DW_AT_sibling points backwards"));
8914 else if (sibling_ptr
> reader
->buffer_end
)
8915 reader
->die_section
->overflow_complaint ();
8921 /* If it isn't DW_AT_sibling, skip this attribute. */
8922 form
= abbrev
->attrs
[i
].form
;
8926 case DW_FORM_ref_addr
:
8927 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8928 and later it is offset sized. */
8929 if (cu
->header
.version
== 2)
8930 info_ptr
+= cu
->header
.addr_size
;
8932 info_ptr
+= cu
->header
.offset_size
;
8934 case DW_FORM_GNU_ref_alt
:
8935 info_ptr
+= cu
->header
.offset_size
;
8938 info_ptr
+= cu
->header
.addr_size
;
8946 case DW_FORM_flag_present
:
8947 case DW_FORM_implicit_const
:
8964 case DW_FORM_ref_sig8
:
8967 case DW_FORM_data16
:
8970 case DW_FORM_string
:
8971 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8972 info_ptr
+= bytes_read
;
8974 case DW_FORM_sec_offset
:
8976 case DW_FORM_GNU_strp_alt
:
8977 info_ptr
+= cu
->header
.offset_size
;
8979 case DW_FORM_exprloc
:
8981 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8982 info_ptr
+= bytes_read
;
8984 case DW_FORM_block1
:
8985 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8987 case DW_FORM_block2
:
8988 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8990 case DW_FORM_block4
:
8991 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8997 case DW_FORM_ref_udata
:
8998 case DW_FORM_GNU_addr_index
:
8999 case DW_FORM_GNU_str_index
:
9000 case DW_FORM_rnglistx
:
9001 case DW_FORM_loclistx
:
9002 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9004 case DW_FORM_indirect
:
9005 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9006 info_ptr
+= bytes_read
;
9007 /* We need to continue parsing from here, so just go back to
9009 goto skip_attribute
;
9012 error (_("Dwarf Error: Cannot handle %s "
9013 "in DWARF reader [in module %s]"),
9014 dwarf_form_name (form
),
9015 bfd_get_filename (abfd
));
9019 if (abbrev
->has_children
)
9020 return skip_children (reader
, info_ptr
);
9025 /* Locate ORIG_PDI's sibling.
9026 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9028 static const gdb_byte
*
9029 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9030 struct partial_die_info
*orig_pdi
,
9031 const gdb_byte
*info_ptr
)
9033 /* Do we know the sibling already? */
9035 if (orig_pdi
->sibling
)
9036 return orig_pdi
->sibling
;
9038 /* Are there any children to deal with? */
9040 if (!orig_pdi
->has_children
)
9043 /* Skip the children the long way. */
9045 return skip_children (reader
, info_ptr
);
9048 /* Expand this partial symbol table into a full symbol table. SELF is
9052 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
9054 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9056 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
9058 /* If this psymtab is constructed from a debug-only objfile, the
9059 has_section_at_zero flag will not necessarily be correct. We
9060 can get the correct value for this flag by looking at the data
9061 associated with the (presumably stripped) associated objfile. */
9062 if (objfile
->separate_debug_objfile_backlink
)
9064 dwarf2_per_objfile
*per_objfile_backlink
9065 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9067 per_objfile
->per_bfd
->has_section_at_zero
9068 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
9071 expand_psymtab (objfile
);
9073 process_cu_includes (per_objfile
);
9076 /* Reading in full CUs. */
9078 /* Add PER_CU to the queue. */
9081 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
9082 dwarf2_per_objfile
*per_objfile
,
9083 enum language pretend_language
)
9087 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
9088 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
9091 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
9093 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9096 Return true if maybe_queue_comp_unit requires the caller to load the CU's
9097 DIEs, false otherwise.
9099 Explanation: there is an invariant that if a CU is queued for expansion
9100 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
9101 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
9102 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
9103 are not yet loaded, the the caller must load the CU's DIEs to ensure the
9104 invariant is respected.
9106 The caller is therefore not required to load the CU's DIEs (we return false)
9109 - the CU is already expanded, and therefore does not get enqueued
9110 - the CU gets enqueued for expansion, but its DIEs are already loaded
9112 Note that the caller should not use this function's return value as an
9113 indicator of whether the CU's DIEs are loaded right now, it should check
9114 that by calling `dwarf2_per_objfile::get_cu` instead. */
9117 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9118 dwarf2_per_cu_data
*per_cu
,
9119 dwarf2_per_objfile
*per_objfile
,
9120 enum language pretend_language
)
9122 /* We may arrive here during partial symbol reading, if we need full
9123 DIEs to process an unusual case (e.g. template arguments). Do
9124 not queue PER_CU, just tell our caller to load its DIEs. */
9125 if (per_cu
->per_bfd
->reading_partial_symbols
)
9127 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9129 if (cu
== NULL
|| cu
->dies
== NULL
)
9134 /* Mark the dependence relation so that we don't flush PER_CU
9136 if (dependent_cu
!= NULL
)
9137 dwarf2_add_dependence (dependent_cu
, per_cu
);
9139 /* If it's already on the queue, we have nothing to do. */
9142 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
9144 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
9146 /* If the CU is queued for expansion, it should not already be
9148 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
9150 /* The DIEs are already loaded, the caller doesn't need to do it. */
9154 bool queued
= false;
9155 if (!per_objfile
->symtab_set_p (per_cu
))
9157 /* Add it to the queue. */
9158 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9162 /* If the compilation unit is already loaded, just mark it as
9164 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9168 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
9169 and the DIEs are not already loaded. */
9170 return queued
&& cu
== nullptr;
9173 /* Process the queue. */
9176 process_queue (dwarf2_per_objfile
*per_objfile
)
9178 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
9179 objfile_name (per_objfile
->objfile
));
9181 /* The queue starts out with one item, but following a DIE reference
9182 may load a new CU, adding it to the end of the queue. */
9183 while (!per_objfile
->per_bfd
->queue
->empty ())
9185 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
9186 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9188 if (!per_objfile
->symtab_set_p (per_cu
))
9190 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9192 /* Skip dummy CUs. */
9195 unsigned int debug_print_threshold
;
9198 if (per_cu
->is_debug_types
)
9200 struct signatured_type
*sig_type
=
9201 (struct signatured_type
*) per_cu
;
9203 sprintf (buf
, "TU %s at offset %s",
9204 hex_string (sig_type
->signature
),
9205 sect_offset_str (per_cu
->sect_off
));
9206 /* There can be 100s of TUs.
9207 Only print them in verbose mode. */
9208 debug_print_threshold
= 2;
9212 sprintf (buf
, "CU at offset %s",
9213 sect_offset_str (per_cu
->sect_off
));
9214 debug_print_threshold
= 1;
9217 if (dwarf_read_debug
>= debug_print_threshold
)
9218 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
9220 if (per_cu
->is_debug_types
)
9221 process_full_type_unit (cu
, item
.pretend_language
);
9223 process_full_comp_unit (cu
, item
.pretend_language
);
9225 if (dwarf_read_debug
>= debug_print_threshold
)
9226 dwarf_read_debug_printf ("Done expanding %s", buf
);
9231 per_objfile
->per_bfd
->queue
->pop ();
9234 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
9235 objfile_name (per_objfile
->objfile
));
9238 /* Read in full symbols for PST, and anything it depends on. */
9241 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9243 gdb_assert (!readin_p (objfile
));
9245 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9246 free_cached_comp_units
freer (per_objfile
);
9247 expand_dependencies (objfile
);
9249 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9250 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9253 /* See psympriv.h. */
9256 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9258 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9259 return per_objfile
->symtab_set_p (per_cu_data
);
9262 /* See psympriv.h. */
9265 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9267 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9268 return per_objfile
->get_symtab (per_cu_data
);
9271 /* Trivial hash function for die_info: the hash value of a DIE
9272 is its offset in .debug_info for this objfile. */
9275 die_hash (const void *item
)
9277 const struct die_info
*die
= (const struct die_info
*) item
;
9279 return to_underlying (die
->sect_off
);
9282 /* Trivial comparison function for die_info structures: two DIEs
9283 are equal if they have the same offset. */
9286 die_eq (const void *item_lhs
, const void *item_rhs
)
9288 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9289 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9291 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9294 /* Load the DIEs associated with PER_CU into memory.
9296 In some cases, the caller, while reading partial symbols, will need to load
9297 the full symbols for the CU for some reason. It will already have a
9298 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
9299 rather than creating a new one. */
9302 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9303 dwarf2_per_objfile
*per_objfile
,
9304 dwarf2_cu
*existing_cu
,
9306 enum language pretend_language
)
9308 gdb_assert (! this_cu
->is_debug_types
);
9310 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9314 struct dwarf2_cu
*cu
= reader
.cu
;
9315 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9317 gdb_assert (cu
->die_hash
== NULL
);
9319 htab_create_alloc_ex (cu
->header
.length
/ 12,
9323 &cu
->comp_unit_obstack
,
9324 hashtab_obstack_allocate
,
9325 dummy_obstack_deallocate
);
9327 if (reader
.comp_unit_die
->has_children
)
9328 reader
.comp_unit_die
->child
9329 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9330 &info_ptr
, reader
.comp_unit_die
);
9331 cu
->dies
= reader
.comp_unit_die
;
9332 /* comp_unit_die is not stored in die_hash, no need. */
9334 /* We try not to read any attributes in this function, because not
9335 all CUs needed for references have been loaded yet, and symbol
9336 table processing isn't initialized. But we have to set the CU language,
9337 or we won't be able to build types correctly.
9338 Similarly, if we do not read the producer, we can not apply
9339 producer-specific interpretation. */
9340 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9345 /* Add a DIE to the delayed physname list. */
9348 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9349 const char *name
, struct die_info
*die
,
9350 struct dwarf2_cu
*cu
)
9352 struct delayed_method_info mi
;
9354 mi
.fnfield_index
= fnfield_index
;
9358 cu
->method_list
.push_back (mi
);
9361 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9362 "const" / "volatile". If so, decrements LEN by the length of the
9363 modifier and return true. Otherwise return false. */
9367 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9369 size_t mod_len
= sizeof (mod
) - 1;
9370 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9378 /* Compute the physnames of any methods on the CU's method list.
9380 The computation of method physnames is delayed in order to avoid the
9381 (bad) condition that one of the method's formal parameters is of an as yet
9385 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9387 /* Only C++ delays computing physnames. */
9388 if (cu
->method_list
.empty ())
9390 gdb_assert (cu
->language
== language_cplus
);
9392 for (const delayed_method_info
&mi
: cu
->method_list
)
9394 const char *physname
;
9395 struct fn_fieldlist
*fn_flp
9396 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9397 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9398 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9399 = physname
? physname
: "";
9401 /* Since there's no tag to indicate whether a method is a
9402 const/volatile overload, extract that information out of the
9404 if (physname
!= NULL
)
9406 size_t len
= strlen (physname
);
9410 if (physname
[len
] == ')') /* shortcut */
9412 else if (check_modifier (physname
, len
, " const"))
9413 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9414 else if (check_modifier (physname
, len
, " volatile"))
9415 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9422 /* The list is no longer needed. */
9423 cu
->method_list
.clear ();
9426 /* Go objects should be embedded in a DW_TAG_module DIE,
9427 and it's not clear if/how imported objects will appear.
9428 To keep Go support simple until that's worked out,
9429 go back through what we've read and create something usable.
9430 We could do this while processing each DIE, and feels kinda cleaner,
9431 but that way is more invasive.
9432 This is to, for example, allow the user to type "p var" or "b main"
9433 without having to specify the package name, and allow lookups
9434 of module.object to work in contexts that use the expression
9438 fixup_go_packaging (struct dwarf2_cu
*cu
)
9440 gdb::unique_xmalloc_ptr
<char> package_name
;
9441 struct pending
*list
;
9444 for (list
= *cu
->get_builder ()->get_global_symbols ();
9448 for (i
= 0; i
< list
->nsyms
; ++i
)
9450 struct symbol
*sym
= list
->symbol
[i
];
9452 if (sym
->language () == language_go
9453 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9455 gdb::unique_xmalloc_ptr
<char> this_package_name
9456 (go_symbol_package_name (sym
));
9458 if (this_package_name
== NULL
)
9460 if (package_name
== NULL
)
9461 package_name
= std::move (this_package_name
);
9464 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9465 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9466 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9467 (symbol_symtab (sym
) != NULL
9468 ? symtab_to_filename_for_display
9469 (symbol_symtab (sym
))
9470 : objfile_name (objfile
)),
9471 this_package_name
.get (), package_name
.get ());
9477 if (package_name
!= NULL
)
9479 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9480 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9481 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9482 saved_package_name
);
9485 sym
= new (&objfile
->objfile_obstack
) symbol
;
9486 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9487 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9488 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9489 e.g., "main" finds the "main" module and not C's main(). */
9490 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9491 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9492 SYMBOL_TYPE (sym
) = type
;
9494 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9498 /* Allocate a fully-qualified name consisting of the two parts on the
9502 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9504 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9507 /* A helper that allocates a variant part to attach to a Rust enum
9508 type. OBSTACK is where the results should be allocated. TYPE is
9509 the type we're processing. DISCRIMINANT_INDEX is the index of the
9510 discriminant. It must be the index of one of the fields of TYPE,
9511 or -1 to mean there is no discriminant (univariant enum).
9512 DEFAULT_INDEX is the index of the default field; or -1 if there is
9513 no default. RANGES is indexed by "effective" field number (the
9514 field index, but omitting the discriminant and default fields) and
9515 must hold the discriminant values used by the variants. Note that
9516 RANGES must have a lifetime at least as long as OBSTACK -- either
9517 already allocated on it, or static. */
9520 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9521 int discriminant_index
, int default_index
,
9522 gdb::array_view
<discriminant_range
> ranges
)
9524 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
9525 gdb_assert (discriminant_index
== -1
9526 || (discriminant_index
>= 0
9527 && discriminant_index
< type
->num_fields ()));
9528 gdb_assert (default_index
== -1
9529 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9531 /* We have one variant for each non-discriminant field. */
9532 int n_variants
= type
->num_fields ();
9533 if (discriminant_index
!= -1)
9536 variant
*variants
= new (obstack
) variant
[n_variants
];
9539 for (int i
= 0; i
< type
->num_fields (); ++i
)
9541 if (i
== discriminant_index
)
9544 variants
[var_idx
].first_field
= i
;
9545 variants
[var_idx
].last_field
= i
+ 1;
9547 /* The default field does not need a range, but other fields do.
9548 We skipped the discriminant above. */
9549 if (i
!= default_index
)
9551 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9558 gdb_assert (range_idx
== ranges
.size ());
9559 gdb_assert (var_idx
== n_variants
);
9561 variant_part
*part
= new (obstack
) variant_part
;
9562 part
->discriminant_index
= discriminant_index
;
9563 /* If there is no discriminant, then whether it is signed is of no
9566 = (discriminant_index
== -1
9568 : type
->field (discriminant_index
).type ()->is_unsigned ());
9569 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9571 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9572 gdb::array_view
<variant_part
> *prop_value
9573 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9575 struct dynamic_prop prop
;
9576 prop
.set_variant_parts (prop_value
);
9578 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9581 /* Some versions of rustc emitted enums in an unusual way.
9583 Ordinary enums were emitted as unions. The first element of each
9584 structure in the union was named "RUST$ENUM$DISR". This element
9585 held the discriminant.
9587 These versions of Rust also implemented the "non-zero"
9588 optimization. When the enum had two values, and one is empty and
9589 the other holds a pointer that cannot be zero, the pointer is used
9590 as the discriminant, with a zero value meaning the empty variant.
9591 Here, the union's first member is of the form
9592 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9593 where the fieldnos are the indices of the fields that should be
9594 traversed in order to find the field (which may be several fields deep)
9595 and the variantname is the name of the variant of the case when the
9598 This function recognizes whether TYPE is of one of these forms,
9599 and, if so, smashes it to be a variant type. */
9602 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9604 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9606 /* We don't need to deal with empty enums. */
9607 if (type
->num_fields () == 0)
9610 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9611 if (type
->num_fields () == 1
9612 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9614 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9616 /* Decode the field name to find the offset of the
9618 ULONGEST bit_offset
= 0;
9619 struct type
*field_type
= type
->field (0).type ();
9620 while (name
[0] >= '0' && name
[0] <= '9')
9623 unsigned long index
= strtoul (name
, &tail
, 10);
9626 || index
>= field_type
->num_fields ()
9627 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9628 != FIELD_LOC_KIND_BITPOS
))
9630 complaint (_("Could not parse Rust enum encoding string \"%s\""
9632 TYPE_FIELD_NAME (type
, 0),
9633 objfile_name (objfile
));
9638 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9639 field_type
= field_type
->field (index
).type ();
9642 /* Smash this type to be a structure type. We have to do this
9643 because the type has already been recorded. */
9644 type
->set_code (TYPE_CODE_STRUCT
);
9645 type
->set_num_fields (3);
9646 /* Save the field we care about. */
9647 struct field saved_field
= type
->field (0);
9649 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9651 /* Put the discriminant at index 0. */
9652 type
->field (0).set_type (field_type
);
9653 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9654 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9655 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9657 /* The order of fields doesn't really matter, so put the real
9658 field at index 1 and the data-less field at index 2. */
9659 type
->field (1) = saved_field
;
9660 TYPE_FIELD_NAME (type
, 1)
9661 = rust_last_path_segment (type
->field (1).type ()->name ());
9662 type
->field (1).type ()->set_name
9663 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9664 TYPE_FIELD_NAME (type
, 1)));
9666 const char *dataless_name
9667 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9669 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9671 type
->field (2).set_type (dataless_type
);
9672 /* NAME points into the original discriminant name, which
9673 already has the correct lifetime. */
9674 TYPE_FIELD_NAME (type
, 2) = name
;
9675 SET_FIELD_BITPOS (type
->field (2), 0);
9677 /* Indicate that this is a variant type. */
9678 static discriminant_range ranges
[1] = { { 0, 0 } };
9679 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9681 /* A union with a single anonymous field is probably an old-style
9683 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9685 /* Smash this type to be a structure type. We have to do this
9686 because the type has already been recorded. */
9687 type
->set_code (TYPE_CODE_STRUCT
);
9689 struct type
*field_type
= type
->field (0).type ();
9690 const char *variant_name
9691 = rust_last_path_segment (field_type
->name ());
9692 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9693 field_type
->set_name
9694 (rust_fully_qualify (&objfile
->objfile_obstack
,
9695 type
->name (), variant_name
));
9697 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9701 struct type
*disr_type
= nullptr;
9702 for (int i
= 0; i
< type
->num_fields (); ++i
)
9704 disr_type
= type
->field (i
).type ();
9706 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9708 /* All fields of a true enum will be structs. */
9711 else if (disr_type
->num_fields () == 0)
9713 /* Could be data-less variant, so keep going. */
9714 disr_type
= nullptr;
9716 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9717 "RUST$ENUM$DISR") != 0)
9719 /* Not a Rust enum. */
9729 /* If we got here without a discriminant, then it's probably
9731 if (disr_type
== nullptr)
9734 /* Smash this type to be a structure type. We have to do this
9735 because the type has already been recorded. */
9736 type
->set_code (TYPE_CODE_STRUCT
);
9738 /* Make space for the discriminant field. */
9739 struct field
*disr_field
= &disr_type
->field (0);
9741 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9742 * sizeof (struct field
)));
9743 memcpy (new_fields
+ 1, type
->fields (),
9744 type
->num_fields () * sizeof (struct field
));
9745 type
->set_fields (new_fields
);
9746 type
->set_num_fields (type
->num_fields () + 1);
9748 /* Install the discriminant at index 0 in the union. */
9749 type
->field (0) = *disr_field
;
9750 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9751 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9753 /* We need a way to find the correct discriminant given a
9754 variant name. For convenience we build a map here. */
9755 struct type
*enum_type
= disr_field
->type ();
9756 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9757 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9759 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9762 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9763 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9767 int n_fields
= type
->num_fields ();
9768 /* We don't need a range entry for the discriminant, but we do
9769 need one for every other field, as there is no default
9771 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9774 /* Skip the discriminant here. */
9775 for (int i
= 1; i
< n_fields
; ++i
)
9777 /* Find the final word in the name of this variant's type.
9778 That name can be used to look up the correct
9780 const char *variant_name
9781 = rust_last_path_segment (type
->field (i
).type ()->name ());
9783 auto iter
= discriminant_map
.find (variant_name
);
9784 if (iter
!= discriminant_map
.end ())
9786 ranges
[i
- 1].low
= iter
->second
;
9787 ranges
[i
- 1].high
= iter
->second
;
9790 /* In Rust, each element should have the size of the
9792 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9794 /* Remove the discriminant field, if it exists. */
9795 struct type
*sub_type
= type
->field (i
).type ();
9796 if (sub_type
->num_fields () > 0)
9798 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9799 sub_type
->set_fields (sub_type
->fields () + 1);
9801 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9803 (rust_fully_qualify (&objfile
->objfile_obstack
,
9804 type
->name (), variant_name
));
9807 /* Indicate that this is a variant type. */
9808 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9809 gdb::array_view
<discriminant_range
> (ranges
,
9814 /* Rewrite some Rust unions to be structures with variants parts. */
9817 rust_union_quirks (struct dwarf2_cu
*cu
)
9819 gdb_assert (cu
->language
== language_rust
);
9820 for (type
*type_
: cu
->rust_unions
)
9821 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9822 /* We don't need this any more. */
9823 cu
->rust_unions
.clear ();
9828 type_unit_group_unshareable
*
9829 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9831 auto iter
= this->m_type_units
.find (tu_group
);
9832 if (iter
!= this->m_type_units
.end ())
9833 return iter
->second
.get ();
9835 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9836 type_unit_group_unshareable
*result
= uniq
.get ();
9837 this->m_type_units
[tu_group
] = std::move (uniq
);
9842 dwarf2_per_objfile::get_type_for_signatured_type
9843 (signatured_type
*sig_type
) const
9845 auto iter
= this->m_type_map
.find (sig_type
);
9846 if (iter
== this->m_type_map
.end ())
9849 return iter
->second
;
9852 void dwarf2_per_objfile::set_type_for_signatured_type
9853 (signatured_type
*sig_type
, struct type
*type
)
9855 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9857 this->m_type_map
[sig_type
] = type
;
9860 /* A helper function for computing the list of all symbol tables
9861 included by PER_CU. */
9864 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9865 htab_t all_children
, htab_t all_type_symtabs
,
9866 dwarf2_per_cu_data
*per_cu
,
9867 dwarf2_per_objfile
*per_objfile
,
9868 struct compunit_symtab
*immediate_parent
)
9870 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9873 /* This inclusion and its children have been processed. */
9879 /* Only add a CU if it has a symbol table. */
9880 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9883 /* If this is a type unit only add its symbol table if we haven't
9884 seen it yet (type unit per_cu's can share symtabs). */
9885 if (per_cu
->is_debug_types
)
9887 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9891 result
->push_back (cust
);
9892 if (cust
->user
== NULL
)
9893 cust
->user
= immediate_parent
;
9898 result
->push_back (cust
);
9899 if (cust
->user
== NULL
)
9900 cust
->user
= immediate_parent
;
9904 if (!per_cu
->imported_symtabs_empty ())
9905 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9907 recursively_compute_inclusions (result
, all_children
,
9908 all_type_symtabs
, ptr
, per_objfile
,
9913 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9917 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9918 dwarf2_per_objfile
*per_objfile
)
9920 gdb_assert (! per_cu
->is_debug_types
);
9922 if (!per_cu
->imported_symtabs_empty ())
9925 std::vector
<compunit_symtab
*> result_symtabs
;
9926 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9928 /* If we don't have a symtab, we can just skip this case. */
9932 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9934 NULL
, xcalloc
, xfree
));
9935 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9937 NULL
, xcalloc
, xfree
));
9939 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9941 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9942 all_type_symtabs
.get (), ptr
,
9946 /* Now we have a transitive closure of all the included symtabs. */
9947 len
= result_symtabs
.size ();
9949 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9950 struct compunit_symtab
*, len
+ 1);
9951 memcpy (cust
->includes
, result_symtabs
.data (),
9952 len
* sizeof (compunit_symtab
*));
9953 cust
->includes
[len
] = NULL
;
9957 /* Compute the 'includes' field for the symtabs of all the CUs we just
9961 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9963 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9965 if (! iter
->is_debug_types
)
9966 compute_compunit_symtab_includes (iter
, per_objfile
);
9969 per_objfile
->per_bfd
->just_read_cus
.clear ();
9972 /* Generate full symbol information for CU, whose DIEs have
9973 already been loaded into memory. */
9976 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9978 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9979 struct objfile
*objfile
= per_objfile
->objfile
;
9980 struct gdbarch
*gdbarch
= objfile
->arch ();
9981 CORE_ADDR lowpc
, highpc
;
9982 struct compunit_symtab
*cust
;
9984 struct block
*static_block
;
9987 baseaddr
= objfile
->text_section_offset ();
9989 /* Clear the list here in case something was left over. */
9990 cu
->method_list
.clear ();
9992 cu
->language
= pretend_language
;
9993 cu
->language_defn
= language_def (cu
->language
);
9995 dwarf2_find_base_address (cu
->dies
, cu
);
9997 /* Do line number decoding in read_file_scope () */
9998 process_die (cu
->dies
, cu
);
10000 /* For now fudge the Go package. */
10001 if (cu
->language
== language_go
)
10002 fixup_go_packaging (cu
);
10004 /* Now that we have processed all the DIEs in the CU, all the types
10005 should be complete, and it should now be safe to compute all of the
10007 compute_delayed_physnames (cu
);
10009 if (cu
->language
== language_rust
)
10010 rust_union_quirks (cu
);
10012 /* Some compilers don't define a DW_AT_high_pc attribute for the
10013 compilation unit. If the DW_AT_high_pc is missing, synthesize
10014 it, by scanning the DIE's below the compilation unit. */
10015 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10017 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10018 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10020 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10021 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10022 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10023 addrmap to help ensure it has an accurate map of pc values belonging to
10025 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10027 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10028 SECT_OFF_TEXT (objfile
),
10033 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10035 /* Set symtab language to language from DW_AT_language. If the
10036 compilation is from a C file generated by language preprocessors, do
10037 not set the language if it was already deduced by start_subfile. */
10038 if (!(cu
->language
== language_c
10039 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10040 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10042 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10043 produce DW_AT_location with location lists but it can be possibly
10044 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10045 there were bugs in prologue debug info, fixed later in GCC-4.5
10046 by "unwind info for epilogues" patch (which is not directly related).
10048 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10049 needed, it would be wrong due to missing DW_AT_producer there.
10051 Still one can confuse GDB by using non-standard GCC compilation
10052 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10054 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10055 cust
->locations_valid
= 1;
10057 if (gcc_4_minor
>= 5)
10058 cust
->epilogue_unwind_valid
= 1;
10060 cust
->call_site_htab
= cu
->call_site_htab
;
10063 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10065 /* Push it for inclusion processing later. */
10066 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
10068 /* Not needed any more. */
10069 cu
->reset_builder ();
10072 /* Generate full symbol information for type unit CU, whose DIEs have
10073 already been loaded into memory. */
10076 process_full_type_unit (dwarf2_cu
*cu
,
10077 enum language pretend_language
)
10079 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10080 struct objfile
*objfile
= per_objfile
->objfile
;
10081 struct compunit_symtab
*cust
;
10082 struct signatured_type
*sig_type
;
10084 gdb_assert (cu
->per_cu
->is_debug_types
);
10085 sig_type
= (struct signatured_type
*) cu
->per_cu
;
10087 /* Clear the list here in case something was left over. */
10088 cu
->method_list
.clear ();
10090 cu
->language
= pretend_language
;
10091 cu
->language_defn
= language_def (cu
->language
);
10093 /* The symbol tables are set up in read_type_unit_scope. */
10094 process_die (cu
->dies
, cu
);
10096 /* For now fudge the Go package. */
10097 if (cu
->language
== language_go
)
10098 fixup_go_packaging (cu
);
10100 /* Now that we have processed all the DIEs in the CU, all the types
10101 should be complete, and it should now be safe to compute all of the
10103 compute_delayed_physnames (cu
);
10105 if (cu
->language
== language_rust
)
10106 rust_union_quirks (cu
);
10108 /* TUs share symbol tables.
10109 If this is the first TU to use this symtab, complete the construction
10110 of it with end_expandable_symtab. Otherwise, complete the addition of
10111 this TU's symbols to the existing symtab. */
10112 type_unit_group_unshareable
*tug_unshare
=
10113 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
10114 if (tug_unshare
->compunit_symtab
== NULL
)
10116 buildsym_compunit
*builder
= cu
->get_builder ();
10117 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10118 tug_unshare
->compunit_symtab
= cust
;
10122 /* Set symtab language to language from DW_AT_language. If the
10123 compilation is from a C file generated by language preprocessors,
10124 do not set the language if it was already deduced by
10126 if (!(cu
->language
== language_c
10127 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10128 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10133 cu
->get_builder ()->augment_type_symtab ();
10134 cust
= tug_unshare
->compunit_symtab
;
10137 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10139 /* Not needed any more. */
10140 cu
->reset_builder ();
10143 /* Process an imported unit DIE. */
10146 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10148 struct attribute
*attr
;
10150 /* For now we don't handle imported units in type units. */
10151 if (cu
->per_cu
->is_debug_types
)
10153 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10154 " supported in type units [in module %s]"),
10155 objfile_name (cu
->per_objfile
->objfile
));
10158 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10161 sect_offset sect_off
= attr
->get_ref_die_offset ();
10162 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10163 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10164 dwarf2_per_cu_data
*per_cu
10165 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10167 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10168 into another compilation unit, at root level. Regard this as a hint,
10170 if (die
->parent
&& die
->parent
->parent
== NULL
10171 && per_cu
->unit_type
== DW_UT_compile
10172 && per_cu
->lang
== language_cplus
)
10175 /* If necessary, add it to the queue and load its DIEs. */
10176 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10177 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
10178 false, cu
->language
);
10180 cu
->per_cu
->imported_symtabs_push (per_cu
);
10184 /* RAII object that represents a process_die scope: i.e.,
10185 starts/finishes processing a DIE. */
10186 class process_die_scope
10189 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10190 : m_die (die
), m_cu (cu
)
10192 /* We should only be processing DIEs not already in process. */
10193 gdb_assert (!m_die
->in_process
);
10194 m_die
->in_process
= true;
10197 ~process_die_scope ()
10199 m_die
->in_process
= false;
10201 /* If we're done processing the DIE for the CU that owns the line
10202 header, we don't need the line header anymore. */
10203 if (m_cu
->line_header_die_owner
== m_die
)
10205 delete m_cu
->line_header
;
10206 m_cu
->line_header
= NULL
;
10207 m_cu
->line_header_die_owner
= NULL
;
10216 /* Process a die and its children. */
10219 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10221 process_die_scope
scope (die
, cu
);
10225 case DW_TAG_padding
:
10227 case DW_TAG_compile_unit
:
10228 case DW_TAG_partial_unit
:
10229 read_file_scope (die
, cu
);
10231 case DW_TAG_type_unit
:
10232 read_type_unit_scope (die
, cu
);
10234 case DW_TAG_subprogram
:
10235 /* Nested subprograms in Fortran get a prefix. */
10236 if (cu
->language
== language_fortran
10237 && die
->parent
!= NULL
10238 && die
->parent
->tag
== DW_TAG_subprogram
)
10239 cu
->processing_has_namespace_info
= true;
10240 /* Fall through. */
10241 case DW_TAG_inlined_subroutine
:
10242 read_func_scope (die
, cu
);
10244 case DW_TAG_lexical_block
:
10245 case DW_TAG_try_block
:
10246 case DW_TAG_catch_block
:
10247 read_lexical_block_scope (die
, cu
);
10249 case DW_TAG_call_site
:
10250 case DW_TAG_GNU_call_site
:
10251 read_call_site_scope (die
, cu
);
10253 case DW_TAG_class_type
:
10254 case DW_TAG_interface_type
:
10255 case DW_TAG_structure_type
:
10256 case DW_TAG_union_type
:
10257 process_structure_scope (die
, cu
);
10259 case DW_TAG_enumeration_type
:
10260 process_enumeration_scope (die
, cu
);
10263 /* These dies have a type, but processing them does not create
10264 a symbol or recurse to process the children. Therefore we can
10265 read them on-demand through read_type_die. */
10266 case DW_TAG_subroutine_type
:
10267 case DW_TAG_set_type
:
10268 case DW_TAG_pointer_type
:
10269 case DW_TAG_ptr_to_member_type
:
10270 case DW_TAG_reference_type
:
10271 case DW_TAG_rvalue_reference_type
:
10272 case DW_TAG_string_type
:
10275 case DW_TAG_array_type
:
10276 /* We only need to handle this case for Ada -- in other
10277 languages, it's normal for the compiler to emit a typedef
10279 if (cu
->language
!= language_ada
)
10282 case DW_TAG_base_type
:
10283 case DW_TAG_subrange_type
:
10284 case DW_TAG_typedef
:
10285 /* Add a typedef symbol for the type definition, if it has a
10287 new_symbol (die
, read_type_die (die
, cu
), cu
);
10289 case DW_TAG_common_block
:
10290 read_common_block (die
, cu
);
10292 case DW_TAG_common_inclusion
:
10294 case DW_TAG_namespace
:
10295 cu
->processing_has_namespace_info
= true;
10296 read_namespace (die
, cu
);
10298 case DW_TAG_module
:
10299 cu
->processing_has_namespace_info
= true;
10300 read_module (die
, cu
);
10302 case DW_TAG_imported_declaration
:
10303 cu
->processing_has_namespace_info
= true;
10304 if (read_namespace_alias (die
, cu
))
10306 /* The declaration is not a global namespace alias. */
10307 /* Fall through. */
10308 case DW_TAG_imported_module
:
10309 cu
->processing_has_namespace_info
= true;
10310 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10311 || cu
->language
!= language_fortran
))
10312 complaint (_("Tag '%s' has unexpected children"),
10313 dwarf_tag_name (die
->tag
));
10314 read_import_statement (die
, cu
);
10317 case DW_TAG_imported_unit
:
10318 process_imported_unit_die (die
, cu
);
10321 case DW_TAG_variable
:
10322 read_variable (die
, cu
);
10326 new_symbol (die
, NULL
, cu
);
10331 /* DWARF name computation. */
10333 /* A helper function for dwarf2_compute_name which determines whether DIE
10334 needs to have the name of the scope prepended to the name listed in the
10338 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10340 struct attribute
*attr
;
10344 case DW_TAG_namespace
:
10345 case DW_TAG_typedef
:
10346 case DW_TAG_class_type
:
10347 case DW_TAG_interface_type
:
10348 case DW_TAG_structure_type
:
10349 case DW_TAG_union_type
:
10350 case DW_TAG_enumeration_type
:
10351 case DW_TAG_enumerator
:
10352 case DW_TAG_subprogram
:
10353 case DW_TAG_inlined_subroutine
:
10354 case DW_TAG_member
:
10355 case DW_TAG_imported_declaration
:
10358 case DW_TAG_variable
:
10359 case DW_TAG_constant
:
10360 /* We only need to prefix "globally" visible variables. These include
10361 any variable marked with DW_AT_external or any variable that
10362 lives in a namespace. [Variables in anonymous namespaces
10363 require prefixing, but they are not DW_AT_external.] */
10365 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10367 struct dwarf2_cu
*spec_cu
= cu
;
10369 return die_needs_namespace (die_specification (die
, &spec_cu
),
10373 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10374 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10375 && die
->parent
->tag
!= DW_TAG_module
)
10377 /* A variable in a lexical block of some kind does not need a
10378 namespace, even though in C++ such variables may be external
10379 and have a mangled name. */
10380 if (die
->parent
->tag
== DW_TAG_lexical_block
10381 || die
->parent
->tag
== DW_TAG_try_block
10382 || die
->parent
->tag
== DW_TAG_catch_block
10383 || die
->parent
->tag
== DW_TAG_subprogram
)
10392 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10393 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10394 defined for the given DIE. */
10396 static struct attribute
*
10397 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10399 struct attribute
*attr
;
10401 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10403 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10408 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10409 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10410 defined for the given DIE. */
10412 static const char *
10413 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10415 const char *linkage_name
;
10417 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10418 if (linkage_name
== NULL
)
10419 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10421 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10422 See https://github.com/rust-lang/rust/issues/32925. */
10423 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10424 && strchr (linkage_name
, '{') != NULL
)
10425 linkage_name
= NULL
;
10427 return linkage_name
;
10430 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10431 compute the physname for the object, which include a method's:
10432 - formal parameters (C++),
10433 - receiver type (Go),
10435 The term "physname" is a bit confusing.
10436 For C++, for example, it is the demangled name.
10437 For Go, for example, it's the mangled name.
10439 For Ada, return the DIE's linkage name rather than the fully qualified
10440 name. PHYSNAME is ignored..
10442 The result is allocated on the objfile->per_bfd's obstack and
10445 static const char *
10446 dwarf2_compute_name (const char *name
,
10447 struct die_info
*die
, struct dwarf2_cu
*cu
,
10450 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10453 name
= dwarf2_name (die
, cu
);
10455 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10456 but otherwise compute it by typename_concat inside GDB.
10457 FIXME: Actually this is not really true, or at least not always true.
10458 It's all very confusing. compute_and_set_names doesn't try to demangle
10459 Fortran names because there is no mangling standard. So new_symbol
10460 will set the demangled name to the result of dwarf2_full_name, and it is
10461 the demangled name that GDB uses if it exists. */
10462 if (cu
->language
== language_ada
10463 || (cu
->language
== language_fortran
&& physname
))
10465 /* For Ada unit, we prefer the linkage name over the name, as
10466 the former contains the exported name, which the user expects
10467 to be able to reference. Ideally, we want the user to be able
10468 to reference this entity using either natural or linkage name,
10469 but we haven't started looking at this enhancement yet. */
10470 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10472 if (linkage_name
!= NULL
)
10473 return linkage_name
;
10476 /* These are the only languages we know how to qualify names in. */
10478 && (cu
->language
== language_cplus
10479 || cu
->language
== language_fortran
|| cu
->language
== language_d
10480 || cu
->language
== language_rust
))
10482 if (die_needs_namespace (die
, cu
))
10484 const char *prefix
;
10485 const char *canonical_name
= NULL
;
10489 prefix
= determine_prefix (die
, cu
);
10490 if (*prefix
!= '\0')
10492 gdb::unique_xmalloc_ptr
<char> prefixed_name
10493 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10495 buf
.puts (prefixed_name
.get ());
10500 /* Template parameters may be specified in the DIE's DW_AT_name, or
10501 as children with DW_TAG_template_type_param or
10502 DW_TAG_value_type_param. If the latter, add them to the name
10503 here. If the name already has template parameters, then
10504 skip this step; some versions of GCC emit both, and
10505 it is more efficient to use the pre-computed name.
10507 Something to keep in mind about this process: it is very
10508 unlikely, or in some cases downright impossible, to produce
10509 something that will match the mangled name of a function.
10510 If the definition of the function has the same debug info,
10511 we should be able to match up with it anyway. But fallbacks
10512 using the minimal symbol, for instance to find a method
10513 implemented in a stripped copy of libstdc++, will not work.
10514 If we do not have debug info for the definition, we will have to
10515 match them up some other way.
10517 When we do name matching there is a related problem with function
10518 templates; two instantiated function templates are allowed to
10519 differ only by their return types, which we do not add here. */
10521 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10523 struct attribute
*attr
;
10524 struct die_info
*child
;
10526 const language_defn
*cplus_lang
= language_def (cu
->language
);
10528 die
->building_fullname
= 1;
10530 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10534 const gdb_byte
*bytes
;
10535 struct dwarf2_locexpr_baton
*baton
;
10538 if (child
->tag
!= DW_TAG_template_type_param
10539 && child
->tag
!= DW_TAG_template_value_param
)
10550 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10553 complaint (_("template parameter missing DW_AT_type"));
10554 buf
.puts ("UNKNOWN_TYPE");
10557 type
= die_type (child
, cu
);
10559 if (child
->tag
== DW_TAG_template_type_param
)
10561 cplus_lang
->print_type (type
, "", &buf
, -1, 0,
10562 &type_print_raw_options
);
10566 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10569 complaint (_("template parameter missing "
10570 "DW_AT_const_value"));
10571 buf
.puts ("UNKNOWN_VALUE");
10575 dwarf2_const_value_attr (attr
, type
, name
,
10576 &cu
->comp_unit_obstack
, cu
,
10577 &value
, &bytes
, &baton
);
10579 if (type
->has_no_signedness ())
10580 /* GDB prints characters as NUMBER 'CHAR'. If that's
10581 changed, this can use value_print instead. */
10582 cplus_lang
->printchar (value
, type
, &buf
);
10585 struct value_print_options opts
;
10588 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10592 baton
->per_objfile
);
10593 else if (bytes
!= NULL
)
10595 v
= allocate_value (type
);
10596 memcpy (value_contents_writeable (v
), bytes
,
10597 TYPE_LENGTH (type
));
10600 v
= value_from_longest (type
, value
);
10602 /* Specify decimal so that we do not depend on
10604 get_formatted_print_options (&opts
, 'd');
10606 value_print (v
, &buf
, &opts
);
10611 die
->building_fullname
= 0;
10615 /* Close the argument list, with a space if necessary
10616 (nested templates). */
10617 if (!buf
.empty () && buf
.string ().back () == '>')
10624 /* For C++ methods, append formal parameter type
10625 information, if PHYSNAME. */
10627 if (physname
&& die
->tag
== DW_TAG_subprogram
10628 && cu
->language
== language_cplus
)
10630 struct type
*type
= read_type_die (die
, cu
);
10632 c_type_print_args (type
, &buf
, 1, cu
->language
,
10633 &type_print_raw_options
);
10635 if (cu
->language
== language_cplus
)
10637 /* Assume that an artificial first parameter is
10638 "this", but do not crash if it is not. RealView
10639 marks unnamed (and thus unused) parameters as
10640 artificial; there is no way to differentiate
10642 if (type
->num_fields () > 0
10643 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10644 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10645 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10646 buf
.puts (" const");
10650 const std::string
&intermediate_name
= buf
.string ();
10652 if (cu
->language
== language_cplus
)
10654 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10657 /* If we only computed INTERMEDIATE_NAME, or if
10658 INTERMEDIATE_NAME is already canonical, then we need to
10660 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10661 name
= objfile
->intern (intermediate_name
);
10663 name
= canonical_name
;
10670 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10671 If scope qualifiers are appropriate they will be added. The result
10672 will be allocated on the storage_obstack, or NULL if the DIE does
10673 not have a name. NAME may either be from a previous call to
10674 dwarf2_name or NULL.
10676 The output string will be canonicalized (if C++). */
10678 static const char *
10679 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10681 return dwarf2_compute_name (name
, die
, cu
, 0);
10684 /* Construct a physname for the given DIE in CU. NAME may either be
10685 from a previous call to dwarf2_name or NULL. The result will be
10686 allocated on the objfile_objstack or NULL if the DIE does not have a
10689 The output string will be canonicalized (if C++). */
10691 static const char *
10692 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10694 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10695 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10698 /* In this case dwarf2_compute_name is just a shortcut not building anything
10700 if (!die_needs_namespace (die
, cu
))
10701 return dwarf2_compute_name (name
, die
, cu
, 1);
10703 if (cu
->language
!= language_rust
)
10704 mangled
= dw2_linkage_name (die
, cu
);
10706 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10708 gdb::unique_xmalloc_ptr
<char> demangled
;
10709 if (mangled
!= NULL
)
10712 if (language_def (cu
->language
)->store_sym_names_in_linkage_form_p ())
10714 /* Do nothing (do not demangle the symbol name). */
10718 /* Use DMGL_RET_DROP for C++ template functions to suppress
10719 their return type. It is easier for GDB users to search
10720 for such functions as `name(params)' than `long name(params)'.
10721 In such case the minimal symbol names do not match the full
10722 symbol names but for template functions there is never a need
10723 to look up their definition from their declaration so
10724 the only disadvantage remains the minimal symbol variant
10725 `long name(params)' does not have the proper inferior type. */
10726 demangled
.reset (gdb_demangle (mangled
,
10727 (DMGL_PARAMS
| DMGL_ANSI
10728 | DMGL_RET_DROP
)));
10731 canon
= demangled
.get ();
10739 if (canon
== NULL
|| check_physname
)
10741 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10743 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10745 /* It may not mean a bug in GDB. The compiler could also
10746 compute DW_AT_linkage_name incorrectly. But in such case
10747 GDB would need to be bug-to-bug compatible. */
10749 complaint (_("Computed physname <%s> does not match demangled <%s> "
10750 "(from linkage <%s>) - DIE at %s [in module %s]"),
10751 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10752 objfile_name (objfile
));
10754 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10755 is available here - over computed PHYSNAME. It is safer
10756 against both buggy GDB and buggy compilers. */
10770 retval
= objfile
->intern (retval
);
10775 /* Inspect DIE in CU for a namespace alias. If one exists, record
10776 a new symbol for it.
10778 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10781 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10783 struct attribute
*attr
;
10785 /* If the die does not have a name, this is not a namespace
10787 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10791 struct die_info
*d
= die
;
10792 struct dwarf2_cu
*imported_cu
= cu
;
10794 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10795 keep inspecting DIEs until we hit the underlying import. */
10796 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10797 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10799 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10803 d
= follow_die_ref (d
, attr
, &imported_cu
);
10804 if (d
->tag
!= DW_TAG_imported_declaration
)
10808 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10810 complaint (_("DIE at %s has too many recursively imported "
10811 "declarations"), sect_offset_str (d
->sect_off
));
10818 sect_offset sect_off
= attr
->get_ref_die_offset ();
10820 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10821 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10823 /* This declaration is a global namespace alias. Add
10824 a symbol for it whose type is the aliased namespace. */
10825 new_symbol (die
, type
, cu
);
10834 /* Return the using directives repository (global or local?) to use in the
10835 current context for CU.
10837 For Ada, imported declarations can materialize renamings, which *may* be
10838 global. However it is impossible (for now?) in DWARF to distinguish
10839 "external" imported declarations and "static" ones. As all imported
10840 declarations seem to be static in all other languages, make them all CU-wide
10841 global only in Ada. */
10843 static struct using_direct
**
10844 using_directives (struct dwarf2_cu
*cu
)
10846 if (cu
->language
== language_ada
10847 && cu
->get_builder ()->outermost_context_p ())
10848 return cu
->get_builder ()->get_global_using_directives ();
10850 return cu
->get_builder ()->get_local_using_directives ();
10853 /* Read the import statement specified by the given die and record it. */
10856 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10858 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10859 struct attribute
*import_attr
;
10860 struct die_info
*imported_die
, *child_die
;
10861 struct dwarf2_cu
*imported_cu
;
10862 const char *imported_name
;
10863 const char *imported_name_prefix
;
10864 const char *canonical_name
;
10865 const char *import_alias
;
10866 const char *imported_declaration
= NULL
;
10867 const char *import_prefix
;
10868 std::vector
<const char *> excludes
;
10870 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10871 if (import_attr
== NULL
)
10873 complaint (_("Tag '%s' has no DW_AT_import"),
10874 dwarf_tag_name (die
->tag
));
10879 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10880 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10881 if (imported_name
== NULL
)
10883 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10885 The import in the following code:
10899 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10900 <52> DW_AT_decl_file : 1
10901 <53> DW_AT_decl_line : 6
10902 <54> DW_AT_import : <0x75>
10903 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10904 <59> DW_AT_name : B
10905 <5b> DW_AT_decl_file : 1
10906 <5c> DW_AT_decl_line : 2
10907 <5d> DW_AT_type : <0x6e>
10909 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10910 <76> DW_AT_byte_size : 4
10911 <77> DW_AT_encoding : 5 (signed)
10913 imports the wrong die ( 0x75 instead of 0x58 ).
10914 This case will be ignored until the gcc bug is fixed. */
10918 /* Figure out the local name after import. */
10919 import_alias
= dwarf2_name (die
, cu
);
10921 /* Figure out where the statement is being imported to. */
10922 import_prefix
= determine_prefix (die
, cu
);
10924 /* Figure out what the scope of the imported die is and prepend it
10925 to the name of the imported die. */
10926 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10928 if (imported_die
->tag
!= DW_TAG_namespace
10929 && imported_die
->tag
!= DW_TAG_module
)
10931 imported_declaration
= imported_name
;
10932 canonical_name
= imported_name_prefix
;
10934 else if (strlen (imported_name_prefix
) > 0)
10935 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10936 imported_name_prefix
,
10937 (cu
->language
== language_d
? "." : "::"),
10938 imported_name
, (char *) NULL
);
10940 canonical_name
= imported_name
;
10942 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10943 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10944 child_die
= child_die
->sibling
)
10946 /* DWARF-4: A Fortran use statement with a “rename list” may be
10947 represented by an imported module entry with an import attribute
10948 referring to the module and owned entries corresponding to those
10949 entities that are renamed as part of being imported. */
10951 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10953 complaint (_("child DW_TAG_imported_declaration expected "
10954 "- DIE at %s [in module %s]"),
10955 sect_offset_str (child_die
->sect_off
),
10956 objfile_name (objfile
));
10960 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10961 if (import_attr
== NULL
)
10963 complaint (_("Tag '%s' has no DW_AT_import"),
10964 dwarf_tag_name (child_die
->tag
));
10969 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10971 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10972 if (imported_name
== NULL
)
10974 complaint (_("child DW_TAG_imported_declaration has unknown "
10975 "imported name - DIE at %s [in module %s]"),
10976 sect_offset_str (child_die
->sect_off
),
10977 objfile_name (objfile
));
10981 excludes
.push_back (imported_name
);
10983 process_die (child_die
, cu
);
10986 add_using_directive (using_directives (cu
),
10990 imported_declaration
,
10993 &objfile
->objfile_obstack
);
10996 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10997 types, but gives them a size of zero. Starting with version 14,
10998 ICC is compatible with GCC. */
11001 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11003 if (!cu
->checked_producer
)
11004 check_producer (cu
);
11006 return cu
->producer_is_icc_lt_14
;
11009 /* ICC generates a DW_AT_type for C void functions. This was observed on
11010 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11011 which says that void functions should not have a DW_AT_type. */
11014 producer_is_icc (struct dwarf2_cu
*cu
)
11016 if (!cu
->checked_producer
)
11017 check_producer (cu
);
11019 return cu
->producer_is_icc
;
11022 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11023 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11024 this, it was first present in GCC release 4.3.0. */
11027 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11029 if (!cu
->checked_producer
)
11030 check_producer (cu
);
11032 return cu
->producer_is_gcc_lt_4_3
;
11035 static file_and_directory
11036 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11038 file_and_directory res
;
11040 /* Find the filename. Do not use dwarf2_name here, since the filename
11041 is not a source language identifier. */
11042 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11043 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11045 if (res
.comp_dir
== NULL
11046 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11047 && IS_ABSOLUTE_PATH (res
.name
))
11049 res
.comp_dir_storage
= ldirname (res
.name
);
11050 if (!res
.comp_dir_storage
.empty ())
11051 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11053 if (res
.comp_dir
!= NULL
)
11055 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11056 directory, get rid of it. */
11057 const char *cp
= strchr (res
.comp_dir
, ':');
11059 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11060 res
.comp_dir
= cp
+ 1;
11063 if (res
.name
== NULL
)
11064 res
.name
= "<unknown>";
11069 /* Handle DW_AT_stmt_list for a compilation unit.
11070 DIE is the DW_TAG_compile_unit die for CU.
11071 COMP_DIR is the compilation directory. LOWPC is passed to
11072 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11075 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11076 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11078 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11079 struct attribute
*attr
;
11080 struct line_header line_header_local
;
11081 hashval_t line_header_local_hash
;
11083 int decode_mapping
;
11085 gdb_assert (! cu
->per_cu
->is_debug_types
);
11087 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11088 if (attr
== NULL
|| !attr
->form_is_unsigned ())
11091 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11093 /* The line header hash table is only created if needed (it exists to
11094 prevent redundant reading of the line table for partial_units).
11095 If we're given a partial_unit, we'll need it. If we're given a
11096 compile_unit, then use the line header hash table if it's already
11097 created, but don't create one just yet. */
11099 if (per_objfile
->line_header_hash
== NULL
11100 && die
->tag
== DW_TAG_partial_unit
)
11102 per_objfile
->line_header_hash
11103 .reset (htab_create_alloc (127, line_header_hash_voidp
,
11104 line_header_eq_voidp
,
11105 free_line_header_voidp
,
11109 line_header_local
.sect_off
= line_offset
;
11110 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11111 line_header_local_hash
= line_header_hash (&line_header_local
);
11112 if (per_objfile
->line_header_hash
!= NULL
)
11114 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11115 &line_header_local
,
11116 line_header_local_hash
, NO_INSERT
);
11118 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11119 is not present in *SLOT (since if there is something in *SLOT then
11120 it will be for a partial_unit). */
11121 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11123 gdb_assert (*slot
!= NULL
);
11124 cu
->line_header
= (struct line_header
*) *slot
;
11129 /* dwarf_decode_line_header does not yet provide sufficient information.
11130 We always have to call also dwarf_decode_lines for it. */
11131 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11135 cu
->line_header
= lh
.release ();
11136 cu
->line_header_die_owner
= die
;
11138 if (per_objfile
->line_header_hash
== NULL
)
11142 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11143 &line_header_local
,
11144 line_header_local_hash
, INSERT
);
11145 gdb_assert (slot
!= NULL
);
11147 if (slot
!= NULL
&& *slot
== NULL
)
11149 /* This newly decoded line number information unit will be owned
11150 by line_header_hash hash table. */
11151 *slot
= cu
->line_header
;
11152 cu
->line_header_die_owner
= NULL
;
11156 /* We cannot free any current entry in (*slot) as that struct line_header
11157 may be already used by multiple CUs. Create only temporary decoded
11158 line_header for this CU - it may happen at most once for each line
11159 number information unit. And if we're not using line_header_hash
11160 then this is what we want as well. */
11161 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11163 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11164 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11169 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11172 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11174 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11175 struct objfile
*objfile
= per_objfile
->objfile
;
11176 struct gdbarch
*gdbarch
= objfile
->arch ();
11177 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11178 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11179 struct attribute
*attr
;
11180 struct die_info
*child_die
;
11181 CORE_ADDR baseaddr
;
11183 prepare_one_comp_unit (cu
, die
, cu
->language
);
11184 baseaddr
= objfile
->text_section_offset ();
11186 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11188 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11189 from finish_block. */
11190 if (lowpc
== ((CORE_ADDR
) -1))
11192 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11194 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11196 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11197 standardised yet. As a workaround for the language detection we fall
11198 back to the DW_AT_producer string. */
11199 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11200 cu
->language
= language_opencl
;
11202 /* Similar hack for Go. */
11203 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11204 set_cu_language (DW_LANG_Go
, cu
);
11206 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11208 /* Decode line number information if present. We do this before
11209 processing child DIEs, so that the line header table is available
11210 for DW_AT_decl_file. */
11211 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11213 /* Process all dies in compilation unit. */
11214 if (die
->child
!= NULL
)
11216 child_die
= die
->child
;
11217 while (child_die
&& child_die
->tag
)
11219 process_die (child_die
, cu
);
11220 child_die
= child_die
->sibling
;
11224 /* Decode macro information, if present. Dwarf 2 macro information
11225 refers to information in the line number info statement program
11226 header, so we can only read it if we've read the header
11228 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11230 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11231 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11233 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11234 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11236 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
11240 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11241 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11243 unsigned int macro_offset
= attr
->as_unsigned ();
11245 dwarf_decode_macros (cu
, macro_offset
, 0);
11251 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11253 struct type_unit_group
*tu_group
;
11255 struct attribute
*attr
;
11257 struct signatured_type
*sig_type
;
11259 gdb_assert (per_cu
->is_debug_types
);
11260 sig_type
= (struct signatured_type
*) per_cu
;
11262 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11264 /* If we're using .gdb_index (includes -readnow) then
11265 per_cu->type_unit_group may not have been set up yet. */
11266 if (sig_type
->type_unit_group
== NULL
)
11267 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11268 tu_group
= sig_type
->type_unit_group
;
11270 /* If we've already processed this stmt_list there's no real need to
11271 do it again, we could fake it and just recreate the part we need
11272 (file name,index -> symtab mapping). If data shows this optimization
11273 is useful we can do it then. */
11274 type_unit_group_unshareable
*tug_unshare
11275 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11276 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11278 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11281 if (attr
!= NULL
&& attr
->form_is_unsigned ())
11283 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11284 lh
= dwarf_decode_line_header (line_offset
, this);
11289 start_symtab ("", NULL
, 0);
11292 gdb_assert (tug_unshare
->symtabs
== NULL
);
11293 gdb_assert (m_builder
== nullptr);
11294 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11295 m_builder
.reset (new struct buildsym_compunit
11296 (COMPUNIT_OBJFILE (cust
), "",
11297 COMPUNIT_DIRNAME (cust
),
11298 compunit_language (cust
),
11300 list_in_scope
= get_builder ()->get_file_symbols ();
11305 line_header
= lh
.release ();
11306 line_header_die_owner
= die
;
11310 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11312 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11313 still initializing it, and our caller (a few levels up)
11314 process_full_type_unit still needs to know if this is the first
11317 tug_unshare
->symtabs
11318 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11319 struct symtab
*, line_header
->file_names_size ());
11321 auto &file_names
= line_header
->file_names ();
11322 for (i
= 0; i
< file_names
.size (); ++i
)
11324 file_entry
&fe
= file_names
[i
];
11325 dwarf2_start_subfile (this, fe
.name
,
11326 fe
.include_dir (line_header
));
11327 buildsym_compunit
*b
= get_builder ();
11328 if (b
->get_current_subfile ()->symtab
== NULL
)
11330 /* NOTE: start_subfile will recognize when it's been
11331 passed a file it has already seen. So we can't
11332 assume there's a simple mapping from
11333 cu->line_header->file_names to subfiles, plus
11334 cu->line_header->file_names may contain dups. */
11335 b
->get_current_subfile ()->symtab
11336 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11339 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11340 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11345 gdb_assert (m_builder
== nullptr);
11346 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11347 m_builder
.reset (new struct buildsym_compunit
11348 (COMPUNIT_OBJFILE (cust
), "",
11349 COMPUNIT_DIRNAME (cust
),
11350 compunit_language (cust
),
11352 list_in_scope
= get_builder ()->get_file_symbols ();
11354 auto &file_names
= line_header
->file_names ();
11355 for (i
= 0; i
< file_names
.size (); ++i
)
11357 file_entry
&fe
= file_names
[i
];
11358 fe
.symtab
= tug_unshare
->symtabs
[i
];
11362 /* The main symtab is allocated last. Type units don't have DW_AT_name
11363 so they don't have a "real" (so to speak) symtab anyway.
11364 There is later code that will assign the main symtab to all symbols
11365 that don't have one. We need to handle the case of a symbol with a
11366 missing symtab (DW_AT_decl_file) anyway. */
11369 /* Process DW_TAG_type_unit.
11370 For TUs we want to skip the first top level sibling if it's not the
11371 actual type being defined by this TU. In this case the first top
11372 level sibling is there to provide context only. */
11375 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11377 struct die_info
*child_die
;
11379 prepare_one_comp_unit (cu
, die
, language_minimal
);
11381 /* Initialize (or reinitialize) the machinery for building symtabs.
11382 We do this before processing child DIEs, so that the line header table
11383 is available for DW_AT_decl_file. */
11384 cu
->setup_type_unit_groups (die
);
11386 if (die
->child
!= NULL
)
11388 child_die
= die
->child
;
11389 while (child_die
&& child_die
->tag
)
11391 process_die (child_die
, cu
);
11392 child_die
= child_die
->sibling
;
11399 http://gcc.gnu.org/wiki/DebugFission
11400 http://gcc.gnu.org/wiki/DebugFissionDWP
11402 To simplify handling of both DWO files ("object" files with the DWARF info)
11403 and DWP files (a file with the DWOs packaged up into one file), we treat
11404 DWP files as having a collection of virtual DWO files. */
11407 hash_dwo_file (const void *item
)
11409 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11412 hash
= htab_hash_string (dwo_file
->dwo_name
);
11413 if (dwo_file
->comp_dir
!= NULL
)
11414 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11419 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11421 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11422 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11424 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11426 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11427 return lhs
->comp_dir
== rhs
->comp_dir
;
11428 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11431 /* Allocate a hash table for DWO files. */
11434 allocate_dwo_file_hash_table ()
11436 auto delete_dwo_file
= [] (void *item
)
11438 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11443 return htab_up (htab_create_alloc (41,
11450 /* Lookup DWO file DWO_NAME. */
11453 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11454 const char *dwo_name
,
11455 const char *comp_dir
)
11457 struct dwo_file find_entry
;
11460 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11461 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11463 find_entry
.dwo_name
= dwo_name
;
11464 find_entry
.comp_dir
= comp_dir
;
11465 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11472 hash_dwo_unit (const void *item
)
11474 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11476 /* This drops the top 32 bits of the id, but is ok for a hash. */
11477 return dwo_unit
->signature
;
11481 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11483 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11484 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11486 /* The signature is assumed to be unique within the DWO file.
11487 So while object file CU dwo_id's always have the value zero,
11488 that's OK, assuming each object file DWO file has only one CU,
11489 and that's the rule for now. */
11490 return lhs
->signature
== rhs
->signature
;
11493 /* Allocate a hash table for DWO CUs,TUs.
11494 There is one of these tables for each of CUs,TUs for each DWO file. */
11497 allocate_dwo_unit_table ()
11499 /* Start out with a pretty small number.
11500 Generally DWO files contain only one CU and maybe some TUs. */
11501 return htab_up (htab_create_alloc (3,
11504 NULL
, xcalloc
, xfree
));
11507 /* die_reader_func for create_dwo_cu. */
11510 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11511 const gdb_byte
*info_ptr
,
11512 struct die_info
*comp_unit_die
,
11513 struct dwo_file
*dwo_file
,
11514 struct dwo_unit
*dwo_unit
)
11516 struct dwarf2_cu
*cu
= reader
->cu
;
11517 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11518 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11520 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11521 if (!signature
.has_value ())
11523 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11524 " its dwo_id [in module %s]"),
11525 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11529 dwo_unit
->dwo_file
= dwo_file
;
11530 dwo_unit
->signature
= *signature
;
11531 dwo_unit
->section
= section
;
11532 dwo_unit
->sect_off
= sect_off
;
11533 dwo_unit
->length
= cu
->per_cu
->length
;
11535 dwarf_read_debug_printf (" offset %s, dwo_id %s",
11536 sect_offset_str (sect_off
),
11537 hex_string (dwo_unit
->signature
));
11540 /* Create the dwo_units for the CUs in a DWO_FILE.
11541 Note: This function processes DWO files only, not DWP files. */
11544 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11545 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11546 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11548 struct objfile
*objfile
= per_objfile
->objfile
;
11549 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11550 const gdb_byte
*info_ptr
, *end_ptr
;
11552 section
.read (objfile
);
11553 info_ptr
= section
.buffer
;
11555 if (info_ptr
== NULL
)
11558 dwarf_read_debug_printf ("Reading %s for %s:",
11559 section
.get_name (),
11560 section
.get_file_name ());
11562 end_ptr
= info_ptr
+ section
.size
;
11563 while (info_ptr
< end_ptr
)
11565 struct dwarf2_per_cu_data per_cu
;
11566 struct dwo_unit read_unit
{};
11567 struct dwo_unit
*dwo_unit
;
11569 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11571 memset (&per_cu
, 0, sizeof (per_cu
));
11572 per_cu
.per_bfd
= per_bfd
;
11573 per_cu
.is_debug_types
= 0;
11574 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11575 per_cu
.section
= §ion
;
11577 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11578 if (!reader
.dummy_p
)
11579 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11580 &dwo_file
, &read_unit
);
11581 info_ptr
+= per_cu
.length
;
11583 // If the unit could not be parsed, skip it.
11584 if (read_unit
.dwo_file
== NULL
)
11587 if (cus_htab
== NULL
)
11588 cus_htab
= allocate_dwo_unit_table ();
11590 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11592 *dwo_unit
= read_unit
;
11593 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11594 gdb_assert (slot
!= NULL
);
11597 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11598 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11600 complaint (_("debug cu entry at offset %s is duplicate to"
11601 " the entry at offset %s, signature %s"),
11602 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11603 hex_string (dwo_unit
->signature
));
11605 *slot
= (void *)dwo_unit
;
11609 /* DWP file .debug_{cu,tu}_index section format:
11610 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11611 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11613 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11614 officially standard DWP format was published with DWARF v5 and is called
11615 Version 5. There are no versions 3 or 4.
11619 Both index sections have the same format, and serve to map a 64-bit
11620 signature to a set of section numbers. Each section begins with a header,
11621 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11622 indexes, and a pool of 32-bit section numbers. The index sections will be
11623 aligned at 8-byte boundaries in the file.
11625 The index section header consists of:
11627 V, 32 bit version number
11629 N, 32 bit number of compilation units or type units in the index
11630 M, 32 bit number of slots in the hash table
11632 Numbers are recorded using the byte order of the application binary.
11634 The hash table begins at offset 16 in the section, and consists of an array
11635 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11636 order of the application binary). Unused slots in the hash table are 0.
11637 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11639 The parallel table begins immediately after the hash table
11640 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11641 array of 32-bit indexes (using the byte order of the application binary),
11642 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11643 table contains a 32-bit index into the pool of section numbers. For unused
11644 hash table slots, the corresponding entry in the parallel table will be 0.
11646 The pool of section numbers begins immediately following the hash table
11647 (at offset 16 + 12 * M from the beginning of the section). The pool of
11648 section numbers consists of an array of 32-bit words (using the byte order
11649 of the application binary). Each item in the array is indexed starting
11650 from 0. The hash table entry provides the index of the first section
11651 number in the set. Additional section numbers in the set follow, and the
11652 set is terminated by a 0 entry (section number 0 is not used in ELF).
11654 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11655 section must be the first entry in the set, and the .debug_abbrev.dwo must
11656 be the second entry. Other members of the set may follow in any order.
11660 DWP Versions 2 and 5:
11662 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11663 and the entries in the index tables are now offsets into these sections.
11664 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11667 Index Section Contents:
11669 Hash Table of Signatures dwp_hash_table.hash_table
11670 Parallel Table of Indices dwp_hash_table.unit_table
11671 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11672 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11674 The index section header consists of:
11676 V, 32 bit version number
11677 L, 32 bit number of columns in the table of section offsets
11678 N, 32 bit number of compilation units or type units in the index
11679 M, 32 bit number of slots in the hash table
11681 Numbers are recorded using the byte order of the application binary.
11683 The hash table has the same format as version 1.
11684 The parallel table of indices has the same format as version 1,
11685 except that the entries are origin-1 indices into the table of sections
11686 offsets and the table of section sizes.
11688 The table of offsets begins immediately following the parallel table
11689 (at offset 16 + 12 * M from the beginning of the section). The table is
11690 a two-dimensional array of 32-bit words (using the byte order of the
11691 application binary), with L columns and N+1 rows, in row-major order.
11692 Each row in the array is indexed starting from 0. The first row provides
11693 a key to the remaining rows: each column in this row provides an identifier
11694 for a debug section, and the offsets in the same column of subsequent rows
11695 refer to that section. The section identifiers for Version 2 are:
11697 DW_SECT_INFO 1 .debug_info.dwo
11698 DW_SECT_TYPES 2 .debug_types.dwo
11699 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11700 DW_SECT_LINE 4 .debug_line.dwo
11701 DW_SECT_LOC 5 .debug_loc.dwo
11702 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11703 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11704 DW_SECT_MACRO 8 .debug_macro.dwo
11706 The section identifiers for Version 5 are:
11708 DW_SECT_INFO_V5 1 .debug_info.dwo
11709 DW_SECT_RESERVED_V5 2 --
11710 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11711 DW_SECT_LINE_V5 4 .debug_line.dwo
11712 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11713 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11714 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11715 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11717 The offsets provided by the CU and TU index sections are the base offsets
11718 for the contributions made by each CU or TU to the corresponding section
11719 in the package file. Each CU and TU header contains an abbrev_offset
11720 field, used to find the abbreviations table for that CU or TU within the
11721 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11722 be interpreted as relative to the base offset given in the index section.
11723 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11724 should be interpreted as relative to the base offset for .debug_line.dwo,
11725 and offsets into other debug sections obtained from DWARF attributes should
11726 also be interpreted as relative to the corresponding base offset.
11728 The table of sizes begins immediately following the table of offsets.
11729 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11730 with L columns and N rows, in row-major order. Each row in the array is
11731 indexed starting from 1 (row 0 is shared by the two tables).
11735 Hash table lookup is handled the same in version 1 and 2:
11737 We assume that N and M will not exceed 2^32 - 1.
11738 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11740 Given a 64-bit compilation unit signature or a type signature S, an entry
11741 in the hash table is located as follows:
11743 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11744 the low-order k bits all set to 1.
11746 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11748 3) If the hash table entry at index H matches the signature, use that
11749 entry. If the hash table entry at index H is unused (all zeroes),
11750 terminate the search: the signature is not present in the table.
11752 4) Let H = (H + H') modulo M. Repeat at Step 3.
11754 Because M > N and H' and M are relatively prime, the search is guaranteed
11755 to stop at an unused slot or find the match. */
11757 /* Create a hash table to map DWO IDs to their CU/TU entry in
11758 .debug_{info,types}.dwo in DWP_FILE.
11759 Returns NULL if there isn't one.
11760 Note: This function processes DWP files only, not DWO files. */
11762 static struct dwp_hash_table
*
11763 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11764 struct dwp_file
*dwp_file
, int is_debug_types
)
11766 struct objfile
*objfile
= per_objfile
->objfile
;
11767 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11768 const gdb_byte
*index_ptr
, *index_end
;
11769 struct dwarf2_section_info
*index
;
11770 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11771 struct dwp_hash_table
*htab
;
11773 if (is_debug_types
)
11774 index
= &dwp_file
->sections
.tu_index
;
11776 index
= &dwp_file
->sections
.cu_index
;
11778 if (index
->empty ())
11780 index
->read (objfile
);
11782 index_ptr
= index
->buffer
;
11783 index_end
= index_ptr
+ index
->size
;
11785 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11786 For now it's safe to just read 4 bytes (particularly as it's difficult to
11787 tell if you're dealing with Version 5 before you've read the version). */
11788 version
= read_4_bytes (dbfd
, index_ptr
);
11790 if (version
== 2 || version
== 5)
11791 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11795 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11797 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11800 if (version
!= 1 && version
!= 2 && version
!= 5)
11802 error (_("Dwarf Error: unsupported DWP file version (%s)"
11803 " [in module %s]"),
11804 pulongest (version
), dwp_file
->name
);
11806 if (nr_slots
!= (nr_slots
& -nr_slots
))
11808 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11809 " is not power of 2 [in module %s]"),
11810 pulongest (nr_slots
), dwp_file
->name
);
11813 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11814 htab
->version
= version
;
11815 htab
->nr_columns
= nr_columns
;
11816 htab
->nr_units
= nr_units
;
11817 htab
->nr_slots
= nr_slots
;
11818 htab
->hash_table
= index_ptr
;
11819 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11821 /* Exit early if the table is empty. */
11822 if (nr_slots
== 0 || nr_units
== 0
11823 || (version
== 2 && nr_columns
== 0)
11824 || (version
== 5 && nr_columns
== 0))
11826 /* All must be zero. */
11827 if (nr_slots
!= 0 || nr_units
!= 0
11828 || (version
== 2 && nr_columns
!= 0)
11829 || (version
== 5 && nr_columns
!= 0))
11831 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11832 " all zero [in modules %s]"),
11840 htab
->section_pool
.v1
.indices
=
11841 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11842 /* It's harder to decide whether the section is too small in v1.
11843 V1 is deprecated anyway so we punt. */
11845 else if (version
== 2)
11847 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11848 int *ids
= htab
->section_pool
.v2
.section_ids
;
11849 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11850 /* Reverse map for error checking. */
11851 int ids_seen
[DW_SECT_MAX
+ 1];
11854 if (nr_columns
< 2)
11856 error (_("Dwarf Error: bad DWP hash table, too few columns"
11857 " in section table [in module %s]"),
11860 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11862 error (_("Dwarf Error: bad DWP hash table, too many columns"
11863 " in section table [in module %s]"),
11866 memset (ids
, 255, sizeof_ids
);
11867 memset (ids_seen
, 255, sizeof (ids_seen
));
11868 for (i
= 0; i
< nr_columns
; ++i
)
11870 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11872 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11874 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11875 " in section table [in module %s]"),
11876 id
, dwp_file
->name
);
11878 if (ids_seen
[id
] != -1)
11880 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11881 " id %d in section table [in module %s]"),
11882 id
, dwp_file
->name
);
11887 /* Must have exactly one info or types section. */
11888 if (((ids_seen
[DW_SECT_INFO
] != -1)
11889 + (ids_seen
[DW_SECT_TYPES
] != -1))
11892 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11893 " DWO info/types section [in module %s]"),
11896 /* Must have an abbrev section. */
11897 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11899 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11900 " section [in module %s]"),
11903 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11904 htab
->section_pool
.v2
.sizes
=
11905 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11906 * nr_units
* nr_columns
);
11907 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11908 * nr_units
* nr_columns
))
11911 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11912 " [in module %s]"),
11916 else /* version == 5 */
11918 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11919 int *ids
= htab
->section_pool
.v5
.section_ids
;
11920 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11921 /* Reverse map for error checking. */
11922 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11924 if (nr_columns
< 2)
11926 error (_("Dwarf Error: bad DWP hash table, too few columns"
11927 " in section table [in module %s]"),
11930 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11932 error (_("Dwarf Error: bad DWP hash table, too many columns"
11933 " in section table [in module %s]"),
11936 memset (ids
, 255, sizeof_ids
);
11937 memset (ids_seen
, 255, sizeof (ids_seen
));
11938 for (int i
= 0; i
< nr_columns
; ++i
)
11940 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11942 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11944 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11945 " in section table [in module %s]"),
11946 id
, dwp_file
->name
);
11948 if (ids_seen
[id
] != -1)
11950 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11951 " id %d in section table [in module %s]"),
11952 id
, dwp_file
->name
);
11957 /* Must have seen an info section. */
11958 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11960 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11961 " DWO info/types section [in module %s]"),
11964 /* Must have an abbrev section. */
11965 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11967 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11968 " section [in module %s]"),
11971 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11972 htab
->section_pool
.v5
.sizes
11973 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11974 * nr_units
* nr_columns
);
11975 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11976 * nr_units
* nr_columns
))
11979 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11980 " [in module %s]"),
11988 /* Update SECTIONS with the data from SECTP.
11990 This function is like the other "locate" section routines, but in
11991 this context the sections to read comes from the DWP V1 hash table,
11992 not the full ELF section table.
11994 The result is non-zero for success, or zero if an error was found. */
11997 locate_v1_virtual_dwo_sections (asection
*sectp
,
11998 struct virtual_v1_dwo_sections
*sections
)
12000 const struct dwop_section_names
*names
= &dwop_section_names
;
12002 if (names
->abbrev_dwo
.matches (sectp
->name
))
12004 /* There can be only one. */
12005 if (sections
->abbrev
.s
.section
!= NULL
)
12007 sections
->abbrev
.s
.section
= sectp
;
12008 sections
->abbrev
.size
= bfd_section_size (sectp
);
12010 else if (names
->info_dwo
.matches (sectp
->name
)
12011 || names
->types_dwo
.matches (sectp
->name
))
12013 /* There can be only one. */
12014 if (sections
->info_or_types
.s
.section
!= NULL
)
12016 sections
->info_or_types
.s
.section
= sectp
;
12017 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12019 else if (names
->line_dwo
.matches (sectp
->name
))
12021 /* There can be only one. */
12022 if (sections
->line
.s
.section
!= NULL
)
12024 sections
->line
.s
.section
= sectp
;
12025 sections
->line
.size
= bfd_section_size (sectp
);
12027 else if (names
->loc_dwo
.matches (sectp
->name
))
12029 /* There can be only one. */
12030 if (sections
->loc
.s
.section
!= NULL
)
12032 sections
->loc
.s
.section
= sectp
;
12033 sections
->loc
.size
= bfd_section_size (sectp
);
12035 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12037 /* There can be only one. */
12038 if (sections
->macinfo
.s
.section
!= NULL
)
12040 sections
->macinfo
.s
.section
= sectp
;
12041 sections
->macinfo
.size
= bfd_section_size (sectp
);
12043 else if (names
->macro_dwo
.matches (sectp
->name
))
12045 /* There can be only one. */
12046 if (sections
->macro
.s
.section
!= NULL
)
12048 sections
->macro
.s
.section
= sectp
;
12049 sections
->macro
.size
= bfd_section_size (sectp
);
12051 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12053 /* There can be only one. */
12054 if (sections
->str_offsets
.s
.section
!= NULL
)
12056 sections
->str_offsets
.s
.section
= sectp
;
12057 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12061 /* No other kind of section is valid. */
12068 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12069 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12070 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12071 This is for DWP version 1 files. */
12073 static struct dwo_unit
*
12074 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
12075 struct dwp_file
*dwp_file
,
12076 uint32_t unit_index
,
12077 const char *comp_dir
,
12078 ULONGEST signature
, int is_debug_types
)
12080 const struct dwp_hash_table
*dwp_htab
=
12081 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12082 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12083 const char *kind
= is_debug_types
? "TU" : "CU";
12084 struct dwo_file
*dwo_file
;
12085 struct dwo_unit
*dwo_unit
;
12086 struct virtual_v1_dwo_sections sections
;
12087 void **dwo_file_slot
;
12090 gdb_assert (dwp_file
->version
== 1);
12092 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
12093 kind
, pulongest (unit_index
), hex_string (signature
),
12096 /* Fetch the sections of this DWO unit.
12097 Put a limit on the number of sections we look for so that bad data
12098 doesn't cause us to loop forever. */
12100 #define MAX_NR_V1_DWO_SECTIONS \
12101 (1 /* .debug_info or .debug_types */ \
12102 + 1 /* .debug_abbrev */ \
12103 + 1 /* .debug_line */ \
12104 + 1 /* .debug_loc */ \
12105 + 1 /* .debug_str_offsets */ \
12106 + 1 /* .debug_macro or .debug_macinfo */ \
12107 + 1 /* trailing zero */)
12109 memset (§ions
, 0, sizeof (sections
));
12111 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12114 uint32_t section_nr
=
12115 read_4_bytes (dbfd
,
12116 dwp_htab
->section_pool
.v1
.indices
12117 + (unit_index
+ i
) * sizeof (uint32_t));
12119 if (section_nr
== 0)
12121 if (section_nr
>= dwp_file
->num_sections
)
12123 error (_("Dwarf Error: bad DWP hash table, section number too large"
12124 " [in module %s]"),
12128 sectp
= dwp_file
->elf_sections
[section_nr
];
12129 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12131 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12132 " [in module %s]"),
12138 || sections
.info_or_types
.empty ()
12139 || sections
.abbrev
.empty ())
12141 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12142 " [in module %s]"),
12145 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12147 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12148 " [in module %s]"),
12152 /* It's easier for the rest of the code if we fake a struct dwo_file and
12153 have dwo_unit "live" in that. At least for now.
12155 The DWP file can be made up of a random collection of CUs and TUs.
12156 However, for each CU + set of TUs that came from the same original DWO
12157 file, we can combine them back into a virtual DWO file to save space
12158 (fewer struct dwo_file objects to allocate). Remember that for really
12159 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12161 std::string virtual_dwo_name
=
12162 string_printf ("virtual-dwo/%d-%d-%d-%d",
12163 sections
.abbrev
.get_id (),
12164 sections
.line
.get_id (),
12165 sections
.loc
.get_id (),
12166 sections
.str_offsets
.get_id ());
12167 /* Can we use an existing virtual DWO file? */
12168 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12170 /* Create one if necessary. */
12171 if (*dwo_file_slot
== NULL
)
12173 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12174 virtual_dwo_name
.c_str ());
12176 dwo_file
= new struct dwo_file
;
12177 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12178 dwo_file
->comp_dir
= comp_dir
;
12179 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12180 dwo_file
->sections
.line
= sections
.line
;
12181 dwo_file
->sections
.loc
= sections
.loc
;
12182 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12183 dwo_file
->sections
.macro
= sections
.macro
;
12184 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12185 /* The "str" section is global to the entire DWP file. */
12186 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12187 /* The info or types section is assigned below to dwo_unit,
12188 there's no need to record it in dwo_file.
12189 Also, we can't simply record type sections in dwo_file because
12190 we record a pointer into the vector in dwo_unit. As we collect more
12191 types we'll grow the vector and eventually have to reallocate space
12192 for it, invalidating all copies of pointers into the previous
12194 *dwo_file_slot
= dwo_file
;
12198 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12199 virtual_dwo_name
.c_str ());
12201 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12204 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12205 dwo_unit
->dwo_file
= dwo_file
;
12206 dwo_unit
->signature
= signature
;
12207 dwo_unit
->section
=
12208 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12209 *dwo_unit
->section
= sections
.info_or_types
;
12210 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12215 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
12216 simplify them. Given a pointer to the containing section SECTION, and
12217 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
12218 virtual section of just that piece. */
12220 static struct dwarf2_section_info
12221 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
12222 struct dwarf2_section_info
*section
,
12223 bfd_size_type offset
, bfd_size_type size
)
12225 struct dwarf2_section_info result
;
12228 gdb_assert (section
!= NULL
);
12229 gdb_assert (!section
->is_virtual
);
12231 memset (&result
, 0, sizeof (result
));
12232 result
.s
.containing_section
= section
;
12233 result
.is_virtual
= true;
12238 sectp
= section
->get_bfd_section ();
12240 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12241 bounds of the real section. This is a pretty-rare event, so just
12242 flag an error (easier) instead of a warning and trying to cope. */
12244 || offset
+ size
> bfd_section_size (sectp
))
12246 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
12247 " in section %s [in module %s]"),
12248 sectp
? bfd_section_name (sectp
) : "<unknown>",
12249 objfile_name (per_objfile
->objfile
));
12252 result
.virtual_offset
= offset
;
12253 result
.size
= size
;
12257 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12258 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12259 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12260 This is for DWP version 2 files. */
12262 static struct dwo_unit
*
12263 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
12264 struct dwp_file
*dwp_file
,
12265 uint32_t unit_index
,
12266 const char *comp_dir
,
12267 ULONGEST signature
, int is_debug_types
)
12269 const struct dwp_hash_table
*dwp_htab
=
12270 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12271 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12272 const char *kind
= is_debug_types
? "TU" : "CU";
12273 struct dwo_file
*dwo_file
;
12274 struct dwo_unit
*dwo_unit
;
12275 struct virtual_v2_or_v5_dwo_sections sections
;
12276 void **dwo_file_slot
;
12279 gdb_assert (dwp_file
->version
== 2);
12281 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
12282 kind
, pulongest (unit_index
), hex_string (signature
),
12285 /* Fetch the section offsets of this DWO unit. */
12287 memset (§ions
, 0, sizeof (sections
));
12289 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12291 uint32_t offset
= read_4_bytes (dbfd
,
12292 dwp_htab
->section_pool
.v2
.offsets
12293 + (((unit_index
- 1) * dwp_htab
->nr_columns
12295 * sizeof (uint32_t)));
12296 uint32_t size
= read_4_bytes (dbfd
,
12297 dwp_htab
->section_pool
.v2
.sizes
12298 + (((unit_index
- 1) * dwp_htab
->nr_columns
12300 * sizeof (uint32_t)));
12302 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12305 case DW_SECT_TYPES
:
12306 sections
.info_or_types_offset
= offset
;
12307 sections
.info_or_types_size
= size
;
12309 case DW_SECT_ABBREV
:
12310 sections
.abbrev_offset
= offset
;
12311 sections
.abbrev_size
= size
;
12314 sections
.line_offset
= offset
;
12315 sections
.line_size
= size
;
12318 sections
.loc_offset
= offset
;
12319 sections
.loc_size
= size
;
12321 case DW_SECT_STR_OFFSETS
:
12322 sections
.str_offsets_offset
= offset
;
12323 sections
.str_offsets_size
= size
;
12325 case DW_SECT_MACINFO
:
12326 sections
.macinfo_offset
= offset
;
12327 sections
.macinfo_size
= size
;
12329 case DW_SECT_MACRO
:
12330 sections
.macro_offset
= offset
;
12331 sections
.macro_size
= size
;
12336 /* It's easier for the rest of the code if we fake a struct dwo_file and
12337 have dwo_unit "live" in that. At least for now.
12339 The DWP file can be made up of a random collection of CUs and TUs.
12340 However, for each CU + set of TUs that came from the same original DWO
12341 file, we can combine them back into a virtual DWO file to save space
12342 (fewer struct dwo_file objects to allocate). Remember that for really
12343 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12345 std::string virtual_dwo_name
=
12346 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12347 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12348 (long) (sections
.line_size
? sections
.line_offset
: 0),
12349 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12350 (long) (sections
.str_offsets_size
12351 ? sections
.str_offsets_offset
: 0));
12352 /* Can we use an existing virtual DWO file? */
12353 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12355 /* Create one if necessary. */
12356 if (*dwo_file_slot
== NULL
)
12358 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12359 virtual_dwo_name
.c_str ());
12361 dwo_file
= new struct dwo_file
;
12362 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12363 dwo_file
->comp_dir
= comp_dir
;
12364 dwo_file
->sections
.abbrev
=
12365 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12366 sections
.abbrev_offset
,
12367 sections
.abbrev_size
);
12368 dwo_file
->sections
.line
=
12369 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
12370 sections
.line_offset
,
12371 sections
.line_size
);
12372 dwo_file
->sections
.loc
=
12373 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
12374 sections
.loc_offset
, sections
.loc_size
);
12375 dwo_file
->sections
.macinfo
=
12376 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12377 sections
.macinfo_offset
,
12378 sections
.macinfo_size
);
12379 dwo_file
->sections
.macro
=
12380 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
12381 sections
.macro_offset
,
12382 sections
.macro_size
);
12383 dwo_file
->sections
.str_offsets
=
12384 create_dwp_v2_or_v5_section (per_objfile
,
12385 &dwp_file
->sections
.str_offsets
,
12386 sections
.str_offsets_offset
,
12387 sections
.str_offsets_size
);
12388 /* The "str" section is global to the entire DWP file. */
12389 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12390 /* The info or types section is assigned below to dwo_unit,
12391 there's no need to record it in dwo_file.
12392 Also, we can't simply record type sections in dwo_file because
12393 we record a pointer into the vector in dwo_unit. As we collect more
12394 types we'll grow the vector and eventually have to reallocate space
12395 for it, invalidating all copies of pointers into the previous
12397 *dwo_file_slot
= dwo_file
;
12401 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12402 virtual_dwo_name
.c_str ());
12404 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12407 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12408 dwo_unit
->dwo_file
= dwo_file
;
12409 dwo_unit
->signature
= signature
;
12410 dwo_unit
->section
=
12411 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12412 *dwo_unit
->section
= create_dwp_v2_or_v5_section
12415 ? &dwp_file
->sections
.types
12416 : &dwp_file
->sections
.info
,
12417 sections
.info_or_types_offset
,
12418 sections
.info_or_types_size
);
12419 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12424 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12425 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12426 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12427 This is for DWP version 5 files. */
12429 static struct dwo_unit
*
12430 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
12431 struct dwp_file
*dwp_file
,
12432 uint32_t unit_index
,
12433 const char *comp_dir
,
12434 ULONGEST signature
, int is_debug_types
)
12436 const struct dwp_hash_table
*dwp_htab
12437 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12438 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12439 const char *kind
= is_debug_types
? "TU" : "CU";
12440 struct dwo_file
*dwo_file
;
12441 struct dwo_unit
*dwo_unit
;
12442 struct virtual_v2_or_v5_dwo_sections sections
{};
12443 void **dwo_file_slot
;
12445 gdb_assert (dwp_file
->version
== 5);
12447 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
12448 kind
, pulongest (unit_index
), hex_string (signature
),
12451 /* Fetch the section offsets of this DWO unit. */
12453 /* memset (§ions, 0, sizeof (sections)); */
12455 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12457 uint32_t offset
= read_4_bytes (dbfd
,
12458 dwp_htab
->section_pool
.v5
.offsets
12459 + (((unit_index
- 1)
12460 * dwp_htab
->nr_columns
12462 * sizeof (uint32_t)));
12463 uint32_t size
= read_4_bytes (dbfd
,
12464 dwp_htab
->section_pool
.v5
.sizes
12465 + (((unit_index
- 1) * dwp_htab
->nr_columns
12467 * sizeof (uint32_t)));
12469 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
12471 case DW_SECT_ABBREV_V5
:
12472 sections
.abbrev_offset
= offset
;
12473 sections
.abbrev_size
= size
;
12475 case DW_SECT_INFO_V5
:
12476 sections
.info_or_types_offset
= offset
;
12477 sections
.info_or_types_size
= size
;
12479 case DW_SECT_LINE_V5
:
12480 sections
.line_offset
= offset
;
12481 sections
.line_size
= size
;
12483 case DW_SECT_LOCLISTS_V5
:
12484 sections
.loclists_offset
= offset
;
12485 sections
.loclists_size
= size
;
12487 case DW_SECT_MACRO_V5
:
12488 sections
.macro_offset
= offset
;
12489 sections
.macro_size
= size
;
12491 case DW_SECT_RNGLISTS_V5
:
12492 sections
.rnglists_offset
= offset
;
12493 sections
.rnglists_size
= size
;
12495 case DW_SECT_STR_OFFSETS_V5
:
12496 sections
.str_offsets_offset
= offset
;
12497 sections
.str_offsets_size
= size
;
12499 case DW_SECT_RESERVED_V5
:
12505 /* It's easier for the rest of the code if we fake a struct dwo_file and
12506 have dwo_unit "live" in that. At least for now.
12508 The DWP file can be made up of a random collection of CUs and TUs.
12509 However, for each CU + set of TUs that came from the same original DWO
12510 file, we can combine them back into a virtual DWO file to save space
12511 (fewer struct dwo_file objects to allocate). Remember that for really
12512 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12514 std::string virtual_dwo_name
=
12515 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
12516 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12517 (long) (sections
.line_size
? sections
.line_offset
: 0),
12518 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
12519 (long) (sections
.str_offsets_size
12520 ? sections
.str_offsets_offset
: 0),
12521 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
12522 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
12523 /* Can we use an existing virtual DWO file? */
12524 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
12525 virtual_dwo_name
.c_str (),
12527 /* Create one if necessary. */
12528 if (*dwo_file_slot
== NULL
)
12530 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12531 virtual_dwo_name
.c_str ());
12533 dwo_file
= new struct dwo_file
;
12534 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12535 dwo_file
->comp_dir
= comp_dir
;
12536 dwo_file
->sections
.abbrev
=
12537 create_dwp_v2_or_v5_section (per_objfile
,
12538 &dwp_file
->sections
.abbrev
,
12539 sections
.abbrev_offset
,
12540 sections
.abbrev_size
);
12541 dwo_file
->sections
.line
=
12542 create_dwp_v2_or_v5_section (per_objfile
,
12543 &dwp_file
->sections
.line
,
12544 sections
.line_offset
, sections
.line_size
);
12545 dwo_file
->sections
.macro
=
12546 create_dwp_v2_or_v5_section (per_objfile
,
12547 &dwp_file
->sections
.macro
,
12548 sections
.macro_offset
,
12549 sections
.macro_size
);
12550 dwo_file
->sections
.loclists
=
12551 create_dwp_v2_or_v5_section (per_objfile
,
12552 &dwp_file
->sections
.loclists
,
12553 sections
.loclists_offset
,
12554 sections
.loclists_size
);
12555 dwo_file
->sections
.rnglists
=
12556 create_dwp_v2_or_v5_section (per_objfile
,
12557 &dwp_file
->sections
.rnglists
,
12558 sections
.rnglists_offset
,
12559 sections
.rnglists_size
);
12560 dwo_file
->sections
.str_offsets
=
12561 create_dwp_v2_or_v5_section (per_objfile
,
12562 &dwp_file
->sections
.str_offsets
,
12563 sections
.str_offsets_offset
,
12564 sections
.str_offsets_size
);
12565 /* The "str" section is global to the entire DWP file. */
12566 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12567 /* The info or types section is assigned below to dwo_unit,
12568 there's no need to record it in dwo_file.
12569 Also, we can't simply record type sections in dwo_file because
12570 we record a pointer into the vector in dwo_unit. As we collect more
12571 types we'll grow the vector and eventually have to reallocate space
12572 for it, invalidating all copies of pointers into the previous
12574 *dwo_file_slot
= dwo_file
;
12578 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12579 virtual_dwo_name
.c_str ());
12581 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12584 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12585 dwo_unit
->dwo_file
= dwo_file
;
12586 dwo_unit
->signature
= signature
;
12588 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12589 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12590 &dwp_file
->sections
.info
,
12591 sections
.info_or_types_offset
,
12592 sections
.info_or_types_size
);
12593 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12598 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12599 Returns NULL if the signature isn't found. */
12601 static struct dwo_unit
*
12602 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12603 struct dwp_file
*dwp_file
, const char *comp_dir
,
12604 ULONGEST signature
, int is_debug_types
)
12606 const struct dwp_hash_table
*dwp_htab
=
12607 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12608 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12609 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12610 uint32_t hash
= signature
& mask
;
12611 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12614 struct dwo_unit find_dwo_cu
;
12616 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12617 find_dwo_cu
.signature
= signature
;
12618 slot
= htab_find_slot (is_debug_types
12619 ? dwp_file
->loaded_tus
.get ()
12620 : dwp_file
->loaded_cus
.get (),
12621 &find_dwo_cu
, INSERT
);
12624 return (struct dwo_unit
*) *slot
;
12626 /* Use a for loop so that we don't loop forever on bad debug info. */
12627 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12629 ULONGEST signature_in_table
;
12631 signature_in_table
=
12632 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12633 if (signature_in_table
== signature
)
12635 uint32_t unit_index
=
12636 read_4_bytes (dbfd
,
12637 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12639 if (dwp_file
->version
== 1)
12641 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12642 unit_index
, comp_dir
,
12643 signature
, is_debug_types
);
12645 else if (dwp_file
->version
== 2)
12647 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12648 unit_index
, comp_dir
,
12649 signature
, is_debug_types
);
12651 else /* version == 5 */
12653 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12654 unit_index
, comp_dir
,
12655 signature
, is_debug_types
);
12657 return (struct dwo_unit
*) *slot
;
12659 if (signature_in_table
== 0)
12661 hash
= (hash
+ hash2
) & mask
;
12664 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12665 " [in module %s]"),
12669 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12670 Open the file specified by FILE_NAME and hand it off to BFD for
12671 preliminary analysis. Return a newly initialized bfd *, which
12672 includes a canonicalized copy of FILE_NAME.
12673 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12674 SEARCH_CWD is true if the current directory is to be searched.
12675 It will be searched before debug-file-directory.
12676 If successful, the file is added to the bfd include table of the
12677 objfile's bfd (see gdb_bfd_record_inclusion).
12678 If unable to find/open the file, return NULL.
12679 NOTE: This function is derived from symfile_bfd_open. */
12681 static gdb_bfd_ref_ptr
12682 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12683 const char *file_name
, int is_dwp
, int search_cwd
)
12686 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12687 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12688 to debug_file_directory. */
12689 const char *search_path
;
12690 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12692 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12695 if (*debug_file_directory
!= '\0')
12697 search_path_holder
.reset (concat (".", dirname_separator_string
,
12698 debug_file_directory
,
12700 search_path
= search_path_holder
.get ();
12706 search_path
= debug_file_directory
;
12708 openp_flags flags
= OPF_RETURN_REALPATH
;
12710 flags
|= OPF_SEARCH_IN_PATH
;
12712 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12713 desc
= openp (search_path
, flags
, file_name
,
12714 O_RDONLY
| O_BINARY
, &absolute_name
);
12718 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12720 if (sym_bfd
== NULL
)
12722 bfd_set_cacheable (sym_bfd
.get (), 1);
12724 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12727 /* Success. Record the bfd as having been included by the objfile's bfd.
12728 This is important because things like demangled_names_hash lives in the
12729 objfile's per_bfd space and may have references to things like symbol
12730 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12731 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12736 /* Try to open DWO file FILE_NAME.
12737 COMP_DIR is the DW_AT_comp_dir attribute.
12738 The result is the bfd handle of the file.
12739 If there is a problem finding or opening the file, return NULL.
12740 Upon success, the canonicalized path of the file is stored in the bfd,
12741 same as symfile_bfd_open. */
12743 static gdb_bfd_ref_ptr
12744 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12745 const char *file_name
, const char *comp_dir
)
12747 if (IS_ABSOLUTE_PATH (file_name
))
12748 return try_open_dwop_file (per_objfile
, file_name
,
12749 0 /*is_dwp*/, 0 /*search_cwd*/);
12751 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12753 if (comp_dir
!= NULL
)
12755 gdb::unique_xmalloc_ptr
<char> path_to_try
12756 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12758 /* NOTE: If comp_dir is a relative path, this will also try the
12759 search path, which seems useful. */
12760 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12762 1 /*search_cwd*/));
12767 /* That didn't work, try debug-file-directory, which, despite its name,
12768 is a list of paths. */
12770 if (*debug_file_directory
== '\0')
12773 return try_open_dwop_file (per_objfile
, file_name
,
12774 0 /*is_dwp*/, 1 /*search_cwd*/);
12777 /* This function is mapped across the sections and remembers the offset and
12778 size of each of the DWO debugging sections we are interested in. */
12781 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12782 dwo_sections
*dwo_sections
)
12784 const struct dwop_section_names
*names
= &dwop_section_names
;
12786 if (names
->abbrev_dwo
.matches (sectp
->name
))
12788 dwo_sections
->abbrev
.s
.section
= sectp
;
12789 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12791 else if (names
->info_dwo
.matches (sectp
->name
))
12793 dwo_sections
->info
.s
.section
= sectp
;
12794 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12796 else if (names
->line_dwo
.matches (sectp
->name
))
12798 dwo_sections
->line
.s
.section
= sectp
;
12799 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12801 else if (names
->loc_dwo
.matches (sectp
->name
))
12803 dwo_sections
->loc
.s
.section
= sectp
;
12804 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12806 else if (names
->loclists_dwo
.matches (sectp
->name
))
12808 dwo_sections
->loclists
.s
.section
= sectp
;
12809 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12811 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12813 dwo_sections
->macinfo
.s
.section
= sectp
;
12814 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12816 else if (names
->macro_dwo
.matches (sectp
->name
))
12818 dwo_sections
->macro
.s
.section
= sectp
;
12819 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12821 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12823 dwo_sections
->rnglists
.s
.section
= sectp
;
12824 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12826 else if (names
->str_dwo
.matches (sectp
->name
))
12828 dwo_sections
->str
.s
.section
= sectp
;
12829 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12831 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12833 dwo_sections
->str_offsets
.s
.section
= sectp
;
12834 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12836 else if (names
->types_dwo
.matches (sectp
->name
))
12838 struct dwarf2_section_info type_section
;
12840 memset (&type_section
, 0, sizeof (type_section
));
12841 type_section
.s
.section
= sectp
;
12842 type_section
.size
= bfd_section_size (sectp
);
12843 dwo_sections
->types
.push_back (type_section
);
12847 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12848 by PER_CU. This is for the non-DWP case.
12849 The result is NULL if DWO_NAME can't be found. */
12851 static struct dwo_file
*
12852 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12853 const char *comp_dir
)
12855 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12857 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12860 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12865 dwo_file_up
dwo_file (new struct dwo_file
);
12866 dwo_file
->dwo_name
= dwo_name
;
12867 dwo_file
->comp_dir
= comp_dir
;
12868 dwo_file
->dbfd
= std::move (dbfd
);
12870 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12871 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12872 &dwo_file
->sections
);
12874 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12877 if (cu
->per_cu
->dwarf_version
< 5)
12879 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12880 dwo_file
->sections
.types
, dwo_file
->tus
);
12884 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12885 &dwo_file
->sections
.info
, dwo_file
->tus
,
12886 rcuh_kind::COMPILE
);
12889 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12891 return dwo_file
.release ();
12894 /* This function is mapped across the sections and remembers the offset and
12895 size of each of the DWP debugging sections common to version 1 and 2 that
12896 we are interested in. */
12899 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12900 dwp_file
*dwp_file
)
12902 const struct dwop_section_names
*names
= &dwop_section_names
;
12903 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12905 /* Record the ELF section number for later lookup: this is what the
12906 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12907 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12908 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12910 /* Look for specific sections that we need. */
12911 if (names
->str_dwo
.matches (sectp
->name
))
12913 dwp_file
->sections
.str
.s
.section
= sectp
;
12914 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12916 else if (names
->cu_index
.matches (sectp
->name
))
12918 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12919 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12921 else if (names
->tu_index
.matches (sectp
->name
))
12923 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12924 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12928 /* This function is mapped across the sections and remembers the offset and
12929 size of each of the DWP version 2 debugging sections that we are interested
12930 in. This is split into a separate function because we don't know if we
12931 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12934 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12936 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12937 const struct dwop_section_names
*names
= &dwop_section_names
;
12938 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12940 /* Record the ELF section number for later lookup: this is what the
12941 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12942 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12943 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12945 /* Look for specific sections that we need. */
12946 if (names
->abbrev_dwo
.matches (sectp
->name
))
12948 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12949 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12951 else if (names
->info_dwo
.matches (sectp
->name
))
12953 dwp_file
->sections
.info
.s
.section
= sectp
;
12954 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12956 else if (names
->line_dwo
.matches (sectp
->name
))
12958 dwp_file
->sections
.line
.s
.section
= sectp
;
12959 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12961 else if (names
->loc_dwo
.matches (sectp
->name
))
12963 dwp_file
->sections
.loc
.s
.section
= sectp
;
12964 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12966 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12968 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12969 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12971 else if (names
->macro_dwo
.matches (sectp
->name
))
12973 dwp_file
->sections
.macro
.s
.section
= sectp
;
12974 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12976 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12978 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12979 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12981 else if (names
->types_dwo
.matches (sectp
->name
))
12983 dwp_file
->sections
.types
.s
.section
= sectp
;
12984 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12988 /* This function is mapped across the sections and remembers the offset and
12989 size of each of the DWP version 5 debugging sections that we are interested
12990 in. This is split into a separate function because we don't know if we
12991 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12994 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12996 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12997 const struct dwop_section_names
*names
= &dwop_section_names
;
12998 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13000 /* Record the ELF section number for later lookup: this is what the
13001 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13002 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13003 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13005 /* Look for specific sections that we need. */
13006 if (names
->abbrev_dwo
.matches (sectp
->name
))
13008 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13009 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13011 else if (names
->info_dwo
.matches (sectp
->name
))
13013 dwp_file
->sections
.info
.s
.section
= sectp
;
13014 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13016 else if (names
->line_dwo
.matches (sectp
->name
))
13018 dwp_file
->sections
.line
.s
.section
= sectp
;
13019 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13021 else if (names
->loclists_dwo
.matches (sectp
->name
))
13023 dwp_file
->sections
.loclists
.s
.section
= sectp
;
13024 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
13026 else if (names
->macro_dwo
.matches (sectp
->name
))
13028 dwp_file
->sections
.macro
.s
.section
= sectp
;
13029 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13031 else if (names
->rnglists_dwo
.matches (sectp
->name
))
13033 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
13034 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
13036 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
13038 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13039 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13043 /* Hash function for dwp_file loaded CUs/TUs. */
13046 hash_dwp_loaded_cutus (const void *item
)
13048 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13050 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13051 return dwo_unit
->signature
;
13054 /* Equality function for dwp_file loaded CUs/TUs. */
13057 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13059 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13060 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13062 return dua
->signature
== dub
->signature
;
13065 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13068 allocate_dwp_loaded_cutus_table ()
13070 return htab_up (htab_create_alloc (3,
13071 hash_dwp_loaded_cutus
,
13072 eq_dwp_loaded_cutus
,
13073 NULL
, xcalloc
, xfree
));
13076 /* Try to open DWP file FILE_NAME.
13077 The result is the bfd handle of the file.
13078 If there is a problem finding or opening the file, return NULL.
13079 Upon success, the canonicalized path of the file is stored in the bfd,
13080 same as symfile_bfd_open. */
13082 static gdb_bfd_ref_ptr
13083 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
13085 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
13087 1 /*search_cwd*/));
13091 /* Work around upstream bug 15652.
13092 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13093 [Whether that's a "bug" is debatable, but it is getting in our way.]
13094 We have no real idea where the dwp file is, because gdb's realpath-ing
13095 of the executable's path may have discarded the needed info.
13096 [IWBN if the dwp file name was recorded in the executable, akin to
13097 .gnu_debuglink, but that doesn't exist yet.]
13098 Strip the directory from FILE_NAME and search again. */
13099 if (*debug_file_directory
!= '\0')
13101 /* Don't implicitly search the current directory here.
13102 If the user wants to search "." to handle this case,
13103 it must be added to debug-file-directory. */
13104 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
13112 /* Initialize the use of the DWP file for the current objfile.
13113 By convention the name of the DWP file is ${objfile}.dwp.
13114 The result is NULL if it can't be found. */
13116 static std::unique_ptr
<struct dwp_file
>
13117 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
13119 struct objfile
*objfile
= per_objfile
->objfile
;
13121 /* Try to find first .dwp for the binary file before any symbolic links
13124 /* If the objfile is a debug file, find the name of the real binary
13125 file and get the name of dwp file from there. */
13126 std::string dwp_name
;
13127 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13129 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13130 const char *backlink_basename
= lbasename (backlink
->original_name
);
13132 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13135 dwp_name
= objfile
->original_name
;
13137 dwp_name
+= ".dwp";
13139 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
13141 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13143 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13144 dwp_name
= objfile_name (objfile
);
13145 dwp_name
+= ".dwp";
13146 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
13151 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
13153 return std::unique_ptr
<dwp_file
> ();
13156 const char *name
= bfd_get_filename (dbfd
.get ());
13157 std::unique_ptr
<struct dwp_file
> dwp_file
13158 (new struct dwp_file (name
, std::move (dbfd
)));
13160 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13161 dwp_file
->elf_sections
=
13162 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
13163 dwp_file
->num_sections
, asection
*);
13165 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13166 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13169 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
13171 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
13173 /* The DWP file version is stored in the hash table. Oh well. */
13174 if (dwp_file
->cus
&& dwp_file
->tus
13175 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13177 /* Technically speaking, we should try to limp along, but this is
13178 pretty bizarre. We use pulongest here because that's the established
13179 portability solution (e.g, we cannot use %u for uint32_t). */
13180 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13181 " TU version %s [in DWP file %s]"),
13182 pulongest (dwp_file
->cus
->version
),
13183 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13187 dwp_file
->version
= dwp_file
->cus
->version
;
13188 else if (dwp_file
->tus
)
13189 dwp_file
->version
= dwp_file
->tus
->version
;
13191 dwp_file
->version
= 2;
13193 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13195 if (dwp_file
->version
== 2)
13196 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13199 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13203 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
13204 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
13206 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
13207 dwarf_read_debug_printf (" %s CUs, %s TUs",
13208 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13209 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13214 /* Wrapper around open_and_init_dwp_file, only open it once. */
13216 static struct dwp_file
*
13217 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
13219 if (!per_objfile
->per_bfd
->dwp_checked
)
13221 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
13222 per_objfile
->per_bfd
->dwp_checked
= 1;
13224 return per_objfile
->per_bfd
->dwp_file
.get ();
13227 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13228 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13229 or in the DWP file for the objfile, referenced by THIS_UNIT.
13230 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13231 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13233 This is called, for example, when wanting to read a variable with a
13234 complex location. Therefore we don't want to do file i/o for every call.
13235 Therefore we don't want to look for a DWO file on every call.
13236 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13237 then we check if we've already seen DWO_NAME, and only THEN do we check
13240 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13241 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13243 static struct dwo_unit
*
13244 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13245 ULONGEST signature
, int is_debug_types
)
13247 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13248 struct objfile
*objfile
= per_objfile
->objfile
;
13249 const char *kind
= is_debug_types
? "TU" : "CU";
13250 void **dwo_file_slot
;
13251 struct dwo_file
*dwo_file
;
13252 struct dwp_file
*dwp_file
;
13254 /* First see if there's a DWP file.
13255 If we have a DWP file but didn't find the DWO inside it, don't
13256 look for the original DWO file. It makes gdb behave differently
13257 depending on whether one is debugging in the build tree. */
13259 dwp_file
= get_dwp_file (per_objfile
);
13260 if (dwp_file
!= NULL
)
13262 const struct dwp_hash_table
*dwp_htab
=
13263 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13265 if (dwp_htab
!= NULL
)
13267 struct dwo_unit
*dwo_cutu
=
13268 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
13271 if (dwo_cutu
!= NULL
)
13273 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
13274 kind
, hex_string (signature
),
13275 host_address_to_string (dwo_cutu
));
13283 /* No DWP file, look for the DWO file. */
13285 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
13286 if (*dwo_file_slot
== NULL
)
13288 /* Read in the file and build a table of the CUs/TUs it contains. */
13289 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
13291 /* NOTE: This will be NULL if unable to open the file. */
13292 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13294 if (dwo_file
!= NULL
)
13296 struct dwo_unit
*dwo_cutu
= NULL
;
13298 if (is_debug_types
&& dwo_file
->tus
)
13300 struct dwo_unit find_dwo_cutu
;
13302 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13303 find_dwo_cutu
.signature
= signature
;
13305 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
13308 else if (!is_debug_types
&& dwo_file
->cus
)
13310 struct dwo_unit find_dwo_cutu
;
13312 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13313 find_dwo_cutu
.signature
= signature
;
13314 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
13318 if (dwo_cutu
!= NULL
)
13320 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
13321 kind
, dwo_name
, hex_string (signature
),
13322 host_address_to_string (dwo_cutu
));
13329 /* We didn't find it. This could mean a dwo_id mismatch, or
13330 someone deleted the DWO/DWP file, or the search path isn't set up
13331 correctly to find the file. */
13333 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
13334 kind
, dwo_name
, hex_string (signature
));
13336 /* This is a warning and not a complaint because it can be caused by
13337 pilot error (e.g., user accidentally deleting the DWO). */
13339 /* Print the name of the DWP file if we looked there, helps the user
13340 better diagnose the problem. */
13341 std::string dwp_text
;
13343 if (dwp_file
!= NULL
)
13344 dwp_text
= string_printf (" [in DWP file %s]",
13345 lbasename (dwp_file
->name
));
13347 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13348 " [in module %s]"),
13349 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
13350 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
13355 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13356 See lookup_dwo_cutu_unit for details. */
13358 static struct dwo_unit
*
13359 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13360 ULONGEST signature
)
13362 gdb_assert (!cu
->per_cu
->is_debug_types
);
13364 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
13367 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13368 See lookup_dwo_cutu_unit for details. */
13370 static struct dwo_unit
*
13371 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
13373 gdb_assert (cu
->per_cu
->is_debug_types
);
13375 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
13377 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
13380 /* Traversal function for queue_and_load_all_dwo_tus. */
13383 queue_and_load_dwo_tu (void **slot
, void *info
)
13385 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13386 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
13387 ULONGEST signature
= dwo_unit
->signature
;
13388 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
13390 if (sig_type
!= NULL
)
13392 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13394 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13395 a real dependency of PER_CU on SIG_TYPE. That is detected later
13396 while processing PER_CU. */
13397 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
13398 load_full_type_unit (sig_cu
, cu
->per_objfile
);
13399 cu
->per_cu
->imported_symtabs_push (sig_cu
);
13405 /* Queue all TUs contained in the DWO of CU to be read in.
13406 The DWO may have the only definition of the type, though it may not be
13407 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13408 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13411 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
13413 struct dwo_unit
*dwo_unit
;
13414 struct dwo_file
*dwo_file
;
13416 gdb_assert (cu
!= nullptr);
13417 gdb_assert (!cu
->per_cu
->is_debug_types
);
13418 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
13420 dwo_unit
= cu
->dwo_unit
;
13421 gdb_assert (dwo_unit
!= NULL
);
13423 dwo_file
= dwo_unit
->dwo_file
;
13424 if (dwo_file
->tus
!= NULL
)
13425 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
13428 /* Read in various DIEs. */
13430 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13431 Inherit only the children of the DW_AT_abstract_origin DIE not being
13432 already referenced by DW_AT_abstract_origin from the children of the
13436 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13438 struct die_info
*child_die
;
13439 sect_offset
*offsetp
;
13440 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13441 struct die_info
*origin_die
;
13442 /* Iterator of the ORIGIN_DIE children. */
13443 struct die_info
*origin_child_die
;
13444 struct attribute
*attr
;
13445 struct dwarf2_cu
*origin_cu
;
13446 struct pending
**origin_previous_list_in_scope
;
13448 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13452 /* Note that following die references may follow to a die in a
13456 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13458 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13460 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13461 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13463 if (die
->tag
!= origin_die
->tag
13464 && !(die
->tag
== DW_TAG_inlined_subroutine
13465 && origin_die
->tag
== DW_TAG_subprogram
))
13466 complaint (_("DIE %s and its abstract origin %s have different tags"),
13467 sect_offset_str (die
->sect_off
),
13468 sect_offset_str (origin_die
->sect_off
));
13470 std::vector
<sect_offset
> offsets
;
13472 for (child_die
= die
->child
;
13473 child_die
&& child_die
->tag
;
13474 child_die
= child_die
->sibling
)
13476 struct die_info
*child_origin_die
;
13477 struct dwarf2_cu
*child_origin_cu
;
13479 /* We are trying to process concrete instance entries:
13480 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13481 it's not relevant to our analysis here. i.e. detecting DIEs that are
13482 present in the abstract instance but not referenced in the concrete
13484 if (child_die
->tag
== DW_TAG_call_site
13485 || child_die
->tag
== DW_TAG_GNU_call_site
)
13488 /* For each CHILD_DIE, find the corresponding child of
13489 ORIGIN_DIE. If there is more than one layer of
13490 DW_AT_abstract_origin, follow them all; there shouldn't be,
13491 but GCC versions at least through 4.4 generate this (GCC PR
13493 child_origin_die
= child_die
;
13494 child_origin_cu
= cu
;
13497 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13501 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13505 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13506 counterpart may exist. */
13507 if (child_origin_die
!= child_die
)
13509 if (child_die
->tag
!= child_origin_die
->tag
13510 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13511 && child_origin_die
->tag
== DW_TAG_subprogram
))
13512 complaint (_("Child DIE %s and its abstract origin %s have "
13514 sect_offset_str (child_die
->sect_off
),
13515 sect_offset_str (child_origin_die
->sect_off
));
13516 if (child_origin_die
->parent
!= origin_die
)
13517 complaint (_("Child DIE %s and its abstract origin %s have "
13518 "different parents"),
13519 sect_offset_str (child_die
->sect_off
),
13520 sect_offset_str (child_origin_die
->sect_off
));
13522 offsets
.push_back (child_origin_die
->sect_off
);
13525 std::sort (offsets
.begin (), offsets
.end ());
13526 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13527 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13528 if (offsetp
[-1] == *offsetp
)
13529 complaint (_("Multiple children of DIE %s refer "
13530 "to DIE %s as their abstract origin"),
13531 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13533 offsetp
= offsets
.data ();
13534 origin_child_die
= origin_die
->child
;
13535 while (origin_child_die
&& origin_child_die
->tag
)
13537 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13538 while (offsetp
< offsets_end
13539 && *offsetp
< origin_child_die
->sect_off
)
13541 if (offsetp
>= offsets_end
13542 || *offsetp
> origin_child_die
->sect_off
)
13544 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13545 Check whether we're already processing ORIGIN_CHILD_DIE.
13546 This can happen with mutually referenced abstract_origins.
13548 if (!origin_child_die
->in_process
)
13549 process_die (origin_child_die
, origin_cu
);
13551 origin_child_die
= origin_child_die
->sibling
;
13553 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13555 if (cu
!= origin_cu
)
13556 compute_delayed_physnames (origin_cu
);
13560 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13562 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13563 struct gdbarch
*gdbarch
= objfile
->arch ();
13564 struct context_stack
*newobj
;
13567 struct die_info
*child_die
;
13568 struct attribute
*attr
, *call_line
, *call_file
;
13570 CORE_ADDR baseaddr
;
13571 struct block
*block
;
13572 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13573 std::vector
<struct symbol
*> template_args
;
13574 struct template_symbol
*templ_func
= NULL
;
13578 /* If we do not have call site information, we can't show the
13579 caller of this inlined function. That's too confusing, so
13580 only use the scope for local variables. */
13581 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13582 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13583 if (call_line
== NULL
|| call_file
== NULL
)
13585 read_lexical_block_scope (die
, cu
);
13590 baseaddr
= objfile
->text_section_offset ();
13592 name
= dwarf2_name (die
, cu
);
13594 /* Ignore functions with missing or empty names. These are actually
13595 illegal according to the DWARF standard. */
13598 complaint (_("missing name for subprogram DIE at %s"),
13599 sect_offset_str (die
->sect_off
));
13603 /* Ignore functions with missing or invalid low and high pc attributes. */
13604 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13605 <= PC_BOUNDS_INVALID
)
13607 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13608 if (attr
== nullptr || !attr
->as_boolean ())
13609 complaint (_("cannot get low and high bounds "
13610 "for subprogram DIE at %s"),
13611 sect_offset_str (die
->sect_off
));
13615 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13616 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13618 /* If we have any template arguments, then we must allocate a
13619 different sort of symbol. */
13620 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13622 if (child_die
->tag
== DW_TAG_template_type_param
13623 || child_die
->tag
== DW_TAG_template_value_param
)
13625 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13626 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13631 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13632 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13633 (struct symbol
*) templ_func
);
13635 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13636 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13639 /* If there is a location expression for DW_AT_frame_base, record
13641 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13642 if (attr
!= nullptr)
13643 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13645 /* If there is a location for the static link, record it. */
13646 newobj
->static_link
= NULL
;
13647 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13648 if (attr
!= nullptr)
13650 newobj
->static_link
13651 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13652 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13656 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13658 if (die
->child
!= NULL
)
13660 child_die
= die
->child
;
13661 while (child_die
&& child_die
->tag
)
13663 if (child_die
->tag
== DW_TAG_template_type_param
13664 || child_die
->tag
== DW_TAG_template_value_param
)
13666 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13669 template_args
.push_back (arg
);
13672 process_die (child_die
, cu
);
13673 child_die
= child_die
->sibling
;
13677 inherit_abstract_dies (die
, cu
);
13679 /* If we have a DW_AT_specification, we might need to import using
13680 directives from the context of the specification DIE. See the
13681 comment in determine_prefix. */
13682 if (cu
->language
== language_cplus
13683 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13685 struct dwarf2_cu
*spec_cu
= cu
;
13686 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13690 child_die
= spec_die
->child
;
13691 while (child_die
&& child_die
->tag
)
13693 if (child_die
->tag
== DW_TAG_imported_module
)
13694 process_die (child_die
, spec_cu
);
13695 child_die
= child_die
->sibling
;
13698 /* In some cases, GCC generates specification DIEs that
13699 themselves contain DW_AT_specification attributes. */
13700 spec_die
= die_specification (spec_die
, &spec_cu
);
13704 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13705 /* Make a block for the local symbols within. */
13706 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13707 cstk
.static_link
, lowpc
, highpc
);
13709 /* For C++, set the block's scope. */
13710 if ((cu
->language
== language_cplus
13711 || cu
->language
== language_fortran
13712 || cu
->language
== language_d
13713 || cu
->language
== language_rust
)
13714 && cu
->processing_has_namespace_info
)
13715 block_set_scope (block
, determine_prefix (die
, cu
),
13716 &objfile
->objfile_obstack
);
13718 /* If we have address ranges, record them. */
13719 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13721 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13723 /* Attach template arguments to function. */
13724 if (!template_args
.empty ())
13726 gdb_assert (templ_func
!= NULL
);
13728 templ_func
->n_template_arguments
= template_args
.size ();
13729 templ_func
->template_arguments
13730 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13731 templ_func
->n_template_arguments
);
13732 memcpy (templ_func
->template_arguments
,
13733 template_args
.data (),
13734 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13736 /* Make sure that the symtab is set on the new symbols. Even
13737 though they don't appear in this symtab directly, other parts
13738 of gdb assume that symbols do, and this is reasonably
13740 for (symbol
*sym
: template_args
)
13741 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13744 /* In C++, we can have functions nested inside functions (e.g., when
13745 a function declares a class that has methods). This means that
13746 when we finish processing a function scope, we may need to go
13747 back to building a containing block's symbol lists. */
13748 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13749 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13751 /* If we've finished processing a top-level function, subsequent
13752 symbols go in the file symbol list. */
13753 if (cu
->get_builder ()->outermost_context_p ())
13754 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13757 /* Process all the DIES contained within a lexical block scope. Start
13758 a new scope, process the dies, and then close the scope. */
13761 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13763 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13764 struct gdbarch
*gdbarch
= objfile
->arch ();
13765 CORE_ADDR lowpc
, highpc
;
13766 struct die_info
*child_die
;
13767 CORE_ADDR baseaddr
;
13769 baseaddr
= objfile
->text_section_offset ();
13771 /* Ignore blocks with missing or invalid low and high pc attributes. */
13772 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13773 as multiple lexical blocks? Handling children in a sane way would
13774 be nasty. Might be easier to properly extend generic blocks to
13775 describe ranges. */
13776 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13778 case PC_BOUNDS_NOT_PRESENT
:
13779 /* DW_TAG_lexical_block has no attributes, process its children as if
13780 there was no wrapping by that DW_TAG_lexical_block.
13781 GCC does no longer produces such DWARF since GCC r224161. */
13782 for (child_die
= die
->child
;
13783 child_die
!= NULL
&& child_die
->tag
;
13784 child_die
= child_die
->sibling
)
13786 /* We might already be processing this DIE. This can happen
13787 in an unusual circumstance -- where a subroutine A
13788 appears lexically in another subroutine B, but A actually
13789 inlines B. The recursion is broken here, rather than in
13790 inherit_abstract_dies, because it seems better to simply
13791 drop concrete children here. */
13792 if (!child_die
->in_process
)
13793 process_die (child_die
, cu
);
13796 case PC_BOUNDS_INVALID
:
13799 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13800 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13802 cu
->get_builder ()->push_context (0, lowpc
);
13803 if (die
->child
!= NULL
)
13805 child_die
= die
->child
;
13806 while (child_die
&& child_die
->tag
)
13808 process_die (child_die
, cu
);
13809 child_die
= child_die
->sibling
;
13812 inherit_abstract_dies (die
, cu
);
13813 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13815 if (*cu
->get_builder ()->get_local_symbols () != NULL
13816 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13818 struct block
*block
13819 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13820 cstk
.start_addr
, highpc
);
13822 /* Note that recording ranges after traversing children, as we
13823 do here, means that recording a parent's ranges entails
13824 walking across all its children's ranges as they appear in
13825 the address map, which is quadratic behavior.
13827 It would be nicer to record the parent's ranges before
13828 traversing its children, simply overriding whatever you find
13829 there. But since we don't even decide whether to create a
13830 block until after we've traversed its children, that's hard
13832 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13834 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13835 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13838 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13841 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13843 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13844 struct objfile
*objfile
= per_objfile
->objfile
;
13845 struct gdbarch
*gdbarch
= objfile
->arch ();
13846 CORE_ADDR pc
, baseaddr
;
13847 struct attribute
*attr
;
13848 struct call_site
*call_site
, call_site_local
;
13851 struct die_info
*child_die
;
13853 baseaddr
= objfile
->text_section_offset ();
13855 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13858 /* This was a pre-DWARF-5 GNU extension alias
13859 for DW_AT_call_return_pc. */
13860 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13864 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13865 "DIE %s [in module %s]"),
13866 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13869 pc
= attr
->as_address () + baseaddr
;
13870 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13872 if (cu
->call_site_htab
== NULL
)
13873 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13874 NULL
, &objfile
->objfile_obstack
,
13875 hashtab_obstack_allocate
, NULL
);
13876 call_site_local
.pc
= pc
;
13877 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13880 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13881 "DIE %s [in module %s]"),
13882 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13883 objfile_name (objfile
));
13887 /* Count parameters at the caller. */
13890 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13891 child_die
= child_die
->sibling
)
13893 if (child_die
->tag
!= DW_TAG_call_site_parameter
13894 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13896 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13897 "DW_TAG_call_site child DIE %s [in module %s]"),
13898 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13899 objfile_name (objfile
));
13907 = ((struct call_site
*)
13908 obstack_alloc (&objfile
->objfile_obstack
,
13909 sizeof (*call_site
)
13910 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13912 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13913 call_site
->pc
= pc
;
13915 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13916 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13918 struct die_info
*func_die
;
13920 /* Skip also over DW_TAG_inlined_subroutine. */
13921 for (func_die
= die
->parent
;
13922 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13923 && func_die
->tag
!= DW_TAG_subroutine_type
;
13924 func_die
= func_die
->parent
);
13926 /* DW_AT_call_all_calls is a superset
13927 of DW_AT_call_all_tail_calls. */
13929 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13930 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13931 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13932 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13934 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13935 not complete. But keep CALL_SITE for look ups via call_site_htab,
13936 both the initial caller containing the real return address PC and
13937 the final callee containing the current PC of a chain of tail
13938 calls do not need to have the tail call list complete. But any
13939 function candidate for a virtual tail call frame searched via
13940 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13941 determined unambiguously. */
13945 struct type
*func_type
= NULL
;
13948 func_type
= get_die_type (func_die
, cu
);
13949 if (func_type
!= NULL
)
13951 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13953 /* Enlist this call site to the function. */
13954 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13955 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13958 complaint (_("Cannot find function owning DW_TAG_call_site "
13959 "DIE %s [in module %s]"),
13960 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13964 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13966 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13968 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13971 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13972 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13974 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13975 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13976 /* Keep NULL DWARF_BLOCK. */;
13977 else if (attr
->form_is_block ())
13979 struct dwarf2_locexpr_baton
*dlbaton
;
13980 struct dwarf_block
*block
= attr
->as_block ();
13982 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13983 dlbaton
->data
= block
->data
;
13984 dlbaton
->size
= block
->size
;
13985 dlbaton
->per_objfile
= per_objfile
;
13986 dlbaton
->per_cu
= cu
->per_cu
;
13988 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13990 else if (attr
->form_is_ref ())
13992 struct dwarf2_cu
*target_cu
= cu
;
13993 struct die_info
*target_die
;
13995 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13996 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13997 if (die_is_declaration (target_die
, target_cu
))
13999 const char *target_physname
;
14001 /* Prefer the mangled name; otherwise compute the demangled one. */
14002 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14003 if (target_physname
== NULL
)
14004 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14005 if (target_physname
== NULL
)
14006 complaint (_("DW_AT_call_target target DIE has invalid "
14007 "physname, for referencing DIE %s [in module %s]"),
14008 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14010 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14016 /* DW_AT_entry_pc should be preferred. */
14017 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14018 <= PC_BOUNDS_INVALID
)
14019 complaint (_("DW_AT_call_target target DIE has invalid "
14020 "low pc, for referencing DIE %s [in module %s]"),
14021 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14024 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14025 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14030 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14031 "block nor reference, for DIE %s [in module %s]"),
14032 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14034 call_site
->per_cu
= cu
->per_cu
;
14035 call_site
->per_objfile
= per_objfile
;
14037 for (child_die
= die
->child
;
14038 child_die
&& child_die
->tag
;
14039 child_die
= child_die
->sibling
)
14041 struct call_site_parameter
*parameter
;
14042 struct attribute
*loc
, *origin
;
14044 if (child_die
->tag
!= DW_TAG_call_site_parameter
14045 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14047 /* Already printed the complaint above. */
14051 gdb_assert (call_site
->parameter_count
< nparams
);
14052 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14054 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14055 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14056 register is contained in DW_AT_call_value. */
14058 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14059 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14060 if (origin
== NULL
)
14062 /* This was a pre-DWARF-5 GNU extension alias
14063 for DW_AT_call_parameter. */
14064 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14066 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
14068 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14070 sect_offset sect_off
= origin
->get_ref_die_offset ();
14071 if (!cu
->header
.offset_in_cu_p (sect_off
))
14073 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14074 binding can be done only inside one CU. Such referenced DIE
14075 therefore cannot be even moved to DW_TAG_partial_unit. */
14076 complaint (_("DW_AT_call_parameter offset is not in CU for "
14077 "DW_TAG_call_site child DIE %s [in module %s]"),
14078 sect_offset_str (child_die
->sect_off
),
14079 objfile_name (objfile
));
14082 parameter
->u
.param_cu_off
14083 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14085 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
14087 complaint (_("No DW_FORM_block* DW_AT_location for "
14088 "DW_TAG_call_site child DIE %s [in module %s]"),
14089 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14094 struct dwarf_block
*block
= loc
->as_block ();
14096 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14097 (block
->data
, &block
->data
[block
->size
]);
14098 if (parameter
->u
.dwarf_reg
!= -1)
14099 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14100 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
14101 &block
->data
[block
->size
],
14102 ¶meter
->u
.fb_offset
))
14103 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14106 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14107 "for DW_FORM_block* DW_AT_location is supported for "
14108 "DW_TAG_call_site child DIE %s "
14110 sect_offset_str (child_die
->sect_off
),
14111 objfile_name (objfile
));
14116 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14118 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14119 if (attr
== NULL
|| !attr
->form_is_block ())
14121 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14122 "DW_TAG_call_site child DIE %s [in module %s]"),
14123 sect_offset_str (child_die
->sect_off
),
14124 objfile_name (objfile
));
14128 struct dwarf_block
*block
= attr
->as_block ();
14129 parameter
->value
= block
->data
;
14130 parameter
->value_size
= block
->size
;
14132 /* Parameters are not pre-cleared by memset above. */
14133 parameter
->data_value
= NULL
;
14134 parameter
->data_value_size
= 0;
14135 call_site
->parameter_count
++;
14137 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14139 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14140 if (attr
!= nullptr)
14142 if (!attr
->form_is_block ())
14143 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14144 "DW_TAG_call_site child DIE %s [in module %s]"),
14145 sect_offset_str (child_die
->sect_off
),
14146 objfile_name (objfile
));
14149 block
= attr
->as_block ();
14150 parameter
->data_value
= block
->data
;
14151 parameter
->data_value_size
= block
->size
;
14157 /* Helper function for read_variable. If DIE represents a virtual
14158 table, then return the type of the concrete object that is
14159 associated with the virtual table. Otherwise, return NULL. */
14161 static struct type
*
14162 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14164 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14168 /* Find the type DIE. */
14169 struct die_info
*type_die
= NULL
;
14170 struct dwarf2_cu
*type_cu
= cu
;
14172 if (attr
->form_is_ref ())
14173 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14174 if (type_die
== NULL
)
14177 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14179 return die_containing_type (type_die
, type_cu
);
14182 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14185 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14187 struct rust_vtable_symbol
*storage
= NULL
;
14189 if (cu
->language
== language_rust
)
14191 struct type
*containing_type
= rust_containing_type (die
, cu
);
14193 if (containing_type
!= NULL
)
14195 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14197 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
14198 storage
->concrete_type
= containing_type
;
14199 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14203 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14204 struct attribute
*abstract_origin
14205 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14206 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14207 if (res
== NULL
&& loc
&& abstract_origin
)
14209 /* We have a variable without a name, but with a location and an abstract
14210 origin. This may be a concrete instance of an abstract variable
14211 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14213 struct dwarf2_cu
*origin_cu
= cu
;
14214 struct die_info
*origin_die
14215 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14216 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14217 per_objfile
->per_bfd
->abstract_to_concrete
14218 [origin_die
->sect_off
].push_back (die
->sect_off
);
14222 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14223 reading .debug_rnglists.
14224 Callback's type should be:
14225 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14226 Return true if the attributes are present and valid, otherwise,
14229 template <typename Callback
>
14231 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14232 dwarf_tag tag
, Callback
&&callback
)
14234 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14235 struct objfile
*objfile
= per_objfile
->objfile
;
14236 bfd
*obfd
= objfile
->obfd
;
14237 /* Base address selection entry. */
14238 gdb::optional
<CORE_ADDR
> base
;
14239 const gdb_byte
*buffer
;
14240 CORE_ADDR baseaddr
;
14241 bool overflow
= false;
14242 ULONGEST addr_index
;
14243 struct dwarf2_section_info
*rnglists_section
;
14245 base
= cu
->base_address
;
14246 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
14247 rnglists_section
->read (objfile
);
14249 if (offset
>= rnglists_section
->size
)
14251 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14255 buffer
= rnglists_section
->buffer
+ offset
;
14257 baseaddr
= objfile
->text_section_offset ();
14261 /* Initialize it due to a false compiler warning. */
14262 CORE_ADDR range_beginning
= 0, range_end
= 0;
14263 const gdb_byte
*buf_end
= (rnglists_section
->buffer
14264 + rnglists_section
->size
);
14265 unsigned int bytes_read
;
14267 if (buffer
== buf_end
)
14272 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14275 case DW_RLE_end_of_list
:
14277 case DW_RLE_base_address
:
14278 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14283 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14284 buffer
+= bytes_read
;
14286 case DW_RLE_base_addressx
:
14287 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14288 buffer
+= bytes_read
;
14289 base
= read_addr_index (cu
, addr_index
);
14291 case DW_RLE_start_length
:
14292 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14297 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14299 buffer
+= bytes_read
;
14300 range_end
= (range_beginning
14301 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14302 buffer
+= bytes_read
;
14303 if (buffer
> buf_end
)
14309 case DW_RLE_startx_length
:
14310 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14311 buffer
+= bytes_read
;
14312 range_beginning
= read_addr_index (cu
, addr_index
);
14313 if (buffer
> buf_end
)
14318 range_end
= (range_beginning
14319 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14320 buffer
+= bytes_read
;
14322 case DW_RLE_offset_pair
:
14323 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14324 buffer
+= bytes_read
;
14325 if (buffer
> buf_end
)
14330 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14331 buffer
+= bytes_read
;
14332 if (buffer
> buf_end
)
14338 case DW_RLE_start_end
:
14339 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14344 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14346 buffer
+= bytes_read
;
14347 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14348 buffer
+= bytes_read
;
14350 case DW_RLE_startx_endx
:
14351 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14352 buffer
+= bytes_read
;
14353 range_beginning
= read_addr_index (cu
, addr_index
);
14354 if (buffer
> buf_end
)
14359 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14360 buffer
+= bytes_read
;
14361 range_end
= read_addr_index (cu
, addr_index
);
14364 complaint (_("Invalid .debug_rnglists data (no base address)"));
14367 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14369 if (rlet
== DW_RLE_base_address
)
14372 if (range_beginning
> range_end
)
14374 /* Inverted range entries are invalid. */
14375 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14379 /* Empty range entries have no effect. */
14380 if (range_beginning
== range_end
)
14383 /* Only DW_RLE_offset_pair needs the base address added. */
14384 if (rlet
== DW_RLE_offset_pair
)
14386 if (!base
.has_value ())
14388 /* We have no valid base address for the DW_RLE_offset_pair. */
14389 complaint (_("Invalid .debug_rnglists data (no base address for "
14390 "DW_RLE_offset_pair)"));
14394 range_beginning
+= *base
;
14395 range_end
+= *base
;
14398 /* A not-uncommon case of bad debug info.
14399 Don't pollute the addrmap with bad data. */
14400 if (range_beginning
+ baseaddr
== 0
14401 && !per_objfile
->per_bfd
->has_section_at_zero
)
14403 complaint (_(".debug_rnglists entry has start address of zero"
14404 " [in module %s]"), objfile_name (objfile
));
14408 callback (range_beginning
, range_end
);
14413 complaint (_("Offset %d is not terminated "
14414 "for DW_AT_ranges attribute"),
14422 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14423 Callback's type should be:
14424 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14425 Return 1 if the attributes are present and valid, otherwise, return 0. */
14427 template <typename Callback
>
14429 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
14430 Callback
&&callback
)
14432 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14433 struct objfile
*objfile
= per_objfile
->objfile
;
14434 struct comp_unit_head
*cu_header
= &cu
->header
;
14435 bfd
*obfd
= objfile
->obfd
;
14436 unsigned int addr_size
= cu_header
->addr_size
;
14437 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14438 /* Base address selection entry. */
14439 gdb::optional
<CORE_ADDR
> base
;
14440 unsigned int dummy
;
14441 const gdb_byte
*buffer
;
14442 CORE_ADDR baseaddr
;
14444 if (cu_header
->version
>= 5)
14445 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
14447 base
= cu
->base_address
;
14449 per_objfile
->per_bfd
->ranges
.read (objfile
);
14450 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
14452 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14456 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
14458 baseaddr
= objfile
->text_section_offset ();
14462 CORE_ADDR range_beginning
, range_end
;
14464 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14465 buffer
+= addr_size
;
14466 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14467 buffer
+= addr_size
;
14468 offset
+= 2 * addr_size
;
14470 /* An end of list marker is a pair of zero addresses. */
14471 if (range_beginning
== 0 && range_end
== 0)
14472 /* Found the end of list entry. */
14475 /* Each base address selection entry is a pair of 2 values.
14476 The first is the largest possible address, the second is
14477 the base address. Check for a base address here. */
14478 if ((range_beginning
& mask
) == mask
)
14480 /* If we found the largest possible address, then we already
14481 have the base address in range_end. */
14486 if (!base
.has_value ())
14488 /* We have no valid base address for the ranges
14490 complaint (_("Invalid .debug_ranges data (no base address)"));
14494 if (range_beginning
> range_end
)
14496 /* Inverted range entries are invalid. */
14497 complaint (_("Invalid .debug_ranges data (inverted range)"));
14501 /* Empty range entries have no effect. */
14502 if (range_beginning
== range_end
)
14505 range_beginning
+= *base
;
14506 range_end
+= *base
;
14508 /* A not-uncommon case of bad debug info.
14509 Don't pollute the addrmap with bad data. */
14510 if (range_beginning
+ baseaddr
== 0
14511 && !per_objfile
->per_bfd
->has_section_at_zero
)
14513 complaint (_(".debug_ranges entry has start address of zero"
14514 " [in module %s]"), objfile_name (objfile
));
14518 callback (range_beginning
, range_end
);
14524 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14525 Return 1 if the attributes are present and valid, otherwise, return 0.
14526 If RANGES_PST is not NULL we should set up the `psymtabs_addrmap'. */
14529 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14530 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14531 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
14533 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14534 dwarf2_per_bfd
*per_bfd
= cu
->per_objfile
->per_bfd
;
14535 struct gdbarch
*gdbarch
= objfile
->arch ();
14536 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14539 CORE_ADDR high
= 0;
14542 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14543 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14545 if (ranges_pst
!= NULL
)
14550 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14551 range_beginning
+ baseaddr
)
14553 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14554 range_end
+ baseaddr
)
14556 addrmap_set_empty (per_bfd
->partial_symtabs
->psymtabs_addrmap
,
14557 lowpc
, highpc
- 1, ranges_pst
);
14560 /* FIXME: This is recording everything as a low-high
14561 segment of consecutive addresses. We should have a
14562 data structure for discontiguous block ranges
14566 low
= range_beginning
;
14572 if (range_beginning
< low
)
14573 low
= range_beginning
;
14574 if (range_end
> high
)
14582 /* If the first entry is an end-of-list marker, the range
14583 describes an empty scope, i.e. no instructions. */
14589 *high_return
= high
;
14593 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14594 definition for the return value. *LOWPC and *HIGHPC are set iff
14595 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14597 static enum pc_bounds_kind
14598 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14599 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14600 dwarf2_psymtab
*pst
)
14602 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14603 struct attribute
*attr
;
14604 struct attribute
*attr_high
;
14606 CORE_ADDR high
= 0;
14607 enum pc_bounds_kind ret
;
14609 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14612 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14613 if (attr
!= nullptr)
14615 low
= attr
->as_address ();
14616 high
= attr_high
->as_address ();
14617 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14621 /* Found high w/o low attribute. */
14622 return PC_BOUNDS_INVALID
;
14624 /* Found consecutive range of addresses. */
14625 ret
= PC_BOUNDS_HIGH_LOW
;
14629 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14630 if (attr
!= nullptr && attr
->form_is_unsigned ())
14632 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14633 on DWARF version). */
14634 ULONGEST ranges_offset
= attr
->as_unsigned ();
14636 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14638 if (die
->tag
!= DW_TAG_compile_unit
)
14639 ranges_offset
+= cu
->gnu_ranges_base
;
14641 /* Value of the DW_AT_ranges attribute is the offset in the
14642 .debug_ranges section. */
14643 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14645 return PC_BOUNDS_INVALID
;
14646 /* Found discontinuous range of addresses. */
14647 ret
= PC_BOUNDS_RANGES
;
14650 return PC_BOUNDS_NOT_PRESENT
;
14653 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14655 return PC_BOUNDS_INVALID
;
14657 /* When using the GNU linker, .gnu.linkonce. sections are used to
14658 eliminate duplicate copies of functions and vtables and such.
14659 The linker will arbitrarily choose one and discard the others.
14660 The AT_*_pc values for such functions refer to local labels in
14661 these sections. If the section from that file was discarded, the
14662 labels are not in the output, so the relocs get a value of 0.
14663 If this is a discarded function, mark the pc bounds as invalid,
14664 so that GDB will ignore it. */
14665 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14666 return PC_BOUNDS_INVALID
;
14674 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14675 its low and high PC addresses. Do nothing if these addresses could not
14676 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14677 and HIGHPC to the high address if greater than HIGHPC. */
14680 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14681 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14682 struct dwarf2_cu
*cu
)
14684 CORE_ADDR low
, high
;
14685 struct die_info
*child
= die
->child
;
14687 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14689 *lowpc
= std::min (*lowpc
, low
);
14690 *highpc
= std::max (*highpc
, high
);
14693 /* If the language does not allow nested subprograms (either inside
14694 subprograms or lexical blocks), we're done. */
14695 if (cu
->language
!= language_ada
)
14698 /* Check all the children of the given DIE. If it contains nested
14699 subprograms, then check their pc bounds. Likewise, we need to
14700 check lexical blocks as well, as they may also contain subprogram
14702 while (child
&& child
->tag
)
14704 if (child
->tag
== DW_TAG_subprogram
14705 || child
->tag
== DW_TAG_lexical_block
)
14706 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14707 child
= child
->sibling
;
14711 /* Get the low and high pc's represented by the scope DIE, and store
14712 them in *LOWPC and *HIGHPC. If the correct values can't be
14713 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14716 get_scope_pc_bounds (struct die_info
*die
,
14717 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14718 struct dwarf2_cu
*cu
)
14720 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14721 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14722 CORE_ADDR current_low
, current_high
;
14724 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14725 >= PC_BOUNDS_RANGES
)
14727 best_low
= current_low
;
14728 best_high
= current_high
;
14732 struct die_info
*child
= die
->child
;
14734 while (child
&& child
->tag
)
14736 switch (child
->tag
) {
14737 case DW_TAG_subprogram
:
14738 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14740 case DW_TAG_namespace
:
14741 case DW_TAG_module
:
14742 /* FIXME: carlton/2004-01-16: Should we do this for
14743 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14744 that current GCC's always emit the DIEs corresponding
14745 to definitions of methods of classes as children of a
14746 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14747 the DIEs giving the declarations, which could be
14748 anywhere). But I don't see any reason why the
14749 standards says that they have to be there. */
14750 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14752 if (current_low
!= ((CORE_ADDR
) -1))
14754 best_low
= std::min (best_low
, current_low
);
14755 best_high
= std::max (best_high
, current_high
);
14763 child
= child
->sibling
;
14768 *highpc
= best_high
;
14771 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14775 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14776 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14778 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14779 struct gdbarch
*gdbarch
= objfile
->arch ();
14780 struct attribute
*attr
;
14781 struct attribute
*attr_high
;
14783 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14786 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14787 if (attr
!= nullptr)
14789 CORE_ADDR low
= attr
->as_address ();
14790 CORE_ADDR high
= attr_high
->as_address ();
14792 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14795 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14796 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14797 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14801 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14802 if (attr
!= nullptr && attr
->form_is_unsigned ())
14804 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14805 on DWARF version). */
14806 ULONGEST ranges_offset
= attr
->as_unsigned ();
14808 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14810 if (die
->tag
!= DW_TAG_compile_unit
)
14811 ranges_offset
+= cu
->gnu_ranges_base
;
14813 std::vector
<blockrange
> blockvec
;
14814 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14815 [&] (CORE_ADDR start
, CORE_ADDR end
)
14819 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14820 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14821 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14822 blockvec
.emplace_back (start
, end
);
14825 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14829 /* Check whether the producer field indicates either of GCC < 4.6, or the
14830 Intel C/C++ compiler, and cache the result in CU. */
14833 check_producer (struct dwarf2_cu
*cu
)
14837 if (cu
->producer
== NULL
)
14839 /* For unknown compilers expect their behavior is DWARF version
14842 GCC started to support .debug_types sections by -gdwarf-4 since
14843 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14844 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14845 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14846 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14848 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14850 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14851 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14853 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14855 cu
->producer_is_icc
= true;
14856 cu
->producer_is_icc_lt_14
= major
< 14;
14858 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14859 cu
->producer_is_codewarrior
= true;
14862 /* For other non-GCC compilers, expect their behavior is DWARF version
14866 cu
->checked_producer
= true;
14869 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14870 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14871 during 4.6.0 experimental. */
14874 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14876 if (!cu
->checked_producer
)
14877 check_producer (cu
);
14879 return cu
->producer_is_gxx_lt_4_6
;
14883 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14884 with incorrect is_stmt attributes. */
14887 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14889 if (!cu
->checked_producer
)
14890 check_producer (cu
);
14892 return cu
->producer_is_codewarrior
;
14895 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14896 If that attribute is not available, return the appropriate
14899 static enum dwarf_access_attribute
14900 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14902 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14903 if (attr
!= nullptr)
14905 LONGEST value
= attr
->constant_value (-1);
14906 if (value
== DW_ACCESS_public
14907 || value
== DW_ACCESS_protected
14908 || value
== DW_ACCESS_private
)
14909 return (dwarf_access_attribute
) value
;
14910 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14914 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14916 /* The default DWARF 2 accessibility for members is public, the default
14917 accessibility for inheritance is private. */
14919 if (die
->tag
!= DW_TAG_inheritance
)
14920 return DW_ACCESS_public
;
14922 return DW_ACCESS_private
;
14926 /* DWARF 3+ defines the default accessibility a different way. The same
14927 rules apply now for DW_TAG_inheritance as for the members and it only
14928 depends on the container kind. */
14930 if (die
->parent
->tag
== DW_TAG_class_type
)
14931 return DW_ACCESS_private
;
14933 return DW_ACCESS_public
;
14937 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14938 offset. If the attribute was not found return 0, otherwise return
14939 1. If it was found but could not properly be handled, set *OFFSET
14943 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14946 struct attribute
*attr
;
14948 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14953 /* Note that we do not check for a section offset first here.
14954 This is because DW_AT_data_member_location is new in DWARF 4,
14955 so if we see it, we can assume that a constant form is really
14956 a constant and not a section offset. */
14957 if (attr
->form_is_constant ())
14958 *offset
= attr
->constant_value (0);
14959 else if (attr
->form_is_section_offset ())
14960 dwarf2_complex_location_expr_complaint ();
14961 else if (attr
->form_is_block ())
14962 *offset
= decode_locdesc (attr
->as_block (), cu
);
14964 dwarf2_complex_location_expr_complaint ();
14972 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14975 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14976 struct field
*field
)
14978 struct attribute
*attr
;
14980 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14983 if (attr
->form_is_constant ())
14985 LONGEST offset
= attr
->constant_value (0);
14986 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14988 else if (attr
->form_is_section_offset ())
14989 dwarf2_complex_location_expr_complaint ();
14990 else if (attr
->form_is_block ())
14993 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14995 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14998 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14999 struct objfile
*objfile
= per_objfile
->objfile
;
15000 struct dwarf2_locexpr_baton
*dlbaton
15001 = XOBNEW (&objfile
->objfile_obstack
,
15002 struct dwarf2_locexpr_baton
);
15003 dlbaton
->data
= attr
->as_block ()->data
;
15004 dlbaton
->size
= attr
->as_block ()->size
;
15005 /* When using this baton, we want to compute the address
15006 of the field, not the value. This is why
15007 is_reference is set to false here. */
15008 dlbaton
->is_reference
= false;
15009 dlbaton
->per_objfile
= per_objfile
;
15010 dlbaton
->per_cu
= cu
->per_cu
;
15012 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
15016 dwarf2_complex_location_expr_complaint ();
15020 /* Add an aggregate field to the field list. */
15023 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15024 struct dwarf2_cu
*cu
)
15026 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15027 struct gdbarch
*gdbarch
= objfile
->arch ();
15028 struct nextfield
*new_field
;
15029 struct attribute
*attr
;
15031 const char *fieldname
= "";
15033 if (die
->tag
== DW_TAG_inheritance
)
15035 fip
->baseclasses
.emplace_back ();
15036 new_field
= &fip
->baseclasses
.back ();
15040 fip
->fields
.emplace_back ();
15041 new_field
= &fip
->fields
.back ();
15044 new_field
->offset
= die
->sect_off
;
15046 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
15047 if (new_field
->accessibility
!= DW_ACCESS_public
)
15048 fip
->non_public_fields
= true;
15050 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15051 if (attr
!= nullptr)
15052 new_field
->virtuality
= attr
->as_virtuality ();
15054 new_field
->virtuality
= DW_VIRTUALITY_none
;
15056 fp
= &new_field
->field
;
15058 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15060 /* Data member other than a C++ static data member. */
15062 /* Get type of field. */
15063 fp
->set_type (die_type (die
, cu
));
15065 SET_FIELD_BITPOS (*fp
, 0);
15067 /* Get bit size of field (zero if none). */
15068 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15069 if (attr
!= nullptr)
15071 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
15075 FIELD_BITSIZE (*fp
) = 0;
15078 /* Get bit offset of field. */
15079 handle_data_member_location (die
, cu
, fp
);
15080 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15081 if (attr
!= nullptr && attr
->form_is_constant ())
15083 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15085 /* For big endian bits, the DW_AT_bit_offset gives the
15086 additional bit offset from the MSB of the containing
15087 anonymous object to the MSB of the field. We don't
15088 have to do anything special since we don't need to
15089 know the size of the anonymous object. */
15090 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15091 + attr
->constant_value (0)));
15095 /* For little endian bits, compute the bit offset to the
15096 MSB of the anonymous object, subtract off the number of
15097 bits from the MSB of the field to the MSB of the
15098 object, and then subtract off the number of bits of
15099 the field itself. The result is the bit offset of
15100 the LSB of the field. */
15101 int anonymous_size
;
15102 int bit_offset
= attr
->constant_value (0);
15104 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15105 if (attr
!= nullptr && attr
->form_is_constant ())
15107 /* The size of the anonymous object containing
15108 the bit field is explicit, so use the
15109 indicated size (in bytes). */
15110 anonymous_size
= attr
->constant_value (0);
15114 /* The size of the anonymous object containing
15115 the bit field must be inferred from the type
15116 attribute of the data member containing the
15118 anonymous_size
= TYPE_LENGTH (fp
->type ());
15120 SET_FIELD_BITPOS (*fp
,
15121 (FIELD_BITPOS (*fp
)
15122 + anonymous_size
* bits_per_byte
15123 - bit_offset
- FIELD_BITSIZE (*fp
)));
15126 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15128 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15129 + attr
->constant_value (0)));
15131 /* Get name of field. */
15132 fieldname
= dwarf2_name (die
, cu
);
15133 if (fieldname
== NULL
)
15136 /* The name is already allocated along with this objfile, so we don't
15137 need to duplicate it for the type. */
15138 fp
->name
= fieldname
;
15140 /* Change accessibility for artificial fields (e.g. virtual table
15141 pointer or virtual base class pointer) to private. */
15142 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15144 FIELD_ARTIFICIAL (*fp
) = 1;
15145 new_field
->accessibility
= DW_ACCESS_private
;
15146 fip
->non_public_fields
= true;
15149 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15151 /* C++ static member. */
15153 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15154 is a declaration, but all versions of G++ as of this writing
15155 (so through at least 3.2.1) incorrectly generate
15156 DW_TAG_variable tags. */
15158 const char *physname
;
15160 /* Get name of field. */
15161 fieldname
= dwarf2_name (die
, cu
);
15162 if (fieldname
== NULL
)
15165 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15167 /* Only create a symbol if this is an external value.
15168 new_symbol checks this and puts the value in the global symbol
15169 table, which we want. If it is not external, new_symbol
15170 will try to put the value in cu->list_in_scope which is wrong. */
15171 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15173 /* A static const member, not much different than an enum as far as
15174 we're concerned, except that we can support more types. */
15175 new_symbol (die
, NULL
, cu
);
15178 /* Get physical name. */
15179 physname
= dwarf2_physname (fieldname
, die
, cu
);
15181 /* The name is already allocated along with this objfile, so we don't
15182 need to duplicate it for the type. */
15183 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15184 fp
->set_type (die_type (die
, cu
));
15185 FIELD_NAME (*fp
) = fieldname
;
15187 else if (die
->tag
== DW_TAG_inheritance
)
15189 /* C++ base class field. */
15190 handle_data_member_location (die
, cu
, fp
);
15191 FIELD_BITSIZE (*fp
) = 0;
15192 fp
->set_type (die_type (die
, cu
));
15193 FIELD_NAME (*fp
) = fp
->type ()->name ();
15196 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15199 /* Can the type given by DIE define another type? */
15202 type_can_define_types (const struct die_info
*die
)
15206 case DW_TAG_typedef
:
15207 case DW_TAG_class_type
:
15208 case DW_TAG_structure_type
:
15209 case DW_TAG_union_type
:
15210 case DW_TAG_enumeration_type
:
15218 /* Add a type definition defined in the scope of the FIP's class. */
15221 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15222 struct dwarf2_cu
*cu
)
15224 struct decl_field fp
;
15225 memset (&fp
, 0, sizeof (fp
));
15227 gdb_assert (type_can_define_types (die
));
15229 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15230 fp
.name
= dwarf2_name (die
, cu
);
15231 fp
.type
= read_type_die (die
, cu
);
15233 /* Save accessibility. */
15234 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15235 switch (accessibility
)
15237 case DW_ACCESS_public
:
15238 /* The assumed value if neither private nor protected. */
15240 case DW_ACCESS_private
:
15243 case DW_ACCESS_protected
:
15244 fp
.is_protected
= 1;
15248 if (die
->tag
== DW_TAG_typedef
)
15249 fip
->typedef_field_list
.push_back (fp
);
15251 fip
->nested_types_list
.push_back (fp
);
15254 /* A convenience typedef that's used when finding the discriminant
15255 field for a variant part. */
15256 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
15259 /* Compute the discriminant range for a given variant. OBSTACK is
15260 where the results will be stored. VARIANT is the variant to
15261 process. IS_UNSIGNED indicates whether the discriminant is signed
15264 static const gdb::array_view
<discriminant_range
>
15265 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
15268 std::vector
<discriminant_range
> ranges
;
15270 if (variant
.default_branch
)
15273 if (variant
.discr_list_data
== nullptr)
15275 discriminant_range r
15276 = {variant
.discriminant_value
, variant
.discriminant_value
};
15277 ranges
.push_back (r
);
15281 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
15282 variant
.discr_list_data
->size
);
15283 while (!data
.empty ())
15285 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
15287 complaint (_("invalid discriminant marker: %d"), data
[0]);
15290 bool is_range
= data
[0] == DW_DSC_range
;
15291 data
= data
.slice (1);
15293 ULONGEST low
, high
;
15294 unsigned int bytes_read
;
15298 complaint (_("DW_AT_discr_list missing low value"));
15302 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
15304 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
15306 data
= data
.slice (bytes_read
);
15312 complaint (_("DW_AT_discr_list missing high value"));
15316 high
= read_unsigned_leb128 (nullptr, data
.data (),
15319 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
15321 data
= data
.slice (bytes_read
);
15326 ranges
.push_back ({ low
, high
});
15330 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
15332 std::copy (ranges
.begin (), ranges
.end (), result
);
15333 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
15336 static const gdb::array_view
<variant_part
> create_variant_parts
15337 (struct obstack
*obstack
,
15338 const offset_map_type
&offset_map
,
15339 struct field_info
*fi
,
15340 const std::vector
<variant_part_builder
> &variant_parts
);
15342 /* Fill in a "struct variant" for a given variant field. RESULT is
15343 the variant to fill in. OBSTACK is where any needed allocations
15344 will be done. OFFSET_MAP holds the mapping from section offsets to
15345 fields for the type. FI describes the fields of the type we're
15346 processing. FIELD is the variant field we're converting. */
15349 create_one_variant (variant
&result
, struct obstack
*obstack
,
15350 const offset_map_type
&offset_map
,
15351 struct field_info
*fi
, const variant_field
&field
)
15353 result
.discriminants
= convert_variant_range (obstack
, field
, false);
15354 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
15355 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
15356 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
15357 field
.variant_parts
);
15360 /* Fill in a "struct variant_part" for a given variant part. RESULT
15361 is the variant part to fill in. OBSTACK is where any needed
15362 allocations will be done. OFFSET_MAP holds the mapping from
15363 section offsets to fields for the type. FI describes the fields of
15364 the type we're processing. BUILDER is the variant part to be
15368 create_one_variant_part (variant_part
&result
,
15369 struct obstack
*obstack
,
15370 const offset_map_type
&offset_map
,
15371 struct field_info
*fi
,
15372 const variant_part_builder
&builder
)
15374 auto iter
= offset_map
.find (builder
.discriminant_offset
);
15375 if (iter
== offset_map
.end ())
15377 result
.discriminant_index
= -1;
15378 /* Doesn't matter. */
15379 result
.is_unsigned
= false;
15383 result
.discriminant_index
= iter
->second
;
15385 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
15388 size_t n
= builder
.variants
.size ();
15389 variant
*output
= new (obstack
) variant
[n
];
15390 for (size_t i
= 0; i
< n
; ++i
)
15391 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
15392 builder
.variants
[i
]);
15394 result
.variants
= gdb::array_view
<variant
> (output
, n
);
15397 /* Create a vector of variant parts that can be attached to a type.
15398 OBSTACK is where any needed allocations will be done. OFFSET_MAP
15399 holds the mapping from section offsets to fields for the type. FI
15400 describes the fields of the type we're processing. VARIANT_PARTS
15401 is the vector to convert. */
15403 static const gdb::array_view
<variant_part
>
15404 create_variant_parts (struct obstack
*obstack
,
15405 const offset_map_type
&offset_map
,
15406 struct field_info
*fi
,
15407 const std::vector
<variant_part_builder
> &variant_parts
)
15409 if (variant_parts
.empty ())
15412 size_t n
= variant_parts
.size ();
15413 variant_part
*result
= new (obstack
) variant_part
[n
];
15414 for (size_t i
= 0; i
< n
; ++i
)
15415 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
15418 return gdb::array_view
<variant_part
> (result
, n
);
15421 /* Compute the variant part vector for FIP, attaching it to TYPE when
15425 add_variant_property (struct field_info
*fip
, struct type
*type
,
15426 struct dwarf2_cu
*cu
)
15428 /* Map section offsets of fields to their field index. Note the
15429 field index here does not take the number of baseclasses into
15431 offset_map_type offset_map
;
15432 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
15433 offset_map
[fip
->fields
[i
].offset
] = i
;
15435 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15436 gdb::array_view
<variant_part
> parts
15437 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
15438 fip
->variant_parts
);
15440 struct dynamic_prop prop
;
15441 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
15442 obstack_copy (&objfile
->objfile_obstack
, &parts
,
15445 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
15448 /* Create the vector of fields, and attach it to the type. */
15451 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15452 struct dwarf2_cu
*cu
)
15454 int nfields
= fip
->nfields ();
15456 /* Record the field count, allocate space for the array of fields,
15457 and create blank accessibility bitfields if necessary. */
15458 type
->set_num_fields (nfields
);
15460 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
15462 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15464 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15466 TYPE_FIELD_PRIVATE_BITS (type
) =
15467 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15468 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15470 TYPE_FIELD_PROTECTED_BITS (type
) =
15471 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15472 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15474 TYPE_FIELD_IGNORE_BITS (type
) =
15475 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15476 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15479 /* If the type has baseclasses, allocate and clear a bit vector for
15480 TYPE_FIELD_VIRTUAL_BITS. */
15481 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15483 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15484 unsigned char *pointer
;
15486 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15487 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15488 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15489 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15490 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15493 if (!fip
->variant_parts
.empty ())
15494 add_variant_property (fip
, type
, cu
);
15496 /* Copy the saved-up fields into the field vector. */
15497 for (int i
= 0; i
< nfields
; ++i
)
15499 struct nextfield
&field
15500 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15501 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15503 type
->field (i
) = field
.field
;
15504 switch (field
.accessibility
)
15506 case DW_ACCESS_private
:
15507 if (cu
->language
!= language_ada
)
15508 SET_TYPE_FIELD_PRIVATE (type
, i
);
15511 case DW_ACCESS_protected
:
15512 if (cu
->language
!= language_ada
)
15513 SET_TYPE_FIELD_PROTECTED (type
, i
);
15516 case DW_ACCESS_public
:
15520 /* Unknown accessibility. Complain and treat it as public. */
15522 complaint (_("unsupported accessibility %d"),
15523 field
.accessibility
);
15527 if (i
< fip
->baseclasses
.size ())
15529 switch (field
.virtuality
)
15531 case DW_VIRTUALITY_virtual
:
15532 case DW_VIRTUALITY_pure_virtual
:
15533 if (cu
->language
== language_ada
)
15534 error (_("unexpected virtuality in component of Ada type"));
15535 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15542 /* Return true if this member function is a constructor, false
15546 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15548 const char *fieldname
;
15549 const char *type_name
;
15552 if (die
->parent
== NULL
)
15555 if (die
->parent
->tag
!= DW_TAG_structure_type
15556 && die
->parent
->tag
!= DW_TAG_union_type
15557 && die
->parent
->tag
!= DW_TAG_class_type
)
15560 fieldname
= dwarf2_name (die
, cu
);
15561 type_name
= dwarf2_name (die
->parent
, cu
);
15562 if (fieldname
== NULL
|| type_name
== NULL
)
15565 len
= strlen (fieldname
);
15566 return (strncmp (fieldname
, type_name
, len
) == 0
15567 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15570 /* Add a member function to the proper fieldlist. */
15573 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15574 struct type
*type
, struct dwarf2_cu
*cu
)
15576 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15577 struct attribute
*attr
;
15579 struct fnfieldlist
*flp
= nullptr;
15580 struct fn_field
*fnp
;
15581 const char *fieldname
;
15582 struct type
*this_type
;
15584 if (cu
->language
== language_ada
)
15585 error (_("unexpected member function in Ada type"));
15587 /* Get name of member function. */
15588 fieldname
= dwarf2_name (die
, cu
);
15589 if (fieldname
== NULL
)
15592 /* Look up member function name in fieldlist. */
15593 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15595 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15597 flp
= &fip
->fnfieldlists
[i
];
15602 /* Create a new fnfieldlist if necessary. */
15603 if (flp
== nullptr)
15605 fip
->fnfieldlists
.emplace_back ();
15606 flp
= &fip
->fnfieldlists
.back ();
15607 flp
->name
= fieldname
;
15608 i
= fip
->fnfieldlists
.size () - 1;
15611 /* Create a new member function field and add it to the vector of
15613 flp
->fnfields
.emplace_back ();
15614 fnp
= &flp
->fnfields
.back ();
15616 /* Delay processing of the physname until later. */
15617 if (cu
->language
== language_cplus
)
15618 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15622 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15623 fnp
->physname
= physname
? physname
: "";
15626 fnp
->type
= alloc_type (objfile
);
15627 this_type
= read_type_die (die
, cu
);
15628 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15630 int nparams
= this_type
->num_fields ();
15632 /* TYPE is the domain of this method, and THIS_TYPE is the type
15633 of the method itself (TYPE_CODE_METHOD). */
15634 smash_to_method_type (fnp
->type
, type
,
15635 TYPE_TARGET_TYPE (this_type
),
15636 this_type
->fields (),
15637 this_type
->num_fields (),
15638 this_type
->has_varargs ());
15640 /* Handle static member functions.
15641 Dwarf2 has no clean way to discern C++ static and non-static
15642 member functions. G++ helps GDB by marking the first
15643 parameter for non-static member functions (which is the this
15644 pointer) as artificial. We obtain this information from
15645 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15646 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15647 fnp
->voffset
= VOFFSET_STATIC
;
15650 complaint (_("member function type missing for '%s'"),
15651 dwarf2_full_name (fieldname
, die
, cu
));
15653 /* Get fcontext from DW_AT_containing_type if present. */
15654 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15655 fnp
->fcontext
= die_containing_type (die
, cu
);
15657 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15658 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15660 /* Get accessibility. */
15661 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15662 switch (accessibility
)
15664 case DW_ACCESS_private
:
15665 fnp
->is_private
= 1;
15667 case DW_ACCESS_protected
:
15668 fnp
->is_protected
= 1;
15672 /* Check for artificial methods. */
15673 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15674 if (attr
&& attr
->as_boolean ())
15675 fnp
->is_artificial
= 1;
15677 /* Check for defaulted methods. */
15678 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15679 if (attr
!= nullptr)
15680 fnp
->defaulted
= attr
->defaulted ();
15682 /* Check for deleted methods. */
15683 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15684 if (attr
!= nullptr && attr
->as_boolean ())
15685 fnp
->is_deleted
= 1;
15687 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15689 /* Get index in virtual function table if it is a virtual member
15690 function. For older versions of GCC, this is an offset in the
15691 appropriate virtual table, as specified by DW_AT_containing_type.
15692 For everyone else, it is an expression to be evaluated relative
15693 to the object address. */
15695 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15696 if (attr
!= nullptr)
15698 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15700 struct dwarf_block
*block
= attr
->as_block ();
15702 if (block
->data
[0] == DW_OP_constu
)
15704 /* Old-style GCC. */
15705 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15707 else if (block
->data
[0] == DW_OP_deref
15708 || (block
->size
> 1
15709 && block
->data
[0] == DW_OP_deref_size
15710 && block
->data
[1] == cu
->header
.addr_size
))
15712 fnp
->voffset
= decode_locdesc (block
, cu
);
15713 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15714 dwarf2_complex_location_expr_complaint ();
15716 fnp
->voffset
/= cu
->header
.addr_size
;
15720 dwarf2_complex_location_expr_complaint ();
15722 if (!fnp
->fcontext
)
15724 /* If there is no `this' field and no DW_AT_containing_type,
15725 we cannot actually find a base class context for the
15727 if (this_type
->num_fields () == 0
15728 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15730 complaint (_("cannot determine context for virtual member "
15731 "function \"%s\" (offset %s)"),
15732 fieldname
, sect_offset_str (die
->sect_off
));
15737 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15741 else if (attr
->form_is_section_offset ())
15743 dwarf2_complex_location_expr_complaint ();
15747 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15753 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15754 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15756 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15757 complaint (_("Member function \"%s\" (offset %s) is virtual "
15758 "but the vtable offset is not specified"),
15759 fieldname
, sect_offset_str (die
->sect_off
));
15760 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15761 TYPE_CPLUS_DYNAMIC (type
) = 1;
15766 /* Create the vector of member function fields, and attach it to the type. */
15769 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15770 struct dwarf2_cu
*cu
)
15772 if (cu
->language
== language_ada
)
15773 error (_("unexpected member functions in Ada type"));
15775 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15776 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15778 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15780 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15782 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15783 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15785 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15786 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15787 fn_flp
->fn_fields
= (struct fn_field
*)
15788 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15790 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15791 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15794 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15797 /* Returns non-zero if NAME is the name of a vtable member in CU's
15798 language, zero otherwise. */
15800 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15802 static const char vptr
[] = "_vptr";
15804 /* Look for the C++ form of the vtable. */
15805 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15811 /* GCC outputs unnamed structures that are really pointers to member
15812 functions, with the ABI-specified layout. If TYPE describes
15813 such a structure, smash it into a member function type.
15815 GCC shouldn't do this; it should just output pointer to member DIEs.
15816 This is GCC PR debug/28767. */
15819 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15821 struct type
*pfn_type
, *self_type
, *new_type
;
15823 /* Check for a structure with no name and two children. */
15824 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15827 /* Check for __pfn and __delta members. */
15828 if (TYPE_FIELD_NAME (type
, 0) == NULL
15829 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15830 || TYPE_FIELD_NAME (type
, 1) == NULL
15831 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15834 /* Find the type of the method. */
15835 pfn_type
= type
->field (0).type ();
15836 if (pfn_type
== NULL
15837 || pfn_type
->code () != TYPE_CODE_PTR
15838 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15841 /* Look for the "this" argument. */
15842 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15843 if (pfn_type
->num_fields () == 0
15844 /* || pfn_type->field (0).type () == NULL */
15845 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15848 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15849 new_type
= alloc_type (objfile
);
15850 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15851 pfn_type
->fields (), pfn_type
->num_fields (),
15852 pfn_type
->has_varargs ());
15853 smash_to_methodptr_type (type
, new_type
);
15856 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15857 requires rewriting, then copy it and return the updated copy.
15858 Otherwise return nullptr. */
15860 static struct type
*
15861 rewrite_array_type (struct type
*type
)
15863 if (type
->code () != TYPE_CODE_ARRAY
)
15866 struct type
*index_type
= type
->index_type ();
15867 range_bounds
*current_bounds
= index_type
->bounds ();
15869 /* Handle multi-dimensional arrays. */
15870 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15871 if (new_target
== nullptr)
15873 /* Maybe we don't need to rewrite this array. */
15874 if (current_bounds
->low
.kind () == PROP_CONST
15875 && current_bounds
->high
.kind () == PROP_CONST
)
15879 /* Either the target type was rewritten, or the bounds have to be
15880 updated. Either way we want to copy the type and update
15882 struct type
*copy
= copy_type (type
);
15883 int nfields
= copy
->num_fields ();
15885 = ((struct field
*) TYPE_ZALLOC (copy
,
15886 nfields
* sizeof (struct field
)));
15887 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15888 copy
->set_fields (new_fields
);
15889 if (new_target
!= nullptr)
15890 TYPE_TARGET_TYPE (copy
) = new_target
;
15892 struct type
*index_copy
= copy_type (index_type
);
15893 range_bounds
*bounds
15894 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15895 sizeof (range_bounds
));
15896 *bounds
= *current_bounds
;
15897 bounds
->low
.set_const_val (1);
15898 bounds
->high
.set_const_val (0);
15899 index_copy
->set_bounds (bounds
);
15900 copy
->set_index_type (index_copy
);
15905 /* While some versions of GCC will generate complicated DWARF for an
15906 array (see quirk_ada_thick_pointer), more recent versions were
15907 modified to emit an explicit thick pointer structure. However, in
15908 this case, the array still has DWARF expressions for its ranges,
15909 and these must be ignored. */
15912 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15915 gdb_assert (cu
->language
== language_ada
);
15917 /* Check for a structure with two children. */
15918 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15921 /* Check for P_ARRAY and P_BOUNDS members. */
15922 if (TYPE_FIELD_NAME (type
, 0) == NULL
15923 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
15924 || TYPE_FIELD_NAME (type
, 1) == NULL
15925 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
15928 /* Make sure we're looking at a pointer to an array. */
15929 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15932 /* The Ada code already knows how to handle these types, so all that
15933 we need to do is turn the bounds into static bounds. However, we
15934 don't want to rewrite existing array or index types in-place,
15935 because those may be referenced in other contexts where this
15936 rewriting is undesirable. */
15937 struct type
*new_ary_type
15938 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15939 if (new_ary_type
!= nullptr)
15940 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15943 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15944 appropriate error checking and issuing complaints if there is a
15948 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15950 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15952 if (attr
== nullptr)
15955 if (!attr
->form_is_constant ())
15957 complaint (_("DW_AT_alignment must have constant form"
15958 " - DIE at %s [in module %s]"),
15959 sect_offset_str (die
->sect_off
),
15960 objfile_name (cu
->per_objfile
->objfile
));
15964 LONGEST val
= attr
->constant_value (0);
15967 complaint (_("DW_AT_alignment value must not be negative"
15968 " - DIE at %s [in module %s]"),
15969 sect_offset_str (die
->sect_off
),
15970 objfile_name (cu
->per_objfile
->objfile
));
15973 ULONGEST align
= val
;
15977 complaint (_("DW_AT_alignment value must not be zero"
15978 " - DIE at %s [in module %s]"),
15979 sect_offset_str (die
->sect_off
),
15980 objfile_name (cu
->per_objfile
->objfile
));
15983 if ((align
& (align
- 1)) != 0)
15985 complaint (_("DW_AT_alignment value must be a power of 2"
15986 " - DIE at %s [in module %s]"),
15987 sect_offset_str (die
->sect_off
),
15988 objfile_name (cu
->per_objfile
->objfile
));
15995 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15996 the alignment for TYPE. */
15999 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
16002 if (!set_type_align (type
, get_alignment (cu
, die
)))
16003 complaint (_("DW_AT_alignment value too large"
16004 " - DIE at %s [in module %s]"),
16005 sect_offset_str (die
->sect_off
),
16006 objfile_name (cu
->per_objfile
->objfile
));
16009 /* Check if the given VALUE is a valid enum dwarf_calling_convention
16010 constant for a type, according to DWARF5 spec, Table 5.5. */
16013 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
16018 case DW_CC_pass_by_reference
:
16019 case DW_CC_pass_by_value
:
16023 complaint (_("unrecognized DW_AT_calling_convention value "
16024 "(%s) for a type"), pulongest (value
));
16029 /* Check if the given VALUE is a valid enum dwarf_calling_convention
16030 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
16031 also according to GNU-specific values (see include/dwarf2.h). */
16034 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
16039 case DW_CC_program
:
16043 case DW_CC_GNU_renesas_sh
:
16044 case DW_CC_GNU_borland_fastcall_i386
:
16045 case DW_CC_GDB_IBM_OpenCL
:
16049 complaint (_("unrecognized DW_AT_calling_convention value "
16050 "(%s) for a subroutine"), pulongest (value
));
16055 /* Called when we find the DIE that starts a structure or union scope
16056 (definition) to create a type for the structure or union. Fill in
16057 the type's name and general properties; the members will not be
16058 processed until process_structure_scope. A symbol table entry for
16059 the type will also not be done until process_structure_scope (assuming
16060 the type has a name).
16062 NOTE: we need to call these functions regardless of whether or not the
16063 DIE has a DW_AT_name attribute, since it might be an anonymous
16064 structure or union. This gets the type entered into our set of
16065 user defined types. */
16067 static struct type
*
16068 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16070 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16072 struct attribute
*attr
;
16075 /* If the definition of this type lives in .debug_types, read that type.
16076 Don't follow DW_AT_specification though, that will take us back up
16077 the chain and we want to go down. */
16078 attr
= die
->attr (DW_AT_signature
);
16079 if (attr
!= nullptr)
16081 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16083 /* The type's CU may not be the same as CU.
16084 Ensure TYPE is recorded with CU in die_type_hash. */
16085 return set_die_type (die
, type
, cu
);
16088 type
= alloc_type (objfile
);
16089 INIT_CPLUS_SPECIFIC (type
);
16091 name
= dwarf2_name (die
, cu
);
16094 if (cu
->language
== language_cplus
16095 || cu
->language
== language_d
16096 || cu
->language
== language_rust
)
16098 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
16100 /* dwarf2_full_name might have already finished building the DIE's
16101 type. If so, there is no need to continue. */
16102 if (get_die_type (die
, cu
) != NULL
)
16103 return get_die_type (die
, cu
);
16105 type
->set_name (full_name
);
16109 /* The name is already allocated along with this objfile, so
16110 we don't need to duplicate it for the type. */
16111 type
->set_name (name
);
16115 if (die
->tag
== DW_TAG_structure_type
)
16117 type
->set_code (TYPE_CODE_STRUCT
);
16119 else if (die
->tag
== DW_TAG_union_type
)
16121 type
->set_code (TYPE_CODE_UNION
);
16125 type
->set_code (TYPE_CODE_STRUCT
);
16128 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
16129 TYPE_DECLARED_CLASS (type
) = 1;
16131 /* Store the calling convention in the type if it's available in
16132 the die. Otherwise the calling convention remains set to
16133 the default value DW_CC_normal. */
16134 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16135 if (attr
!= nullptr
16136 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
16138 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16139 TYPE_CPLUS_CALLING_CONVENTION (type
)
16140 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
16143 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16144 if (attr
!= nullptr)
16146 if (attr
->form_is_constant ())
16147 TYPE_LENGTH (type
) = attr
->constant_value (0);
16150 struct dynamic_prop prop
;
16151 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
16152 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
16153 TYPE_LENGTH (type
) = 0;
16158 TYPE_LENGTH (type
) = 0;
16161 maybe_set_alignment (cu
, die
, type
);
16163 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16165 /* ICC<14 does not output the required DW_AT_declaration on
16166 incomplete types, but gives them a size of zero. */
16167 type
->set_is_stub (true);
16170 type
->set_stub_is_supported (true);
16172 if (die_is_declaration (die
, cu
))
16173 type
->set_is_stub (true);
16174 else if (attr
== NULL
&& die
->child
== NULL
16175 && producer_is_realview (cu
->producer
))
16176 /* RealView does not output the required DW_AT_declaration
16177 on incomplete types. */
16178 type
->set_is_stub (true);
16180 /* We need to add the type field to the die immediately so we don't
16181 infinitely recurse when dealing with pointers to the structure
16182 type within the structure itself. */
16183 set_die_type (die
, type
, cu
);
16185 /* set_die_type should be already done. */
16186 set_descriptive_type (type
, die
, cu
);
16191 static void handle_struct_member_die
16192 (struct die_info
*child_die
,
16194 struct field_info
*fi
,
16195 std::vector
<struct symbol
*> *template_args
,
16196 struct dwarf2_cu
*cu
);
16198 /* A helper for handle_struct_member_die that handles
16199 DW_TAG_variant_part. */
16202 handle_variant_part (struct die_info
*die
, struct type
*type
,
16203 struct field_info
*fi
,
16204 std::vector
<struct symbol
*> *template_args
,
16205 struct dwarf2_cu
*cu
)
16207 variant_part_builder
*new_part
;
16208 if (fi
->current_variant_part
== nullptr)
16210 fi
->variant_parts
.emplace_back ();
16211 new_part
= &fi
->variant_parts
.back ();
16213 else if (!fi
->current_variant_part
->processing_variant
)
16215 complaint (_("nested DW_TAG_variant_part seen "
16216 "- DIE at %s [in module %s]"),
16217 sect_offset_str (die
->sect_off
),
16218 objfile_name (cu
->per_objfile
->objfile
));
16223 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
16224 current
.variant_parts
.emplace_back ();
16225 new_part
= ¤t
.variant_parts
.back ();
16228 /* When we recurse, we want callees to add to this new variant
16230 scoped_restore save_current_variant_part
16231 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
16233 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16236 /* It's a univariant form, an extension we support. */
16238 else if (discr
->form_is_ref ())
16240 struct dwarf2_cu
*target_cu
= cu
;
16241 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16243 new_part
->discriminant_offset
= target_die
->sect_off
;
16247 complaint (_("DW_AT_discr does not have DIE reference form"
16248 " - DIE at %s [in module %s]"),
16249 sect_offset_str (die
->sect_off
),
16250 objfile_name (cu
->per_objfile
->objfile
));
16253 for (die_info
*child_die
= die
->child
;
16255 child_die
= child_die
->sibling
)
16256 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
16259 /* A helper for handle_struct_member_die that handles
16263 handle_variant (struct die_info
*die
, struct type
*type
,
16264 struct field_info
*fi
,
16265 std::vector
<struct symbol
*> *template_args
,
16266 struct dwarf2_cu
*cu
)
16268 if (fi
->current_variant_part
== nullptr)
16270 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
16271 "- DIE at %s [in module %s]"),
16272 sect_offset_str (die
->sect_off
),
16273 objfile_name (cu
->per_objfile
->objfile
));
16276 if (fi
->current_variant_part
->processing_variant
)
16278 complaint (_("nested DW_TAG_variant seen "
16279 "- DIE at %s [in module %s]"),
16280 sect_offset_str (die
->sect_off
),
16281 objfile_name (cu
->per_objfile
->objfile
));
16285 scoped_restore save_processing_variant
16286 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
16289 fi
->current_variant_part
->variants
.emplace_back ();
16290 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
16291 variant
.first_field
= fi
->fields
.size ();
16293 /* In a variant we want to get the discriminant and also add a
16294 field for our sole member child. */
16295 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
16296 if (discr
== nullptr || !discr
->form_is_constant ())
16298 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
16299 if (discr
== nullptr || discr
->as_block ()->size
== 0)
16300 variant
.default_branch
= true;
16302 variant
.discr_list_data
= discr
->as_block ();
16305 variant
.discriminant_value
= discr
->constant_value (0);
16307 for (die_info
*variant_child
= die
->child
;
16308 variant_child
!= NULL
;
16309 variant_child
= variant_child
->sibling
)
16310 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
16312 variant
.last_field
= fi
->fields
.size ();
16315 /* A helper for process_structure_scope that handles a single member
16319 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16320 struct field_info
*fi
,
16321 std::vector
<struct symbol
*> *template_args
,
16322 struct dwarf2_cu
*cu
)
16324 if (child_die
->tag
== DW_TAG_member
16325 || child_die
->tag
== DW_TAG_variable
)
16327 /* NOTE: carlton/2002-11-05: A C++ static data member
16328 should be a DW_TAG_member that is a declaration, but
16329 all versions of G++ as of this writing (so through at
16330 least 3.2.1) incorrectly generate DW_TAG_variable
16331 tags for them instead. */
16332 dwarf2_add_field (fi
, child_die
, cu
);
16334 else if (child_die
->tag
== DW_TAG_subprogram
)
16336 /* Rust doesn't have member functions in the C++ sense.
16337 However, it does emit ordinary functions as children
16338 of a struct DIE. */
16339 if (cu
->language
== language_rust
)
16340 read_func_scope (child_die
, cu
);
16343 /* C++ member function. */
16344 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16347 else if (child_die
->tag
== DW_TAG_inheritance
)
16349 /* C++ base class field. */
16350 dwarf2_add_field (fi
, child_die
, cu
);
16352 else if (type_can_define_types (child_die
))
16353 dwarf2_add_type_defn (fi
, child_die
, cu
);
16354 else if (child_die
->tag
== DW_TAG_template_type_param
16355 || child_die
->tag
== DW_TAG_template_value_param
)
16357 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16360 template_args
->push_back (arg
);
16362 else if (child_die
->tag
== DW_TAG_variant_part
)
16363 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
16364 else if (child_die
->tag
== DW_TAG_variant
)
16365 handle_variant (child_die
, type
, fi
, template_args
, cu
);
16368 /* Finish creating a structure or union type, including filling in
16369 its members and creating a symbol for it. */
16372 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16374 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16375 struct die_info
*child_die
;
16378 type
= get_die_type (die
, cu
);
16380 type
= read_structure_type (die
, cu
);
16382 bool has_template_parameters
= false;
16383 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16385 struct field_info fi
;
16386 std::vector
<struct symbol
*> template_args
;
16388 child_die
= die
->child
;
16390 while (child_die
&& child_die
->tag
)
16392 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16393 child_die
= child_die
->sibling
;
16396 /* Attach template arguments to type. */
16397 if (!template_args
.empty ())
16399 has_template_parameters
= true;
16400 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16401 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16402 TYPE_TEMPLATE_ARGUMENTS (type
)
16403 = XOBNEWVEC (&objfile
->objfile_obstack
,
16405 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16406 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16407 template_args
.data (),
16408 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16409 * sizeof (struct symbol
*)));
16412 /* Attach fields and member functions to the type. */
16413 if (fi
.nfields () > 0)
16414 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16415 if (!fi
.fnfieldlists
.empty ())
16417 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16419 /* Get the type which refers to the base class (possibly this
16420 class itself) which contains the vtable pointer for the current
16421 class from the DW_AT_containing_type attribute. This use of
16422 DW_AT_containing_type is a GNU extension. */
16424 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16426 struct type
*t
= die_containing_type (die
, cu
);
16428 set_type_vptr_basetype (type
, t
);
16433 /* Our own class provides vtbl ptr. */
16434 for (i
= t
->num_fields () - 1;
16435 i
>= TYPE_N_BASECLASSES (t
);
16438 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16440 if (is_vtable_name (fieldname
, cu
))
16442 set_type_vptr_fieldno (type
, i
);
16447 /* Complain if virtual function table field not found. */
16448 if (i
< TYPE_N_BASECLASSES (t
))
16449 complaint (_("virtual function table pointer "
16450 "not found when defining class '%s'"),
16451 type
->name () ? type
->name () : "");
16455 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16458 else if (cu
->producer
16459 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16461 /* The IBM XLC compiler does not provide direct indication
16462 of the containing type, but the vtable pointer is
16463 always named __vfp. */
16467 for (i
= type
->num_fields () - 1;
16468 i
>= TYPE_N_BASECLASSES (type
);
16471 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16473 set_type_vptr_fieldno (type
, i
);
16474 set_type_vptr_basetype (type
, type
);
16481 /* Copy fi.typedef_field_list linked list elements content into the
16482 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16483 if (!fi
.typedef_field_list
.empty ())
16485 int count
= fi
.typedef_field_list
.size ();
16487 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16488 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16489 = ((struct decl_field
*)
16491 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16492 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16494 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16495 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16498 /* Copy fi.nested_types_list linked list elements content into the
16499 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16500 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16502 int count
= fi
.nested_types_list
.size ();
16504 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16505 TYPE_NESTED_TYPES_ARRAY (type
)
16506 = ((struct decl_field
*)
16507 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16508 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16510 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16511 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16515 quirk_gcc_member_function_pointer (type
, objfile
);
16516 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16517 cu
->rust_unions
.push_back (type
);
16518 else if (cu
->language
== language_ada
)
16519 quirk_ada_thick_pointer_struct (die
, cu
, type
);
16521 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16522 snapshots) has been known to create a die giving a declaration
16523 for a class that has, as a child, a die giving a definition for a
16524 nested class. So we have to process our children even if the
16525 current die is a declaration. Normally, of course, a declaration
16526 won't have any children at all. */
16528 child_die
= die
->child
;
16530 while (child_die
!= NULL
&& child_die
->tag
)
16532 if (child_die
->tag
== DW_TAG_member
16533 || child_die
->tag
== DW_TAG_variable
16534 || child_die
->tag
== DW_TAG_inheritance
16535 || child_die
->tag
== DW_TAG_template_value_param
16536 || child_die
->tag
== DW_TAG_template_type_param
)
16541 process_die (child_die
, cu
);
16543 child_die
= child_die
->sibling
;
16546 /* Do not consider external references. According to the DWARF standard,
16547 these DIEs are identified by the fact that they have no byte_size
16548 attribute, and a declaration attribute. */
16549 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16550 || !die_is_declaration (die
, cu
)
16551 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16553 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16555 if (has_template_parameters
)
16557 struct symtab
*symtab
;
16558 if (sym
!= nullptr)
16559 symtab
= symbol_symtab (sym
);
16560 else if (cu
->line_header
!= nullptr)
16562 /* Any related symtab will do. */
16564 = cu
->line_header
->file_names ()[0].symtab
;
16569 complaint (_("could not find suitable "
16570 "symtab for template parameter"
16571 " - DIE at %s [in module %s]"),
16572 sect_offset_str (die
->sect_off
),
16573 objfile_name (objfile
));
16576 if (symtab
!= nullptr)
16578 /* Make sure that the symtab is set on the new symbols.
16579 Even though they don't appear in this symtab directly,
16580 other parts of gdb assume that symbols do, and this is
16581 reasonably true. */
16582 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16583 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16589 /* Assuming DIE is an enumeration type, and TYPE is its associated
16590 type, update TYPE using some information only available in DIE's
16591 children. In particular, the fields are computed. */
16594 update_enumeration_type_from_children (struct die_info
*die
,
16596 struct dwarf2_cu
*cu
)
16598 struct die_info
*child_die
;
16599 int unsigned_enum
= 1;
16602 auto_obstack obstack
;
16603 std::vector
<struct field
> fields
;
16605 for (child_die
= die
->child
;
16606 child_die
!= NULL
&& child_die
->tag
;
16607 child_die
= child_die
->sibling
)
16609 struct attribute
*attr
;
16611 const gdb_byte
*bytes
;
16612 struct dwarf2_locexpr_baton
*baton
;
16615 if (child_die
->tag
!= DW_TAG_enumerator
)
16618 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16622 name
= dwarf2_name (child_die
, cu
);
16624 name
= "<anonymous enumerator>";
16626 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16627 &value
, &bytes
, &baton
);
16635 if (count_one_bits_ll (value
) >= 2)
16639 fields
.emplace_back ();
16640 struct field
&field
= fields
.back ();
16641 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16642 SET_FIELD_ENUMVAL (field
, value
);
16645 if (!fields
.empty ())
16647 type
->set_num_fields (fields
.size ());
16650 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16651 memcpy (type
->fields (), fields
.data (),
16652 sizeof (struct field
) * fields
.size ());
16656 type
->set_is_unsigned (true);
16659 TYPE_FLAG_ENUM (type
) = 1;
16662 /* Given a DW_AT_enumeration_type die, set its type. We do not
16663 complete the type's fields yet, or create any symbols. */
16665 static struct type
*
16666 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16668 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16670 struct attribute
*attr
;
16673 /* If the definition of this type lives in .debug_types, read that type.
16674 Don't follow DW_AT_specification though, that will take us back up
16675 the chain and we want to go down. */
16676 attr
= die
->attr (DW_AT_signature
);
16677 if (attr
!= nullptr)
16679 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16681 /* The type's CU may not be the same as CU.
16682 Ensure TYPE is recorded with CU in die_type_hash. */
16683 return set_die_type (die
, type
, cu
);
16686 type
= alloc_type (objfile
);
16688 type
->set_code (TYPE_CODE_ENUM
);
16689 name
= dwarf2_full_name (NULL
, die
, cu
);
16691 type
->set_name (name
);
16693 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16696 struct type
*underlying_type
= die_type (die
, cu
);
16698 TYPE_TARGET_TYPE (type
) = underlying_type
;
16701 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16702 if (attr
!= nullptr)
16704 TYPE_LENGTH (type
) = attr
->constant_value (0);
16708 TYPE_LENGTH (type
) = 0;
16711 maybe_set_alignment (cu
, die
, type
);
16713 /* The enumeration DIE can be incomplete. In Ada, any type can be
16714 declared as private in the package spec, and then defined only
16715 inside the package body. Such types are known as Taft Amendment
16716 Types. When another package uses such a type, an incomplete DIE
16717 may be generated by the compiler. */
16718 if (die_is_declaration (die
, cu
))
16719 type
->set_is_stub (true);
16721 /* If this type has an underlying type that is not a stub, then we
16722 may use its attributes. We always use the "unsigned" attribute
16723 in this situation, because ordinarily we guess whether the type
16724 is unsigned -- but the guess can be wrong and the underlying type
16725 can tell us the reality. However, we defer to a local size
16726 attribute if one exists, because this lets the compiler override
16727 the underlying type if needed. */
16728 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16730 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16731 underlying_type
= check_typedef (underlying_type
);
16733 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16735 if (TYPE_LENGTH (type
) == 0)
16736 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16738 if (TYPE_RAW_ALIGN (type
) == 0
16739 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16740 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16743 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16745 set_die_type (die
, type
, cu
);
16747 /* Finish the creation of this type by using the enum's children.
16748 Note that, as usual, this must come after set_die_type to avoid
16749 infinite recursion when trying to compute the names of the
16751 update_enumeration_type_from_children (die
, type
, cu
);
16756 /* Given a pointer to a die which begins an enumeration, process all
16757 the dies that define the members of the enumeration, and create the
16758 symbol for the enumeration type.
16760 NOTE: We reverse the order of the element list. */
16763 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16765 struct type
*this_type
;
16767 this_type
= get_die_type (die
, cu
);
16768 if (this_type
== NULL
)
16769 this_type
= read_enumeration_type (die
, cu
);
16771 if (die
->child
!= NULL
)
16773 struct die_info
*child_die
;
16776 child_die
= die
->child
;
16777 while (child_die
&& child_die
->tag
)
16779 if (child_die
->tag
!= DW_TAG_enumerator
)
16781 process_die (child_die
, cu
);
16785 name
= dwarf2_name (child_die
, cu
);
16787 new_symbol (child_die
, this_type
, cu
);
16790 child_die
= child_die
->sibling
;
16794 /* If we are reading an enum from a .debug_types unit, and the enum
16795 is a declaration, and the enum is not the signatured type in the
16796 unit, then we do not want to add a symbol for it. Adding a
16797 symbol would in some cases obscure the true definition of the
16798 enum, giving users an incomplete type when the definition is
16799 actually available. Note that we do not want to do this for all
16800 enums which are just declarations, because C++0x allows forward
16801 enum declarations. */
16802 if (cu
->per_cu
->is_debug_types
16803 && die_is_declaration (die
, cu
))
16805 struct signatured_type
*sig_type
;
16807 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16808 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16809 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16813 new_symbol (die
, this_type
, cu
);
16816 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16817 expression for an index type and finds the corresponding field
16818 offset in the hidden "P_BOUNDS" structure. Returns true on success
16819 and updates *FIELD, false if it fails to recognize an
16823 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16824 int *bounds_offset
, struct field
*field
,
16825 struct dwarf2_cu
*cu
)
16827 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16828 if (attr
== nullptr || !attr
->form_is_block ())
16831 const struct dwarf_block
*block
= attr
->as_block ();
16832 const gdb_byte
*start
= block
->data
;
16833 const gdb_byte
*end
= block
->data
+ block
->size
;
16835 /* The expression to recognize generally looks like:
16837 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16838 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16840 However, the second "plus_uconst" may be missing:
16842 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16843 DW_OP_deref_size: 4)
16845 This happens when the field is at the start of the structure.
16847 Also, the final deref may not be sized:
16849 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16852 This happens when the size of the index type happens to be the
16853 same as the architecture's word size. This can occur with or
16854 without the second plus_uconst. */
16856 if (end
- start
< 2)
16858 if (*start
++ != DW_OP_push_object_address
)
16860 if (*start
++ != DW_OP_plus_uconst
)
16863 uint64_t this_bound_off
;
16864 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16865 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16867 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16868 is consistent among all bounds. */
16869 if (*bounds_offset
== -1)
16870 *bounds_offset
= this_bound_off
;
16871 else if (*bounds_offset
!= this_bound_off
)
16874 if (start
== end
|| *start
++ != DW_OP_deref
)
16880 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16882 /* This means an offset of 0. */
16884 else if (*start
++ != DW_OP_plus_uconst
)
16888 /* The size is the parameter to DW_OP_plus_uconst. */
16890 start
= gdb_read_uleb128 (start
, end
, &val
);
16891 if (start
== nullptr)
16893 if ((int) val
!= val
)
16902 if (*start
== DW_OP_deref_size
)
16904 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16905 if (start
== nullptr)
16908 else if (*start
== DW_OP_deref
)
16910 size
= cu
->header
.addr_size
;
16916 SET_FIELD_BITPOS (*field
, 8 * offset
);
16917 if (size
!= TYPE_LENGTH (field
->type ()))
16918 FIELD_BITSIZE (*field
) = 8 * size
;
16923 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16924 some kinds of Ada arrays:
16926 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16927 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16928 <11e0> DW_AT_data_location: 2 byte block: 97 6
16929 (DW_OP_push_object_address; DW_OP_deref)
16930 <11e3> DW_AT_type : <0x1173>
16931 <11e7> DW_AT_sibling : <0x1201>
16932 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16933 <11ec> DW_AT_type : <0x1206>
16934 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16935 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16936 DW_OP_deref_size: 4)
16937 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16938 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16939 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16941 This actually represents a "thick pointer", which is a structure
16942 with two elements: one that is a pointer to the array data, and one
16943 that is a pointer to another structure; this second structure holds
16946 This returns a new type on success, or nullptr if this didn't
16947 recognize the type. */
16949 static struct type
*
16950 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16953 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16954 /* So far we've only seen this with block form. */
16955 if (attr
== nullptr || !attr
->form_is_block ())
16958 /* Note that this will fail if the structure layout is changed by
16959 the compiler. However, we have no good way to recognize some
16960 other layout, because we don't know what expression the compiler
16961 might choose to emit should this happen. */
16962 struct dwarf_block
*blk
= attr
->as_block ();
16964 || blk
->data
[0] != DW_OP_push_object_address
16965 || blk
->data
[1] != DW_OP_deref
)
16968 int bounds_offset
= -1;
16969 int max_align
= -1;
16970 std::vector
<struct field
> range_fields
;
16971 for (struct die_info
*child_die
= die
->child
;
16973 child_die
= child_die
->sibling
)
16975 if (child_die
->tag
== DW_TAG_subrange_type
)
16977 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16979 int this_align
= type_align (underlying
);
16980 if (this_align
> max_align
)
16981 max_align
= this_align
;
16983 range_fields
.emplace_back ();
16984 range_fields
.emplace_back ();
16986 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16987 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16989 lower
.set_type (underlying
);
16990 FIELD_ARTIFICIAL (lower
) = 1;
16992 upper
.set_type (underlying
);
16993 FIELD_ARTIFICIAL (upper
) = 1;
16995 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16996 &bounds_offset
, &lower
, cu
)
16997 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16998 &bounds_offset
, &upper
, cu
))
17003 /* This shouldn't really happen, but double-check that we found
17004 where the bounds are stored. */
17005 if (bounds_offset
== -1)
17008 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17009 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
17013 /* Set the name of each field in the bounds. */
17014 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
17015 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
17016 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
17017 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
17020 struct type
*bounds
= alloc_type (objfile
);
17021 bounds
->set_code (TYPE_CODE_STRUCT
);
17023 bounds
->set_num_fields (range_fields
.size ());
17025 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
17026 * sizeof (struct field
))));
17027 memcpy (bounds
->fields (), range_fields
.data (),
17028 bounds
->num_fields () * sizeof (struct field
));
17030 int last_fieldno
= range_fields
.size () - 1;
17031 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
17032 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
17033 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
17035 /* Rewrite the existing array type in place. Specifically, we
17036 remove any dynamic properties we might have read, and we replace
17037 the index types. */
17038 struct type
*iter
= type
;
17039 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
17041 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
17042 iter
->main_type
->dyn_prop_list
= nullptr;
17043 iter
->set_index_type
17044 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
17045 iter
= TYPE_TARGET_TYPE (iter
);
17048 struct type
*result
= alloc_type (objfile
);
17049 result
->set_code (TYPE_CODE_STRUCT
);
17051 result
->set_num_fields (2);
17053 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
17054 * sizeof (struct field
))));
17056 /* The names are chosen to coincide with what the compiler does with
17057 -fgnat-encodings=all, which the Ada code in gdb already
17059 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
17060 result
->field (0).set_type (lookup_pointer_type (type
));
17062 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
17063 result
->field (1).set_type (lookup_pointer_type (bounds
));
17064 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
17066 result
->set_name (type
->name ());
17067 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
17068 + TYPE_LENGTH (result
->field (1).type ()));
17073 /* Extract all information from a DW_TAG_array_type DIE and put it in
17074 the DIE's type field. For now, this only handles one dimensional
17077 static struct type
*
17078 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17080 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17081 struct die_info
*child_die
;
17083 struct type
*element_type
, *range_type
, *index_type
;
17084 struct attribute
*attr
;
17086 struct dynamic_prop
*byte_stride_prop
= NULL
;
17087 unsigned int bit_stride
= 0;
17089 element_type
= die_type (die
, cu
);
17091 /* The die_type call above may have already set the type for this DIE. */
17092 type
= get_die_type (die
, cu
);
17096 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17100 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17103 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
17104 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
17108 complaint (_("unable to read array DW_AT_byte_stride "
17109 " - DIE at %s [in module %s]"),
17110 sect_offset_str (die
->sect_off
),
17111 objfile_name (cu
->per_objfile
->objfile
));
17112 /* Ignore this attribute. We will likely not be able to print
17113 arrays of this type correctly, but there is little we can do
17114 to help if we cannot read the attribute's value. */
17115 byte_stride_prop
= NULL
;
17119 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17121 bit_stride
= attr
->constant_value (0);
17123 /* Irix 6.2 native cc creates array types without children for
17124 arrays with unspecified length. */
17125 if (die
->child
== NULL
)
17127 index_type
= objfile_type (objfile
)->builtin_int
;
17128 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
17129 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
17130 byte_stride_prop
, bit_stride
);
17131 return set_die_type (die
, type
, cu
);
17134 std::vector
<struct type
*> range_types
;
17135 child_die
= die
->child
;
17136 while (child_die
&& child_die
->tag
)
17138 if (child_die
->tag
== DW_TAG_subrange_type
)
17140 struct type
*child_type
= read_type_die (child_die
, cu
);
17142 if (child_type
!= NULL
)
17144 /* The range type was succesfully read. Save it for the
17145 array type creation. */
17146 range_types
.push_back (child_type
);
17149 child_die
= child_die
->sibling
;
17152 if (range_types
.empty ())
17154 complaint (_("unable to find array range - DIE at %s [in module %s]"),
17155 sect_offset_str (die
->sect_off
),
17156 objfile_name (cu
->per_objfile
->objfile
));
17160 /* Dwarf2 dimensions are output from left to right, create the
17161 necessary array types in backwards order. */
17163 type
= element_type
;
17165 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
17169 while (i
< range_types
.size ())
17171 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
17172 byte_stride_prop
, bit_stride
);
17174 byte_stride_prop
= nullptr;
17179 size_t ndim
= range_types
.size ();
17182 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
17183 byte_stride_prop
, bit_stride
);
17185 byte_stride_prop
= nullptr;
17189 gdb_assert (type
!= element_type
);
17191 /* Understand Dwarf2 support for vector types (like they occur on
17192 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
17193 array type. This is not part of the Dwarf2/3 standard yet, but a
17194 custom vendor extension. The main difference between a regular
17195 array and the vector variant is that vectors are passed by value
17197 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
17198 if (attr
!= nullptr)
17199 make_vector_type (type
);
17201 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
17202 implementation may choose to implement triple vectors using this
17204 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17205 if (attr
!= nullptr && attr
->form_is_unsigned ())
17207 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
17208 TYPE_LENGTH (type
) = attr
->as_unsigned ();
17210 complaint (_("DW_AT_byte_size for array type smaller "
17211 "than the total size of elements"));
17214 name
= dwarf2_name (die
, cu
);
17216 type
->set_name (name
);
17218 maybe_set_alignment (cu
, die
, type
);
17220 struct type
*replacement_type
= nullptr;
17221 if (cu
->language
== language_ada
)
17223 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
17224 if (replacement_type
!= nullptr)
17225 type
= replacement_type
;
17228 /* Install the type in the die. */
17229 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
17231 /* set_die_type should be already done. */
17232 set_descriptive_type (type
, die
, cu
);
17237 static enum dwarf_array_dim_ordering
17238 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
17240 struct attribute
*attr
;
17242 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
17244 if (attr
!= nullptr)
17246 LONGEST val
= attr
->constant_value (-1);
17247 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
17248 return (enum dwarf_array_dim_ordering
) val
;
17251 /* GNU F77 is a special case, as at 08/2004 array type info is the
17252 opposite order to the dwarf2 specification, but data is still
17253 laid out as per normal fortran.
17255 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
17256 version checking. */
17258 if (cu
->language
== language_fortran
17259 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
17261 return DW_ORD_row_major
;
17264 switch (cu
->language_defn
->array_ordering ())
17266 case array_column_major
:
17267 return DW_ORD_col_major
;
17268 case array_row_major
:
17270 return DW_ORD_row_major
;
17274 /* Extract all information from a DW_TAG_set_type DIE and put it in
17275 the DIE's type field. */
17277 static struct type
*
17278 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17280 struct type
*domain_type
, *set_type
;
17281 struct attribute
*attr
;
17283 domain_type
= die_type (die
, cu
);
17285 /* The die_type call above may have already set the type for this DIE. */
17286 set_type
= get_die_type (die
, cu
);
17290 set_type
= create_set_type (NULL
, domain_type
);
17292 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17293 if (attr
!= nullptr && attr
->form_is_unsigned ())
17294 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
17296 maybe_set_alignment (cu
, die
, set_type
);
17298 return set_die_type (die
, set_type
, cu
);
17301 /* A helper for read_common_block that creates a locexpr baton.
17302 SYM is the symbol which we are marking as computed.
17303 COMMON_DIE is the DIE for the common block.
17304 COMMON_LOC is the location expression attribute for the common
17306 MEMBER_LOC is the location expression attribute for the particular
17307 member of the common block that we are processing.
17308 CU is the CU from which the above come. */
17311 mark_common_block_symbol_computed (struct symbol
*sym
,
17312 struct die_info
*common_die
,
17313 struct attribute
*common_loc
,
17314 struct attribute
*member_loc
,
17315 struct dwarf2_cu
*cu
)
17317 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17318 struct objfile
*objfile
= per_objfile
->objfile
;
17319 struct dwarf2_locexpr_baton
*baton
;
17321 unsigned int cu_off
;
17322 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
17323 LONGEST offset
= 0;
17325 gdb_assert (common_loc
&& member_loc
);
17326 gdb_assert (common_loc
->form_is_block ());
17327 gdb_assert (member_loc
->form_is_block ()
17328 || member_loc
->form_is_constant ());
17330 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
17331 baton
->per_objfile
= per_objfile
;
17332 baton
->per_cu
= cu
->per_cu
;
17333 gdb_assert (baton
->per_cu
);
17335 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
17337 if (member_loc
->form_is_constant ())
17339 offset
= member_loc
->constant_value (0);
17340 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
17343 baton
->size
+= member_loc
->as_block ()->size
;
17345 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
17348 *ptr
++ = DW_OP_call4
;
17349 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
17350 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
17353 if (member_loc
->form_is_constant ())
17355 *ptr
++ = DW_OP_addr
;
17356 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
17357 ptr
+= cu
->header
.addr_size
;
17361 /* We have to copy the data here, because DW_OP_call4 will only
17362 use a DW_AT_location attribute. */
17363 struct dwarf_block
*block
= member_loc
->as_block ();
17364 memcpy (ptr
, block
->data
, block
->size
);
17365 ptr
+= block
->size
;
17368 *ptr
++ = DW_OP_plus
;
17369 gdb_assert (ptr
- baton
->data
== baton
->size
);
17371 SYMBOL_LOCATION_BATON (sym
) = baton
;
17372 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
17375 /* Create appropriate locally-scoped variables for all the
17376 DW_TAG_common_block entries. Also create a struct common_block
17377 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
17378 is used to separate the common blocks name namespace from regular
17382 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
17384 struct attribute
*attr
;
17386 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17387 if (attr
!= nullptr)
17389 /* Support the .debug_loc offsets. */
17390 if (attr
->form_is_block ())
17394 else if (attr
->form_is_section_offset ())
17396 dwarf2_complex_location_expr_complaint ();
17401 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17402 "common block member");
17407 if (die
->child
!= NULL
)
17409 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17410 struct die_info
*child_die
;
17411 size_t n_entries
= 0, size
;
17412 struct common_block
*common_block
;
17413 struct symbol
*sym
;
17415 for (child_die
= die
->child
;
17416 child_die
&& child_die
->tag
;
17417 child_die
= child_die
->sibling
)
17420 size
= (sizeof (struct common_block
)
17421 + (n_entries
- 1) * sizeof (struct symbol
*));
17423 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17425 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17426 common_block
->n_entries
= 0;
17428 for (child_die
= die
->child
;
17429 child_die
&& child_die
->tag
;
17430 child_die
= child_die
->sibling
)
17432 /* Create the symbol in the DW_TAG_common_block block in the current
17434 sym
= new_symbol (child_die
, NULL
, cu
);
17437 struct attribute
*member_loc
;
17439 common_block
->contents
[common_block
->n_entries
++] = sym
;
17441 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17445 /* GDB has handled this for a long time, but it is
17446 not specified by DWARF. It seems to have been
17447 emitted by gfortran at least as recently as:
17448 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17449 complaint (_("Variable in common block has "
17450 "DW_AT_data_member_location "
17451 "- DIE at %s [in module %s]"),
17452 sect_offset_str (child_die
->sect_off
),
17453 objfile_name (objfile
));
17455 if (member_loc
->form_is_section_offset ())
17456 dwarf2_complex_location_expr_complaint ();
17457 else if (member_loc
->form_is_constant ()
17458 || member_loc
->form_is_block ())
17460 if (attr
!= nullptr)
17461 mark_common_block_symbol_computed (sym
, die
, attr
,
17465 dwarf2_complex_location_expr_complaint ();
17470 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17471 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17475 /* Create a type for a C++ namespace. */
17477 static struct type
*
17478 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17480 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17481 const char *previous_prefix
, *name
;
17485 /* For extensions, reuse the type of the original namespace. */
17486 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17488 struct die_info
*ext_die
;
17489 struct dwarf2_cu
*ext_cu
= cu
;
17491 ext_die
= dwarf2_extension (die
, &ext_cu
);
17492 type
= read_type_die (ext_die
, ext_cu
);
17494 /* EXT_CU may not be the same as CU.
17495 Ensure TYPE is recorded with CU in die_type_hash. */
17496 return set_die_type (die
, type
, cu
);
17499 name
= namespace_name (die
, &is_anonymous
, cu
);
17501 /* Now build the name of the current namespace. */
17503 previous_prefix
= determine_prefix (die
, cu
);
17504 if (previous_prefix
[0] != '\0')
17505 name
= typename_concat (&objfile
->objfile_obstack
,
17506 previous_prefix
, name
, 0, cu
);
17508 /* Create the type. */
17509 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17511 return set_die_type (die
, type
, cu
);
17514 /* Read a namespace scope. */
17517 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17519 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17522 /* Add a symbol associated to this if we haven't seen the namespace
17523 before. Also, add a using directive if it's an anonymous
17526 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17530 type
= read_type_die (die
, cu
);
17531 new_symbol (die
, type
, cu
);
17533 namespace_name (die
, &is_anonymous
, cu
);
17536 const char *previous_prefix
= determine_prefix (die
, cu
);
17538 std::vector
<const char *> excludes
;
17539 add_using_directive (using_directives (cu
),
17540 previous_prefix
, type
->name (), NULL
,
17541 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17545 if (die
->child
!= NULL
)
17547 struct die_info
*child_die
= die
->child
;
17549 while (child_die
&& child_die
->tag
)
17551 process_die (child_die
, cu
);
17552 child_die
= child_die
->sibling
;
17557 /* Read a Fortran module as type. This DIE can be only a declaration used for
17558 imported module. Still we need that type as local Fortran "use ... only"
17559 declaration imports depend on the created type in determine_prefix. */
17561 static struct type
*
17562 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17564 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17565 const char *module_name
;
17568 module_name
= dwarf2_name (die
, cu
);
17569 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17571 return set_die_type (die
, type
, cu
);
17574 /* Read a Fortran module. */
17577 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17579 struct die_info
*child_die
= die
->child
;
17582 type
= read_type_die (die
, cu
);
17583 new_symbol (die
, type
, cu
);
17585 while (child_die
&& child_die
->tag
)
17587 process_die (child_die
, cu
);
17588 child_die
= child_die
->sibling
;
17592 /* Return the name of the namespace represented by DIE. Set
17593 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17596 static const char *
17597 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17599 struct die_info
*current_die
;
17600 const char *name
= NULL
;
17602 /* Loop through the extensions until we find a name. */
17604 for (current_die
= die
;
17605 current_die
!= NULL
;
17606 current_die
= dwarf2_extension (die
, &cu
))
17608 /* We don't use dwarf2_name here so that we can detect the absence
17609 of a name -> anonymous namespace. */
17610 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17616 /* Is it an anonymous namespace? */
17618 *is_anonymous
= (name
== NULL
);
17620 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17625 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17626 the user defined type vector. */
17628 static struct type
*
17629 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17631 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17632 struct comp_unit_head
*cu_header
= &cu
->header
;
17634 struct attribute
*attr_byte_size
;
17635 struct attribute
*attr_address_class
;
17636 int byte_size
, addr_class
;
17637 struct type
*target_type
;
17639 target_type
= die_type (die
, cu
);
17641 /* The die_type call above may have already set the type for this DIE. */
17642 type
= get_die_type (die
, cu
);
17646 type
= lookup_pointer_type (target_type
);
17648 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17649 if (attr_byte_size
)
17650 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17652 byte_size
= cu_header
->addr_size
;
17654 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17655 if (attr_address_class
)
17656 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17658 addr_class
= DW_ADDR_none
;
17660 ULONGEST alignment
= get_alignment (cu
, die
);
17662 /* If the pointer size, alignment, or address class is different
17663 than the default, create a type variant marked as such and set
17664 the length accordingly. */
17665 if (TYPE_LENGTH (type
) != byte_size
17666 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17667 && alignment
!= TYPE_RAW_ALIGN (type
))
17668 || addr_class
!= DW_ADDR_none
)
17670 if (gdbarch_address_class_type_flags_p (gdbarch
))
17672 type_instance_flags type_flags
17673 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17675 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17677 type
= make_type_with_address_space (type
, type_flags
);
17679 else if (TYPE_LENGTH (type
) != byte_size
)
17681 complaint (_("invalid pointer size %d"), byte_size
);
17683 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17685 complaint (_("Invalid DW_AT_alignment"
17686 " - DIE at %s [in module %s]"),
17687 sect_offset_str (die
->sect_off
),
17688 objfile_name (cu
->per_objfile
->objfile
));
17692 /* Should we also complain about unhandled address classes? */
17696 TYPE_LENGTH (type
) = byte_size
;
17697 set_type_align (type
, alignment
);
17698 return set_die_type (die
, type
, cu
);
17701 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17702 the user defined type vector. */
17704 static struct type
*
17705 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17708 struct type
*to_type
;
17709 struct type
*domain
;
17711 to_type
= die_type (die
, cu
);
17712 domain
= die_containing_type (die
, cu
);
17714 /* The calls above may have already set the type for this DIE. */
17715 type
= get_die_type (die
, cu
);
17719 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17720 type
= lookup_methodptr_type (to_type
);
17721 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17723 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17725 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17726 to_type
->fields (), to_type
->num_fields (),
17727 to_type
->has_varargs ());
17728 type
= lookup_methodptr_type (new_type
);
17731 type
= lookup_memberptr_type (to_type
, domain
);
17733 return set_die_type (die
, type
, cu
);
17736 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17737 the user defined type vector. */
17739 static struct type
*
17740 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17741 enum type_code refcode
)
17743 struct comp_unit_head
*cu_header
= &cu
->header
;
17744 struct type
*type
, *target_type
;
17745 struct attribute
*attr
;
17747 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17749 target_type
= die_type (die
, cu
);
17751 /* The die_type call above may have already set the type for this DIE. */
17752 type
= get_die_type (die
, cu
);
17756 type
= lookup_reference_type (target_type
, refcode
);
17757 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17758 if (attr
!= nullptr)
17760 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17764 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17766 maybe_set_alignment (cu
, die
, type
);
17767 return set_die_type (die
, type
, cu
);
17770 /* Add the given cv-qualifiers to the element type of the array. GCC
17771 outputs DWARF type qualifiers that apply to an array, not the
17772 element type. But GDB relies on the array element type to carry
17773 the cv-qualifiers. This mimics section 6.7.3 of the C99
17776 static struct type
*
17777 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17778 struct type
*base_type
, int cnst
, int voltl
)
17780 struct type
*el_type
, *inner_array
;
17782 base_type
= copy_type (base_type
);
17783 inner_array
= base_type
;
17785 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17787 TYPE_TARGET_TYPE (inner_array
) =
17788 copy_type (TYPE_TARGET_TYPE (inner_array
));
17789 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17792 el_type
= TYPE_TARGET_TYPE (inner_array
);
17793 cnst
|= TYPE_CONST (el_type
);
17794 voltl
|= TYPE_VOLATILE (el_type
);
17795 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17797 return set_die_type (die
, base_type
, cu
);
17800 static struct type
*
17801 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17803 struct type
*base_type
, *cv_type
;
17805 base_type
= die_type (die
, cu
);
17807 /* The die_type call above may have already set the type for this DIE. */
17808 cv_type
= get_die_type (die
, cu
);
17812 /* In case the const qualifier is applied to an array type, the element type
17813 is so qualified, not the array type (section 6.7.3 of C99). */
17814 if (base_type
->code () == TYPE_CODE_ARRAY
)
17815 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17817 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17818 return set_die_type (die
, cv_type
, cu
);
17821 static struct type
*
17822 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17824 struct type
*base_type
, *cv_type
;
17826 base_type
= die_type (die
, cu
);
17828 /* The die_type call above may have already set the type for this DIE. */
17829 cv_type
= get_die_type (die
, cu
);
17833 /* In case the volatile qualifier is applied to an array type, the
17834 element type is so qualified, not the array type (section 6.7.3
17836 if (base_type
->code () == TYPE_CODE_ARRAY
)
17837 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17839 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17840 return set_die_type (die
, cv_type
, cu
);
17843 /* Handle DW_TAG_restrict_type. */
17845 static struct type
*
17846 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17848 struct type
*base_type
, *cv_type
;
17850 base_type
= die_type (die
, cu
);
17852 /* The die_type call above may have already set the type for this DIE. */
17853 cv_type
= get_die_type (die
, cu
);
17857 cv_type
= make_restrict_type (base_type
);
17858 return set_die_type (die
, cv_type
, cu
);
17861 /* Handle DW_TAG_atomic_type. */
17863 static struct type
*
17864 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17866 struct type
*base_type
, *cv_type
;
17868 base_type
= die_type (die
, cu
);
17870 /* The die_type call above may have already set the type for this DIE. */
17871 cv_type
= get_die_type (die
, cu
);
17875 cv_type
= make_atomic_type (base_type
);
17876 return set_die_type (die
, cv_type
, cu
);
17879 /* Extract all information from a DW_TAG_string_type DIE and add to
17880 the user defined type vector. It isn't really a user defined type,
17881 but it behaves like one, with other DIE's using an AT_user_def_type
17882 attribute to reference it. */
17884 static struct type
*
17885 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17887 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17888 struct gdbarch
*gdbarch
= objfile
->arch ();
17889 struct type
*type
, *range_type
, *index_type
, *char_type
;
17890 struct attribute
*attr
;
17891 struct dynamic_prop prop
;
17892 bool length_is_constant
= true;
17895 /* There are a couple of places where bit sizes might be made use of
17896 when parsing a DW_TAG_string_type, however, no producer that we know
17897 of make use of these. Handling bit sizes that are a multiple of the
17898 byte size is easy enough, but what about other bit sizes? Lets deal
17899 with that problem when we have to. Warn about these attributes being
17900 unsupported, then parse the type and ignore them like we always
17902 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17903 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17905 static bool warning_printed
= false;
17906 if (!warning_printed
)
17908 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17909 "currently supported on DW_TAG_string_type."));
17910 warning_printed
= true;
17914 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17915 if (attr
!= nullptr && !attr
->form_is_constant ())
17917 /* The string length describes the location at which the length of
17918 the string can be found. The size of the length field can be
17919 specified with one of the attributes below. */
17920 struct type
*prop_type
;
17921 struct attribute
*len
17922 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17923 if (len
== nullptr)
17924 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17925 if (len
!= nullptr && len
->form_is_constant ())
17927 /* Pass 0 as the default as we know this attribute is constant
17928 and the default value will not be returned. */
17929 LONGEST sz
= len
->constant_value (0);
17930 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17934 /* If the size is not specified then we assume it is the size of
17935 an address on this target. */
17936 prop_type
= cu
->addr_sized_int_type (true);
17939 /* Convert the attribute into a dynamic property. */
17940 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17943 length_is_constant
= false;
17945 else if (attr
!= nullptr)
17947 /* This DW_AT_string_length just contains the length with no
17948 indirection. There's no need to create a dynamic property in this
17949 case. Pass 0 for the default value as we know it will not be
17950 returned in this case. */
17951 length
= attr
->constant_value (0);
17953 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17955 /* We don't currently support non-constant byte sizes for strings. */
17956 length
= attr
->constant_value (1);
17960 /* Use 1 as a fallback length if we have nothing else. */
17964 index_type
= objfile_type (objfile
)->builtin_int
;
17965 if (length_is_constant
)
17966 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17969 struct dynamic_prop low_bound
;
17971 low_bound
.set_const_val (1);
17972 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17974 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17975 type
= create_string_type (NULL
, char_type
, range_type
);
17977 return set_die_type (die
, type
, cu
);
17980 /* Assuming that DIE corresponds to a function, returns nonzero
17981 if the function is prototyped. */
17984 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17986 struct attribute
*attr
;
17988 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17989 if (attr
&& attr
->as_boolean ())
17992 /* The DWARF standard implies that the DW_AT_prototyped attribute
17993 is only meaningful for C, but the concept also extends to other
17994 languages that allow unprototyped functions (Eg: Objective C).
17995 For all other languages, assume that functions are always
17997 if (cu
->language
!= language_c
17998 && cu
->language
!= language_objc
17999 && cu
->language
!= language_opencl
)
18002 /* RealView does not emit DW_AT_prototyped. We can not distinguish
18003 prototyped and unprototyped functions; default to prototyped,
18004 since that is more common in modern code (and RealView warns
18005 about unprototyped functions). */
18006 if (producer_is_realview (cu
->producer
))
18012 /* Handle DIES due to C code like:
18016 int (*funcp)(int a, long l);
18020 ('funcp' generates a DW_TAG_subroutine_type DIE). */
18022 static struct type
*
18023 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18025 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18026 struct type
*type
; /* Type that this function returns. */
18027 struct type
*ftype
; /* Function that returns above type. */
18028 struct attribute
*attr
;
18030 type
= die_type (die
, cu
);
18032 /* The die_type call above may have already set the type for this DIE. */
18033 ftype
= get_die_type (die
, cu
);
18037 ftype
= lookup_function_type (type
);
18039 if (prototyped_function_p (die
, cu
))
18040 ftype
->set_is_prototyped (true);
18042 /* Store the calling convention in the type if it's available in
18043 the subroutine die. Otherwise set the calling convention to
18044 the default value DW_CC_normal. */
18045 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
18046 if (attr
!= nullptr
18047 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
18048 TYPE_CALLING_CONVENTION (ftype
)
18049 = (enum dwarf_calling_convention
) attr
->constant_value (0);
18050 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
18051 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
18053 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
18055 /* Record whether the function returns normally to its caller or not
18056 if the DWARF producer set that information. */
18057 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
18058 if (attr
&& attr
->as_boolean ())
18059 TYPE_NO_RETURN (ftype
) = 1;
18061 /* We need to add the subroutine type to the die immediately so
18062 we don't infinitely recurse when dealing with parameters
18063 declared as the same subroutine type. */
18064 set_die_type (die
, ftype
, cu
);
18066 if (die
->child
!= NULL
)
18068 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
18069 struct die_info
*child_die
;
18070 int nparams
, iparams
;
18072 /* Count the number of parameters.
18073 FIXME: GDB currently ignores vararg functions, but knows about
18074 vararg member functions. */
18076 child_die
= die
->child
;
18077 while (child_die
&& child_die
->tag
)
18079 if (child_die
->tag
== DW_TAG_formal_parameter
)
18081 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
18082 ftype
->set_has_varargs (true);
18084 child_die
= child_die
->sibling
;
18087 /* Allocate storage for parameters and fill them in. */
18088 ftype
->set_num_fields (nparams
);
18090 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
18092 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
18093 even if we error out during the parameters reading below. */
18094 for (iparams
= 0; iparams
< nparams
; iparams
++)
18095 ftype
->field (iparams
).set_type (void_type
);
18098 child_die
= die
->child
;
18099 while (child_die
&& child_die
->tag
)
18101 if (child_die
->tag
== DW_TAG_formal_parameter
)
18103 struct type
*arg_type
;
18105 /* DWARF version 2 has no clean way to discern C++
18106 static and non-static member functions. G++ helps
18107 GDB by marking the first parameter for non-static
18108 member functions (which is the this pointer) as
18109 artificial. We pass this information to
18110 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
18112 DWARF version 3 added DW_AT_object_pointer, which GCC
18113 4.5 does not yet generate. */
18114 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
18115 if (attr
!= nullptr)
18116 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
18118 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
18119 arg_type
= die_type (child_die
, cu
);
18121 /* RealView does not mark THIS as const, which the testsuite
18122 expects. GCC marks THIS as const in method definitions,
18123 but not in the class specifications (GCC PR 43053). */
18124 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
18125 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
18128 struct dwarf2_cu
*arg_cu
= cu
;
18129 const char *name
= dwarf2_name (child_die
, cu
);
18131 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
18132 if (attr
!= nullptr)
18134 /* If the compiler emits this, use it. */
18135 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
18138 else if (name
&& strcmp (name
, "this") == 0)
18139 /* Function definitions will have the argument names. */
18141 else if (name
== NULL
&& iparams
== 0)
18142 /* Declarations may not have the names, so like
18143 elsewhere in GDB, assume an artificial first
18144 argument is "this". */
18148 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
18152 ftype
->field (iparams
).set_type (arg_type
);
18155 child_die
= child_die
->sibling
;
18162 static struct type
*
18163 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
18165 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18166 const char *name
= NULL
;
18167 struct type
*this_type
, *target_type
;
18169 name
= dwarf2_full_name (NULL
, die
, cu
);
18170 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
18171 this_type
->set_target_is_stub (true);
18172 set_die_type (die
, this_type
, cu
);
18173 target_type
= die_type (die
, cu
);
18174 if (target_type
!= this_type
)
18175 TYPE_TARGET_TYPE (this_type
) = target_type
;
18178 /* Self-referential typedefs are, it seems, not allowed by the DWARF
18179 spec and cause infinite loops in GDB. */
18180 complaint (_("Self-referential DW_TAG_typedef "
18181 "- DIE at %s [in module %s]"),
18182 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
18183 TYPE_TARGET_TYPE (this_type
) = NULL
;
18187 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
18188 anonymous typedefs, which is, strictly speaking, invalid DWARF.
18189 Handle these by just returning the target type, rather than
18190 constructing an anonymous typedef type and trying to handle this
18192 set_die_type (die
, target_type
, cu
);
18193 return target_type
;
18198 /* Helper for get_dwarf2_rational_constant that computes the value of
18199 a given gmp_mpz given an attribute. */
18202 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
18204 /* GCC will sometimes emit a 16-byte constant value as a DWARF
18205 location expression that pushes an implicit value. */
18206 if (attr
->form
== DW_FORM_exprloc
)
18208 dwarf_block
*blk
= attr
->as_block ();
18209 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
18212 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
18213 blk
->data
+ blk
->size
,
18215 if (ptr
- blk
->data
+ len
<= blk
->size
)
18217 mpz_import (value
->val
, len
,
18218 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
18224 /* On failure set it to 1. */
18225 *value
= gdb_mpz (1);
18227 else if (attr
->form_is_block ())
18229 dwarf_block
*blk
= attr
->as_block ();
18230 mpz_import (value
->val
, blk
->size
,
18231 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
18232 1, 0, 0, blk
->data
);
18235 *value
= gdb_mpz (attr
->constant_value (1));
18238 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
18239 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
18241 If the numerator and/or numerator attribute is missing,
18242 a complaint is filed, and NUMERATOR and DENOMINATOR are left
18246 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
18247 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
18249 struct attribute
*num_attr
, *denom_attr
;
18251 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
18252 if (num_attr
== nullptr)
18253 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
18254 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18256 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
18257 if (denom_attr
== nullptr)
18258 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
18259 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18261 if (num_attr
== nullptr || denom_attr
== nullptr)
18264 get_mpz (cu
, numerator
, num_attr
);
18265 get_mpz (cu
, denominator
, denom_attr
);
18268 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
18269 rational constant, rather than a signed one.
18271 If the rational constant has a negative value, a complaint
18272 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
18275 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
18276 struct dwarf2_cu
*cu
,
18277 gdb_mpz
*numerator
,
18278 gdb_mpz
*denominator
)
18283 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
18284 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
18286 mpz_neg (num
.val
, num
.val
);
18287 mpz_neg (denom
.val
, denom
.val
);
18289 else if (mpz_sgn (num
.val
) == -1)
18291 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
18293 sect_offset_str (die
->sect_off
));
18296 else if (mpz_sgn (denom
.val
) == -1)
18298 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
18300 sect_offset_str (die
->sect_off
));
18304 *numerator
= std::move (num
);
18305 *denominator
= std::move (denom
);
18308 /* Assuming that ENCODING is a string whose contents starting at the
18309 K'th character is "_nn" where "nn" is a decimal number, scan that
18310 number and set RESULT to the value. K is updated to point to the
18311 character immediately following the number.
18313 If the string does not conform to the format described above, false
18314 is returned, and K may or may not be changed. */
18317 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
18319 /* The next character should be an underscore ('_') followed
18321 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
18324 /* Skip the underscore. */
18328 /* Determine the number of digits for our number. */
18329 while (isdigit (encoding
[k
]))
18334 std::string
copy (&encoding
[start
], k
- start
);
18335 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
18341 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
18342 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
18343 DENOM, update OFFSET, and return true on success. Return false on
18347 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
18348 gdb_mpz
*num
, gdb_mpz
*denom
)
18350 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
18352 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
18355 /* Assuming DIE corresponds to a fixed point type, finish the creation
18356 of the corresponding TYPE by setting its type-specific data. CU is
18357 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
18358 encodings. It is nullptr if the GNAT encoding should be
18362 finish_fixed_point_type (struct type
*type
, const char *suffix
,
18363 struct die_info
*die
, struct dwarf2_cu
*cu
)
18365 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
18366 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
18368 /* If GNAT encodings are preferred, don't examine the
18370 struct attribute
*attr
= nullptr;
18371 if (suffix
== nullptr)
18373 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
18374 if (attr
== nullptr)
18375 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
18376 if (attr
== nullptr)
18377 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18380 /* Numerator and denominator of our fixed-point type's scaling factor.
18381 The default is a scaling factor of 1, which we use as a fallback
18382 when we are not able to decode it (problem with the debugging info,
18383 unsupported forms, bug in GDB, etc...). Using that as the default
18384 allows us to at least print the unscaled value, which might still
18385 be useful to a user. */
18386 gdb_mpz
scale_num (1);
18387 gdb_mpz
scale_denom (1);
18389 if (attr
== nullptr)
18392 if (suffix
!= nullptr
18393 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
18395 /* The number might be encoded as _nn_dd_nn_dd, where the
18396 second ratio is the 'small value. In this situation, we
18397 want the second value. */
18398 && (suffix
[offset
] != '_'
18399 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
18406 /* Scaling factor not found. Assume a scaling factor of 1,
18407 and hope for the best. At least the user will be able to
18408 see the encoded value. */
18411 complaint (_("no scale found for fixed-point type (DIE at %s)"),
18412 sect_offset_str (die
->sect_off
));
18415 else if (attr
->name
== DW_AT_binary_scale
)
18417 LONGEST scale_exp
= attr
->constant_value (0);
18418 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18420 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
18422 else if (attr
->name
== DW_AT_decimal_scale
)
18424 LONGEST scale_exp
= attr
->constant_value (0);
18425 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18427 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
18429 else if (attr
->name
== DW_AT_small
)
18431 struct die_info
*scale_die
;
18432 struct dwarf2_cu
*scale_cu
= cu
;
18434 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
18435 if (scale_die
->tag
== DW_TAG_constant
)
18436 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
18437 &scale_num
, &scale_denom
);
18439 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
18441 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18445 complaint (_("unsupported scale attribute %s for fixed-point type"
18447 dwarf_attr_name (attr
->name
),
18448 sect_offset_str (die
->sect_off
));
18451 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
18452 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
18453 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
18454 mpq_canonicalize (scaling_factor
.val
);
18457 /* The gnat-encoding suffix for fixed point. */
18459 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
18461 /* If NAME encodes an Ada fixed-point type, return a pointer to the
18462 "XF" suffix of the name. The text after this is what encodes the
18463 'small and 'delta information. Otherwise, return nullptr. */
18465 static const char *
18466 gnat_encoded_fixed_point_type_info (const char *name
)
18468 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
18471 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
18472 (which may be different from NAME) to the architecture back-end to allow
18473 it to guess the correct format if necessary. */
18475 static struct type
*
18476 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
18477 const char *name_hint
, enum bfd_endian byte_order
)
18479 struct gdbarch
*gdbarch
= objfile
->arch ();
18480 const struct floatformat
**format
;
18483 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
18485 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
18487 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18492 /* Allocate an integer type of size BITS and name NAME. */
18494 static struct type
*
18495 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
18496 int bits
, int unsigned_p
, const char *name
)
18500 /* Versions of Intel's C Compiler generate an integer type called "void"
18501 instead of using DW_TAG_unspecified_type. This has been seen on
18502 at least versions 14, 17, and 18. */
18503 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18504 && strcmp (name
, "void") == 0)
18505 type
= objfile_type (objfile
)->builtin_void
;
18507 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18512 /* Return true if DIE has a DW_AT_small attribute whose value is
18513 a constant rational, where both the numerator and denominator
18516 CU is the DIE's Compilation Unit. */
18519 has_zero_over_zero_small_attribute (struct die_info
*die
,
18520 struct dwarf2_cu
*cu
)
18522 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18523 if (attr
== nullptr)
18526 struct dwarf2_cu
*scale_cu
= cu
;
18527 struct die_info
*scale_die
18528 = follow_die_ref (die
, attr
, &scale_cu
);
18530 if (scale_die
->tag
!= DW_TAG_constant
)
18533 gdb_mpz
num (1), denom (1);
18534 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18535 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
18538 /* Initialise and return a floating point type of size BITS suitable for
18539 use as a component of a complex number. The NAME_HINT is passed through
18540 when initialising the floating point type and is the name of the complex
18543 As DWARF doesn't currently provide an explicit name for the components
18544 of a complex number, but it can be helpful to have these components
18545 named, we try to select a suitable name based on the size of the
18547 static struct type
*
18548 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18549 struct objfile
*objfile
,
18550 int bits
, const char *name_hint
,
18551 enum bfd_endian byte_order
)
18553 gdbarch
*gdbarch
= objfile
->arch ();
18554 struct type
*tt
= nullptr;
18556 /* Try to find a suitable floating point builtin type of size BITS.
18557 We're going to use the name of this type as the name for the complex
18558 target type that we are about to create. */
18559 switch (cu
->language
)
18561 case language_fortran
:
18565 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18568 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18570 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18572 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18580 tt
= builtin_type (gdbarch
)->builtin_float
;
18583 tt
= builtin_type (gdbarch
)->builtin_double
;
18585 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18587 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18593 /* If the type we found doesn't match the size we were looking for, then
18594 pretend we didn't find a type at all, the complex target type we
18595 create will then be nameless. */
18596 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18599 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18600 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18603 /* Find a representation of a given base type and install
18604 it in the TYPE field of the die. */
18606 static struct type
*
18607 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18609 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18611 struct attribute
*attr
;
18612 int encoding
= 0, bits
= 0;
18616 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18617 if (attr
!= nullptr && attr
->form_is_constant ())
18618 encoding
= attr
->constant_value (0);
18619 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18620 if (attr
!= nullptr)
18621 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18622 name
= dwarf2_name (die
, cu
);
18624 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18626 arch
= objfile
->arch ();
18627 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18629 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18630 if (attr
!= nullptr && attr
->form_is_constant ())
18632 int endianity
= attr
->constant_value (0);
18637 byte_order
= BFD_ENDIAN_BIG
;
18639 case DW_END_little
:
18640 byte_order
= BFD_ENDIAN_LITTLE
;
18643 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18648 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18649 && cu
->language
== language_ada
18650 && has_zero_over_zero_small_attribute (die
, cu
))
18652 /* brobecker/2018-02-24: This is a fixed point type for which
18653 the scaling factor is represented as fraction whose value
18654 does not make sense (zero divided by zero), so we should
18655 normally never see these. However, there is a small category
18656 of fixed point types for which GNAT is unable to provide
18657 the scaling factor via the standard DWARF mechanisms, and
18658 for which the info is provided via the GNAT encodings instead.
18659 This is likely what this DIE is about. */
18660 encoding
= (encoding
== DW_ATE_signed_fixed
18662 : DW_ATE_unsigned
);
18665 /* With GNAT encodings, fixed-point information will be encoded in
18666 the type name. Note that this can also occur with the above
18667 zero-over-zero case, which is why this is a separate "if" rather
18668 than an "else if". */
18669 const char *gnat_encoding_suffix
= nullptr;
18670 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18671 && cu
->language
== language_ada
18672 && name
!= nullptr)
18674 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18675 if (gnat_encoding_suffix
!= nullptr)
18677 gdb_assert (startswith (gnat_encoding_suffix
,
18678 GNAT_FIXED_POINT_SUFFIX
));
18679 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18680 name
, gnat_encoding_suffix
- name
);
18681 /* Use -1 here so that SUFFIX points at the "_" after the
18683 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18685 encoding
= (encoding
== DW_ATE_signed
18686 ? DW_ATE_signed_fixed
18687 : DW_ATE_unsigned_fixed
);
18693 case DW_ATE_address
:
18694 /* Turn DW_ATE_address into a void * pointer. */
18695 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18696 type
= init_pointer_type (objfile
, bits
, name
, type
);
18698 case DW_ATE_boolean
:
18699 type
= init_boolean_type (objfile
, bits
, 1, name
);
18701 case DW_ATE_complex_float
:
18702 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18704 if (type
->code () == TYPE_CODE_ERROR
)
18706 if (name
== nullptr)
18708 struct obstack
*obstack
18709 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18710 name
= obconcat (obstack
, "_Complex ", type
->name (),
18713 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18716 type
= init_complex_type (name
, type
);
18718 case DW_ATE_decimal_float
:
18719 type
= init_decfloat_type (objfile
, bits
, name
);
18722 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18724 case DW_ATE_signed
:
18725 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18727 case DW_ATE_unsigned
:
18728 if (cu
->language
== language_fortran
18730 && startswith (name
, "character("))
18731 type
= init_character_type (objfile
, bits
, 1, name
);
18733 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18735 case DW_ATE_signed_char
:
18736 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18737 || cu
->language
== language_pascal
18738 || cu
->language
== language_fortran
)
18739 type
= init_character_type (objfile
, bits
, 0, name
);
18741 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18743 case DW_ATE_unsigned_char
:
18744 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18745 || cu
->language
== language_pascal
18746 || cu
->language
== language_fortran
18747 || cu
->language
== language_rust
)
18748 type
= init_character_type (objfile
, bits
, 1, name
);
18750 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18755 type
= builtin_type (arch
)->builtin_char16
;
18756 else if (bits
== 32)
18757 type
= builtin_type (arch
)->builtin_char32
;
18760 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18762 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18764 return set_die_type (die
, type
, cu
);
18767 case DW_ATE_signed_fixed
:
18768 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18769 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18771 case DW_ATE_unsigned_fixed
:
18772 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18773 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18777 complaint (_("unsupported DW_AT_encoding: '%s'"),
18778 dwarf_type_encoding_name (encoding
));
18779 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18783 if (name
&& strcmp (name
, "char") == 0)
18784 type
->set_has_no_signedness (true);
18786 maybe_set_alignment (cu
, die
, type
);
18788 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18790 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18792 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18793 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18795 unsigned real_bit_size
= attr
->as_unsigned ();
18796 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18797 /* Only use the attributes if they make sense together. */
18798 if (attr
== nullptr
18799 || (attr
->as_unsigned () + real_bit_size
18800 <= 8 * TYPE_LENGTH (type
)))
18802 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18804 if (attr
!= nullptr)
18805 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18806 = attr
->as_unsigned ();
18811 return set_die_type (die
, type
, cu
);
18814 /* Parse dwarf attribute if it's a block, reference or constant and put the
18815 resulting value of the attribute into struct bound_prop.
18816 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18819 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18820 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18821 struct type
*default_type
)
18823 struct dwarf2_property_baton
*baton
;
18824 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18825 struct objfile
*objfile
= per_objfile
->objfile
;
18826 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18828 gdb_assert (default_type
!= NULL
);
18830 if (attr
== NULL
|| prop
== NULL
)
18833 if (attr
->form_is_block ())
18835 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18836 baton
->property_type
= default_type
;
18837 baton
->locexpr
.per_cu
= cu
->per_cu
;
18838 baton
->locexpr
.per_objfile
= per_objfile
;
18840 struct dwarf_block
*block
= attr
->as_block ();
18841 baton
->locexpr
.size
= block
->size
;
18842 baton
->locexpr
.data
= block
->data
;
18843 switch (attr
->name
)
18845 case DW_AT_string_length
:
18846 baton
->locexpr
.is_reference
= true;
18849 baton
->locexpr
.is_reference
= false;
18853 prop
->set_locexpr (baton
);
18854 gdb_assert (prop
->baton () != NULL
);
18856 else if (attr
->form_is_ref ())
18858 struct dwarf2_cu
*target_cu
= cu
;
18859 struct die_info
*target_die
;
18860 struct attribute
*target_attr
;
18862 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18863 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18864 if (target_attr
== NULL
)
18865 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18867 if (target_attr
== NULL
)
18870 switch (target_attr
->name
)
18872 case DW_AT_location
:
18873 if (target_attr
->form_is_section_offset ())
18875 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18876 baton
->property_type
= die_type (target_die
, target_cu
);
18877 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18878 prop
->set_loclist (baton
);
18879 gdb_assert (prop
->baton () != NULL
);
18881 else if (target_attr
->form_is_block ())
18883 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18884 baton
->property_type
= die_type (target_die
, target_cu
);
18885 baton
->locexpr
.per_cu
= cu
->per_cu
;
18886 baton
->locexpr
.per_objfile
= per_objfile
;
18887 struct dwarf_block
*block
= target_attr
->as_block ();
18888 baton
->locexpr
.size
= block
->size
;
18889 baton
->locexpr
.data
= block
->data
;
18890 baton
->locexpr
.is_reference
= true;
18891 prop
->set_locexpr (baton
);
18892 gdb_assert (prop
->baton () != NULL
);
18896 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18897 "dynamic property");
18901 case DW_AT_data_member_location
:
18905 if (!handle_data_member_location (target_die
, target_cu
,
18909 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18910 baton
->property_type
= read_type_die (target_die
->parent
,
18912 baton
->offset_info
.offset
= offset
;
18913 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18914 prop
->set_addr_offset (baton
);
18919 else if (attr
->form_is_constant ())
18920 prop
->set_const_val (attr
->constant_value (0));
18923 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18924 dwarf2_name (die
, cu
));
18934 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18936 struct type
*int_type
;
18938 /* Helper macro to examine the various builtin types. */
18939 #define TRY_TYPE(F) \
18940 int_type = (unsigned_p \
18941 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18942 : objfile_type (objfile)->builtin_ ## F); \
18943 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18950 TRY_TYPE (long_long
);
18954 gdb_assert_not_reached ("unable to find suitable integer type");
18960 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
18962 int addr_size
= this->per_cu
->addr_size ();
18963 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
18966 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18967 present (which is valid) then compute the default type based on the
18968 compilation units address size. */
18970 static struct type
*
18971 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18973 struct type
*index_type
= die_type (die
, cu
);
18975 /* Dwarf-2 specifications explicitly allows to create subrange types
18976 without specifying a base type.
18977 In that case, the base type must be set to the type of
18978 the lower bound, upper bound or count, in that order, if any of these
18979 three attributes references an object that has a type.
18980 If no base type is found, the Dwarf-2 specifications say that
18981 a signed integer type of size equal to the size of an address should
18983 For the following C code: `extern char gdb_int [];'
18984 GCC produces an empty range DIE.
18985 FIXME: muller/2010-05-28: Possible references to object for low bound,
18986 high bound or count are not yet handled by this code. */
18987 if (index_type
->code () == TYPE_CODE_VOID
)
18988 index_type
= cu
->addr_sized_int_type (false);
18993 /* Read the given DW_AT_subrange DIE. */
18995 static struct type
*
18996 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18998 struct type
*base_type
, *orig_base_type
;
18999 struct type
*range_type
;
19000 struct attribute
*attr
;
19001 struct dynamic_prop low
, high
;
19002 int low_default_is_valid
;
19003 int high_bound_is_count
= 0;
19005 ULONGEST negative_mask
;
19007 orig_base_type
= read_subrange_index_type (die
, cu
);
19009 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
19010 whereas the real type might be. So, we use ORIG_BASE_TYPE when
19011 creating the range type, but we use the result of check_typedef
19012 when examining properties of the type. */
19013 base_type
= check_typedef (orig_base_type
);
19015 /* The die_type call above may have already set the type for this DIE. */
19016 range_type
= get_die_type (die
, cu
);
19020 high
.set_const_val (0);
19022 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
19023 omitting DW_AT_lower_bound. */
19024 switch (cu
->language
)
19027 case language_cplus
:
19028 low
.set_const_val (0);
19029 low_default_is_valid
= 1;
19031 case language_fortran
:
19032 low
.set_const_val (1);
19033 low_default_is_valid
= 1;
19036 case language_objc
:
19037 case language_rust
:
19038 low
.set_const_val (0);
19039 low_default_is_valid
= (cu
->header
.version
>= 4);
19043 case language_pascal
:
19044 low
.set_const_val (1);
19045 low_default_is_valid
= (cu
->header
.version
>= 4);
19048 low
.set_const_val (0);
19049 low_default_is_valid
= 0;
19053 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
19054 if (attr
!= nullptr)
19055 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
19056 else if (!low_default_is_valid
)
19057 complaint (_("Missing DW_AT_lower_bound "
19058 "- DIE at %s [in module %s]"),
19059 sect_offset_str (die
->sect_off
),
19060 objfile_name (cu
->per_objfile
->objfile
));
19062 struct attribute
*attr_ub
, *attr_count
;
19063 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
19064 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
19066 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
19067 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
19069 /* If bounds are constant do the final calculation here. */
19070 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
19071 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
19073 high_bound_is_count
= 1;
19077 if (attr_ub
!= NULL
)
19078 complaint (_("Unresolved DW_AT_upper_bound "
19079 "- DIE at %s [in module %s]"),
19080 sect_offset_str (die
->sect_off
),
19081 objfile_name (cu
->per_objfile
->objfile
));
19082 if (attr_count
!= NULL
)
19083 complaint (_("Unresolved DW_AT_count "
19084 "- DIE at %s [in module %s]"),
19085 sect_offset_str (die
->sect_off
),
19086 objfile_name (cu
->per_objfile
->objfile
));
19091 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
19092 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
19093 bias
= bias_attr
->constant_value (0);
19095 /* Normally, the DWARF producers are expected to use a signed
19096 constant form (Eg. DW_FORM_sdata) to express negative bounds.
19097 But this is unfortunately not always the case, as witnessed
19098 with GCC, for instance, where the ambiguous DW_FORM_dataN form
19099 is used instead. To work around that ambiguity, we treat
19100 the bounds as signed, and thus sign-extend their values, when
19101 the base type is signed. */
19103 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
19104 if (low
.kind () == PROP_CONST
19105 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
19106 low
.set_const_val (low
.const_val () | negative_mask
);
19107 if (high
.kind () == PROP_CONST
19108 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
19109 high
.set_const_val (high
.const_val () | negative_mask
);
19111 /* Check for bit and byte strides. */
19112 struct dynamic_prop byte_stride_prop
;
19113 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
19114 if (attr_byte_stride
!= nullptr)
19116 struct type
*prop_type
= cu
->addr_sized_int_type (false);
19117 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
19121 struct dynamic_prop bit_stride_prop
;
19122 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
19123 if (attr_bit_stride
!= nullptr)
19125 /* It only makes sense to have either a bit or byte stride. */
19126 if (attr_byte_stride
!= nullptr)
19128 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
19129 "- DIE at %s [in module %s]"),
19130 sect_offset_str (die
->sect_off
),
19131 objfile_name (cu
->per_objfile
->objfile
));
19132 attr_bit_stride
= nullptr;
19136 struct type
*prop_type
= cu
->addr_sized_int_type (false);
19137 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
19142 if (attr_byte_stride
!= nullptr
19143 || attr_bit_stride
!= nullptr)
19145 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
19146 struct dynamic_prop
*stride
19147 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
19150 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
19151 &high
, bias
, stride
, byte_stride_p
);
19154 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
19156 if (high_bound_is_count
)
19157 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
19159 /* Ada expects an empty array on no boundary attributes. */
19160 if (attr
== NULL
&& cu
->language
!= language_ada
)
19161 range_type
->bounds ()->high
.set_undefined ();
19163 name
= dwarf2_name (die
, cu
);
19165 range_type
->set_name (name
);
19167 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
19168 if (attr
!= nullptr)
19169 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
19171 maybe_set_alignment (cu
, die
, range_type
);
19173 set_die_type (die
, range_type
, cu
);
19175 /* set_die_type should be already done. */
19176 set_descriptive_type (range_type
, die
, cu
);
19181 static struct type
*
19182 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19186 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
19187 type
->set_name (dwarf2_name (die
, cu
));
19189 /* In Ada, an unspecified type is typically used when the description
19190 of the type is deferred to a different unit. When encountering
19191 such a type, we treat it as a stub, and try to resolve it later on,
19193 if (cu
->language
== language_ada
)
19194 type
->set_is_stub (true);
19196 return set_die_type (die
, type
, cu
);
19199 /* Read a single die and all its descendents. Set the die's sibling
19200 field to NULL; set other fields in the die correctly, and set all
19201 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
19202 location of the info_ptr after reading all of those dies. PARENT
19203 is the parent of the die in question. */
19205 static struct die_info
*
19206 read_die_and_children (const struct die_reader_specs
*reader
,
19207 const gdb_byte
*info_ptr
,
19208 const gdb_byte
**new_info_ptr
,
19209 struct die_info
*parent
)
19211 struct die_info
*die
;
19212 const gdb_byte
*cur_ptr
;
19214 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
19217 *new_info_ptr
= cur_ptr
;
19220 store_in_ref_table (die
, reader
->cu
);
19222 if (die
->has_children
)
19223 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
19227 *new_info_ptr
= cur_ptr
;
19230 die
->sibling
= NULL
;
19231 die
->parent
= parent
;
19235 /* Read a die, all of its descendents, and all of its siblings; set
19236 all of the fields of all of the dies correctly. Arguments are as
19237 in read_die_and_children. */
19239 static struct die_info
*
19240 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
19241 const gdb_byte
*info_ptr
,
19242 const gdb_byte
**new_info_ptr
,
19243 struct die_info
*parent
)
19245 struct die_info
*first_die
, *last_sibling
;
19246 const gdb_byte
*cur_ptr
;
19248 cur_ptr
= info_ptr
;
19249 first_die
= last_sibling
= NULL
;
19253 struct die_info
*die
19254 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
19258 *new_info_ptr
= cur_ptr
;
19265 last_sibling
->sibling
= die
;
19267 last_sibling
= die
;
19271 /* Read a die, all of its descendents, and all of its siblings; set
19272 all of the fields of all of the dies correctly. Arguments are as
19273 in read_die_and_children.
19274 This the main entry point for reading a DIE and all its children. */
19276 static struct die_info
*
19277 read_die_and_siblings (const struct die_reader_specs
*reader
,
19278 const gdb_byte
*info_ptr
,
19279 const gdb_byte
**new_info_ptr
,
19280 struct die_info
*parent
)
19282 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
19283 new_info_ptr
, parent
);
19285 if (dwarf_die_debug
)
19287 fprintf_unfiltered (gdb_stdlog
,
19288 "Read die from %s@0x%x of %s:\n",
19289 reader
->die_section
->get_name (),
19290 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19291 bfd_get_filename (reader
->abfd
));
19292 dump_die (die
, dwarf_die_debug
);
19298 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
19300 The caller is responsible for filling in the extra attributes
19301 and updating (*DIEP)->num_attrs.
19302 Set DIEP to point to a newly allocated die with its information,
19303 except for its child, sibling, and parent fields. */
19305 static const gdb_byte
*
19306 read_full_die_1 (const struct die_reader_specs
*reader
,
19307 struct die_info
**diep
, const gdb_byte
*info_ptr
,
19308 int num_extra_attrs
)
19310 unsigned int abbrev_number
, bytes_read
, i
;
19311 const struct abbrev_info
*abbrev
;
19312 struct die_info
*die
;
19313 struct dwarf2_cu
*cu
= reader
->cu
;
19314 bfd
*abfd
= reader
->abfd
;
19316 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
19317 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19318 info_ptr
+= bytes_read
;
19319 if (!abbrev_number
)
19325 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
19327 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
19329 bfd_get_filename (abfd
));
19331 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
19332 die
->sect_off
= sect_off
;
19333 die
->tag
= abbrev
->tag
;
19334 die
->abbrev
= abbrev_number
;
19335 die
->has_children
= abbrev
->has_children
;
19337 /* Make the result usable.
19338 The caller needs to update num_attrs after adding the extra
19340 die
->num_attrs
= abbrev
->num_attrs
;
19342 bool any_need_reprocess
= false;
19343 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19345 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
19347 if (die
->attrs
[i
].requires_reprocessing_p ())
19348 any_need_reprocess
= true;
19351 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
19352 if (attr
!= nullptr && attr
->form_is_unsigned ())
19353 cu
->str_offsets_base
= attr
->as_unsigned ();
19355 attr
= die
->attr (DW_AT_loclists_base
);
19356 if (attr
!= nullptr)
19357 cu
->loclist_base
= attr
->as_unsigned ();
19359 auto maybe_addr_base
= die
->addr_base ();
19360 if (maybe_addr_base
.has_value ())
19361 cu
->addr_base
= *maybe_addr_base
;
19363 attr
= die
->attr (DW_AT_rnglists_base
);
19364 if (attr
!= nullptr)
19365 cu
->rnglists_base
= attr
->as_unsigned ();
19367 if (any_need_reprocess
)
19369 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19371 if (die
->attrs
[i
].requires_reprocessing_p ())
19372 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
19379 /* Read a die and all its attributes.
19380 Set DIEP to point to a newly allocated die with its information,
19381 except for its child, sibling, and parent fields. */
19383 static const gdb_byte
*
19384 read_full_die (const struct die_reader_specs
*reader
,
19385 struct die_info
**diep
, const gdb_byte
*info_ptr
)
19387 const gdb_byte
*result
;
19389 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
19391 if (dwarf_die_debug
)
19393 fprintf_unfiltered (gdb_stdlog
,
19394 "Read die from %s@0x%x of %s:\n",
19395 reader
->die_section
->get_name (),
19396 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19397 bfd_get_filename (reader
->abfd
));
19398 dump_die (*diep
, dwarf_die_debug
);
19405 /* Returns nonzero if TAG represents a type that we might generate a partial
19409 is_type_tag_for_partial (int tag
, enum language lang
)
19414 /* Some types that would be reasonable to generate partial symbols for,
19415 that we don't at present. Note that normally this does not
19416 matter, mainly because C compilers don't give names to these
19417 types, but instead emit DW_TAG_typedef. */
19418 case DW_TAG_file_type
:
19419 case DW_TAG_ptr_to_member_type
:
19420 case DW_TAG_set_type
:
19421 case DW_TAG_string_type
:
19422 case DW_TAG_subroutine_type
:
19425 /* GNAT may emit an array with a name, but no typedef, so we
19426 need to make a symbol in this case. */
19427 case DW_TAG_array_type
:
19428 return lang
== language_ada
;
19430 case DW_TAG_base_type
:
19431 case DW_TAG_class_type
:
19432 case DW_TAG_interface_type
:
19433 case DW_TAG_enumeration_type
:
19434 case DW_TAG_structure_type
:
19435 case DW_TAG_subrange_type
:
19436 case DW_TAG_typedef
:
19437 case DW_TAG_union_type
:
19444 /* Load all DIEs that are interesting for partial symbols into memory. */
19446 static struct partial_die_info
*
19447 load_partial_dies (const struct die_reader_specs
*reader
,
19448 const gdb_byte
*info_ptr
, int building_psymtab
)
19450 struct dwarf2_cu
*cu
= reader
->cu
;
19451 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19452 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
19453 unsigned int bytes_read
;
19454 unsigned int load_all
= 0;
19455 int nesting_level
= 1;
19460 gdb_assert (cu
->per_cu
!= NULL
);
19461 if (cu
->per_cu
->load_all_dies
)
19465 = htab_create_alloc_ex (cu
->header
.length
/ 12,
19469 &cu
->comp_unit_obstack
,
19470 hashtab_obstack_allocate
,
19471 dummy_obstack_deallocate
);
19475 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
19478 /* A NULL abbrev means the end of a series of children. */
19479 if (abbrev
== NULL
)
19481 if (--nesting_level
== 0)
19484 info_ptr
+= bytes_read
;
19485 last_die
= parent_die
;
19486 parent_die
= parent_die
->die_parent
;
19490 /* Check for template arguments. We never save these; if
19491 they're seen, we just mark the parent, and go on our way. */
19492 if (parent_die
!= NULL
19493 && cu
->language
== language_cplus
19494 && (abbrev
->tag
== DW_TAG_template_type_param
19495 || abbrev
->tag
== DW_TAG_template_value_param
))
19497 parent_die
->has_template_arguments
= 1;
19501 /* We don't need a partial DIE for the template argument. */
19502 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19507 /* We only recurse into c++ subprograms looking for template arguments.
19508 Skip their other children. */
19510 && cu
->language
== language_cplus
19511 && parent_die
!= NULL
19512 && parent_die
->tag
== DW_TAG_subprogram
19513 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19515 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19519 /* Check whether this DIE is interesting enough to save. Normally
19520 we would not be interested in members here, but there may be
19521 later variables referencing them via DW_AT_specification (for
19522 static members). */
19524 && !is_type_tag_for_partial (abbrev
->tag
, cu
->language
)
19525 && abbrev
->tag
!= DW_TAG_constant
19526 && abbrev
->tag
!= DW_TAG_enumerator
19527 && abbrev
->tag
!= DW_TAG_subprogram
19528 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19529 && abbrev
->tag
!= DW_TAG_lexical_block
19530 && abbrev
->tag
!= DW_TAG_variable
19531 && abbrev
->tag
!= DW_TAG_namespace
19532 && abbrev
->tag
!= DW_TAG_module
19533 && abbrev
->tag
!= DW_TAG_member
19534 && abbrev
->tag
!= DW_TAG_imported_unit
19535 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19537 /* Otherwise we skip to the next sibling, if any. */
19538 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19542 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19545 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19547 /* This two-pass algorithm for processing partial symbols has a
19548 high cost in cache pressure. Thus, handle some simple cases
19549 here which cover the majority of C partial symbols. DIEs
19550 which neither have specification tags in them, nor could have
19551 specification tags elsewhere pointing at them, can simply be
19552 processed and discarded.
19554 This segment is also optional; scan_partial_symbols and
19555 add_partial_symbol will handle these DIEs if we chain
19556 them in normally. When compilers which do not emit large
19557 quantities of duplicate debug information are more common,
19558 this code can probably be removed. */
19560 /* Any complete simple types at the top level (pretty much all
19561 of them, for a language without namespaces), can be processed
19563 if (parent_die
== NULL
19564 && pdi
.has_specification
== 0
19565 && pdi
.is_declaration
== 0
19566 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19567 || pdi
.tag
== DW_TAG_base_type
19568 || pdi
.tag
== DW_TAG_array_type
19569 || pdi
.tag
== DW_TAG_subrange_type
))
19571 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19572 add_partial_symbol (&pdi
, cu
);
19574 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19578 /* The exception for DW_TAG_typedef with has_children above is
19579 a workaround of GCC PR debug/47510. In the case of this complaint
19580 type_name_or_error will error on such types later.
19582 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19583 it could not find the child DIEs referenced later, this is checked
19584 above. In correct DWARF DW_TAG_typedef should have no children. */
19586 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19587 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19588 "- DIE at %s [in module %s]"),
19589 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19591 /* If we're at the second level, and we're an enumerator, and
19592 our parent has no specification (meaning possibly lives in a
19593 namespace elsewhere), then we can add the partial symbol now
19594 instead of queueing it. */
19595 if (pdi
.tag
== DW_TAG_enumerator
19596 && parent_die
!= NULL
19597 && parent_die
->die_parent
== NULL
19598 && parent_die
->tag
== DW_TAG_enumeration_type
19599 && parent_die
->has_specification
== 0)
19601 if (pdi
.raw_name
== NULL
)
19602 complaint (_("malformed enumerator DIE ignored"));
19603 else if (building_psymtab
)
19604 add_partial_symbol (&pdi
, cu
);
19606 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19610 struct partial_die_info
*part_die
19611 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19613 /* We'll save this DIE so link it in. */
19614 part_die
->die_parent
= parent_die
;
19615 part_die
->die_sibling
= NULL
;
19616 part_die
->die_child
= NULL
;
19618 if (last_die
&& last_die
== parent_die
)
19619 last_die
->die_child
= part_die
;
19621 last_die
->die_sibling
= part_die
;
19623 last_die
= part_die
;
19625 if (first_die
== NULL
)
19626 first_die
= part_die
;
19628 /* Maybe add the DIE to the hash table. Not all DIEs that we
19629 find interesting need to be in the hash table, because we
19630 also have the parent/sibling/child chains; only those that we
19631 might refer to by offset later during partial symbol reading.
19633 For now this means things that might have be the target of a
19634 DW_AT_specification, DW_AT_abstract_origin, or
19635 DW_AT_extension. DW_AT_extension will refer only to
19636 namespaces; DW_AT_abstract_origin refers to functions (and
19637 many things under the function DIE, but we do not recurse
19638 into function DIEs during partial symbol reading) and
19639 possibly variables as well; DW_AT_specification refers to
19640 declarations. Declarations ought to have the DW_AT_declaration
19641 flag. It happens that GCC forgets to put it in sometimes, but
19642 only for functions, not for types.
19644 Adding more things than necessary to the hash table is harmless
19645 except for the performance cost. Adding too few will result in
19646 wasted time in find_partial_die, when we reread the compilation
19647 unit with load_all_dies set. */
19650 || abbrev
->tag
== DW_TAG_constant
19651 || abbrev
->tag
== DW_TAG_subprogram
19652 || abbrev
->tag
== DW_TAG_variable
19653 || abbrev
->tag
== DW_TAG_namespace
19654 || part_die
->is_declaration
)
19658 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19659 to_underlying (part_die
->sect_off
),
19664 /* For some DIEs we want to follow their children (if any). For C
19665 we have no reason to follow the children of structures; for other
19666 languages we have to, so that we can get at method physnames
19667 to infer fully qualified class names, for DW_AT_specification,
19668 and for C++ template arguments. For C++, we also look one level
19669 inside functions to find template arguments (if the name of the
19670 function does not already contain the template arguments).
19672 For Ada and Fortran, we need to scan the children of subprograms
19673 and lexical blocks as well because these languages allow the
19674 definition of nested entities that could be interesting for the
19675 debugger, such as nested subprograms for instance. */
19676 if (last_die
->has_children
19678 || last_die
->tag
== DW_TAG_namespace
19679 || last_die
->tag
== DW_TAG_module
19680 || last_die
->tag
== DW_TAG_enumeration_type
19681 || (cu
->language
== language_cplus
19682 && last_die
->tag
== DW_TAG_subprogram
19683 && (last_die
->raw_name
== NULL
19684 || strchr (last_die
->raw_name
, '<') == NULL
))
19685 || (cu
->language
!= language_c
19686 && (last_die
->tag
== DW_TAG_class_type
19687 || last_die
->tag
== DW_TAG_interface_type
19688 || last_die
->tag
== DW_TAG_structure_type
19689 || last_die
->tag
== DW_TAG_union_type
))
19690 || ((cu
->language
== language_ada
19691 || cu
->language
== language_fortran
)
19692 && (last_die
->tag
== DW_TAG_subprogram
19693 || last_die
->tag
== DW_TAG_lexical_block
))))
19696 parent_die
= last_die
;
19700 /* Otherwise we skip to the next sibling, if any. */
19701 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19703 /* Back to the top, do it again. */
19707 partial_die_info::partial_die_info (sect_offset sect_off_
,
19708 const struct abbrev_info
*abbrev
)
19709 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19713 /* See class definition. */
19716 partial_die_info::name (dwarf2_cu
*cu
)
19718 if (!canonical_name
&& raw_name
!= nullptr)
19720 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19721 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19722 canonical_name
= 1;
19728 /* Read a minimal amount of information into the minimal die structure.
19729 INFO_PTR should point just after the initial uleb128 of a DIE. */
19732 partial_die_info::read (const struct die_reader_specs
*reader
,
19733 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19735 struct dwarf2_cu
*cu
= reader
->cu
;
19736 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19738 int has_low_pc_attr
= 0;
19739 int has_high_pc_attr
= 0;
19740 int high_pc_relative
= 0;
19742 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19745 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19746 /* String and address offsets that need to do the reprocessing have
19747 already been read at this point, so there is no need to wait until
19748 the loop terminates to do the reprocessing. */
19749 if (attr
.requires_reprocessing_p ())
19750 read_attribute_reprocess (reader
, &attr
, tag
);
19751 /* Store the data if it is of an attribute we want to keep in a
19752 partial symbol table. */
19758 case DW_TAG_compile_unit
:
19759 case DW_TAG_partial_unit
:
19760 case DW_TAG_type_unit
:
19761 /* Compilation units have a DW_AT_name that is a filename, not
19762 a source language identifier. */
19763 case DW_TAG_enumeration_type
:
19764 case DW_TAG_enumerator
:
19765 /* These tags always have simple identifiers already; no need
19766 to canonicalize them. */
19767 canonical_name
= 1;
19768 raw_name
= attr
.as_string ();
19771 canonical_name
= 0;
19772 raw_name
= attr
.as_string ();
19776 case DW_AT_linkage_name
:
19777 case DW_AT_MIPS_linkage_name
:
19778 /* Note that both forms of linkage name might appear. We
19779 assume they will be the same, and we only store the last
19781 linkage_name
= attr
.as_string ();
19784 has_low_pc_attr
= 1;
19785 lowpc
= attr
.as_address ();
19787 case DW_AT_high_pc
:
19788 has_high_pc_attr
= 1;
19789 highpc
= attr
.as_address ();
19790 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19791 high_pc_relative
= 1;
19793 case DW_AT_location
:
19794 /* Support the .debug_loc offsets. */
19795 if (attr
.form_is_block ())
19797 d
.locdesc
= attr
.as_block ();
19799 else if (attr
.form_is_section_offset ())
19801 dwarf2_complex_location_expr_complaint ();
19805 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19806 "partial symbol information");
19809 case DW_AT_external
:
19810 is_external
= attr
.as_boolean ();
19812 case DW_AT_declaration
:
19813 is_declaration
= attr
.as_boolean ();
19818 case DW_AT_abstract_origin
:
19819 case DW_AT_specification
:
19820 case DW_AT_extension
:
19821 has_specification
= 1;
19822 spec_offset
= attr
.get_ref_die_offset ();
19823 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19824 || cu
->per_cu
->is_dwz
);
19826 case DW_AT_sibling
:
19827 /* Ignore absolute siblings, they might point outside of
19828 the current compile unit. */
19829 if (attr
.form
== DW_FORM_ref_addr
)
19830 complaint (_("ignoring absolute DW_AT_sibling"));
19833 const gdb_byte
*buffer
= reader
->buffer
;
19834 sect_offset off
= attr
.get_ref_die_offset ();
19835 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19837 if (sibling_ptr
< info_ptr
)
19838 complaint (_("DW_AT_sibling points backwards"));
19839 else if (sibling_ptr
> reader
->buffer_end
)
19840 reader
->die_section
->overflow_complaint ();
19842 sibling
= sibling_ptr
;
19845 case DW_AT_byte_size
:
19848 case DW_AT_const_value
:
19849 has_const_value
= 1;
19851 case DW_AT_calling_convention
:
19852 /* DWARF doesn't provide a way to identify a program's source-level
19853 entry point. DW_AT_calling_convention attributes are only meant
19854 to describe functions' calling conventions.
19856 However, because it's a necessary piece of information in
19857 Fortran, and before DWARF 4 DW_CC_program was the only
19858 piece of debugging information whose definition refers to
19859 a 'main program' at all, several compilers marked Fortran
19860 main programs with DW_CC_program --- even when those
19861 functions use the standard calling conventions.
19863 Although DWARF now specifies a way to provide this
19864 information, we support this practice for backward
19866 if (attr
.constant_value (0) == DW_CC_program
19867 && cu
->language
== language_fortran
)
19868 main_subprogram
= 1;
19872 LONGEST value
= attr
.constant_value (-1);
19873 if (value
== DW_INL_inlined
19874 || value
== DW_INL_declared_inlined
)
19875 may_be_inlined
= 1;
19880 if (tag
== DW_TAG_imported_unit
)
19882 d
.sect_off
= attr
.get_ref_die_offset ();
19883 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19884 || cu
->per_cu
->is_dwz
);
19888 case DW_AT_main_subprogram
:
19889 main_subprogram
= attr
.as_boolean ();
19894 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19895 on DWARF version). */
19896 ULONGEST ranges_offset
= attr
.as_unsigned ();
19898 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19900 if (tag
!= DW_TAG_compile_unit
)
19901 ranges_offset
+= cu
->gnu_ranges_base
;
19903 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19914 /* For Ada, if both the name and the linkage name appear, we prefer
19915 the latter. This lets "catch exception" work better, regardless
19916 of the order in which the name and linkage name were emitted.
19917 Really, though, this is just a workaround for the fact that gdb
19918 doesn't store both the name and the linkage name. */
19919 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19920 raw_name
= linkage_name
;
19922 if (high_pc_relative
)
19925 if (has_low_pc_attr
&& has_high_pc_attr
)
19927 /* When using the GNU linker, .gnu.linkonce. sections are used to
19928 eliminate duplicate copies of functions and vtables and such.
19929 The linker will arbitrarily choose one and discard the others.
19930 The AT_*_pc values for such functions refer to local labels in
19931 these sections. If the section from that file was discarded, the
19932 labels are not in the output, so the relocs get a value of 0.
19933 If this is a discarded function, mark the pc bounds as invalid,
19934 so that GDB will ignore it. */
19935 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19937 struct objfile
*objfile
= per_objfile
->objfile
;
19938 struct gdbarch
*gdbarch
= objfile
->arch ();
19940 complaint (_("DW_AT_low_pc %s is zero "
19941 "for DIE at %s [in module %s]"),
19942 paddress (gdbarch
, lowpc
),
19943 sect_offset_str (sect_off
),
19944 objfile_name (objfile
));
19946 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19947 else if (lowpc
>= highpc
)
19949 struct objfile
*objfile
= per_objfile
->objfile
;
19950 struct gdbarch
*gdbarch
= objfile
->arch ();
19952 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19953 "for DIE at %s [in module %s]"),
19954 paddress (gdbarch
, lowpc
),
19955 paddress (gdbarch
, highpc
),
19956 sect_offset_str (sect_off
),
19957 objfile_name (objfile
));
19966 /* Find a cached partial DIE at OFFSET in CU. */
19968 struct partial_die_info
*
19969 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19971 struct partial_die_info
*lookup_die
= NULL
;
19972 struct partial_die_info
part_die (sect_off
);
19974 lookup_die
= ((struct partial_die_info
*)
19975 htab_find_with_hash (partial_dies
, &part_die
,
19976 to_underlying (sect_off
)));
19981 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19982 except in the case of .debug_types DIEs which do not reference
19983 outside their CU (they do however referencing other types via
19984 DW_FORM_ref_sig8). */
19986 static const struct cu_partial_die_info
19987 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19989 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19990 struct objfile
*objfile
= per_objfile
->objfile
;
19991 struct partial_die_info
*pd
= NULL
;
19993 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19994 && cu
->header
.offset_in_cu_p (sect_off
))
19996 pd
= cu
->find_partial_die (sect_off
);
19999 /* We missed recording what we needed.
20000 Load all dies and try again. */
20004 /* TUs don't reference other CUs/TUs (except via type signatures). */
20005 if (cu
->per_cu
->is_debug_types
)
20007 error (_("Dwarf Error: Type Unit at offset %s contains"
20008 " external reference to offset %s [in module %s].\n"),
20009 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
20010 bfd_get_filename (objfile
->obfd
));
20012 dwarf2_per_cu_data
*per_cu
20013 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
20016 cu
= per_objfile
->get_cu (per_cu
);
20017 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
20018 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
20020 cu
= per_objfile
->get_cu (per_cu
);
20023 pd
= cu
->find_partial_die (sect_off
);
20026 /* If we didn't find it, and not all dies have been loaded,
20027 load them all and try again. */
20029 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
20031 cu
->per_cu
->load_all_dies
= 1;
20033 /* This is nasty. When we reread the DIEs, somewhere up the call chain
20034 THIS_CU->cu may already be in use. So we can't just free it and
20035 replace its DIEs with the ones we read in. Instead, we leave those
20036 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
20037 and clobber THIS_CU->cu->partial_dies with the hash table for the new
20039 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
20041 pd
= cu
->find_partial_die (sect_off
);
20045 error (_("Dwarf Error: Cannot not find DIE at %s [from module %s]\n"),
20046 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
20050 /* See if we can figure out if the class lives in a namespace. We do
20051 this by looking for a member function; its demangled name will
20052 contain namespace info, if there is any. */
20055 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
20056 struct dwarf2_cu
*cu
)
20058 /* NOTE: carlton/2003-10-07: Getting the info this way changes
20059 what template types look like, because the demangler
20060 frequently doesn't give the same name as the debug info. We
20061 could fix this by only using the demangled name to get the
20062 prefix (but see comment in read_structure_type). */
20064 struct partial_die_info
*real_pdi
;
20065 struct partial_die_info
*child_pdi
;
20067 /* If this DIE (this DIE's specification, if any) has a parent, then
20068 we should not do this. We'll prepend the parent's fully qualified
20069 name when we create the partial symbol. */
20071 real_pdi
= struct_pdi
;
20072 while (real_pdi
->has_specification
)
20074 auto res
= find_partial_die (real_pdi
->spec_offset
,
20075 real_pdi
->spec_is_dwz
, cu
);
20076 real_pdi
= res
.pdi
;
20080 if (real_pdi
->die_parent
!= NULL
)
20083 for (child_pdi
= struct_pdi
->die_child
;
20085 child_pdi
= child_pdi
->die_sibling
)
20087 if (child_pdi
->tag
== DW_TAG_subprogram
20088 && child_pdi
->linkage_name
!= NULL
)
20090 gdb::unique_xmalloc_ptr
<char> actual_class_name
20091 (cu
->language_defn
->class_name_from_physname
20092 (child_pdi
->linkage_name
));
20093 if (actual_class_name
!= NULL
)
20095 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20096 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
20097 struct_pdi
->canonical_name
= 1;
20104 /* Return true if a DIE with TAG may have the DW_AT_const_value
20108 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
20112 case DW_TAG_constant
:
20113 case DW_TAG_enumerator
:
20114 case DW_TAG_formal_parameter
:
20115 case DW_TAG_template_value_param
:
20116 case DW_TAG_variable
:
20124 partial_die_info::fixup (struct dwarf2_cu
*cu
)
20126 /* Once we've fixed up a die, there's no point in doing so again.
20127 This also avoids a memory leak if we were to call
20128 guess_partial_die_structure_name multiple times. */
20132 /* If we found a reference attribute and the DIE has no name, try
20133 to find a name in the referred to DIE. */
20135 if (raw_name
== NULL
&& has_specification
)
20137 struct partial_die_info
*spec_die
;
20139 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
20140 spec_die
= res
.pdi
;
20143 spec_die
->fixup (cu
);
20145 if (spec_die
->raw_name
)
20147 raw_name
= spec_die
->raw_name
;
20148 canonical_name
= spec_die
->canonical_name
;
20150 /* Copy DW_AT_external attribute if it is set. */
20151 if (spec_die
->is_external
)
20152 is_external
= spec_die
->is_external
;
20156 if (!has_const_value
&& has_specification
20157 && can_have_DW_AT_const_value_p (tag
))
20159 struct partial_die_info
*spec_die
;
20161 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
20162 spec_die
= res
.pdi
;
20165 spec_die
->fixup (cu
);
20167 if (spec_die
->has_const_value
)
20169 /* Copy DW_AT_const_value attribute if it is set. */
20170 has_const_value
= spec_die
->has_const_value
;
20174 /* Set default names for some unnamed DIEs. */
20176 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
20178 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
20179 canonical_name
= 1;
20182 /* If there is no parent die to provide a namespace, and there are
20183 children, see if we can determine the namespace from their linkage
20185 if (cu
->language
== language_cplus
20186 && !cu
->per_objfile
->per_bfd
->types
.empty ()
20187 && die_parent
== NULL
20189 && (tag
== DW_TAG_class_type
20190 || tag
== DW_TAG_structure_type
20191 || tag
== DW_TAG_union_type
))
20192 guess_partial_die_structure_name (this, cu
);
20194 /* GCC might emit a nameless struct or union that has a linkage
20195 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20196 if (raw_name
== NULL
20197 && (tag
== DW_TAG_class_type
20198 || tag
== DW_TAG_interface_type
20199 || tag
== DW_TAG_structure_type
20200 || tag
== DW_TAG_union_type
)
20201 && linkage_name
!= NULL
)
20203 gdb::unique_xmalloc_ptr
<char> demangled
20204 (gdb_demangle (linkage_name
, DMGL_TYPES
));
20205 if (demangled
!= nullptr)
20209 /* Strip any leading namespaces/classes, keep only the base name.
20210 DW_AT_name for named DIEs does not contain the prefixes. */
20211 base
= strrchr (demangled
.get (), ':');
20212 if (base
&& base
> demangled
.get () && base
[-1] == ':')
20215 base
= demangled
.get ();
20217 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20218 raw_name
= objfile
->intern (base
);
20219 canonical_name
= 1;
20226 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
20227 contents from the given SECTION in the HEADER.
20229 HEADER_OFFSET is the offset of the header in the section. */
20231 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
20232 struct dwarf2_section_info
*section
,
20233 sect_offset header_offset
)
20235 unsigned int bytes_read
;
20236 bfd
*abfd
= section
->get_bfd_owner ();
20237 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
20239 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
20240 info_ptr
+= bytes_read
;
20242 header
->version
= read_2_bytes (abfd
, info_ptr
);
20245 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
20248 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
20251 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
20254 /* Return the DW_AT_loclists_base value for the CU. */
20256 lookup_loclist_base (struct dwarf2_cu
*cu
)
20258 /* For the .dwo unit, the loclist_base points to the first offset following
20259 the header. The header consists of the following entities-
20260 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
20262 2. version (2 bytes)
20263 3. address size (1 byte)
20264 4. segment selector size (1 byte)
20265 5. offset entry count (4 bytes)
20266 These sizes are derived as per the DWARFv5 standard. */
20267 if (cu
->dwo_unit
!= nullptr)
20269 if (cu
->header
.initial_length_size
== 4)
20270 return LOCLIST_HEADER_SIZE32
;
20271 return LOCLIST_HEADER_SIZE64
;
20273 return cu
->loclist_base
;
20276 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
20277 array of offsets in the .debug_loclists section. */
20280 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
20282 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20283 struct objfile
*objfile
= per_objfile
->objfile
;
20284 bfd
*abfd
= objfile
->obfd
;
20285 ULONGEST loclist_header_size
=
20286 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
20287 : LOCLIST_HEADER_SIZE64
);
20288 ULONGEST loclist_base
= lookup_loclist_base (cu
);
20290 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
20291 ULONGEST start_offset
=
20292 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
20294 /* Get loclists section. */
20295 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
20297 /* Read the loclists section content. */
20298 section
->read (objfile
);
20299 if (section
->buffer
== NULL
)
20300 error (_("DW_FORM_loclistx used without .debug_loclists "
20301 "section [in module %s]"), objfile_name (objfile
));
20303 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
20304 so if loclist_base is smaller than the header size, we have a problem. */
20305 if (loclist_base
< loclist_header_size
)
20306 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
20307 objfile_name (objfile
));
20309 /* Read the header of the loclists contribution. */
20310 struct loclists_rnglists_header header
;
20311 read_loclists_rnglists_header (&header
, section
,
20312 (sect_offset
) (loclist_base
- loclist_header_size
));
20314 /* Verify the loclist index is valid. */
20315 if (loclist_index
>= header
.offset_entry_count
)
20316 error (_("DW_FORM_loclistx pointing outside of "
20317 ".debug_loclists offset array [in module %s]"),
20318 objfile_name (objfile
));
20320 /* Validate that reading won't go beyond the end of the section. */
20321 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
20322 error (_("Reading DW_FORM_loclistx index beyond end of"
20323 ".debug_loclists section [in module %s]"),
20324 objfile_name (objfile
));
20326 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20328 if (cu
->header
.offset_size
== 4)
20329 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
20331 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
20334 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
20335 array of offsets in the .debug_rnglists section. */
20338 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
20341 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
20342 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20343 bfd
*abfd
= objfile
->obfd
;
20344 ULONGEST rnglist_header_size
=
20345 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
20346 : RNGLIST_HEADER_SIZE64
);
20348 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
20349 .debug_rnglists.dwo section. The rnglists base given in the skeleton
20351 ULONGEST rnglist_base
=
20352 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
20354 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
20355 ULONGEST start_offset
=
20356 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
20358 /* Get rnglists section. */
20359 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
20361 /* Read the rnglists section content. */
20362 section
->read (objfile
);
20363 if (section
->buffer
== nullptr)
20364 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
20366 objfile_name (objfile
));
20368 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
20369 so if rnglist_base is smaller than the header size, we have a problem. */
20370 if (rnglist_base
< rnglist_header_size
)
20371 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
20372 objfile_name (objfile
));
20374 /* Read the header of the rnglists contribution. */
20375 struct loclists_rnglists_header header
;
20376 read_loclists_rnglists_header (&header
, section
,
20377 (sect_offset
) (rnglist_base
- rnglist_header_size
));
20379 /* Verify the rnglist index is valid. */
20380 if (rnglist_index
>= header
.offset_entry_count
)
20381 error (_("DW_FORM_rnglistx index pointing outside of "
20382 ".debug_rnglists offset array [in module %s]"),
20383 objfile_name (objfile
));
20385 /* Validate that reading won't go beyond the end of the section. */
20386 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
20387 error (_("Reading DW_FORM_rnglistx index beyond end of"
20388 ".debug_rnglists section [in module %s]"),
20389 objfile_name (objfile
));
20391 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20393 if (cu
->header
.offset_size
== 4)
20394 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
20396 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
20399 /* Process the attributes that had to be skipped in the first round. These
20400 attributes are the ones that need str_offsets_base or addr_base attributes.
20401 They could not have been processed in the first round, because at the time
20402 the values of str_offsets_base or addr_base may not have been known. */
20404 read_attribute_reprocess (const struct die_reader_specs
*reader
,
20405 struct attribute
*attr
, dwarf_tag tag
)
20407 struct dwarf2_cu
*cu
= reader
->cu
;
20408 switch (attr
->form
)
20410 case DW_FORM_addrx
:
20411 case DW_FORM_GNU_addr_index
:
20412 attr
->set_address (read_addr_index (cu
,
20413 attr
->as_unsigned_reprocess ()));
20415 case DW_FORM_loclistx
:
20417 sect_offset loclists_sect_off
20418 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
20420 attr
->set_unsigned (to_underlying (loclists_sect_off
));
20423 case DW_FORM_rnglistx
:
20425 sect_offset rnglists_sect_off
20426 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
20428 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
20432 case DW_FORM_strx1
:
20433 case DW_FORM_strx2
:
20434 case DW_FORM_strx3
:
20435 case DW_FORM_strx4
:
20436 case DW_FORM_GNU_str_index
:
20438 unsigned int str_index
= attr
->as_unsigned_reprocess ();
20439 gdb_assert (!attr
->canonical_string_p ());
20440 if (reader
->dwo_file
!= NULL
)
20441 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
20444 attr
->set_string_noncanonical (read_stub_str_index (cu
,
20449 gdb_assert_not_reached (_("Unexpected DWARF form."));
20453 /* Read an attribute value described by an attribute form. */
20455 static const gdb_byte
*
20456 read_attribute_value (const struct die_reader_specs
*reader
,
20457 struct attribute
*attr
, unsigned form
,
20458 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
20460 struct dwarf2_cu
*cu
= reader
->cu
;
20461 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20462 struct objfile
*objfile
= per_objfile
->objfile
;
20463 bfd
*abfd
= reader
->abfd
;
20464 struct comp_unit_head
*cu_header
= &cu
->header
;
20465 unsigned int bytes_read
;
20466 struct dwarf_block
*blk
;
20468 attr
->form
= (enum dwarf_form
) form
;
20471 case DW_FORM_ref_addr
:
20472 if (cu_header
->version
== 2)
20473 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
20476 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20478 info_ptr
+= bytes_read
;
20480 case DW_FORM_GNU_ref_alt
:
20481 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20483 info_ptr
+= bytes_read
;
20487 struct gdbarch
*gdbarch
= objfile
->arch ();
20488 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
20489 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
20490 attr
->set_address (addr
);
20491 info_ptr
+= bytes_read
;
20494 case DW_FORM_block2
:
20495 blk
= dwarf_alloc_block (cu
);
20496 blk
->size
= read_2_bytes (abfd
, info_ptr
);
20498 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20499 info_ptr
+= blk
->size
;
20500 attr
->set_block (blk
);
20502 case DW_FORM_block4
:
20503 blk
= dwarf_alloc_block (cu
);
20504 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20506 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20507 info_ptr
+= blk
->size
;
20508 attr
->set_block (blk
);
20510 case DW_FORM_data2
:
20511 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20514 case DW_FORM_data4
:
20515 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20518 case DW_FORM_data8
:
20519 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20522 case DW_FORM_data16
:
20523 blk
= dwarf_alloc_block (cu
);
20525 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20527 attr
->set_block (blk
);
20529 case DW_FORM_sec_offset
:
20530 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20532 info_ptr
+= bytes_read
;
20534 case DW_FORM_loclistx
:
20536 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20538 info_ptr
+= bytes_read
;
20541 case DW_FORM_string
:
20542 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20544 info_ptr
+= bytes_read
;
20547 if (!cu
->per_cu
->is_dwz
)
20549 attr
->set_string_noncanonical
20550 (read_indirect_string (per_objfile
,
20551 abfd
, info_ptr
, cu_header
,
20553 info_ptr
+= bytes_read
;
20557 case DW_FORM_line_strp
:
20558 if (!cu
->per_cu
->is_dwz
)
20560 attr
->set_string_noncanonical
20561 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20563 info_ptr
+= bytes_read
;
20567 case DW_FORM_GNU_strp_alt
:
20569 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20570 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20573 attr
->set_string_noncanonical
20574 (dwz
->read_string (objfile
, str_offset
));
20575 info_ptr
+= bytes_read
;
20578 case DW_FORM_exprloc
:
20579 case DW_FORM_block
:
20580 blk
= dwarf_alloc_block (cu
);
20581 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20582 info_ptr
+= bytes_read
;
20583 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20584 info_ptr
+= blk
->size
;
20585 attr
->set_block (blk
);
20587 case DW_FORM_block1
:
20588 blk
= dwarf_alloc_block (cu
);
20589 blk
->size
= read_1_byte (abfd
, info_ptr
);
20591 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20592 info_ptr
+= blk
->size
;
20593 attr
->set_block (blk
);
20595 case DW_FORM_data1
:
20597 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20600 case DW_FORM_flag_present
:
20601 attr
->set_unsigned (1);
20603 case DW_FORM_sdata
:
20604 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20605 info_ptr
+= bytes_read
;
20607 case DW_FORM_rnglistx
:
20609 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20611 info_ptr
+= bytes_read
;
20614 case DW_FORM_udata
:
20615 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20616 info_ptr
+= bytes_read
;
20619 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20620 + read_1_byte (abfd
, info_ptr
)));
20624 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20625 + read_2_bytes (abfd
, info_ptr
)));
20629 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20630 + read_4_bytes (abfd
, info_ptr
)));
20634 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20635 + read_8_bytes (abfd
, info_ptr
)));
20638 case DW_FORM_ref_sig8
:
20639 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20642 case DW_FORM_ref_udata
:
20643 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20644 + read_unsigned_leb128 (abfd
, info_ptr
,
20646 info_ptr
+= bytes_read
;
20648 case DW_FORM_indirect
:
20649 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20650 info_ptr
+= bytes_read
;
20651 if (form
== DW_FORM_implicit_const
)
20653 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20654 info_ptr
+= bytes_read
;
20656 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20659 case DW_FORM_implicit_const
:
20660 attr
->set_signed (implicit_const
);
20662 case DW_FORM_addrx
:
20663 case DW_FORM_GNU_addr_index
:
20664 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20666 info_ptr
+= bytes_read
;
20669 case DW_FORM_strx1
:
20670 case DW_FORM_strx2
:
20671 case DW_FORM_strx3
:
20672 case DW_FORM_strx4
:
20673 case DW_FORM_GNU_str_index
:
20675 ULONGEST str_index
;
20676 if (form
== DW_FORM_strx1
)
20678 str_index
= read_1_byte (abfd
, info_ptr
);
20681 else if (form
== DW_FORM_strx2
)
20683 str_index
= read_2_bytes (abfd
, info_ptr
);
20686 else if (form
== DW_FORM_strx3
)
20688 str_index
= read_3_bytes (abfd
, info_ptr
);
20691 else if (form
== DW_FORM_strx4
)
20693 str_index
= read_4_bytes (abfd
, info_ptr
);
20698 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20699 info_ptr
+= bytes_read
;
20701 attr
->set_unsigned_reprocess (str_index
);
20705 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20706 dwarf_form_name (form
),
20707 bfd_get_filename (abfd
));
20711 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20712 attr
->form
= DW_FORM_GNU_ref_alt
;
20714 /* We have seen instances where the compiler tried to emit a byte
20715 size attribute of -1 which ended up being encoded as an unsigned
20716 0xffffffff. Although 0xffffffff is technically a valid size value,
20717 an object of this size seems pretty unlikely so we can relatively
20718 safely treat these cases as if the size attribute was invalid and
20719 treat them as zero by default. */
20720 if (attr
->name
== DW_AT_byte_size
20721 && form
== DW_FORM_data4
20722 && attr
->as_unsigned () >= 0xffffffff)
20725 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20726 hex_string (attr
->as_unsigned ()));
20727 attr
->set_unsigned (0);
20733 /* Read an attribute described by an abbreviated attribute. */
20735 static const gdb_byte
*
20736 read_attribute (const struct die_reader_specs
*reader
,
20737 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20738 const gdb_byte
*info_ptr
)
20740 attr
->name
= abbrev
->name
;
20741 attr
->string_is_canonical
= 0;
20742 attr
->requires_reprocessing
= 0;
20743 return read_attribute_value (reader
, attr
, abbrev
->form
,
20744 abbrev
->implicit_const
, info_ptr
);
20747 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20749 static const char *
20750 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20751 LONGEST str_offset
)
20753 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20754 str_offset
, "DW_FORM_strp");
20757 /* Return pointer to string at .debug_str offset as read from BUF.
20758 BUF is assumed to be in a compilation unit described by CU_HEADER.
20759 Return *BYTES_READ_PTR count of bytes read from BUF. */
20761 static const char *
20762 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20763 const gdb_byte
*buf
,
20764 const struct comp_unit_head
*cu_header
,
20765 unsigned int *bytes_read_ptr
)
20767 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20769 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20775 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20776 const struct comp_unit_head
*cu_header
,
20777 unsigned int *bytes_read_ptr
)
20779 bfd
*abfd
= objfile
->obfd
;
20780 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20782 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20785 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20786 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20787 ADDR_SIZE is the size of addresses from the CU header. */
20790 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20791 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20793 struct objfile
*objfile
= per_objfile
->objfile
;
20794 bfd
*abfd
= objfile
->obfd
;
20795 const gdb_byte
*info_ptr
;
20796 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20798 per_objfile
->per_bfd
->addr
.read (objfile
);
20799 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20800 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20801 objfile_name (objfile
));
20802 if (addr_base_or_zero
+ addr_index
* addr_size
20803 >= per_objfile
->per_bfd
->addr
.size
)
20804 error (_("DW_FORM_addr_index pointing outside of "
20805 ".debug_addr section [in module %s]"),
20806 objfile_name (objfile
));
20807 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20808 + addr_index
* addr_size
);
20809 if (addr_size
== 4)
20810 return bfd_get_32 (abfd
, info_ptr
);
20812 return bfd_get_64 (abfd
, info_ptr
);
20815 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20818 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20820 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20821 cu
->addr_base
, cu
->header
.addr_size
);
20824 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20827 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20828 unsigned int *bytes_read
)
20830 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20831 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20833 return read_addr_index (cu
, addr_index
);
20839 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20840 dwarf2_per_objfile
*per_objfile
,
20841 unsigned int addr_index
)
20843 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20844 gdb::optional
<ULONGEST
> addr_base
;
20847 /* We need addr_base and addr_size.
20848 If we don't have PER_CU->cu, we have to get it.
20849 Nasty, but the alternative is storing the needed info in PER_CU,
20850 which at this point doesn't seem justified: it's not clear how frequently
20851 it would get used and it would increase the size of every PER_CU.
20852 Entry points like dwarf2_per_cu_addr_size do a similar thing
20853 so we're not in uncharted territory here.
20854 Alas we need to be a bit more complicated as addr_base is contained
20857 We don't need to read the entire CU(/TU).
20858 We just need the header and top level die.
20860 IWBN to use the aging mechanism to let us lazily later discard the CU.
20861 For now we skip this optimization. */
20865 addr_base
= cu
->addr_base
;
20866 addr_size
= cu
->header
.addr_size
;
20870 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20871 addr_base
= reader
.cu
->addr_base
;
20872 addr_size
= reader
.cu
->header
.addr_size
;
20875 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20878 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20879 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20882 static const char *
20883 read_str_index (struct dwarf2_cu
*cu
,
20884 struct dwarf2_section_info
*str_section
,
20885 struct dwarf2_section_info
*str_offsets_section
,
20886 ULONGEST str_offsets_base
, ULONGEST str_index
)
20888 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20889 struct objfile
*objfile
= per_objfile
->objfile
;
20890 const char *objf_name
= objfile_name (objfile
);
20891 bfd
*abfd
= objfile
->obfd
;
20892 const gdb_byte
*info_ptr
;
20893 ULONGEST str_offset
;
20894 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20896 str_section
->read (objfile
);
20897 str_offsets_section
->read (objfile
);
20898 if (str_section
->buffer
== NULL
)
20899 error (_("%s used without %s section"
20900 " in CU at offset %s [in module %s]"),
20901 form_name
, str_section
->get_name (),
20902 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20903 if (str_offsets_section
->buffer
== NULL
)
20904 error (_("%s used without %s section"
20905 " in CU at offset %s [in module %s]"),
20906 form_name
, str_section
->get_name (),
20907 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20908 info_ptr
= (str_offsets_section
->buffer
20910 + str_index
* cu
->header
.offset_size
);
20911 if (cu
->header
.offset_size
== 4)
20912 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20914 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20915 if (str_offset
>= str_section
->size
)
20916 error (_("Offset from %s pointing outside of"
20917 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20918 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20919 return (const char *) (str_section
->buffer
+ str_offset
);
20922 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20924 static const char *
20925 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20927 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20928 ? reader
->cu
->header
.addr_size
: 0;
20929 return read_str_index (reader
->cu
,
20930 &reader
->dwo_file
->sections
.str
,
20931 &reader
->dwo_file
->sections
.str_offsets
,
20932 str_offsets_base
, str_index
);
20935 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20937 static const char *
20938 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20940 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20941 const char *objf_name
= objfile_name (objfile
);
20942 static const char form_name
[] = "DW_FORM_GNU_str_index";
20943 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20945 if (!cu
->str_offsets_base
.has_value ())
20946 error (_("%s used in Fission stub without %s"
20947 " in CU at offset 0x%lx [in module %s]"),
20948 form_name
, str_offsets_attr_name
,
20949 (long) cu
->header
.offset_size
, objf_name
);
20951 return read_str_index (cu
,
20952 &cu
->per_objfile
->per_bfd
->str
,
20953 &cu
->per_objfile
->per_bfd
->str_offsets
,
20954 *cu
->str_offsets_base
, str_index
);
20957 /* Return the length of an LEB128 number in BUF. */
20960 leb128_size (const gdb_byte
*buf
)
20962 const gdb_byte
*begin
= buf
;
20968 if ((byte
& 128) == 0)
20969 return buf
- begin
;
20974 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20983 cu
->language
= language_c
;
20986 case DW_LANG_C_plus_plus
:
20987 case DW_LANG_C_plus_plus_11
:
20988 case DW_LANG_C_plus_plus_14
:
20989 cu
->language
= language_cplus
;
20992 cu
->language
= language_d
;
20994 case DW_LANG_Fortran77
:
20995 case DW_LANG_Fortran90
:
20996 case DW_LANG_Fortran95
:
20997 case DW_LANG_Fortran03
:
20998 case DW_LANG_Fortran08
:
20999 cu
->language
= language_fortran
;
21002 cu
->language
= language_go
;
21004 case DW_LANG_Mips_Assembler
:
21005 cu
->language
= language_asm
;
21007 case DW_LANG_Ada83
:
21008 case DW_LANG_Ada95
:
21009 cu
->language
= language_ada
;
21011 case DW_LANG_Modula2
:
21012 cu
->language
= language_m2
;
21014 case DW_LANG_Pascal83
:
21015 cu
->language
= language_pascal
;
21018 cu
->language
= language_objc
;
21021 case DW_LANG_Rust_old
:
21022 cu
->language
= language_rust
;
21024 case DW_LANG_Cobol74
:
21025 case DW_LANG_Cobol85
:
21027 cu
->language
= language_minimal
;
21030 cu
->language_defn
= language_def (cu
->language
);
21033 /* Return the named attribute or NULL if not there. */
21035 static struct attribute
*
21036 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
21041 struct attribute
*spec
= NULL
;
21043 for (i
= 0; i
< die
->num_attrs
; ++i
)
21045 if (die
->attrs
[i
].name
== name
)
21046 return &die
->attrs
[i
];
21047 if (die
->attrs
[i
].name
== DW_AT_specification
21048 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
21049 spec
= &die
->attrs
[i
];
21055 die
= follow_die_ref (die
, spec
, &cu
);
21061 /* Return the string associated with a string-typed attribute, or NULL if it
21062 is either not found or is of an incorrect type. */
21064 static const char *
21065 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
21067 struct attribute
*attr
;
21068 const char *str
= NULL
;
21070 attr
= dwarf2_attr (die
, name
, cu
);
21074 str
= attr
->as_string ();
21075 if (str
== nullptr)
21076 complaint (_("string type expected for attribute %s for "
21077 "DIE at %s in module %s"),
21078 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
21079 objfile_name (cu
->per_objfile
->objfile
));
21085 /* Return the dwo name or NULL if not present. If present, it is in either
21086 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
21087 static const char *
21088 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21090 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
21091 if (dwo_name
== nullptr)
21092 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
21096 /* Return non-zero iff the attribute NAME is defined for the given DIE,
21097 and holds a non-zero value. This function should only be used for
21098 DW_FORM_flag or DW_FORM_flag_present attributes. */
21101 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
21103 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
21105 return attr
!= nullptr && attr
->as_boolean ();
21109 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
21111 /* A DIE is a declaration if it has a DW_AT_declaration attribute
21112 which value is non-zero. However, we have to be careful with
21113 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
21114 (via dwarf2_flag_true_p) follows this attribute. So we may
21115 end up accidently finding a declaration attribute that belongs
21116 to a different DIE referenced by the specification attribute,
21117 even though the given DIE does not have a declaration attribute. */
21118 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
21119 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
21122 /* Return the die giving the specification for DIE, if there is
21123 one. *SPEC_CU is the CU containing DIE on input, and the CU
21124 containing the return value on output. If there is no
21125 specification, but there is an abstract origin, that is
21128 static struct die_info
*
21129 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
21131 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
21134 if (spec_attr
== NULL
)
21135 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
21137 if (spec_attr
== NULL
)
21140 return follow_die_ref (die
, spec_attr
, spec_cu
);
21143 /* Stub for free_line_header to match void * callback types. */
21146 free_line_header_voidp (void *arg
)
21148 struct line_header
*lh
= (struct line_header
*) arg
;
21153 /* A convenience function to find the proper .debug_line section for a CU. */
21155 static struct dwarf2_section_info
*
21156 get_debug_line_section (struct dwarf2_cu
*cu
)
21158 struct dwarf2_section_info
*section
;
21159 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21161 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
21163 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
21164 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
21165 else if (cu
->per_cu
->is_dwz
)
21167 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
21169 section
= &dwz
->line
;
21172 section
= &per_objfile
->per_bfd
->line
;
21177 /* Read the statement program header starting at OFFSET in
21178 .debug_line, or .debug_line.dwo. Return a pointer
21179 to a struct line_header, allocated using xmalloc.
21180 Returns NULL if there is a problem reading the header, e.g., if it
21181 has a version we don't understand.
21183 NOTE: the strings in the include directory and file name tables of
21184 the returned object point into the dwarf line section buffer,
21185 and must not be freed. */
21187 static line_header_up
21188 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
21190 struct dwarf2_section_info
*section
;
21191 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21193 section
= get_debug_line_section (cu
);
21194 section
->read (per_objfile
->objfile
);
21195 if (section
->buffer
== NULL
)
21197 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
21198 complaint (_("missing .debug_line.dwo section"));
21200 complaint (_("missing .debug_line section"));
21204 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
21205 per_objfile
, section
, &cu
->header
);
21208 /* Subroutine of dwarf_decode_lines to simplify it.
21209 Return the file name of the psymtab for the given file_entry.
21210 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21211 If space for the result is malloc'd, *NAME_HOLDER will be set.
21212 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
21214 static const char *
21215 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
21216 const dwarf2_psymtab
*pst
,
21217 const char *comp_dir
,
21218 gdb::unique_xmalloc_ptr
<char> *name_holder
)
21220 const char *include_name
= fe
.name
;
21221 const char *include_name_to_compare
= include_name
;
21222 const char *pst_filename
;
21225 const char *dir_name
= fe
.include_dir (lh
);
21227 gdb::unique_xmalloc_ptr
<char> hold_compare
;
21228 if (!IS_ABSOLUTE_PATH (include_name
)
21229 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
21231 /* Avoid creating a duplicate psymtab for PST.
21232 We do this by comparing INCLUDE_NAME and PST_FILENAME.
21233 Before we do the comparison, however, we need to account
21234 for DIR_NAME and COMP_DIR.
21235 First prepend dir_name (if non-NULL). If we still don't
21236 have an absolute path prepend comp_dir (if non-NULL).
21237 However, the directory we record in the include-file's
21238 psymtab does not contain COMP_DIR (to match the
21239 corresponding symtab(s)).
21244 bash$ gcc -g ./hello.c
21245 include_name = "hello.c"
21247 DW_AT_comp_dir = comp_dir = "/tmp"
21248 DW_AT_name = "./hello.c"
21252 if (dir_name
!= NULL
)
21254 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
21255 include_name
, (char *) NULL
));
21256 include_name
= name_holder
->get ();
21257 include_name_to_compare
= include_name
;
21259 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
21261 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
21262 include_name
, (char *) NULL
));
21263 include_name_to_compare
= hold_compare
.get ();
21267 pst_filename
= pst
->filename
;
21268 gdb::unique_xmalloc_ptr
<char> copied_name
;
21269 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
21271 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
21272 pst_filename
, (char *) NULL
));
21273 pst_filename
= copied_name
.get ();
21276 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
21280 return include_name
;
21283 /* State machine to track the state of the line number program. */
21285 class lnp_state_machine
21288 /* Initialize a machine state for the start of a line number
21290 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
21291 bool record_lines_p
);
21293 file_entry
*current_file ()
21295 /* lh->file_names is 0-based, but the file name numbers in the
21296 statement program are 1-based. */
21297 return m_line_header
->file_name_at (m_file
);
21300 /* Record the line in the state machine. END_SEQUENCE is true if
21301 we're processing the end of a sequence. */
21302 void record_line (bool end_sequence
);
21304 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
21305 nop-out rest of the lines in this sequence. */
21306 void check_line_address (struct dwarf2_cu
*cu
,
21307 const gdb_byte
*line_ptr
,
21308 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
21310 void handle_set_discriminator (unsigned int discriminator
)
21312 m_discriminator
= discriminator
;
21313 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21316 /* Handle DW_LNE_set_address. */
21317 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21320 address
+= baseaddr
;
21321 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21324 /* Handle DW_LNS_advance_pc. */
21325 void handle_advance_pc (CORE_ADDR adjust
);
21327 /* Handle a special opcode. */
21328 void handle_special_opcode (unsigned char op_code
);
21330 /* Handle DW_LNS_advance_line. */
21331 void handle_advance_line (int line_delta
)
21333 advance_line (line_delta
);
21336 /* Handle DW_LNS_set_file. */
21337 void handle_set_file (file_name_index file
);
21339 /* Handle DW_LNS_negate_stmt. */
21340 void handle_negate_stmt ()
21342 m_is_stmt
= !m_is_stmt
;
21345 /* Handle DW_LNS_const_add_pc. */
21346 void handle_const_add_pc ();
21348 /* Handle DW_LNS_fixed_advance_pc. */
21349 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21351 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21355 /* Handle DW_LNS_copy. */
21356 void handle_copy ()
21358 record_line (false);
21359 m_discriminator
= 0;
21362 /* Handle DW_LNE_end_sequence. */
21363 void handle_end_sequence ()
21365 m_currently_recording_lines
= true;
21369 /* Advance the line by LINE_DELTA. */
21370 void advance_line (int line_delta
)
21372 m_line
+= line_delta
;
21374 if (line_delta
!= 0)
21375 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21378 struct dwarf2_cu
*m_cu
;
21380 gdbarch
*m_gdbarch
;
21382 /* True if we're recording lines.
21383 Otherwise we're building partial symtabs and are just interested in
21384 finding include files mentioned by the line number program. */
21385 bool m_record_lines_p
;
21387 /* The line number header. */
21388 line_header
*m_line_header
;
21390 /* These are part of the standard DWARF line number state machine,
21391 and initialized according to the DWARF spec. */
21393 unsigned char m_op_index
= 0;
21394 /* The line table index of the current file. */
21395 file_name_index m_file
= 1;
21396 unsigned int m_line
= 1;
21398 /* These are initialized in the constructor. */
21400 CORE_ADDR m_address
;
21402 unsigned int m_discriminator
;
21404 /* Additional bits of state we need to track. */
21406 /* The last file that we called dwarf2_start_subfile for.
21407 This is only used for TLLs. */
21408 unsigned int m_last_file
= 0;
21409 /* The last file a line number was recorded for. */
21410 struct subfile
*m_last_subfile
= NULL
;
21412 /* The address of the last line entry. */
21413 CORE_ADDR m_last_address
;
21415 /* Set to true when a previous line at the same address (using
21416 m_last_address) had m_is_stmt true. This is reset to false when a
21417 line entry at a new address (m_address different to m_last_address) is
21419 bool m_stmt_at_address
= false;
21421 /* When true, record the lines we decode. */
21422 bool m_currently_recording_lines
= false;
21424 /* The last line number that was recorded, used to coalesce
21425 consecutive entries for the same line. This can happen, for
21426 example, when discriminators are present. PR 17276. */
21427 unsigned int m_last_line
= 0;
21428 bool m_line_has_non_zero_discriminator
= false;
21432 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21434 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21435 / m_line_header
->maximum_ops_per_instruction
)
21436 * m_line_header
->minimum_instruction_length
);
21437 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21438 m_op_index
= ((m_op_index
+ adjust
)
21439 % m_line_header
->maximum_ops_per_instruction
);
21443 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21445 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21446 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
21447 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
21448 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
21449 / m_line_header
->maximum_ops_per_instruction
)
21450 * m_line_header
->minimum_instruction_length
);
21451 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21452 m_op_index
= ((m_op_index
+ adj_opcode_d
)
21453 % m_line_header
->maximum_ops_per_instruction
);
21455 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
21456 advance_line (line_delta
);
21457 record_line (false);
21458 m_discriminator
= 0;
21462 lnp_state_machine::handle_set_file (file_name_index file
)
21466 const file_entry
*fe
= current_file ();
21468 dwarf2_debug_line_missing_file_complaint ();
21469 else if (m_record_lines_p
)
21471 const char *dir
= fe
->include_dir (m_line_header
);
21473 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21474 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21475 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21480 lnp_state_machine::handle_const_add_pc ()
21483 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21486 = (((m_op_index
+ adjust
)
21487 / m_line_header
->maximum_ops_per_instruction
)
21488 * m_line_header
->minimum_instruction_length
);
21490 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21491 m_op_index
= ((m_op_index
+ adjust
)
21492 % m_line_header
->maximum_ops_per_instruction
);
21495 /* Return non-zero if we should add LINE to the line number table.
21496 LINE is the line to add, LAST_LINE is the last line that was added,
21497 LAST_SUBFILE is the subfile for LAST_LINE.
21498 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21499 had a non-zero discriminator.
21501 We have to be careful in the presence of discriminators.
21502 E.g., for this line:
21504 for (i = 0; i < 100000; i++);
21506 clang can emit four line number entries for that one line,
21507 each with a different discriminator.
21508 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21510 However, we want gdb to coalesce all four entries into one.
21511 Otherwise the user could stepi into the middle of the line and
21512 gdb would get confused about whether the pc really was in the
21513 middle of the line.
21515 Things are further complicated by the fact that two consecutive
21516 line number entries for the same line is a heuristic used by gcc
21517 to denote the end of the prologue. So we can't just discard duplicate
21518 entries, we have to be selective about it. The heuristic we use is
21519 that we only collapse consecutive entries for the same line if at least
21520 one of those entries has a non-zero discriminator. PR 17276.
21522 Note: Addresses in the line number state machine can never go backwards
21523 within one sequence, thus this coalescing is ok. */
21526 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21527 unsigned int line
, unsigned int last_line
,
21528 int line_has_non_zero_discriminator
,
21529 struct subfile
*last_subfile
)
21531 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21533 if (line
!= last_line
)
21535 /* Same line for the same file that we've seen already.
21536 As a last check, for pr 17276, only record the line if the line
21537 has never had a non-zero discriminator. */
21538 if (!line_has_non_zero_discriminator
)
21543 /* Use the CU's builder to record line number LINE beginning at
21544 address ADDRESS in the line table of subfile SUBFILE. */
21547 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21548 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
21549 struct dwarf2_cu
*cu
)
21551 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21553 if (dwarf_line_debug
)
21555 fprintf_unfiltered (gdb_stdlog
,
21556 "Recording line %u, file %s, address %s\n",
21557 line
, lbasename (subfile
->name
),
21558 paddress (gdbarch
, address
));
21562 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21565 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21566 Mark the end of a set of line number records.
21567 The arguments are the same as for dwarf_record_line_1.
21568 If SUBFILE is NULL the request is ignored. */
21571 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21572 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21574 if (subfile
== NULL
)
21577 if (dwarf_line_debug
)
21579 fprintf_unfiltered (gdb_stdlog
,
21580 "Finishing current line, file %s, address %s\n",
21581 lbasename (subfile
->name
),
21582 paddress (gdbarch
, address
));
21585 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21589 lnp_state_machine::record_line (bool end_sequence
)
21591 if (dwarf_line_debug
)
21593 fprintf_unfiltered (gdb_stdlog
,
21594 "Processing actual line %u: file %u,"
21595 " address %s, is_stmt %u, discrim %u%s\n",
21597 paddress (m_gdbarch
, m_address
),
21598 m_is_stmt
, m_discriminator
,
21599 (end_sequence
? "\t(end sequence)" : ""));
21602 file_entry
*fe
= current_file ();
21605 dwarf2_debug_line_missing_file_complaint ();
21606 /* For now we ignore lines not starting on an instruction boundary.
21607 But not when processing end_sequence for compatibility with the
21608 previous version of the code. */
21609 else if (m_op_index
== 0 || end_sequence
)
21611 fe
->included_p
= 1;
21612 if (m_record_lines_p
)
21614 /* When we switch files we insert an end maker in the first file,
21615 switch to the second file and add a new line entry. The
21616 problem is that the end marker inserted in the first file will
21617 discard any previous line entries at the same address. If the
21618 line entries in the first file are marked as is-stmt, while
21619 the new line in the second file is non-stmt, then this means
21620 the end marker will discard is-stmt lines so we can have a
21621 non-stmt line. This means that there are less addresses at
21622 which the user can insert a breakpoint.
21624 To improve this we track the last address in m_last_address,
21625 and whether we have seen an is-stmt at this address. Then
21626 when switching files, if we have seen a stmt at the current
21627 address, and we are switching to create a non-stmt line, then
21628 discard the new line. */
21630 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21631 bool ignore_this_line
21632 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21633 && !m_is_stmt
&& m_stmt_at_address
)
21634 || (!end_sequence
&& m_line
== 0));
21636 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21638 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21639 m_currently_recording_lines
? m_cu
: nullptr);
21642 if (!end_sequence
&& !ignore_this_line
)
21644 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21646 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21647 m_line_has_non_zero_discriminator
,
21650 buildsym_compunit
*builder
= m_cu
->get_builder ();
21651 dwarf_record_line_1 (m_gdbarch
,
21652 builder
->get_current_subfile (),
21653 m_line
, m_address
, is_stmt
,
21654 m_currently_recording_lines
? m_cu
: nullptr);
21656 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21657 m_last_line
= m_line
;
21662 /* Track whether we have seen any m_is_stmt true at m_address in case we
21663 have multiple line table entries all at m_address. */
21664 if (m_last_address
!= m_address
)
21666 m_stmt_at_address
= false;
21667 m_last_address
= m_address
;
21669 m_stmt_at_address
|= m_is_stmt
;
21672 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21673 line_header
*lh
, bool record_lines_p
)
21677 m_record_lines_p
= record_lines_p
;
21678 m_line_header
= lh
;
21680 m_currently_recording_lines
= true;
21682 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21683 was a line entry for it so that the backend has a chance to adjust it
21684 and also record it in case it needs it. This is currently used by MIPS
21685 code, cf. `mips_adjust_dwarf2_line'. */
21686 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21687 m_is_stmt
= lh
->default_is_stmt
;
21688 m_discriminator
= 0;
21690 m_last_address
= m_address
;
21691 m_stmt_at_address
= false;
21695 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21696 const gdb_byte
*line_ptr
,
21697 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21699 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21700 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21701 located at 0x0. In this case, additionally check that if
21702 ADDRESS < UNRELOCATED_LOWPC. */
21704 if ((address
== 0 && address
< unrelocated_lowpc
)
21705 || address
== (CORE_ADDR
) -1)
21707 /* This line table is for a function which has been
21708 GCd by the linker. Ignore it. PR gdb/12528 */
21710 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21711 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21713 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21714 line_offset
, objfile_name (objfile
));
21715 m_currently_recording_lines
= false;
21716 /* Note: m_currently_recording_lines is left as false until we see
21717 DW_LNE_end_sequence. */
21721 /* Subroutine of dwarf_decode_lines to simplify it.
21722 Process the line number information in LH.
21723 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21724 program in order to set included_p for every referenced header. */
21727 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21728 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21730 const gdb_byte
*line_ptr
, *extended_end
;
21731 const gdb_byte
*line_end
;
21732 unsigned int bytes_read
, extended_len
;
21733 unsigned char op_code
, extended_op
;
21734 CORE_ADDR baseaddr
;
21735 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21736 bfd
*abfd
= objfile
->obfd
;
21737 struct gdbarch
*gdbarch
= objfile
->arch ();
21738 /* True if we're recording line info (as opposed to building partial
21739 symtabs and just interested in finding include files mentioned by
21740 the line number program). */
21741 bool record_lines_p
= !decode_for_pst_p
;
21743 baseaddr
= objfile
->text_section_offset ();
21745 line_ptr
= lh
->statement_program_start
;
21746 line_end
= lh
->statement_program_end
;
21748 /* Read the statement sequences until there's nothing left. */
21749 while (line_ptr
< line_end
)
21751 /* The DWARF line number program state machine. Reset the state
21752 machine at the start of each sequence. */
21753 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21754 bool end_sequence
= false;
21756 if (record_lines_p
)
21758 /* Start a subfile for the current file of the state
21760 const file_entry
*fe
= state_machine
.current_file ();
21763 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21766 /* Decode the table. */
21767 while (line_ptr
< line_end
&& !end_sequence
)
21769 op_code
= read_1_byte (abfd
, line_ptr
);
21772 if (op_code
>= lh
->opcode_base
)
21774 /* Special opcode. */
21775 state_machine
.handle_special_opcode (op_code
);
21777 else switch (op_code
)
21779 case DW_LNS_extended_op
:
21780 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21782 line_ptr
+= bytes_read
;
21783 extended_end
= line_ptr
+ extended_len
;
21784 extended_op
= read_1_byte (abfd
, line_ptr
);
21786 if (DW_LNE_lo_user
<= extended_op
21787 && extended_op
<= DW_LNE_hi_user
)
21789 /* Vendor extension, ignore. */
21790 line_ptr
= extended_end
;
21793 switch (extended_op
)
21795 case DW_LNE_end_sequence
:
21796 state_machine
.handle_end_sequence ();
21797 end_sequence
= true;
21799 case DW_LNE_set_address
:
21802 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21803 line_ptr
+= bytes_read
;
21805 state_machine
.check_line_address (cu
, line_ptr
,
21806 lowpc
- baseaddr
, address
);
21807 state_machine
.handle_set_address (baseaddr
, address
);
21810 case DW_LNE_define_file
:
21812 const char *cur_file
;
21813 unsigned int mod_time
, length
;
21816 cur_file
= read_direct_string (abfd
, line_ptr
,
21818 line_ptr
+= bytes_read
;
21819 dindex
= (dir_index
)
21820 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21821 line_ptr
+= bytes_read
;
21823 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21824 line_ptr
+= bytes_read
;
21826 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21827 line_ptr
+= bytes_read
;
21828 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21831 case DW_LNE_set_discriminator
:
21833 /* The discriminator is not interesting to the
21834 debugger; just ignore it. We still need to
21835 check its value though:
21836 if there are consecutive entries for the same
21837 (non-prologue) line we want to coalesce them.
21840 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21841 line_ptr
+= bytes_read
;
21843 state_machine
.handle_set_discriminator (discr
);
21847 complaint (_("mangled .debug_line section"));
21850 /* Make sure that we parsed the extended op correctly. If e.g.
21851 we expected a different address size than the producer used,
21852 we may have read the wrong number of bytes. */
21853 if (line_ptr
!= extended_end
)
21855 complaint (_("mangled .debug_line section"));
21860 state_machine
.handle_copy ();
21862 case DW_LNS_advance_pc
:
21865 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21866 line_ptr
+= bytes_read
;
21868 state_machine
.handle_advance_pc (adjust
);
21871 case DW_LNS_advance_line
:
21874 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21875 line_ptr
+= bytes_read
;
21877 state_machine
.handle_advance_line (line_delta
);
21880 case DW_LNS_set_file
:
21882 file_name_index file
21883 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21885 line_ptr
+= bytes_read
;
21887 state_machine
.handle_set_file (file
);
21890 case DW_LNS_set_column
:
21891 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21892 line_ptr
+= bytes_read
;
21894 case DW_LNS_negate_stmt
:
21895 state_machine
.handle_negate_stmt ();
21897 case DW_LNS_set_basic_block
:
21899 /* Add to the address register of the state machine the
21900 address increment value corresponding to special opcode
21901 255. I.e., this value is scaled by the minimum
21902 instruction length since special opcode 255 would have
21903 scaled the increment. */
21904 case DW_LNS_const_add_pc
:
21905 state_machine
.handle_const_add_pc ();
21907 case DW_LNS_fixed_advance_pc
:
21909 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21912 state_machine
.handle_fixed_advance_pc (addr_adj
);
21917 /* Unknown standard opcode, ignore it. */
21920 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21922 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21923 line_ptr
+= bytes_read
;
21930 dwarf2_debug_line_missing_end_sequence_complaint ();
21932 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21933 in which case we still finish recording the last line). */
21934 state_machine
.record_line (true);
21938 /* Decode the Line Number Program (LNP) for the given line_header
21939 structure and CU. The actual information extracted and the type
21940 of structures created from the LNP depends on the value of PST.
21942 1. If PST is NULL, then this procedure uses the data from the program
21943 to create all necessary symbol tables, and their linetables.
21945 2. If PST is not NULL, this procedure reads the program to determine
21946 the list of files included by the unit represented by PST, and
21947 builds all the associated partial symbol tables.
21949 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21950 It is used for relative paths in the line table.
21951 NOTE: When processing partial symtabs (pst != NULL),
21952 comp_dir == pst->dirname.
21954 NOTE: It is important that psymtabs have the same file name (via strcmp)
21955 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21956 symtab we don't use it in the name of the psymtabs we create.
21957 E.g. expand_line_sal requires this when finding psymtabs to expand.
21958 A good testcase for this is mb-inline.exp.
21960 LOWPC is the lowest address in CU (or 0 if not known).
21962 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21963 for its PC<->lines mapping information. Otherwise only the filename
21964 table is read in. */
21967 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21968 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21969 CORE_ADDR lowpc
, int decode_mapping
)
21971 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21972 const int decode_for_pst_p
= (pst
!= NULL
);
21974 if (decode_mapping
)
21975 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21977 if (decode_for_pst_p
)
21979 /* Now that we're done scanning the Line Header Program, we can
21980 create the psymtab of each included file. */
21981 for (auto &file_entry
: lh
->file_names ())
21982 if (file_entry
.included_p
== 1)
21984 gdb::unique_xmalloc_ptr
<char> name_holder
;
21985 const char *include_name
=
21986 psymtab_include_file_name (lh
, file_entry
, pst
,
21987 comp_dir
, &name_holder
);
21988 if (include_name
!= NULL
)
21989 dwarf2_create_include_psymtab
21990 (cu
->per_objfile
->per_bfd
, include_name
, pst
,
21991 cu
->per_objfile
->per_bfd
->partial_symtabs
.get (),
21997 /* Make sure a symtab is created for every file, even files
21998 which contain only variables (i.e. no code with associated
22000 buildsym_compunit
*builder
= cu
->get_builder ();
22001 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
22003 for (auto &fe
: lh
->file_names ())
22005 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
22006 if (builder
->get_current_subfile ()->symtab
== NULL
)
22008 builder
->get_current_subfile ()->symtab
22009 = allocate_symtab (cust
,
22010 builder
->get_current_subfile ()->name
);
22012 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
22017 /* Start a subfile for DWARF. FILENAME is the name of the file and
22018 DIRNAME the name of the source directory which contains FILENAME
22019 or NULL if not known.
22020 This routine tries to keep line numbers from identical absolute and
22021 relative file names in a common subfile.
22023 Using the `list' example from the GDB testsuite, which resides in
22024 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
22025 of /srcdir/list0.c yields the following debugging information for list0.c:
22027 DW_AT_name: /srcdir/list0.c
22028 DW_AT_comp_dir: /compdir
22029 files.files[0].name: list0.h
22030 files.files[0].dir: /srcdir
22031 files.files[1].name: list0.c
22032 files.files[1].dir: /srcdir
22034 The line number information for list0.c has to end up in a single
22035 subfile, so that `break /srcdir/list0.c:1' works as expected.
22036 start_subfile will ensure that this happens provided that we pass the
22037 concatenation of files.files[1].dir and files.files[1].name as the
22041 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
22042 const char *dirname
)
22044 gdb::unique_xmalloc_ptr
<char> copy
;
22046 /* In order not to lose the line information directory,
22047 we concatenate it to the filename when it makes sense.
22048 Note that the Dwarf3 standard says (speaking of filenames in line
22049 information): ``The directory index is ignored for file names
22050 that represent full path names''. Thus ignoring dirname in the
22051 `else' branch below isn't an issue. */
22053 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
22055 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
22056 filename
= copy
.get ();
22059 cu
->get_builder ()->start_subfile (filename
);
22062 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
22063 buildsym_compunit constructor. */
22065 struct compunit_symtab
*
22066 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
22069 gdb_assert (m_builder
== nullptr);
22071 m_builder
.reset (new struct buildsym_compunit
22072 (this->per_objfile
->objfile
,
22073 name
, comp_dir
, language
, low_pc
));
22075 list_in_scope
= get_builder ()->get_file_symbols ();
22077 get_builder ()->record_debugformat ("DWARF 2");
22078 get_builder ()->record_producer (producer
);
22080 processing_has_namespace_info
= false;
22082 return get_builder ()->get_compunit_symtab ();
22086 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
22087 struct dwarf2_cu
*cu
)
22089 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22090 struct comp_unit_head
*cu_header
= &cu
->header
;
22092 /* NOTE drow/2003-01-30: There used to be a comment and some special
22093 code here to turn a symbol with DW_AT_external and a
22094 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
22095 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
22096 with some versions of binutils) where shared libraries could have
22097 relocations against symbols in their debug information - the
22098 minimal symbol would have the right address, but the debug info
22099 would not. It's no longer necessary, because we will explicitly
22100 apply relocations when we read in the debug information now. */
22102 /* A DW_AT_location attribute with no contents indicates that a
22103 variable has been optimized away. */
22104 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
22106 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22110 /* Handle one degenerate form of location expression specially, to
22111 preserve GDB's previous behavior when section offsets are
22112 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
22113 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
22115 if (attr
->form_is_block ())
22117 struct dwarf_block
*block
= attr
->as_block ();
22119 if ((block
->data
[0] == DW_OP_addr
22120 && block
->size
== 1 + cu_header
->addr_size
)
22121 || ((block
->data
[0] == DW_OP_GNU_addr_index
22122 || block
->data
[0] == DW_OP_addrx
)
22124 == 1 + leb128_size (&block
->data
[1]))))
22126 unsigned int dummy
;
22128 if (block
->data
[0] == DW_OP_addr
)
22129 SET_SYMBOL_VALUE_ADDRESS
22130 (sym
, cu
->header
.read_address (objfile
->obfd
,
22134 SET_SYMBOL_VALUE_ADDRESS
22135 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
22137 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
22138 fixup_symbol_section (sym
, objfile
);
22139 SET_SYMBOL_VALUE_ADDRESS
22141 SYMBOL_VALUE_ADDRESS (sym
)
22142 + objfile
->section_offsets
[sym
->section_index ()]);
22147 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
22148 expression evaluator, and use LOC_COMPUTED only when necessary
22149 (i.e. when the value of a register or memory location is
22150 referenced, or a thread-local block, etc.). Then again, it might
22151 not be worthwhile. I'm assuming that it isn't unless performance
22152 or memory numbers show me otherwise. */
22154 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
22156 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
22157 cu
->has_loclist
= true;
22160 /* Given a pointer to a DWARF information entry, figure out if we need
22161 to make a symbol table entry for it, and if so, create a new entry
22162 and return a pointer to it.
22163 If TYPE is NULL, determine symbol type from the die, otherwise
22164 used the passed type.
22165 If SPACE is not NULL, use it to hold the new symbol. If it is
22166 NULL, allocate a new symbol on the objfile's obstack. */
22168 static struct symbol
*
22169 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
22170 struct symbol
*space
)
22172 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22173 struct objfile
*objfile
= per_objfile
->objfile
;
22174 struct gdbarch
*gdbarch
= objfile
->arch ();
22175 struct symbol
*sym
= NULL
;
22177 struct attribute
*attr
= NULL
;
22178 struct attribute
*attr2
= NULL
;
22179 CORE_ADDR baseaddr
;
22180 struct pending
**list_to_add
= NULL
;
22182 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
22184 baseaddr
= objfile
->text_section_offset ();
22186 name
= dwarf2_name (die
, cu
);
22189 int suppress_add
= 0;
22194 sym
= new (&objfile
->objfile_obstack
) symbol
;
22195 OBJSTAT (objfile
, n_syms
++);
22197 /* Cache this symbol's name and the name's demangled form (if any). */
22198 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
22199 /* Fortran does not have mangling standard and the mangling does differ
22200 between gfortran, iFort etc. */
22201 const char *physname
22202 = (cu
->language
== language_fortran
22203 ? dwarf2_full_name (name
, die
, cu
)
22204 : dwarf2_physname (name
, die
, cu
));
22205 const char *linkagename
= dw2_linkage_name (die
, cu
);
22207 if (linkagename
== nullptr || cu
->language
== language_ada
)
22208 sym
->set_linkage_name (physname
);
22211 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
22212 sym
->set_linkage_name (linkagename
);
22215 /* Default assumptions.
22216 Use the passed type or decode it from the die. */
22217 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22218 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22220 SYMBOL_TYPE (sym
) = type
;
22222 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
22223 attr
= dwarf2_attr (die
,
22224 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
22226 if (attr
!= nullptr)
22227 SYMBOL_LINE (sym
) = attr
->constant_value (0);
22229 attr
= dwarf2_attr (die
,
22230 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
22232 if (attr
!= nullptr && attr
->is_nonnegative ())
22234 file_name_index file_index
22235 = (file_name_index
) attr
->as_nonnegative ();
22236 struct file_entry
*fe
;
22238 if (cu
->line_header
!= NULL
)
22239 fe
= cu
->line_header
->file_name_at (file_index
);
22244 complaint (_("file index out of range"));
22246 symbol_set_symtab (sym
, fe
->symtab
);
22252 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
22253 if (attr
!= nullptr)
22257 addr
= attr
->as_address ();
22258 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
22259 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
22260 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
22263 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22264 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
22265 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
22266 add_symbol_to_list (sym
, cu
->list_in_scope
);
22268 case DW_TAG_subprogram
:
22269 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22271 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22272 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22273 if ((attr2
!= nullptr && attr2
->as_boolean ())
22274 || cu
->language
== language_ada
22275 || cu
->language
== language_fortran
)
22277 /* Subprograms marked external are stored as a global symbol.
22278 Ada and Fortran subprograms, whether marked external or
22279 not, are always stored as a global symbol, because we want
22280 to be able to access them globally. For instance, we want
22281 to be able to break on a nested subprogram without having
22282 to specify the context. */
22283 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22287 list_to_add
= cu
->list_in_scope
;
22290 case DW_TAG_inlined_subroutine
:
22291 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22293 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22294 SYMBOL_INLINED (sym
) = 1;
22295 list_to_add
= cu
->list_in_scope
;
22297 case DW_TAG_template_value_param
:
22299 /* Fall through. */
22300 case DW_TAG_constant
:
22301 case DW_TAG_variable
:
22302 case DW_TAG_member
:
22303 /* Compilation with minimal debug info may result in
22304 variables with missing type entries. Change the
22305 misleading `void' type to something sensible. */
22306 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
22307 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
22309 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22310 /* In the case of DW_TAG_member, we should only be called for
22311 static const members. */
22312 if (die
->tag
== DW_TAG_member
)
22314 /* dwarf2_add_field uses die_is_declaration,
22315 so we do the same. */
22316 gdb_assert (die_is_declaration (die
, cu
));
22319 if (attr
!= nullptr)
22321 dwarf2_const_value (attr
, sym
, cu
);
22322 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22325 if (attr2
!= nullptr && attr2
->as_boolean ())
22326 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22328 list_to_add
= cu
->list_in_scope
;
22332 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22333 if (attr
!= nullptr)
22335 var_decode_location (attr
, sym
, cu
);
22336 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22338 /* Fortran explicitly imports any global symbols to the local
22339 scope by DW_TAG_common_block. */
22340 if (cu
->language
== language_fortran
&& die
->parent
22341 && die
->parent
->tag
== DW_TAG_common_block
)
22344 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22345 && SYMBOL_VALUE_ADDRESS (sym
) == 0
22346 && !per_objfile
->per_bfd
->has_section_at_zero
)
22348 /* When a static variable is eliminated by the linker,
22349 the corresponding debug information is not stripped
22350 out, but the variable address is set to null;
22351 do not add such variables into symbol table. */
22353 else if (attr2
!= nullptr && attr2
->as_boolean ())
22355 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22356 && (objfile
->flags
& OBJF_MAINLINE
) == 0
22357 && per_objfile
->per_bfd
->can_copy
)
22359 /* A global static variable might be subject to
22360 copy relocation. We first check for a local
22361 minsym, though, because maybe the symbol was
22362 marked hidden, in which case this would not
22364 bound_minimal_symbol found
22365 = (lookup_minimal_symbol_linkage
22366 (sym
->linkage_name (), objfile
));
22367 if (found
.minsym
!= nullptr)
22368 sym
->maybe_copied
= 1;
22371 /* A variable with DW_AT_external is never static,
22372 but it may be block-scoped. */
22374 = ((cu
->list_in_scope
22375 == cu
->get_builder ()->get_file_symbols ())
22376 ? cu
->get_builder ()->get_global_symbols ()
22377 : cu
->list_in_scope
);
22380 list_to_add
= cu
->list_in_scope
;
22384 /* We do not know the address of this symbol.
22385 If it is an external symbol and we have type information
22386 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22387 The address of the variable will then be determined from
22388 the minimal symbol table whenever the variable is
22390 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22392 /* Fortran explicitly imports any global symbols to the local
22393 scope by DW_TAG_common_block. */
22394 if (cu
->language
== language_fortran
&& die
->parent
22395 && die
->parent
->tag
== DW_TAG_common_block
)
22397 /* SYMBOL_CLASS doesn't matter here because
22398 read_common_block is going to reset it. */
22400 list_to_add
= cu
->list_in_scope
;
22402 else if (attr2
!= nullptr && attr2
->as_boolean ()
22403 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22405 /* A variable with DW_AT_external is never static, but it
22406 may be block-scoped. */
22408 = ((cu
->list_in_scope
22409 == cu
->get_builder ()->get_file_symbols ())
22410 ? cu
->get_builder ()->get_global_symbols ()
22411 : cu
->list_in_scope
);
22413 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22415 else if (!die_is_declaration (die
, cu
))
22417 /* Use the default LOC_OPTIMIZED_OUT class. */
22418 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22420 list_to_add
= cu
->list_in_scope
;
22424 case DW_TAG_formal_parameter
:
22426 /* If we are inside a function, mark this as an argument. If
22427 not, we might be looking at an argument to an inlined function
22428 when we do not have enough information to show inlined frames;
22429 pretend it's a local variable in that case so that the user can
22431 struct context_stack
*curr
22432 = cu
->get_builder ()->get_current_context_stack ();
22433 if (curr
!= nullptr && curr
->name
!= nullptr)
22434 SYMBOL_IS_ARGUMENT (sym
) = 1;
22435 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22436 if (attr
!= nullptr)
22438 var_decode_location (attr
, sym
, cu
);
22440 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22441 if (attr
!= nullptr)
22443 dwarf2_const_value (attr
, sym
, cu
);
22446 list_to_add
= cu
->list_in_scope
;
22449 case DW_TAG_unspecified_parameters
:
22450 /* From varargs functions; gdb doesn't seem to have any
22451 interest in this information, so just ignore it for now.
22454 case DW_TAG_template_type_param
:
22456 /* Fall through. */
22457 case DW_TAG_class_type
:
22458 case DW_TAG_interface_type
:
22459 case DW_TAG_structure_type
:
22460 case DW_TAG_union_type
:
22461 case DW_TAG_set_type
:
22462 case DW_TAG_enumeration_type
:
22463 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22464 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22467 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22468 really ever be static objects: otherwise, if you try
22469 to, say, break of a class's method and you're in a file
22470 which doesn't mention that class, it won't work unless
22471 the check for all static symbols in lookup_symbol_aux
22472 saves you. See the OtherFileClass tests in
22473 gdb.c++/namespace.exp. */
22477 buildsym_compunit
*builder
= cu
->get_builder ();
22479 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22480 && cu
->language
== language_cplus
22481 ? builder
->get_global_symbols ()
22482 : cu
->list_in_scope
);
22484 /* The semantics of C++ state that "struct foo {
22485 ... }" also defines a typedef for "foo". */
22486 if (cu
->language
== language_cplus
22487 || cu
->language
== language_ada
22488 || cu
->language
== language_d
22489 || cu
->language
== language_rust
)
22491 /* The symbol's name is already allocated along
22492 with this objfile, so we don't need to
22493 duplicate it for the type. */
22494 if (SYMBOL_TYPE (sym
)->name () == 0)
22495 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
22500 case DW_TAG_typedef
:
22501 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22502 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22503 list_to_add
= cu
->list_in_scope
;
22505 case DW_TAG_array_type
:
22506 case DW_TAG_base_type
:
22507 case DW_TAG_subrange_type
:
22508 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22509 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22510 list_to_add
= cu
->list_in_scope
;
22512 case DW_TAG_enumerator
:
22513 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22514 if (attr
!= nullptr)
22516 dwarf2_const_value (attr
, sym
, cu
);
22519 /* NOTE: carlton/2003-11-10: See comment above in the
22520 DW_TAG_class_type, etc. block. */
22523 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22524 && cu
->language
== language_cplus
22525 ? cu
->get_builder ()->get_global_symbols ()
22526 : cu
->list_in_scope
);
22529 case DW_TAG_imported_declaration
:
22530 case DW_TAG_namespace
:
22531 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22532 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22534 case DW_TAG_module
:
22535 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22536 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22537 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22539 case DW_TAG_common_block
:
22540 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22541 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22542 add_symbol_to_list (sym
, cu
->list_in_scope
);
22545 /* Not a tag we recognize. Hopefully we aren't processing
22546 trash data, but since we must specifically ignore things
22547 we don't recognize, there is nothing else we should do at
22549 complaint (_("unsupported tag: '%s'"),
22550 dwarf_tag_name (die
->tag
));
22556 sym
->hash_next
= objfile
->template_symbols
;
22557 objfile
->template_symbols
= sym
;
22558 list_to_add
= NULL
;
22561 if (list_to_add
!= NULL
)
22562 add_symbol_to_list (sym
, list_to_add
);
22564 /* For the benefit of old versions of GCC, check for anonymous
22565 namespaces based on the demangled name. */
22566 if (!cu
->processing_has_namespace_info
22567 && cu
->language
== language_cplus
)
22568 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22573 /* Given an attr with a DW_FORM_dataN value in host byte order,
22574 zero-extend it as appropriate for the symbol's type. The DWARF
22575 standard (v4) is not entirely clear about the meaning of using
22576 DW_FORM_dataN for a constant with a signed type, where the type is
22577 wider than the data. The conclusion of a discussion on the DWARF
22578 list was that this is unspecified. We choose to always zero-extend
22579 because that is the interpretation long in use by GCC. */
22582 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22583 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22585 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22586 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22587 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22588 LONGEST l
= attr
->constant_value (0);
22590 if (bits
< sizeof (*value
) * 8)
22592 l
&= ((LONGEST
) 1 << bits
) - 1;
22595 else if (bits
== sizeof (*value
) * 8)
22599 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22600 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22607 /* Read a constant value from an attribute. Either set *VALUE, or if
22608 the value does not fit in *VALUE, set *BYTES - either already
22609 allocated on the objfile obstack, or newly allocated on OBSTACK,
22610 or, set *BATON, if we translated the constant to a location
22614 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22615 const char *name
, struct obstack
*obstack
,
22616 struct dwarf2_cu
*cu
,
22617 LONGEST
*value
, const gdb_byte
**bytes
,
22618 struct dwarf2_locexpr_baton
**baton
)
22620 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22621 struct objfile
*objfile
= per_objfile
->objfile
;
22622 struct comp_unit_head
*cu_header
= &cu
->header
;
22623 struct dwarf_block
*blk
;
22624 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22625 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22631 switch (attr
->form
)
22634 case DW_FORM_addrx
:
22635 case DW_FORM_GNU_addr_index
:
22639 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22640 dwarf2_const_value_length_mismatch_complaint (name
,
22641 cu_header
->addr_size
,
22642 TYPE_LENGTH (type
));
22643 /* Symbols of this form are reasonably rare, so we just
22644 piggyback on the existing location code rather than writing
22645 a new implementation of symbol_computed_ops. */
22646 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22647 (*baton
)->per_objfile
= per_objfile
;
22648 (*baton
)->per_cu
= cu
->per_cu
;
22649 gdb_assert ((*baton
)->per_cu
);
22651 (*baton
)->size
= 2 + cu_header
->addr_size
;
22652 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22653 (*baton
)->data
= data
;
22655 data
[0] = DW_OP_addr
;
22656 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22657 byte_order
, attr
->as_address ());
22658 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22661 case DW_FORM_string
:
22664 case DW_FORM_GNU_str_index
:
22665 case DW_FORM_GNU_strp_alt
:
22666 /* The string is already allocated on the objfile obstack, point
22668 *bytes
= (const gdb_byte
*) attr
->as_string ();
22670 case DW_FORM_block1
:
22671 case DW_FORM_block2
:
22672 case DW_FORM_block4
:
22673 case DW_FORM_block
:
22674 case DW_FORM_exprloc
:
22675 case DW_FORM_data16
:
22676 blk
= attr
->as_block ();
22677 if (TYPE_LENGTH (type
) != blk
->size
)
22678 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22679 TYPE_LENGTH (type
));
22680 *bytes
= blk
->data
;
22683 /* The DW_AT_const_value attributes are supposed to carry the
22684 symbol's value "represented as it would be on the target
22685 architecture." By the time we get here, it's already been
22686 converted to host endianness, so we just need to sign- or
22687 zero-extend it as appropriate. */
22688 case DW_FORM_data1
:
22689 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22691 case DW_FORM_data2
:
22692 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22694 case DW_FORM_data4
:
22695 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22697 case DW_FORM_data8
:
22698 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22701 case DW_FORM_sdata
:
22702 case DW_FORM_implicit_const
:
22703 *value
= attr
->as_signed ();
22706 case DW_FORM_udata
:
22707 *value
= attr
->as_unsigned ();
22711 complaint (_("unsupported const value attribute form: '%s'"),
22712 dwarf_form_name (attr
->form
));
22719 /* Copy constant value from an attribute to a symbol. */
22722 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22723 struct dwarf2_cu
*cu
)
22725 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22727 const gdb_byte
*bytes
;
22728 struct dwarf2_locexpr_baton
*baton
;
22730 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22731 sym
->print_name (),
22732 &objfile
->objfile_obstack
, cu
,
22733 &value
, &bytes
, &baton
);
22737 SYMBOL_LOCATION_BATON (sym
) = baton
;
22738 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22740 else if (bytes
!= NULL
)
22742 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22743 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22747 SYMBOL_VALUE (sym
) = value
;
22748 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22752 /* Return the type of the die in question using its DW_AT_type attribute. */
22754 static struct type
*
22755 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22757 struct attribute
*type_attr
;
22759 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22762 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22763 /* A missing DW_AT_type represents a void type. */
22764 return objfile_type (objfile
)->builtin_void
;
22767 return lookup_die_type (die
, type_attr
, cu
);
22770 /* True iff CU's producer generates GNAT Ada auxiliary information
22771 that allows to find parallel types through that information instead
22772 of having to do expensive parallel lookups by type name. */
22775 need_gnat_info (struct dwarf2_cu
*cu
)
22777 /* Assume that the Ada compiler was GNAT, which always produces
22778 the auxiliary information. */
22779 return (cu
->language
== language_ada
);
22782 /* Return the auxiliary type of the die in question using its
22783 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22784 attribute is not present. */
22786 static struct type
*
22787 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22789 struct attribute
*type_attr
;
22791 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22795 return lookup_die_type (die
, type_attr
, cu
);
22798 /* If DIE has a descriptive_type attribute, then set the TYPE's
22799 descriptive type accordingly. */
22802 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22803 struct dwarf2_cu
*cu
)
22805 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22807 if (descriptive_type
)
22809 ALLOCATE_GNAT_AUX_TYPE (type
);
22810 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22814 /* Return the containing type of the die in question using its
22815 DW_AT_containing_type attribute. */
22817 static struct type
*
22818 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22820 struct attribute
*type_attr
;
22821 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22823 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22825 error (_("Dwarf Error: Problem turning containing type into gdb type "
22826 "[in module %s]"), objfile_name (objfile
));
22828 return lookup_die_type (die
, type_attr
, cu
);
22831 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22833 static struct type
*
22834 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22836 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22837 struct objfile
*objfile
= per_objfile
->objfile
;
22840 std::string message
22841 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22842 objfile_name (objfile
),
22843 sect_offset_str (cu
->header
.sect_off
),
22844 sect_offset_str (die
->sect_off
));
22845 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22847 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22850 /* Look up the type of DIE in CU using its type attribute ATTR.
22851 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22852 DW_AT_containing_type.
22853 If there is no type substitute an error marker. */
22855 static struct type
*
22856 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22857 struct dwarf2_cu
*cu
)
22859 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22860 struct objfile
*objfile
= per_objfile
->objfile
;
22861 struct type
*this_type
;
22863 gdb_assert (attr
->name
== DW_AT_type
22864 || attr
->name
== DW_AT_GNAT_descriptive_type
22865 || attr
->name
== DW_AT_containing_type
);
22867 /* First see if we have it cached. */
22869 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22871 struct dwarf2_per_cu_data
*per_cu
;
22872 sect_offset sect_off
= attr
->get_ref_die_offset ();
22874 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22875 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22877 else if (attr
->form_is_ref ())
22879 sect_offset sect_off
= attr
->get_ref_die_offset ();
22881 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22883 else if (attr
->form
== DW_FORM_ref_sig8
)
22885 ULONGEST signature
= attr
->as_signature ();
22887 return get_signatured_type (die
, signature
, cu
);
22891 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22892 " at %s [in module %s]"),
22893 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22894 objfile_name (objfile
));
22895 return build_error_marker_type (cu
, die
);
22898 /* If not cached we need to read it in. */
22900 if (this_type
== NULL
)
22902 struct die_info
*type_die
= NULL
;
22903 struct dwarf2_cu
*type_cu
= cu
;
22905 if (attr
->form_is_ref ())
22906 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22907 if (type_die
== NULL
)
22908 return build_error_marker_type (cu
, die
);
22909 /* If we find the type now, it's probably because the type came
22910 from an inter-CU reference and the type's CU got expanded before
22912 this_type
= read_type_die (type_die
, type_cu
);
22915 /* If we still don't have a type use an error marker. */
22917 if (this_type
== NULL
)
22918 return build_error_marker_type (cu
, die
);
22923 /* Return the type in DIE, CU.
22924 Returns NULL for invalid types.
22926 This first does a lookup in die_type_hash,
22927 and only reads the die in if necessary.
22929 NOTE: This can be called when reading in partial or full symbols. */
22931 static struct type
*
22932 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22934 struct type
*this_type
;
22936 this_type
= get_die_type (die
, cu
);
22940 return read_type_die_1 (die
, cu
);
22943 /* Read the type in DIE, CU.
22944 Returns NULL for invalid types. */
22946 static struct type
*
22947 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22949 struct type
*this_type
= NULL
;
22953 case DW_TAG_class_type
:
22954 case DW_TAG_interface_type
:
22955 case DW_TAG_structure_type
:
22956 case DW_TAG_union_type
:
22957 this_type
= read_structure_type (die
, cu
);
22959 case DW_TAG_enumeration_type
:
22960 this_type
= read_enumeration_type (die
, cu
);
22962 case DW_TAG_subprogram
:
22963 case DW_TAG_subroutine_type
:
22964 case DW_TAG_inlined_subroutine
:
22965 this_type
= read_subroutine_type (die
, cu
);
22967 case DW_TAG_array_type
:
22968 this_type
= read_array_type (die
, cu
);
22970 case DW_TAG_set_type
:
22971 this_type
= read_set_type (die
, cu
);
22973 case DW_TAG_pointer_type
:
22974 this_type
= read_tag_pointer_type (die
, cu
);
22976 case DW_TAG_ptr_to_member_type
:
22977 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22979 case DW_TAG_reference_type
:
22980 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22982 case DW_TAG_rvalue_reference_type
:
22983 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22985 case DW_TAG_const_type
:
22986 this_type
= read_tag_const_type (die
, cu
);
22988 case DW_TAG_volatile_type
:
22989 this_type
= read_tag_volatile_type (die
, cu
);
22991 case DW_TAG_restrict_type
:
22992 this_type
= read_tag_restrict_type (die
, cu
);
22994 case DW_TAG_string_type
:
22995 this_type
= read_tag_string_type (die
, cu
);
22997 case DW_TAG_typedef
:
22998 this_type
= read_typedef (die
, cu
);
23000 case DW_TAG_subrange_type
:
23001 this_type
= read_subrange_type (die
, cu
);
23003 case DW_TAG_base_type
:
23004 this_type
= read_base_type (die
, cu
);
23006 case DW_TAG_unspecified_type
:
23007 this_type
= read_unspecified_type (die
, cu
);
23009 case DW_TAG_namespace
:
23010 this_type
= read_namespace_type (die
, cu
);
23012 case DW_TAG_module
:
23013 this_type
= read_module_type (die
, cu
);
23015 case DW_TAG_atomic_type
:
23016 this_type
= read_tag_atomic_type (die
, cu
);
23019 complaint (_("unexpected tag in read_type_die: '%s'"),
23020 dwarf_tag_name (die
->tag
));
23027 /* See if we can figure out if the class lives in a namespace. We do
23028 this by looking for a member function; its demangled name will
23029 contain namespace info, if there is any.
23030 Return the computed name or NULL.
23031 Space for the result is allocated on the objfile's obstack.
23032 This is the full-die version of guess_partial_die_structure_name.
23033 In this case we know DIE has no useful parent. */
23035 static const char *
23036 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23038 struct die_info
*spec_die
;
23039 struct dwarf2_cu
*spec_cu
;
23040 struct die_info
*child
;
23041 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23044 spec_die
= die_specification (die
, &spec_cu
);
23045 if (spec_die
!= NULL
)
23051 for (child
= die
->child
;
23053 child
= child
->sibling
)
23055 if (child
->tag
== DW_TAG_subprogram
)
23057 const char *linkage_name
= dw2_linkage_name (child
, cu
);
23059 if (linkage_name
!= NULL
)
23061 gdb::unique_xmalloc_ptr
<char> actual_name
23062 (cu
->language_defn
->class_name_from_physname (linkage_name
));
23063 const char *name
= NULL
;
23065 if (actual_name
!= NULL
)
23067 const char *die_name
= dwarf2_name (die
, cu
);
23069 if (die_name
!= NULL
23070 && strcmp (die_name
, actual_name
.get ()) != 0)
23072 /* Strip off the class name from the full name.
23073 We want the prefix. */
23074 int die_name_len
= strlen (die_name
);
23075 int actual_name_len
= strlen (actual_name
.get ());
23076 const char *ptr
= actual_name
.get ();
23078 /* Test for '::' as a sanity check. */
23079 if (actual_name_len
> die_name_len
+ 2
23080 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
23081 name
= obstack_strndup (
23082 &objfile
->per_bfd
->storage_obstack
,
23083 ptr
, actual_name_len
- die_name_len
- 2);
23094 /* GCC might emit a nameless typedef that has a linkage name. Determine the
23095 prefix part in such case. See
23096 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23098 static const char *
23099 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
23101 struct attribute
*attr
;
23104 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
23105 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
23108 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
23111 attr
= dw2_linkage_name_attr (die
, cu
);
23112 const char *attr_name
= attr
->as_string ();
23113 if (attr
== NULL
|| attr_name
== NULL
)
23116 /* dwarf2_name had to be already called. */
23117 gdb_assert (attr
->canonical_string_p ());
23119 /* Strip the base name, keep any leading namespaces/classes. */
23120 base
= strrchr (attr_name
, ':');
23121 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
23124 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23125 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
23127 &base
[-1] - attr_name
);
23130 /* Return the name of the namespace/class that DIE is defined within,
23131 or "" if we can't tell. The caller should not xfree the result.
23133 For example, if we're within the method foo() in the following
23143 then determine_prefix on foo's die will return "N::C". */
23145 static const char *
23146 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
23148 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23149 struct die_info
*parent
, *spec_die
;
23150 struct dwarf2_cu
*spec_cu
;
23151 struct type
*parent_type
;
23152 const char *retval
;
23154 if (cu
->language
!= language_cplus
23155 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
23156 && cu
->language
!= language_rust
)
23159 retval
= anonymous_struct_prefix (die
, cu
);
23163 /* We have to be careful in the presence of DW_AT_specification.
23164 For example, with GCC 3.4, given the code
23168 // Definition of N::foo.
23172 then we'll have a tree of DIEs like this:
23174 1: DW_TAG_compile_unit
23175 2: DW_TAG_namespace // N
23176 3: DW_TAG_subprogram // declaration of N::foo
23177 4: DW_TAG_subprogram // definition of N::foo
23178 DW_AT_specification // refers to die #3
23180 Thus, when processing die #4, we have to pretend that we're in
23181 the context of its DW_AT_specification, namely the contex of die
23184 spec_die
= die_specification (die
, &spec_cu
);
23185 if (spec_die
== NULL
)
23186 parent
= die
->parent
;
23189 parent
= spec_die
->parent
;
23193 if (parent
== NULL
)
23195 else if (parent
->building_fullname
)
23198 const char *parent_name
;
23200 /* It has been seen on RealView 2.2 built binaries,
23201 DW_TAG_template_type_param types actually _defined_ as
23202 children of the parent class:
23205 template class <class Enum> Class{};
23206 Class<enum E> class_e;
23208 1: DW_TAG_class_type (Class)
23209 2: DW_TAG_enumeration_type (E)
23210 3: DW_TAG_enumerator (enum1:0)
23211 3: DW_TAG_enumerator (enum2:1)
23213 2: DW_TAG_template_type_param
23214 DW_AT_type DW_FORM_ref_udata (E)
23216 Besides being broken debug info, it can put GDB into an
23217 infinite loop. Consider:
23219 When we're building the full name for Class<E>, we'll start
23220 at Class, and go look over its template type parameters,
23221 finding E. We'll then try to build the full name of E, and
23222 reach here. We're now trying to build the full name of E,
23223 and look over the parent DIE for containing scope. In the
23224 broken case, if we followed the parent DIE of E, we'd again
23225 find Class, and once again go look at its template type
23226 arguments, etc., etc. Simply don't consider such parent die
23227 as source-level parent of this die (it can't be, the language
23228 doesn't allow it), and break the loop here. */
23229 name
= dwarf2_name (die
, cu
);
23230 parent_name
= dwarf2_name (parent
, cu
);
23231 complaint (_("template param type '%s' defined within parent '%s'"),
23232 name
? name
: "<unknown>",
23233 parent_name
? parent_name
: "<unknown>");
23237 switch (parent
->tag
)
23239 case DW_TAG_namespace
:
23240 parent_type
= read_type_die (parent
, cu
);
23241 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
23242 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
23243 Work around this problem here. */
23244 if (cu
->language
== language_cplus
23245 && strcmp (parent_type
->name (), "::") == 0)
23247 /* We give a name to even anonymous namespaces. */
23248 return parent_type
->name ();
23249 case DW_TAG_class_type
:
23250 case DW_TAG_interface_type
:
23251 case DW_TAG_structure_type
:
23252 case DW_TAG_union_type
:
23253 case DW_TAG_module
:
23254 parent_type
= read_type_die (parent
, cu
);
23255 if (parent_type
->name () != NULL
)
23256 return parent_type
->name ();
23258 /* An anonymous structure is only allowed non-static data
23259 members; no typedefs, no member functions, et cetera.
23260 So it does not need a prefix. */
23262 case DW_TAG_compile_unit
:
23263 case DW_TAG_partial_unit
:
23264 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
23265 if (cu
->language
== language_cplus
23266 && !per_objfile
->per_bfd
->types
.empty ()
23267 && die
->child
!= NULL
23268 && (die
->tag
== DW_TAG_class_type
23269 || die
->tag
== DW_TAG_structure_type
23270 || die
->tag
== DW_TAG_union_type
))
23272 const char *name
= guess_full_die_structure_name (die
, cu
);
23277 case DW_TAG_subprogram
:
23278 /* Nested subroutines in Fortran get a prefix with the name
23279 of the parent's subroutine. */
23280 if (cu
->language
== language_fortran
)
23282 if ((die
->tag
== DW_TAG_subprogram
)
23283 && (dwarf2_name (parent
, cu
) != NULL
))
23284 return dwarf2_name (parent
, cu
);
23286 return determine_prefix (parent
, cu
);
23287 case DW_TAG_enumeration_type
:
23288 parent_type
= read_type_die (parent
, cu
);
23289 if (TYPE_DECLARED_CLASS (parent_type
))
23291 if (parent_type
->name () != NULL
)
23292 return parent_type
->name ();
23295 /* Fall through. */
23297 return determine_prefix (parent
, cu
);
23301 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
23302 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
23303 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
23304 an obconcat, otherwise allocate storage for the result. The CU argument is
23305 used to determine the language and hence, the appropriate separator. */
23307 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
23310 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
23311 int physname
, struct dwarf2_cu
*cu
)
23313 const char *lead
= "";
23316 if (suffix
== NULL
|| suffix
[0] == '\0'
23317 || prefix
== NULL
|| prefix
[0] == '\0')
23319 else if (cu
->language
== language_d
)
23321 /* For D, the 'main' function could be defined in any module, but it
23322 should never be prefixed. */
23323 if (strcmp (suffix
, "D main") == 0)
23331 else if (cu
->language
== language_fortran
&& physname
)
23333 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
23334 DW_AT_MIPS_linkage_name is preferred and used instead. */
23342 if (prefix
== NULL
)
23344 if (suffix
== NULL
)
23351 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
23353 strcpy (retval
, lead
);
23354 strcat (retval
, prefix
);
23355 strcat (retval
, sep
);
23356 strcat (retval
, suffix
);
23361 /* We have an obstack. */
23362 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
23366 /* Get name of a die, return NULL if not found. */
23368 static const char *
23369 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
23370 struct objfile
*objfile
)
23372 if (name
&& cu
->language
== language_cplus
)
23374 gdb::unique_xmalloc_ptr
<char> canon_name
23375 = cp_canonicalize_string (name
);
23377 if (canon_name
!= nullptr)
23378 name
= objfile
->intern (canon_name
.get ());
23384 /* Get name of a die, return NULL if not found.
23385 Anonymous namespaces are converted to their magic string. */
23387 static const char *
23388 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23390 struct attribute
*attr
;
23391 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23393 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23394 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23395 if (attr_name
== nullptr
23396 && die
->tag
!= DW_TAG_namespace
23397 && die
->tag
!= DW_TAG_class_type
23398 && die
->tag
!= DW_TAG_interface_type
23399 && die
->tag
!= DW_TAG_structure_type
23400 && die
->tag
!= DW_TAG_union_type
)
23405 case DW_TAG_compile_unit
:
23406 case DW_TAG_partial_unit
:
23407 /* Compilation units have a DW_AT_name that is a filename, not
23408 a source language identifier. */
23409 case DW_TAG_enumeration_type
:
23410 case DW_TAG_enumerator
:
23411 /* These tags always have simple identifiers already; no need
23412 to canonicalize them. */
23415 case DW_TAG_namespace
:
23416 if (attr_name
!= nullptr)
23418 return CP_ANONYMOUS_NAMESPACE_STR
;
23420 case DW_TAG_class_type
:
23421 case DW_TAG_interface_type
:
23422 case DW_TAG_structure_type
:
23423 case DW_TAG_union_type
:
23424 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23425 structures or unions. These were of the form "._%d" in GCC 4.1,
23426 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23427 and GCC 4.4. We work around this problem by ignoring these. */
23428 if (attr_name
!= nullptr
23429 && (startswith (attr_name
, "._")
23430 || startswith (attr_name
, "<anonymous")))
23433 /* GCC might emit a nameless typedef that has a linkage name. See
23434 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23435 if (!attr
|| attr_name
== NULL
)
23437 attr
= dw2_linkage_name_attr (die
, cu
);
23438 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23439 if (attr
== NULL
|| attr_name
== NULL
)
23442 /* Avoid demangling attr_name the second time on a second
23443 call for the same DIE. */
23444 if (!attr
->canonical_string_p ())
23446 gdb::unique_xmalloc_ptr
<char> demangled
23447 (gdb_demangle (attr_name
, DMGL_TYPES
));
23448 if (demangled
== nullptr)
23451 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
23452 attr_name
= attr
->as_string ();
23455 /* Strip any leading namespaces/classes, keep only the
23456 base name. DW_AT_name for named DIEs does not
23457 contain the prefixes. */
23458 const char *base
= strrchr (attr_name
, ':');
23459 if (base
&& base
> attr_name
&& base
[-1] == ':')
23470 if (!attr
->canonical_string_p ())
23471 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
23473 return attr
->as_string ();
23476 /* Return the die that this die in an extension of, or NULL if there
23477 is none. *EXT_CU is the CU containing DIE on input, and the CU
23478 containing the return value on output. */
23480 static struct die_info
*
23481 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23483 struct attribute
*attr
;
23485 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23489 return follow_die_ref (die
, attr
, ext_cu
);
23493 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23497 print_spaces (indent
, f
);
23498 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23499 dwarf_tag_name (die
->tag
), die
->abbrev
,
23500 sect_offset_str (die
->sect_off
));
23502 if (die
->parent
!= NULL
)
23504 print_spaces (indent
, f
);
23505 fprintf_unfiltered (f
, " parent at offset: %s\n",
23506 sect_offset_str (die
->parent
->sect_off
));
23509 print_spaces (indent
, f
);
23510 fprintf_unfiltered (f
, " has children: %s\n",
23511 dwarf_bool_name (die
->child
!= NULL
));
23513 print_spaces (indent
, f
);
23514 fprintf_unfiltered (f
, " attributes:\n");
23516 for (i
= 0; i
< die
->num_attrs
; ++i
)
23518 print_spaces (indent
, f
);
23519 fprintf_unfiltered (f
, " %s (%s) ",
23520 dwarf_attr_name (die
->attrs
[i
].name
),
23521 dwarf_form_name (die
->attrs
[i
].form
));
23523 switch (die
->attrs
[i
].form
)
23526 case DW_FORM_addrx
:
23527 case DW_FORM_GNU_addr_index
:
23528 fprintf_unfiltered (f
, "address: ");
23529 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
23531 case DW_FORM_block2
:
23532 case DW_FORM_block4
:
23533 case DW_FORM_block
:
23534 case DW_FORM_block1
:
23535 fprintf_unfiltered (f
, "block: size %s",
23536 pulongest (die
->attrs
[i
].as_block ()->size
));
23538 case DW_FORM_exprloc
:
23539 fprintf_unfiltered (f
, "expression: size %s",
23540 pulongest (die
->attrs
[i
].as_block ()->size
));
23542 case DW_FORM_data16
:
23543 fprintf_unfiltered (f
, "constant of 16 bytes");
23545 case DW_FORM_ref_addr
:
23546 fprintf_unfiltered (f
, "ref address: ");
23547 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23549 case DW_FORM_GNU_ref_alt
:
23550 fprintf_unfiltered (f
, "alt ref address: ");
23551 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23557 case DW_FORM_ref_udata
:
23558 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23559 (long) (die
->attrs
[i
].as_unsigned ()));
23561 case DW_FORM_data1
:
23562 case DW_FORM_data2
:
23563 case DW_FORM_data4
:
23564 case DW_FORM_data8
:
23565 case DW_FORM_udata
:
23566 fprintf_unfiltered (f
, "constant: %s",
23567 pulongest (die
->attrs
[i
].as_unsigned ()));
23569 case DW_FORM_sec_offset
:
23570 fprintf_unfiltered (f
, "section offset: %s",
23571 pulongest (die
->attrs
[i
].as_unsigned ()));
23573 case DW_FORM_ref_sig8
:
23574 fprintf_unfiltered (f
, "signature: %s",
23575 hex_string (die
->attrs
[i
].as_signature ()));
23577 case DW_FORM_string
:
23579 case DW_FORM_line_strp
:
23581 case DW_FORM_GNU_str_index
:
23582 case DW_FORM_GNU_strp_alt
:
23583 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23584 die
->attrs
[i
].as_string ()
23585 ? die
->attrs
[i
].as_string () : "",
23586 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23589 if (die
->attrs
[i
].as_boolean ())
23590 fprintf_unfiltered (f
, "flag: TRUE");
23592 fprintf_unfiltered (f
, "flag: FALSE");
23594 case DW_FORM_flag_present
:
23595 fprintf_unfiltered (f
, "flag: TRUE");
23597 case DW_FORM_indirect
:
23598 /* The reader will have reduced the indirect form to
23599 the "base form" so this form should not occur. */
23600 fprintf_unfiltered (f
,
23601 "unexpected attribute form: DW_FORM_indirect");
23603 case DW_FORM_sdata
:
23604 case DW_FORM_implicit_const
:
23605 fprintf_unfiltered (f
, "constant: %s",
23606 plongest (die
->attrs
[i
].as_signed ()));
23609 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23610 die
->attrs
[i
].form
);
23613 fprintf_unfiltered (f
, "\n");
23618 dump_die_for_error (struct die_info
*die
)
23620 dump_die_shallow (gdb_stderr
, 0, die
);
23624 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23626 int indent
= level
* 4;
23628 gdb_assert (die
!= NULL
);
23630 if (level
>= max_level
)
23633 dump_die_shallow (f
, indent
, die
);
23635 if (die
->child
!= NULL
)
23637 print_spaces (indent
, f
);
23638 fprintf_unfiltered (f
, " Children:");
23639 if (level
+ 1 < max_level
)
23641 fprintf_unfiltered (f
, "\n");
23642 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23646 fprintf_unfiltered (f
,
23647 " [not printed, max nesting level reached]\n");
23651 if (die
->sibling
!= NULL
&& level
> 0)
23653 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23657 /* This is called from the pdie macro in gdbinit.in.
23658 It's not static so gcc will keep a copy callable from gdb. */
23661 dump_die (struct die_info
*die
, int max_level
)
23663 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23667 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23671 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23672 to_underlying (die
->sect_off
),
23678 /* Follow reference or signature attribute ATTR of SRC_DIE.
23679 On entry *REF_CU is the CU of SRC_DIE.
23680 On exit *REF_CU is the CU of the result. */
23682 static struct die_info
*
23683 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23684 struct dwarf2_cu
**ref_cu
)
23686 struct die_info
*die
;
23688 if (attr
->form_is_ref ())
23689 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23690 else if (attr
->form
== DW_FORM_ref_sig8
)
23691 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23694 dump_die_for_error (src_die
);
23695 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23696 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23702 /* Follow reference OFFSET.
23703 On entry *REF_CU is the CU of the source die referencing OFFSET.
23704 On exit *REF_CU is the CU of the result.
23705 Returns NULL if OFFSET is invalid. */
23707 static struct die_info
*
23708 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23709 struct dwarf2_cu
**ref_cu
)
23711 struct die_info temp_die
;
23712 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23713 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23715 gdb_assert (cu
->per_cu
!= NULL
);
23719 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23720 "source CU contains target offset: %d",
23721 sect_offset_str (cu
->per_cu
->sect_off
),
23722 sect_offset_str (sect_off
),
23723 cu
->header
.offset_in_cu_p (sect_off
));
23725 if (cu
->per_cu
->is_debug_types
)
23727 /* .debug_types CUs cannot reference anything outside their CU.
23728 If they need to, they have to reference a signatured type via
23729 DW_FORM_ref_sig8. */
23730 if (!cu
->header
.offset_in_cu_p (sect_off
))
23733 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23734 || !cu
->header
.offset_in_cu_p (sect_off
))
23736 struct dwarf2_per_cu_data
*per_cu
;
23738 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23741 dwarf_read_debug_printf_v ("target CU offset: %s, "
23742 "target CU DIEs loaded: %d",
23743 sect_offset_str (per_cu
->sect_off
),
23744 per_objfile
->get_cu (per_cu
) != nullptr);
23746 /* If necessary, add it to the queue and load its DIEs.
23748 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23749 it doesn't mean they are currently loaded. Since we require them
23750 to be loaded, we must check for ourselves. */
23751 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
)
23752 || per_objfile
->get_cu (per_cu
) == nullptr)
23753 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23754 false, cu
->language
);
23756 target_cu
= per_objfile
->get_cu (per_cu
);
23757 gdb_assert (target_cu
!= nullptr);
23759 else if (cu
->dies
== NULL
)
23761 /* We're loading full DIEs during partial symbol reading. */
23762 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23763 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23767 *ref_cu
= target_cu
;
23768 temp_die
.sect_off
= sect_off
;
23770 if (target_cu
!= cu
)
23771 target_cu
->ancestor
= cu
;
23773 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23775 to_underlying (sect_off
));
23778 /* Follow reference attribute ATTR of SRC_DIE.
23779 On entry *REF_CU is the CU of SRC_DIE.
23780 On exit *REF_CU is the CU of the result. */
23782 static struct die_info
*
23783 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23784 struct dwarf2_cu
**ref_cu
)
23786 sect_offset sect_off
= attr
->get_ref_die_offset ();
23787 struct dwarf2_cu
*cu
= *ref_cu
;
23788 struct die_info
*die
;
23790 die
= follow_die_offset (sect_off
,
23791 (attr
->form
== DW_FORM_GNU_ref_alt
23792 || cu
->per_cu
->is_dwz
),
23795 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23796 "at %s [in module %s]"),
23797 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23798 objfile_name (cu
->per_objfile
->objfile
));
23805 struct dwarf2_locexpr_baton
23806 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23807 dwarf2_per_cu_data
*per_cu
,
23808 dwarf2_per_objfile
*per_objfile
,
23809 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23810 bool resolve_abstract_p
)
23812 struct die_info
*die
;
23813 struct attribute
*attr
;
23814 struct dwarf2_locexpr_baton retval
;
23815 struct objfile
*objfile
= per_objfile
->objfile
;
23817 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23819 cu
= load_cu (per_cu
, per_objfile
, false);
23823 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23824 Instead just throw an error, not much else we can do. */
23825 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23826 sect_offset_str (sect_off
), objfile_name (objfile
));
23829 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23831 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23832 sect_offset_str (sect_off
), objfile_name (objfile
));
23834 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23835 if (!attr
&& resolve_abstract_p
23836 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23837 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23839 CORE_ADDR pc
= get_frame_pc ();
23840 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23841 struct gdbarch
*gdbarch
= objfile
->arch ();
23843 for (const auto &cand_off
23844 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23846 struct dwarf2_cu
*cand_cu
= cu
;
23847 struct die_info
*cand
23848 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23851 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23854 CORE_ADDR pc_low
, pc_high
;
23855 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23856 if (pc_low
== ((CORE_ADDR
) -1))
23858 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23859 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23860 if (!(pc_low
<= pc
&& pc
< pc_high
))
23864 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23871 /* DWARF: "If there is no such attribute, then there is no effect.".
23872 DATA is ignored if SIZE is 0. */
23874 retval
.data
= NULL
;
23877 else if (attr
->form_is_section_offset ())
23879 struct dwarf2_loclist_baton loclist_baton
;
23880 CORE_ADDR pc
= get_frame_pc ();
23883 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23885 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23887 retval
.size
= size
;
23891 if (!attr
->form_is_block ())
23892 error (_("Dwarf Error: DIE at %s referenced in module %s "
23893 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23894 sect_offset_str (sect_off
), objfile_name (objfile
));
23896 struct dwarf_block
*block
= attr
->as_block ();
23897 retval
.data
= block
->data
;
23898 retval
.size
= block
->size
;
23900 retval
.per_objfile
= per_objfile
;
23901 retval
.per_cu
= cu
->per_cu
;
23903 per_objfile
->age_comp_units ();
23910 struct dwarf2_locexpr_baton
23911 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23912 dwarf2_per_cu_data
*per_cu
,
23913 dwarf2_per_objfile
*per_objfile
,
23914 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23916 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23918 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23922 /* Write a constant of a given type as target-ordered bytes into
23925 static const gdb_byte
*
23926 write_constant_as_bytes (struct obstack
*obstack
,
23927 enum bfd_endian byte_order
,
23934 *len
= TYPE_LENGTH (type
);
23935 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23936 store_unsigned_integer (result
, *len
, byte_order
, value
);
23944 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23945 dwarf2_per_cu_data
*per_cu
,
23946 dwarf2_per_objfile
*per_objfile
,
23950 struct die_info
*die
;
23951 struct attribute
*attr
;
23952 const gdb_byte
*result
= NULL
;
23955 enum bfd_endian byte_order
;
23956 struct objfile
*objfile
= per_objfile
->objfile
;
23958 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23960 cu
= load_cu (per_cu
, per_objfile
, false);
23964 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23965 Instead just throw an error, not much else we can do. */
23966 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23967 sect_offset_str (sect_off
), objfile_name (objfile
));
23970 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23972 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23973 sect_offset_str (sect_off
), objfile_name (objfile
));
23975 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23979 byte_order
= (bfd_big_endian (objfile
->obfd
)
23980 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23982 switch (attr
->form
)
23985 case DW_FORM_addrx
:
23986 case DW_FORM_GNU_addr_index
:
23990 *len
= cu
->header
.addr_size
;
23991 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23992 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23996 case DW_FORM_string
:
23999 case DW_FORM_GNU_str_index
:
24000 case DW_FORM_GNU_strp_alt
:
24001 /* The string is already allocated on the objfile obstack, point
24004 const char *attr_name
= attr
->as_string ();
24005 result
= (const gdb_byte
*) attr_name
;
24006 *len
= strlen (attr_name
);
24009 case DW_FORM_block1
:
24010 case DW_FORM_block2
:
24011 case DW_FORM_block4
:
24012 case DW_FORM_block
:
24013 case DW_FORM_exprloc
:
24014 case DW_FORM_data16
:
24016 struct dwarf_block
*block
= attr
->as_block ();
24017 result
= block
->data
;
24018 *len
= block
->size
;
24022 /* The DW_AT_const_value attributes are supposed to carry the
24023 symbol's value "represented as it would be on the target
24024 architecture." By the time we get here, it's already been
24025 converted to host endianness, so we just need to sign- or
24026 zero-extend it as appropriate. */
24027 case DW_FORM_data1
:
24028 type
= die_type (die
, cu
);
24029 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
24030 if (result
== NULL
)
24031 result
= write_constant_as_bytes (obstack
, byte_order
,
24034 case DW_FORM_data2
:
24035 type
= die_type (die
, cu
);
24036 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
24037 if (result
== NULL
)
24038 result
= write_constant_as_bytes (obstack
, byte_order
,
24041 case DW_FORM_data4
:
24042 type
= die_type (die
, cu
);
24043 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
24044 if (result
== NULL
)
24045 result
= write_constant_as_bytes (obstack
, byte_order
,
24048 case DW_FORM_data8
:
24049 type
= die_type (die
, cu
);
24050 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
24051 if (result
== NULL
)
24052 result
= write_constant_as_bytes (obstack
, byte_order
,
24056 case DW_FORM_sdata
:
24057 case DW_FORM_implicit_const
:
24058 type
= die_type (die
, cu
);
24059 result
= write_constant_as_bytes (obstack
, byte_order
,
24060 type
, attr
->as_signed (), len
);
24063 case DW_FORM_udata
:
24064 type
= die_type (die
, cu
);
24065 result
= write_constant_as_bytes (obstack
, byte_order
,
24066 type
, attr
->as_unsigned (), len
);
24070 complaint (_("unsupported const value attribute form: '%s'"),
24071 dwarf_form_name (attr
->form
));
24081 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
24082 dwarf2_per_cu_data
*per_cu
,
24083 dwarf2_per_objfile
*per_objfile
)
24085 struct die_info
*die
;
24087 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
24089 cu
= load_cu (per_cu
, per_objfile
, false);
24094 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
24098 return die_type (die
, cu
);
24104 dwarf2_get_die_type (cu_offset die_offset
,
24105 dwarf2_per_cu_data
*per_cu
,
24106 dwarf2_per_objfile
*per_objfile
)
24108 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
24109 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
24112 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
24113 On entry *REF_CU is the CU of SRC_DIE.
24114 On exit *REF_CU is the CU of the result.
24115 Returns NULL if the referenced DIE isn't found. */
24117 static struct die_info
*
24118 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
24119 struct dwarf2_cu
**ref_cu
)
24121 struct die_info temp_die
;
24122 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
24123 struct die_info
*die
;
24124 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
24127 /* While it might be nice to assert sig_type->type == NULL here,
24128 we can get here for DW_AT_imported_declaration where we need
24129 the DIE not the type. */
24131 /* If necessary, add it to the queue and load its DIEs.
24133 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
24134 it doesn't mean they are currently loaded. Since we require them
24135 to be loaded, we must check for ourselves. */
24136 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
24138 || per_objfile
->get_cu (&sig_type
->per_cu
) == nullptr)
24139 read_signatured_type (sig_type
, per_objfile
);
24141 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
24142 gdb_assert (sig_cu
!= NULL
);
24143 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
24144 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
24145 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
24146 to_underlying (temp_die
.sect_off
));
24149 /* For .gdb_index version 7 keep track of included TUs.
24150 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
24151 if (per_objfile
->per_bfd
->index_table
!= NULL
24152 && per_objfile
->per_bfd
->index_table
->version
<= 7)
24154 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
24159 sig_cu
->ancestor
= cu
;
24167 /* Follow signatured type referenced by ATTR in SRC_DIE.
24168 On entry *REF_CU is the CU of SRC_DIE.
24169 On exit *REF_CU is the CU of the result.
24170 The result is the DIE of the type.
24171 If the referenced type cannot be found an error is thrown. */
24173 static struct die_info
*
24174 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
24175 struct dwarf2_cu
**ref_cu
)
24177 ULONGEST signature
= attr
->as_signature ();
24178 struct signatured_type
*sig_type
;
24179 struct die_info
*die
;
24181 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
24183 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
24184 /* sig_type will be NULL if the signatured type is missing from
24186 if (sig_type
== NULL
)
24188 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24189 " from DIE at %s [in module %s]"),
24190 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
24191 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
24194 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
24197 dump_die_for_error (src_die
);
24198 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24199 " from DIE at %s [in module %s]"),
24200 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
24201 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
24207 /* Get the type specified by SIGNATURE referenced in DIE/CU,
24208 reading in and processing the type unit if necessary. */
24210 static struct type
*
24211 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
24212 struct dwarf2_cu
*cu
)
24214 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24215 struct signatured_type
*sig_type
;
24216 struct dwarf2_cu
*type_cu
;
24217 struct die_info
*type_die
;
24220 sig_type
= lookup_signatured_type (cu
, signature
);
24221 /* sig_type will be NULL if the signatured type is missing from
24223 if (sig_type
== NULL
)
24225 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24226 " from DIE at %s [in module %s]"),
24227 hex_string (signature
), sect_offset_str (die
->sect_off
),
24228 objfile_name (per_objfile
->objfile
));
24229 return build_error_marker_type (cu
, die
);
24232 /* If we already know the type we're done. */
24233 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
24234 if (type
!= nullptr)
24238 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
24239 if (type_die
!= NULL
)
24241 /* N.B. We need to call get_die_type to ensure only one type for this DIE
24242 is created. This is important, for example, because for c++ classes
24243 we need TYPE_NAME set which is only done by new_symbol. Blech. */
24244 type
= read_type_die (type_die
, type_cu
);
24247 complaint (_("Dwarf Error: Cannot build signatured type %s"
24248 " referenced from DIE at %s [in module %s]"),
24249 hex_string (signature
), sect_offset_str (die
->sect_off
),
24250 objfile_name (per_objfile
->objfile
));
24251 type
= build_error_marker_type (cu
, die
);
24256 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24257 " from DIE at %s [in module %s]"),
24258 hex_string (signature
), sect_offset_str (die
->sect_off
),
24259 objfile_name (per_objfile
->objfile
));
24260 type
= build_error_marker_type (cu
, die
);
24263 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
24268 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
24269 reading in and processing the type unit if necessary. */
24271 static struct type
*
24272 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
24273 struct dwarf2_cu
*cu
) /* ARI: editCase function */
24275 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
24276 if (attr
->form_is_ref ())
24278 struct dwarf2_cu
*type_cu
= cu
;
24279 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24281 return read_type_die (type_die
, type_cu
);
24283 else if (attr
->form
== DW_FORM_ref_sig8
)
24285 return get_signatured_type (die
, attr
->as_signature (), cu
);
24289 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24291 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24292 " at %s [in module %s]"),
24293 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24294 objfile_name (per_objfile
->objfile
));
24295 return build_error_marker_type (cu
, die
);
24299 /* Load the DIEs associated with type unit PER_CU into memory. */
24302 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
24303 dwarf2_per_objfile
*per_objfile
)
24305 struct signatured_type
*sig_type
;
24307 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24308 gdb_assert (! per_cu
->type_unit_group_p ());
24310 /* We have the per_cu, but we need the signatured_type.
24311 Fortunately this is an easy translation. */
24312 gdb_assert (per_cu
->is_debug_types
);
24313 sig_type
= (struct signatured_type
*) per_cu
;
24315 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
24317 read_signatured_type (sig_type
, per_objfile
);
24319 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
24322 /* Read in a signatured type and build its CU and DIEs.
24323 If the type is a stub for the real type in a DWO file,
24324 read in the real type from the DWO file as well. */
24327 read_signatured_type (signatured_type
*sig_type
,
24328 dwarf2_per_objfile
*per_objfile
)
24330 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24332 gdb_assert (per_cu
->is_debug_types
);
24333 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
24335 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
24337 if (!reader
.dummy_p
)
24339 struct dwarf2_cu
*cu
= reader
.cu
;
24340 const gdb_byte
*info_ptr
= reader
.info_ptr
;
24342 gdb_assert (cu
->die_hash
== NULL
);
24344 htab_create_alloc_ex (cu
->header
.length
/ 12,
24348 &cu
->comp_unit_obstack
,
24349 hashtab_obstack_allocate
,
24350 dummy_obstack_deallocate
);
24352 if (reader
.comp_unit_die
->has_children
)
24353 reader
.comp_unit_die
->child
24354 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
24355 reader
.comp_unit_die
);
24356 cu
->dies
= reader
.comp_unit_die
;
24357 /* comp_unit_die is not stored in die_hash, no need. */
24359 /* We try not to read any attributes in this function, because
24360 not all CUs needed for references have been loaded yet, and
24361 symbol table processing isn't initialized. But we have to
24362 set the CU language, or we won't be able to build types
24363 correctly. Similarly, if we do not read the producer, we can
24364 not apply producer-specific interpretation. */
24365 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24370 sig_type
->per_cu
.tu_read
= 1;
24373 /* Decode simple location descriptions.
24374 Given a pointer to a dwarf block that defines a location, compute
24375 the location and return the value. If COMPUTED is non-null, it is
24376 set to true to indicate that decoding was successful, and false
24377 otherwise. If COMPUTED is null, then this function may emit a
24381 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
24383 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
24385 size_t size
= blk
->size
;
24386 const gdb_byte
*data
= blk
->data
;
24387 CORE_ADDR stack
[64];
24389 unsigned int bytes_read
, unsnd
;
24392 if (computed
!= nullptr)
24398 stack
[++stacki
] = 0;
24437 stack
[++stacki
] = op
- DW_OP_lit0
;
24472 stack
[++stacki
] = op
- DW_OP_reg0
;
24475 if (computed
== nullptr)
24476 dwarf2_complex_location_expr_complaint ();
24483 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24485 stack
[++stacki
] = unsnd
;
24488 if (computed
== nullptr)
24489 dwarf2_complex_location_expr_complaint ();
24496 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
24501 case DW_OP_const1u
:
24502 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24506 case DW_OP_const1s
:
24507 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24511 case DW_OP_const2u
:
24512 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24516 case DW_OP_const2s
:
24517 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24521 case DW_OP_const4u
:
24522 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24526 case DW_OP_const4s
:
24527 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24531 case DW_OP_const8u
:
24532 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24537 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24543 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24548 stack
[stacki
+ 1] = stack
[stacki
];
24553 stack
[stacki
- 1] += stack
[stacki
];
24557 case DW_OP_plus_uconst
:
24558 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24564 stack
[stacki
- 1] -= stack
[stacki
];
24569 /* If we're not the last op, then we definitely can't encode
24570 this using GDB's address_class enum. This is valid for partial
24571 global symbols, although the variable's address will be bogus
24575 if (computed
== nullptr)
24576 dwarf2_complex_location_expr_complaint ();
24582 case DW_OP_GNU_push_tls_address
:
24583 case DW_OP_form_tls_address
:
24584 /* The top of the stack has the offset from the beginning
24585 of the thread control block at which the variable is located. */
24586 /* Nothing should follow this operator, so the top of stack would
24588 /* This is valid for partial global symbols, but the variable's
24589 address will be bogus in the psymtab. Make it always at least
24590 non-zero to not look as a variable garbage collected by linker
24591 which have DW_OP_addr 0. */
24594 if (computed
== nullptr)
24595 dwarf2_complex_location_expr_complaint ();
24602 case DW_OP_GNU_uninit
:
24603 if (computed
!= nullptr)
24608 case DW_OP_GNU_addr_index
:
24609 case DW_OP_GNU_const_index
:
24610 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24616 if (computed
== nullptr)
24618 const char *name
= get_DW_OP_name (op
);
24621 complaint (_("unsupported stack op: '%s'"),
24624 complaint (_("unsupported stack op: '%02x'"),
24628 return (stack
[stacki
]);
24631 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24632 outside of the allocated space. Also enforce minimum>0. */
24633 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24635 if (computed
== nullptr)
24636 complaint (_("location description stack overflow"));
24642 if (computed
== nullptr)
24643 complaint (_("location description stack underflow"));
24648 if (computed
!= nullptr)
24650 return (stack
[stacki
]);
24653 /* memory allocation interface */
24655 static struct dwarf_block
*
24656 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24658 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24661 static struct die_info
*
24662 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24664 struct die_info
*die
;
24665 size_t size
= sizeof (struct die_info
);
24668 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24670 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24671 memset (die
, 0, sizeof (struct die_info
));
24677 /* Macro support. */
24679 /* An overload of dwarf_decode_macros that finds the correct section
24680 and ensures it is read in before calling the other overload. */
24683 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24684 int section_is_gnu
)
24686 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24687 struct objfile
*objfile
= per_objfile
->objfile
;
24688 const struct line_header
*lh
= cu
->line_header
;
24689 unsigned int offset_size
= cu
->header
.offset_size
;
24690 struct dwarf2_section_info
*section
;
24691 const char *section_name
;
24693 if (cu
->dwo_unit
!= nullptr)
24695 if (section_is_gnu
)
24697 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24698 section_name
= ".debug_macro.dwo";
24702 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24703 section_name
= ".debug_macinfo.dwo";
24708 if (section_is_gnu
)
24710 section
= &per_objfile
->per_bfd
->macro
;
24711 section_name
= ".debug_macro";
24715 section
= &per_objfile
->per_bfd
->macinfo
;
24716 section_name
= ".debug_macinfo";
24720 section
->read (objfile
);
24721 if (section
->buffer
== nullptr)
24723 complaint (_("missing %s section"), section_name
);
24727 buildsym_compunit
*builder
= cu
->get_builder ();
24729 struct dwarf2_section_info
*str_offsets_section
;
24730 struct dwarf2_section_info
*str_section
;
24731 ULONGEST str_offsets_base
;
24733 if (cu
->dwo_unit
!= nullptr)
24735 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24736 ->sections
.str_offsets
;
24737 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24738 str_offsets_base
= cu
->header
.addr_size
;
24742 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24743 str_section
= &per_objfile
->per_bfd
->str
;
24744 str_offsets_base
= *cu
->str_offsets_base
;
24747 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24748 offset_size
, offset
, str_section
, str_offsets_section
,
24749 str_offsets_base
, section_is_gnu
);
24752 /* Return the .debug_loc section to use for CU.
24753 For DWO files use .debug_loc.dwo. */
24755 static struct dwarf2_section_info
*
24756 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24758 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24762 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24764 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24766 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24767 : &per_objfile
->per_bfd
->loc
);
24770 /* Return the .debug_rnglists section to use for CU. */
24771 static struct dwarf2_section_info
*
24772 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24774 if (cu
->header
.version
< 5)
24775 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24776 cu
->header
.version
);
24777 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24779 /* Make sure we read the .debug_rnglists section from the file that
24780 contains the DW_AT_ranges attribute we are reading. Normally that
24781 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24782 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24784 if (cu
->dwo_unit
!= nullptr
24785 && tag
!= DW_TAG_compile_unit
24786 && tag
!= DW_TAG_skeleton_unit
)
24788 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24790 if (sections
->rnglists
.size
> 0)
24791 return §ions
->rnglists
;
24793 error (_(".debug_rnglists section is missing from .dwo file."));
24795 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24798 /* A helper function that fills in a dwarf2_loclist_baton. */
24801 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24802 struct dwarf2_loclist_baton
*baton
,
24803 const struct attribute
*attr
)
24805 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24806 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24808 section
->read (per_objfile
->objfile
);
24810 baton
->per_objfile
= per_objfile
;
24811 baton
->per_cu
= cu
->per_cu
;
24812 gdb_assert (baton
->per_cu
);
24813 /* We don't know how long the location list is, but make sure we
24814 don't run off the edge of the section. */
24815 baton
->size
= section
->size
- attr
->as_unsigned ();
24816 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24817 if (cu
->base_address
.has_value ())
24818 baton
->base_address
= *cu
->base_address
;
24820 baton
->base_address
= 0;
24821 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24825 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24826 struct dwarf2_cu
*cu
, int is_block
)
24828 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24829 struct objfile
*objfile
= per_objfile
->objfile
;
24830 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24832 if (attr
->form_is_section_offset ()
24833 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24834 the section. If so, fall through to the complaint in the
24836 && attr
->as_unsigned () < section
->get_size (objfile
))
24838 struct dwarf2_loclist_baton
*baton
;
24840 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24842 fill_in_loclist_baton (cu
, baton
, attr
);
24844 if (!cu
->base_address
.has_value ())
24845 complaint (_("Location list used without "
24846 "specifying the CU base address."));
24848 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24849 ? dwarf2_loclist_block_index
24850 : dwarf2_loclist_index
);
24851 SYMBOL_LOCATION_BATON (sym
) = baton
;
24855 struct dwarf2_locexpr_baton
*baton
;
24857 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24858 baton
->per_objfile
= per_objfile
;
24859 baton
->per_cu
= cu
->per_cu
;
24860 gdb_assert (baton
->per_cu
);
24862 if (attr
->form_is_block ())
24864 /* Note that we're just copying the block's data pointer
24865 here, not the actual data. We're still pointing into the
24866 info_buffer for SYM's objfile; right now we never release
24867 that buffer, but when we do clean up properly this may
24869 struct dwarf_block
*block
= attr
->as_block ();
24870 baton
->size
= block
->size
;
24871 baton
->data
= block
->data
;
24875 dwarf2_invalid_attrib_class_complaint ("location description",
24876 sym
->natural_name ());
24880 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24881 ? dwarf2_locexpr_block_index
24882 : dwarf2_locexpr_index
);
24883 SYMBOL_LOCATION_BATON (sym
) = baton
;
24889 const comp_unit_head
*
24890 dwarf2_per_cu_data::get_header () const
24892 if (!m_header_read_in
)
24894 const gdb_byte
*info_ptr
24895 = this->section
->buffer
+ to_underlying (this->sect_off
);
24897 memset (&m_header
, 0, sizeof (m_header
));
24899 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24900 rcuh_kind::COMPILE
);
24902 m_header_read_in
= true;
24911 dwarf2_per_cu_data::addr_size () const
24913 return this->get_header ()->addr_size
;
24919 dwarf2_per_cu_data::offset_size () const
24921 return this->get_header ()->offset_size
;
24927 dwarf2_per_cu_data::ref_addr_size () const
24929 const comp_unit_head
*header
= this->get_header ();
24931 if (header
->version
== 2)
24932 return header
->addr_size
;
24934 return header
->offset_size
;
24940 dwarf2_cu::addr_type () const
24942 struct objfile
*objfile
= this->per_objfile
->objfile
;
24943 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24944 struct type
*addr_type
= lookup_pointer_type (void_type
);
24945 int addr_size
= this->per_cu
->addr_size ();
24947 if (TYPE_LENGTH (addr_type
) == addr_size
)
24950 addr_type
= addr_sized_int_type (addr_type
->is_unsigned ());
24954 /* A helper function for dwarf2_find_containing_comp_unit that returns
24955 the index of the result, and that searches a vector. It will
24956 return a result even if the offset in question does not actually
24957 occur in any CU. This is separate so that it can be unit
24961 dwarf2_find_containing_comp_unit
24962 (sect_offset sect_off
,
24963 unsigned int offset_in_dwz
,
24964 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
24969 high
= all_comp_units
.size () - 1;
24972 struct dwarf2_per_cu_data
*mid_cu
;
24973 int mid
= low
+ (high
- low
) / 2;
24975 mid_cu
= all_comp_units
[mid
];
24976 if (mid_cu
->is_dwz
> offset_in_dwz
24977 || (mid_cu
->is_dwz
== offset_in_dwz
24978 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24983 gdb_assert (low
== high
);
24987 /* Locate the .debug_info compilation unit from CU's objfile which contains
24988 the DIE at OFFSET. Raises an error on failure. */
24990 static struct dwarf2_per_cu_data
*
24991 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24992 unsigned int offset_in_dwz
,
24993 dwarf2_per_objfile
*per_objfile
)
24995 int low
= dwarf2_find_containing_comp_unit
24996 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24997 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
24999 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25001 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25002 error (_("Dwarf Error: could not find partial DIE containing "
25003 "offset %s [in module %s]"),
25004 sect_offset_str (sect_off
),
25005 bfd_get_filename (per_objfile
->objfile
->obfd
));
25007 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
25009 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
25013 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
25014 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25015 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25016 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25023 namespace selftests
{
25024 namespace find_containing_comp_unit
{
25029 struct dwarf2_per_cu_data one
{};
25030 struct dwarf2_per_cu_data two
{};
25031 struct dwarf2_per_cu_data three
{};
25032 struct dwarf2_per_cu_data four
{};
25035 two
.sect_off
= sect_offset (one
.length
);
25040 four
.sect_off
= sect_offset (three
.length
);
25044 std::vector
<dwarf2_per_cu_data
*> units
;
25045 units
.push_back (&one
);
25046 units
.push_back (&two
);
25047 units
.push_back (&three
);
25048 units
.push_back (&four
);
25052 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
25053 SELF_CHECK (units
[result
] == &one
);
25054 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
25055 SELF_CHECK (units
[result
] == &one
);
25056 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
25057 SELF_CHECK (units
[result
] == &two
);
25059 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
25060 SELF_CHECK (units
[result
] == &three
);
25061 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
25062 SELF_CHECK (units
[result
] == &three
);
25063 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
25064 SELF_CHECK (units
[result
] == &four
);
25070 #endif /* GDB_SELF_TEST */
25072 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
25074 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
25075 dwarf2_per_objfile
*per_objfile
)
25077 per_objfile (per_objfile
),
25079 has_loclist (false),
25080 checked_producer (false),
25081 producer_is_gxx_lt_4_6 (false),
25082 producer_is_gcc_lt_4_3 (false),
25083 producer_is_icc (false),
25084 producer_is_icc_lt_14 (false),
25085 producer_is_codewarrior (false),
25086 processing_has_namespace_info (false)
25090 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25093 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25094 enum language pretend_language
)
25096 struct attribute
*attr
;
25098 /* Set the language we're debugging. */
25099 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25100 if (attr
!= nullptr)
25101 set_cu_language (attr
->constant_value (0), cu
);
25104 cu
->language
= pretend_language
;
25105 cu
->language_defn
= language_def (cu
->language
);
25108 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25114 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
25116 auto it
= m_dwarf2_cus
.find (per_cu
);
25117 if (it
== m_dwarf2_cus
.end ())
25126 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
25128 gdb_assert (this->get_cu (per_cu
) == nullptr);
25130 m_dwarf2_cus
[per_cu
] = cu
;
25136 dwarf2_per_objfile::age_comp_units ()
25138 dwarf_read_debug_printf_v ("running");
25140 /* This is not expected to be called in the middle of CU expansion. There is
25141 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
25142 loaded in memory. Calling age_comp_units while the queue is in use could
25143 make us free the DIEs for a CU that is in the queue and therefore break
25145 gdb_assert (!this->per_bfd
->queue
.has_value ());
25147 /* Start by clearing all marks. */
25148 for (auto pair
: m_dwarf2_cus
)
25149 pair
.second
->mark
= false;
25151 /* Traverse all CUs, mark them and their dependencies if used recently
25153 for (auto pair
: m_dwarf2_cus
)
25155 dwarf2_cu
*cu
= pair
.second
;
25158 if (cu
->last_used
<= dwarf_max_cache_age
)
25162 /* Delete all CUs still not marked. */
25163 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
25165 dwarf2_cu
*cu
= it
->second
;
25169 dwarf_read_debug_printf_v ("deleting old CU %s",
25170 sect_offset_str (cu
->per_cu
->sect_off
));
25172 it
= m_dwarf2_cus
.erase (it
);
25182 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
25184 auto it
= m_dwarf2_cus
.find (per_cu
);
25185 if (it
== m_dwarf2_cus
.end ())
25190 m_dwarf2_cus
.erase (it
);
25193 dwarf2_per_objfile::~dwarf2_per_objfile ()
25198 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25199 We store these in a hash table separate from the DIEs, and preserve them
25200 when the DIEs are flushed out of cache.
25202 The CU "per_cu" pointer is needed because offset alone is not enough to
25203 uniquely identify the type. A file may have multiple .debug_types sections,
25204 or the type may come from a DWO file. Furthermore, while it's more logical
25205 to use per_cu->section+offset, with Fission the section with the data is in
25206 the DWO file but we don't know that section at the point we need it.
25207 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25208 because we can enter the lookup routine, get_die_type_at_offset, from
25209 outside this file, and thus won't necessarily have PER_CU->cu.
25210 Fortunately, PER_CU is stable for the life of the objfile. */
25212 struct dwarf2_per_cu_offset_and_type
25214 const struct dwarf2_per_cu_data
*per_cu
;
25215 sect_offset sect_off
;
25219 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25222 per_cu_offset_and_type_hash (const void *item
)
25224 const struct dwarf2_per_cu_offset_and_type
*ofs
25225 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25227 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25230 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25233 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25235 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25236 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25237 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25238 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25240 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25241 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25244 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25245 table if necessary. For convenience, return TYPE.
25247 The DIEs reading must have careful ordering to:
25248 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25249 reading current DIE.
25250 * Not trying to dereference contents of still incompletely read in types
25251 while reading in other DIEs.
25252 * Enable referencing still incompletely read in types just by a pointer to
25253 the type without accessing its fields.
25255 Therefore caller should follow these rules:
25256 * Try to fetch any prerequisite types we may need to build this DIE type
25257 before building the type and calling set_die_type.
25258 * After building type call set_die_type for current DIE as soon as
25259 possible before fetching more types to complete the current type.
25260 * Make the type as complete as possible before fetching more types. */
25262 static struct type
*
25263 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
25264 bool skip_data_location
)
25266 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
25267 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25268 struct objfile
*objfile
= per_objfile
->objfile
;
25269 struct attribute
*attr
;
25270 struct dynamic_prop prop
;
25272 /* For Ada types, make sure that the gnat-specific data is always
25273 initialized (if not already set). There are a few types where
25274 we should not be doing so, because the type-specific area is
25275 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25276 where the type-specific area is used to store the floatformat).
25277 But this is not a problem, because the gnat-specific information
25278 is actually not needed for these types. */
25279 if (need_gnat_info (cu
)
25280 && type
->code () != TYPE_CODE_FUNC
25281 && type
->code () != TYPE_CODE_FLT
25282 && type
->code () != TYPE_CODE_METHODPTR
25283 && type
->code () != TYPE_CODE_MEMBERPTR
25284 && type
->code () != TYPE_CODE_METHOD
25285 && type
->code () != TYPE_CODE_FIXED_POINT
25286 && !HAVE_GNAT_AUX_INFO (type
))
25287 INIT_GNAT_SPECIFIC (type
);
25289 /* Read DW_AT_allocated and set in type. */
25290 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25293 struct type
*prop_type
= cu
->addr_sized_int_type (false);
25294 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25295 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
25298 /* Read DW_AT_associated and set in type. */
25299 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25302 struct type
*prop_type
= cu
->addr_sized_int_type (false);
25303 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25304 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
25307 /* Read DW_AT_data_location and set in type. */
25308 if (!skip_data_location
)
25310 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25311 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
25312 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
25315 if (per_objfile
->die_type_hash
== NULL
)
25316 per_objfile
->die_type_hash
25317 = htab_up (htab_create_alloc (127,
25318 per_cu_offset_and_type_hash
,
25319 per_cu_offset_and_type_eq
,
25320 NULL
, xcalloc
, xfree
));
25322 ofs
.per_cu
= cu
->per_cu
;
25323 ofs
.sect_off
= die
->sect_off
;
25325 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25326 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
25328 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25329 sect_offset_str (die
->sect_off
));
25330 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25331 struct dwarf2_per_cu_offset_and_type
);
25336 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25337 or return NULL if the die does not have a saved type. */
25339 static struct type
*
25340 get_die_type_at_offset (sect_offset sect_off
,
25341 dwarf2_per_cu_data
*per_cu
,
25342 dwarf2_per_objfile
*per_objfile
)
25344 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25346 if (per_objfile
->die_type_hash
== NULL
)
25349 ofs
.per_cu
= per_cu
;
25350 ofs
.sect_off
= sect_off
;
25351 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25352 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
25359 /* Look up the type for DIE in CU in die_type_hash,
25360 or return NULL if DIE does not have a saved type. */
25362 static struct type
*
25363 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25365 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
25368 /* Add a dependence relationship from CU to REF_PER_CU. */
25371 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25372 struct dwarf2_per_cu_data
*ref_per_cu
)
25376 if (cu
->dependencies
== NULL
)
25378 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25379 NULL
, &cu
->comp_unit_obstack
,
25380 hashtab_obstack_allocate
,
25381 dummy_obstack_deallocate
);
25383 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25385 *slot
= ref_per_cu
;
25388 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25389 Set the mark field in every compilation unit in the
25390 cache that we must keep because we are keeping CU.
25392 DATA is the dwarf2_per_objfile object in which to look up CUs. */
25395 dwarf2_mark_helper (void **slot
, void *data
)
25397 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
25398 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
25399 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
25401 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25402 reading of the chain. As such dependencies remain valid it is not much
25403 useful to track and undo them during QUIT cleanups. */
25412 if (cu
->dependencies
!= nullptr)
25413 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
25418 /* Set the mark field in CU and in every other compilation unit in the
25419 cache that we must keep because we are keeping CU. */
25422 dwarf2_mark (struct dwarf2_cu
*cu
)
25429 if (cu
->dependencies
!= nullptr)
25430 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
25433 /* Trivial hash function for partial_die_info: the hash value of a DIE
25434 is its offset in .debug_info for this objfile. */
25437 partial_die_hash (const void *item
)
25439 const struct partial_die_info
*part_die
25440 = (const struct partial_die_info
*) item
;
25442 return to_underlying (part_die
->sect_off
);
25445 /* Trivial comparison function for partial_die_info structures: two DIEs
25446 are equal if they have the same offset. */
25449 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25451 const struct partial_die_info
*part_die_lhs
25452 = (const struct partial_die_info
*) item_lhs
;
25453 const struct partial_die_info
*part_die_rhs
25454 = (const struct partial_die_info
*) item_rhs
;
25456 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25459 struct cmd_list_element
*set_dwarf_cmdlist
;
25460 struct cmd_list_element
*show_dwarf_cmdlist
;
25463 show_check_physname (struct ui_file
*file
, int from_tty
,
25464 struct cmd_list_element
*c
, const char *value
)
25466 fprintf_filtered (file
,
25467 _("Whether to check \"physname\" is %s.\n"),
25471 void _initialize_dwarf2_read ();
25473 _initialize_dwarf2_read ()
25475 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
25476 Set DWARF specific variables.\n\
25477 Configure DWARF variables such as the cache size."),
25478 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25479 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25481 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
25482 Show DWARF specific variables.\n\
25483 Show DWARF variables such as the cache size."),
25484 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25485 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25487 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25488 &dwarf_max_cache_age
, _("\
25489 Set the upper bound on the age of cached DWARF compilation units."), _("\
25490 Show the upper bound on the age of cached DWARF compilation units."), _("\
25491 A higher limit means that cached compilation units will be stored\n\
25492 in memory longer, and more total memory will be used. Zero disables\n\
25493 caching, which can slow down startup."),
25495 show_dwarf_max_cache_age
,
25496 &set_dwarf_cmdlist
,
25497 &show_dwarf_cmdlist
);
25499 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25500 Set debugging of the DWARF reader."), _("\
25501 Show debugging of the DWARF reader."), _("\
25502 When enabled (non-zero), debugging messages are printed during DWARF\n\
25503 reading and symtab expansion. A value of 1 (one) provides basic\n\
25504 information. A value greater than 1 provides more verbose information."),
25507 &setdebuglist
, &showdebuglist
);
25509 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25510 Set debugging of the DWARF DIE reader."), _("\
25511 Show debugging of the DWARF DIE reader."), _("\
25512 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25513 The value is the maximum depth to print."),
25516 &setdebuglist
, &showdebuglist
);
25518 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25519 Set debugging of the dwarf line reader."), _("\
25520 Show debugging of the dwarf line reader."), _("\
25521 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25522 A value of 1 (one) provides basic information.\n\
25523 A value greater than 1 provides more verbose information."),
25526 &setdebuglist
, &showdebuglist
);
25528 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25529 Set cross-checking of \"physname\" code against demangler."), _("\
25530 Show cross-checking of \"physname\" code against demangler."), _("\
25531 When enabled, GDB's internal \"physname\" code is checked against\n\
25533 NULL
, show_check_physname
,
25534 &setdebuglist
, &showdebuglist
);
25536 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25537 no_class
, &use_deprecated_index_sections
, _("\
25538 Set whether to use deprecated gdb_index sections."), _("\
25539 Show whether to use deprecated gdb_index sections."), _("\
25540 When enabled, deprecated .gdb_index sections are used anyway.\n\
25541 Normally they are ignored either because of a missing feature or\n\
25542 performance issue.\n\
25543 Warning: This option must be enabled before gdb reads the file."),
25546 &setlist
, &showlist
);
25548 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25549 &dwarf2_locexpr_funcs
);
25550 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25551 &dwarf2_loclist_funcs
);
25553 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25554 &dwarf2_block_frame_base_locexpr_funcs
);
25555 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25556 &dwarf2_block_frame_base_loclist_funcs
);
25559 selftests::register_test ("dw2_expand_symtabs_matching",
25560 selftests::dw2_expand_symtabs_matching::run_test
);
25561 selftests::register_test ("dwarf2_find_containing_comp_unit",
25562 selftests::find_containing_comp_unit::run_test
);