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 and if there aren't partial symbols
1956 from some other reader. */
1957 if (!objfile
->has_partial_symbols ()
1958 && !gdb_bfd_requires_relocations (objfile
->obfd
))
1960 /* See if one has been created for this BFD yet. */
1961 per_bfd
= dwarf2_per_bfd_bfd_data_key
.get (objfile
->obfd
);
1963 if (per_bfd
== nullptr)
1965 /* No, create it now. */
1966 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1967 dwarf2_per_bfd_bfd_data_key
.set (objfile
->obfd
, per_bfd
);
1972 /* No sharing possible, create one specifically for this objfile. */
1973 per_bfd
= new dwarf2_per_bfd (objfile
->obfd
, names
, can_copy
);
1974 dwarf2_per_bfd_objfile_data_key
.set (objfile
, per_bfd
);
1977 per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
, per_bfd
);
1980 return (!per_objfile
->per_bfd
->info
.is_virtual
1981 && per_objfile
->per_bfd
->info
.s
.section
!= NULL
1982 && !per_objfile
->per_bfd
->abbrev
.is_virtual
1983 && per_objfile
->per_bfd
->abbrev
.s
.section
!= NULL
);
1986 /* See declaration. */
1989 dwarf2_per_bfd::locate_sections (bfd
*abfd
, asection
*sectp
,
1990 const dwarf2_debug_sections
&names
)
1992 flagword aflag
= bfd_section_flags (sectp
);
1994 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1997 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1998 > bfd_get_file_size (abfd
))
2000 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2001 warning (_("Discarding section %s which has a section size (%s"
2002 ") larger than the file size [in module %s]"),
2003 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2004 bfd_get_filename (abfd
));
2006 else if (names
.info
.matches (sectp
->name
))
2008 this->info
.s
.section
= sectp
;
2009 this->info
.size
= bfd_section_size (sectp
);
2011 else if (names
.abbrev
.matches (sectp
->name
))
2013 this->abbrev
.s
.section
= sectp
;
2014 this->abbrev
.size
= bfd_section_size (sectp
);
2016 else if (names
.line
.matches (sectp
->name
))
2018 this->line
.s
.section
= sectp
;
2019 this->line
.size
= bfd_section_size (sectp
);
2021 else if (names
.loc
.matches (sectp
->name
))
2023 this->loc
.s
.section
= sectp
;
2024 this->loc
.size
= bfd_section_size (sectp
);
2026 else if (names
.loclists
.matches (sectp
->name
))
2028 this->loclists
.s
.section
= sectp
;
2029 this->loclists
.size
= bfd_section_size (sectp
);
2031 else if (names
.macinfo
.matches (sectp
->name
))
2033 this->macinfo
.s
.section
= sectp
;
2034 this->macinfo
.size
= bfd_section_size (sectp
);
2036 else if (names
.macro
.matches (sectp
->name
))
2038 this->macro
.s
.section
= sectp
;
2039 this->macro
.size
= bfd_section_size (sectp
);
2041 else if (names
.str
.matches (sectp
->name
))
2043 this->str
.s
.section
= sectp
;
2044 this->str
.size
= bfd_section_size (sectp
);
2046 else if (names
.str_offsets
.matches (sectp
->name
))
2048 this->str_offsets
.s
.section
= sectp
;
2049 this->str_offsets
.size
= bfd_section_size (sectp
);
2051 else if (names
.line_str
.matches (sectp
->name
))
2053 this->line_str
.s
.section
= sectp
;
2054 this->line_str
.size
= bfd_section_size (sectp
);
2056 else if (names
.addr
.matches (sectp
->name
))
2058 this->addr
.s
.section
= sectp
;
2059 this->addr
.size
= bfd_section_size (sectp
);
2061 else if (names
.frame
.matches (sectp
->name
))
2063 this->frame
.s
.section
= sectp
;
2064 this->frame
.size
= bfd_section_size (sectp
);
2066 else if (names
.eh_frame
.matches (sectp
->name
))
2068 this->eh_frame
.s
.section
= sectp
;
2069 this->eh_frame
.size
= bfd_section_size (sectp
);
2071 else if (names
.ranges
.matches (sectp
->name
))
2073 this->ranges
.s
.section
= sectp
;
2074 this->ranges
.size
= bfd_section_size (sectp
);
2076 else if (names
.rnglists
.matches (sectp
->name
))
2078 this->rnglists
.s
.section
= sectp
;
2079 this->rnglists
.size
= bfd_section_size (sectp
);
2081 else if (names
.types
.matches (sectp
->name
))
2083 struct dwarf2_section_info type_section
;
2085 memset (&type_section
, 0, sizeof (type_section
));
2086 type_section
.s
.section
= sectp
;
2087 type_section
.size
= bfd_section_size (sectp
);
2089 this->types
.push_back (type_section
);
2091 else if (names
.gdb_index
.matches (sectp
->name
))
2093 this->gdb_index
.s
.section
= sectp
;
2094 this->gdb_index
.size
= bfd_section_size (sectp
);
2096 else if (names
.debug_names
.matches (sectp
->name
))
2098 this->debug_names
.s
.section
= sectp
;
2099 this->debug_names
.size
= bfd_section_size (sectp
);
2101 else if (names
.debug_aranges
.matches (sectp
->name
))
2103 this->debug_aranges
.s
.section
= sectp
;
2104 this->debug_aranges
.size
= bfd_section_size (sectp
);
2107 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2108 && bfd_section_vma (sectp
) == 0)
2109 this->has_section_at_zero
= true;
2112 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2116 dwarf2_get_section_info (struct objfile
*objfile
,
2117 enum dwarf2_section_enum sect
,
2118 asection
**sectp
, const gdb_byte
**bufp
,
2119 bfd_size_type
*sizep
)
2121 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
2122 struct dwarf2_section_info
*info
;
2124 /* We may see an objfile without any DWARF, in which case we just
2126 if (per_objfile
== NULL
)
2135 case DWARF2_DEBUG_FRAME
:
2136 info
= &per_objfile
->per_bfd
->frame
;
2138 case DWARF2_EH_FRAME
:
2139 info
= &per_objfile
->per_bfd
->eh_frame
;
2142 gdb_assert_not_reached ("unexpected section");
2145 info
->read (objfile
);
2147 *sectp
= info
->get_bfd_section ();
2148 *bufp
= info
->buffer
;
2149 *sizep
= info
->size
;
2153 /* DWARF quick_symbol_functions support. */
2155 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2156 unique line tables, so we maintain a separate table of all .debug_line
2157 derived entries to support the sharing.
2158 All the quick functions need is the list of file names. We discard the
2159 line_header when we're done and don't need to record it here. */
2160 struct quick_file_names
2162 /* The data used to construct the hash key. */
2163 struct stmt_list_hash hash
;
2165 /* The number of entries in file_names, real_names. */
2166 unsigned int num_file_names
;
2168 /* The file names from the line table, after being run through
2170 const char **file_names
;
2172 /* The file names from the line table after being run through
2173 gdb_realpath. These are computed lazily. */
2174 const char **real_names
;
2177 /* When using the index (and thus not using psymtabs), each CU has an
2178 object of this type. This is used to hold information needed by
2179 the various "quick" methods. */
2180 struct dwarf2_per_cu_quick_data
2182 /* The file table. This can be NULL if there was no file table
2183 or it's currently not read in.
2184 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2185 struct quick_file_names
*file_names
;
2187 /* A temporary mark bit used when iterating over all CUs in
2188 expand_symtabs_matching. */
2189 unsigned int mark
: 1;
2191 /* True if we've tried to read the file table and found there isn't one.
2192 There will be no point in trying to read it again next time. */
2193 unsigned int no_file_data
: 1;
2196 struct dwarf2_base_index_functions
: public quick_symbol_functions
2198 bool has_symbols (struct objfile
*objfile
) override
;
2200 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
2202 void forget_cached_source_info (struct objfile
*objfile
) override
;
2204 bool map_symtabs_matching_filename
2205 (struct objfile
*objfile
, const char *name
, const char *real_path
,
2206 gdb::function_view
<bool (symtab
*)> callback
) override
;
2208 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
2211 bool *symbol_found_p
) override
2213 *symbol_found_p
= false;
2214 return language_unknown
;
2217 void print_stats (struct objfile
*objfile
) override
;
2219 void expand_all_symtabs (struct objfile
*objfile
) override
;
2221 void expand_symtabs_with_fullname (struct objfile
*objfile
,
2222 const char *fullname
) override
;
2224 struct compunit_symtab
*find_pc_sect_compunit_symtab
2225 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
2226 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
) override
;
2228 struct compunit_symtab
*find_compunit_symtab_by_address
2229 (struct objfile
*objfile
, CORE_ADDR address
) override
2234 void map_symbol_filenames (struct objfile
*objfile
,
2235 symbol_filename_ftype
*fun
, void *data
,
2236 int need_fullname
) override
;
2239 struct dwarf2_gdb_index
: public dwarf2_base_index_functions
2241 struct compunit_symtab
*lookup_symbol (struct objfile
*objfile
,
2242 block_enum block_index
,
2244 domain_enum domain
) override
;
2246 void dump (struct objfile
*objfile
) override
;
2248 void expand_symtabs_for_function (struct objfile
*objfile
,
2249 const char *func_name
) override
;
2251 void map_matching_symbols
2253 const lookup_name_info
&lookup_name
,
2256 gdb::function_view
<symbol_found_callback_ftype
> callback
,
2257 symbol_compare_ftype
*ordered_compare
) override
;
2259 void expand_symtabs_matching
2260 (struct objfile
*objfile
,
2261 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2262 const lookup_name_info
*lookup_name
,
2263 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2264 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2265 enum search_domain kind
) override
;
2268 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
2270 struct compunit_symtab
*lookup_symbol (struct objfile
*objfile
,
2271 block_enum block_index
,
2273 domain_enum domain
) override
;
2275 void dump (struct objfile
*objfile
) override
;
2277 void expand_symtabs_for_function (struct objfile
*objfile
,
2278 const char *func_name
) override
;
2280 void map_matching_symbols
2282 const lookup_name_info
&lookup_name
,
2285 gdb::function_view
<symbol_found_callback_ftype
> callback
,
2286 symbol_compare_ftype
*ordered_compare
) override
;
2288 void expand_symtabs_matching
2289 (struct objfile
*objfile
,
2290 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
2291 const lookup_name_info
*lookup_name
,
2292 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
2293 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
2294 enum search_domain kind
) override
;
2297 quick_symbol_functions_up
2298 make_dwarf_gdb_index ()
2300 return quick_symbol_functions_up (new dwarf2_gdb_index
);
2303 quick_symbol_functions_up
2304 make_dwarf_debug_names ()
2306 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
2309 /* Utility hash function for a stmt_list_hash. */
2312 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2316 if (stmt_list_hash
->dwo_unit
!= NULL
)
2317 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2318 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2322 /* Utility equality function for a stmt_list_hash. */
2325 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2326 const struct stmt_list_hash
*rhs
)
2328 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2330 if (lhs
->dwo_unit
!= NULL
2331 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2334 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2337 /* Hash function for a quick_file_names. */
2340 hash_file_name_entry (const void *e
)
2342 const struct quick_file_names
*file_data
2343 = (const struct quick_file_names
*) e
;
2345 return hash_stmt_list_entry (&file_data
->hash
);
2348 /* Equality function for a quick_file_names. */
2351 eq_file_name_entry (const void *a
, const void *b
)
2353 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2354 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2356 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2359 /* Delete function for a quick_file_names. */
2362 delete_file_name_entry (void *e
)
2364 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2367 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2369 xfree ((void*) file_data
->file_names
[i
]);
2370 if (file_data
->real_names
)
2371 xfree ((void*) file_data
->real_names
[i
]);
2374 /* The space for the struct itself lives on the obstack, so we don't
2378 /* Create a quick_file_names hash table. */
2381 create_quick_file_names_table (unsigned int nr_initial_entries
)
2383 return htab_up (htab_create_alloc (nr_initial_entries
,
2384 hash_file_name_entry
, eq_file_name_entry
,
2385 delete_file_name_entry
, xcalloc
, xfree
));
2388 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2389 function is unrelated to symtabs, symtab would have to be created afterwards.
2390 You should call age_cached_comp_units after processing the CU. */
2393 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2396 if (per_cu
->is_debug_types
)
2397 load_full_type_unit (per_cu
, per_objfile
);
2399 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2400 skip_partial
, language_minimal
);
2402 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2404 return nullptr; /* Dummy CU. */
2406 dwarf2_find_base_address (cu
->dies
, cu
);
2411 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2414 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2415 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2417 /* Skip type_unit_groups, reading the type units they contain
2418 is handled elsewhere. */
2419 if (per_cu
->type_unit_group_p ())
2423 /* The destructor of dwarf2_queue_guard frees any entries left on
2424 the queue. After this point we're guaranteed to leave this function
2425 with the dwarf queue empty. */
2426 dwarf2_queue_guard
q_guard (per_objfile
);
2428 if (!per_objfile
->symtab_set_p (per_cu
))
2430 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2431 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2433 /* If we just loaded a CU from a DWO, and we're working with an index
2434 that may badly handle TUs, load all the TUs in that DWO as well.
2435 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2436 if (!per_cu
->is_debug_types
2438 && cu
->dwo_unit
!= NULL
2439 && per_objfile
->per_bfd
->index_table
!= NULL
2440 && per_objfile
->per_bfd
->index_table
->version
<= 7
2441 /* DWP files aren't supported yet. */
2442 && get_dwp_file (per_objfile
) == NULL
)
2443 queue_and_load_all_dwo_tus (cu
);
2446 process_queue (per_objfile
);
2449 /* Age the cache, releasing compilation units that have not
2450 been used recently. */
2451 per_objfile
->age_comp_units ();
2454 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2455 the per-objfile for which this symtab is instantiated.
2457 Returns the resulting symbol table. */
2459 static struct compunit_symtab
*
2460 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2461 dwarf2_per_objfile
*per_objfile
,
2464 gdb_assert (per_objfile
->per_bfd
->using_index
);
2466 if (!per_objfile
->symtab_set_p (per_cu
))
2468 free_cached_comp_units
freer (per_objfile
);
2469 scoped_restore decrementer
= increment_reading_symtab ();
2470 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2471 process_cu_includes (per_objfile
);
2474 return per_objfile
->get_symtab (per_cu
);
2477 /* See declaration. */
2479 dwarf2_per_cu_data
*
2480 dwarf2_per_bfd::get_cutu (int index
)
2482 if (index
>= this->all_comp_units
.size ())
2484 index
-= this->all_comp_units
.size ();
2485 gdb_assert (index
< this->all_type_units
.size ());
2486 return &this->all_type_units
[index
]->per_cu
;
2489 return this->all_comp_units
[index
];
2492 /* See declaration. */
2494 dwarf2_per_cu_data
*
2495 dwarf2_per_bfd::get_cu (int index
)
2497 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2499 return this->all_comp_units
[index
];
2502 /* See declaration. */
2505 dwarf2_per_bfd::get_tu (int index
)
2507 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2509 return this->all_type_units
[index
];
2514 dwarf2_per_cu_data
*
2515 dwarf2_per_bfd::allocate_per_cu ()
2517 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2518 result
->per_bfd
= this;
2519 result
->index
= m_num_psymtabs
++;
2526 dwarf2_per_bfd::allocate_signatured_type ()
2528 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2529 result
->per_cu
.per_bfd
= this;
2530 result
->per_cu
.index
= m_num_psymtabs
++;
2534 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2535 obstack, and constructed with the specified field values. */
2537 static dwarf2_per_cu_data
*
2538 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2539 struct dwarf2_section_info
*section
,
2541 sect_offset sect_off
, ULONGEST length
)
2543 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2544 the_cu
->sect_off
= sect_off
;
2545 the_cu
->length
= length
;
2546 the_cu
->section
= section
;
2547 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2548 struct dwarf2_per_cu_quick_data
);
2549 the_cu
->is_dwz
= is_dwz
;
2553 /* A helper for create_cus_from_index that handles a given list of
2557 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2558 const gdb_byte
*cu_list
, offset_type n_elements
,
2559 struct dwarf2_section_info
*section
,
2562 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2564 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2566 sect_offset sect_off
2567 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2568 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2571 dwarf2_per_cu_data
*per_cu
2572 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2574 per_bfd
->all_comp_units
.push_back (per_cu
);
2578 /* Read the CU list from the mapped index, and use it to create all
2579 the CU objects for PER_BFD. */
2582 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2583 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2584 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2586 gdb_assert (per_bfd
->all_comp_units
.empty ());
2587 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2589 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2592 if (dwz_elements
== 0)
2595 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2596 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2600 /* Create the signatured type hash table from the index. */
2603 create_signatured_type_table_from_index
2604 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2605 const gdb_byte
*bytes
, offset_type elements
)
2607 gdb_assert (per_bfd
->all_type_units
.empty ());
2608 per_bfd
->all_type_units
.reserve (elements
/ 3);
2610 htab_up sig_types_hash
= allocate_signatured_type_table ();
2612 for (offset_type i
= 0; i
< elements
; i
+= 3)
2614 struct signatured_type
*sig_type
;
2617 cu_offset type_offset_in_tu
;
2619 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2620 sect_offset sect_off
2621 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2623 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2625 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2628 sig_type
= per_bfd
->allocate_signatured_type ();
2629 sig_type
->signature
= signature
;
2630 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2631 sig_type
->per_cu
.is_debug_types
= 1;
2632 sig_type
->per_cu
.section
= section
;
2633 sig_type
->per_cu
.sect_off
= sect_off
;
2634 sig_type
->per_cu
.v
.quick
2635 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2636 struct dwarf2_per_cu_quick_data
);
2638 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2641 per_bfd
->all_type_units
.push_back (sig_type
);
2644 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2647 /* Create the signatured type hash table from .debug_names. */
2650 create_signatured_type_table_from_debug_names
2651 (dwarf2_per_objfile
*per_objfile
,
2652 const mapped_debug_names
&map
,
2653 struct dwarf2_section_info
*section
,
2654 struct dwarf2_section_info
*abbrev_section
)
2656 struct objfile
*objfile
= per_objfile
->objfile
;
2658 section
->read (objfile
);
2659 abbrev_section
->read (objfile
);
2661 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
2662 per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2664 htab_up sig_types_hash
= allocate_signatured_type_table ();
2666 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2668 struct signatured_type
*sig_type
;
2671 sect_offset sect_off
2672 = (sect_offset
) (extract_unsigned_integer
2673 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2675 map
.dwarf5_byte_order
));
2677 comp_unit_head cu_header
;
2678 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2680 section
->buffer
+ to_underlying (sect_off
),
2683 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2684 sig_type
->signature
= cu_header
.signature
;
2685 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2686 sig_type
->per_cu
.is_debug_types
= 1;
2687 sig_type
->per_cu
.section
= section
;
2688 sig_type
->per_cu
.sect_off
= sect_off
;
2689 sig_type
->per_cu
.v
.quick
2690 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2691 struct dwarf2_per_cu_quick_data
);
2693 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2696 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2699 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2702 /* Read the address map data from the mapped index, and use it to
2703 populate the objfile's psymtabs_addrmap. */
2706 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2707 struct mapped_index
*index
)
2709 struct objfile
*objfile
= per_objfile
->objfile
;
2710 struct gdbarch
*gdbarch
= objfile
->arch ();
2711 const gdb_byte
*iter
, *end
;
2712 struct addrmap
*mutable_map
;
2715 auto_obstack temp_obstack
;
2717 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2719 iter
= index
->address_table
.data ();
2720 end
= iter
+ index
->address_table
.size ();
2722 baseaddr
= objfile
->text_section_offset ();
2726 ULONGEST hi
, lo
, cu_index
;
2727 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2729 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2731 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2736 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2737 hex_string (lo
), hex_string (hi
));
2741 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
2743 complaint (_(".gdb_index address table has invalid CU number %u"),
2744 (unsigned) cu_index
);
2748 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2749 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2750 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2751 per_objfile
->per_bfd
->get_cu (cu_index
));
2754 objfile
->partial_symtabs
->psymtabs_addrmap
2755 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2758 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2759 populate the objfile's psymtabs_addrmap. */
2762 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2763 struct dwarf2_section_info
*section
)
2765 struct objfile
*objfile
= per_objfile
->objfile
;
2766 bfd
*abfd
= objfile
->obfd
;
2767 struct gdbarch
*gdbarch
= objfile
->arch ();
2768 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
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_objfile
->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 objfile
->partial_symtabs
->psymtabs_addrmap
2920 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
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 ());
3187 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
3188 objfiles using the same BFD. */
3189 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
3190 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
3195 /* die_reader_func for dw2_get_file_names. */
3198 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3199 struct die_info
*comp_unit_die
)
3201 struct dwarf2_cu
*cu
= reader
->cu
;
3202 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3203 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3204 struct dwarf2_per_cu_data
*lh_cu
;
3205 struct attribute
*attr
;
3207 struct quick_file_names
*qfn
;
3209 gdb_assert (! this_cu
->is_debug_types
);
3211 /* Our callers never want to match partial units -- instead they
3212 will match the enclosing full CU. */
3213 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3215 this_cu
->v
.quick
->no_file_data
= 1;
3223 sect_offset line_offset
{};
3225 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3226 if (attr
!= nullptr && attr
->form_is_unsigned ())
3228 struct quick_file_names find_entry
;
3230 line_offset
= (sect_offset
) attr
->as_unsigned ();
3232 /* We may have already read in this line header (TU line header sharing).
3233 If we have we're done. */
3234 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3235 find_entry
.hash
.line_sect_off
= line_offset
;
3236 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3237 &find_entry
, INSERT
);
3240 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3244 lh
= dwarf_decode_line_header (line_offset
, cu
);
3248 lh_cu
->v
.quick
->no_file_data
= 1;
3252 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3253 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3254 qfn
->hash
.line_sect_off
= line_offset
;
3255 gdb_assert (slot
!= NULL
);
3258 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3261 if (strcmp (fnd
.name
, "<unknown>") != 0)
3264 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3266 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3267 qfn
->num_file_names
);
3269 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3270 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3271 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3272 fnd
.comp_dir
).release ();
3273 qfn
->real_names
= NULL
;
3275 lh_cu
->v
.quick
->file_names
= qfn
;
3278 /* A helper for the "quick" functions which attempts to read the line
3279 table for THIS_CU. */
3281 static struct quick_file_names
*
3282 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3283 dwarf2_per_objfile
*per_objfile
)
3285 /* This should never be called for TUs. */
3286 gdb_assert (! this_cu
->is_debug_types
);
3287 /* Nor type unit groups. */
3288 gdb_assert (! this_cu
->type_unit_group_p ());
3290 if (this_cu
->v
.quick
->file_names
!= NULL
)
3291 return this_cu
->v
.quick
->file_names
;
3292 /* If we know there is no line data, no point in looking again. */
3293 if (this_cu
->v
.quick
->no_file_data
)
3296 cutu_reader
reader (this_cu
, per_objfile
);
3297 if (!reader
.dummy_p
)
3298 dw2_get_file_names_reader (&reader
, reader
.comp_unit_die
);
3300 if (this_cu
->v
.quick
->no_file_data
)
3302 return this_cu
->v
.quick
->file_names
;
3305 /* A helper for the "quick" functions which computes and caches the
3306 real path for a given file name from the line table. */
3309 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3310 struct quick_file_names
*qfn
, int index
)
3312 if (qfn
->real_names
== NULL
)
3313 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3314 qfn
->num_file_names
, const char *);
3316 if (qfn
->real_names
[index
] == NULL
)
3317 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3319 return qfn
->real_names
[index
];
3323 dwarf2_base_index_functions::find_last_source_symtab (struct objfile
*objfile
)
3325 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3326 dwarf2_per_cu_data
*dwarf_cu
= per_objfile
->per_bfd
->all_comp_units
.back ();
3327 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3332 return compunit_primary_filetab (cust
);
3335 /* Traversal function for dw2_forget_cached_source_info. */
3338 dw2_free_cached_file_names (void **slot
, void *info
)
3340 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3342 if (file_data
->real_names
)
3346 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3348 xfree ((void*) file_data
->real_names
[i
]);
3349 file_data
->real_names
[i
] = NULL
;
3357 dwarf2_base_index_functions::forget_cached_source_info
3358 (struct objfile
*objfile
)
3360 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3362 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3363 dw2_free_cached_file_names
, NULL
);
3366 /* Helper function for dw2_map_symtabs_matching_filename that expands
3367 the symtabs and calls the iterator. */
3370 dw2_map_expand_apply (struct objfile
*objfile
,
3371 struct dwarf2_per_cu_data
*per_cu
,
3372 const char *name
, const char *real_path
,
3373 gdb::function_view
<bool (symtab
*)> callback
)
3375 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3377 /* Don't visit already-expanded CUs. */
3378 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3379 if (per_objfile
->symtab_set_p (per_cu
))
3382 /* This may expand more than one symtab, and we want to iterate over
3384 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3386 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3387 last_made
, callback
);
3390 /* Implementation of the map_symtabs_matching_filename method. */
3393 dwarf2_base_index_functions::map_symtabs_matching_filename
3394 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3395 gdb::function_view
<bool (symtab
*)> callback
)
3397 const char *name_basename
= lbasename (name
);
3398 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3400 /* The rule is CUs specify all the files, including those used by
3401 any TU, so there's no need to scan TUs here. */
3403 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3405 /* We only need to look at symtabs not already expanded. */
3406 if (per_objfile
->symtab_set_p (per_cu
))
3409 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3410 if (file_data
== NULL
)
3413 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3415 const char *this_name
= file_data
->file_names
[j
];
3416 const char *this_real_name
;
3418 if (compare_filenames_for_search (this_name
, name
))
3420 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3426 /* Before we invoke realpath, which can get expensive when many
3427 files are involved, do a quick comparison of the basenames. */
3428 if (! basenames_may_differ
3429 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3432 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3433 if (compare_filenames_for_search (this_real_name
, name
))
3435 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3441 if (real_path
!= NULL
)
3443 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3444 gdb_assert (IS_ABSOLUTE_PATH (name
));
3445 if (this_real_name
!= NULL
3446 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3448 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3460 /* Struct used to manage iterating over all CUs looking for a symbol. */
3462 struct dw2_symtab_iterator
3464 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3465 dwarf2_per_objfile
*per_objfile
;
3466 /* If set, only look for symbols that match that block. Valid values are
3467 GLOBAL_BLOCK and STATIC_BLOCK. */
3468 gdb::optional
<block_enum
> block_index
;
3469 /* The kind of symbol we're looking for. */
3471 /* The list of CUs from the index entry of the symbol,
3472 or NULL if not found. */
3474 /* The next element in VEC to look at. */
3476 /* The number of elements in VEC, or zero if there is no match. */
3478 /* Have we seen a global version of the symbol?
3479 If so we can ignore all further global instances.
3480 This is to work around gold/15646, inefficient gold-generated
3485 /* Initialize the index symtab iterator ITER, common part. */
3488 dw2_symtab_iter_init_common (struct dw2_symtab_iterator
*iter
,
3489 dwarf2_per_objfile
*per_objfile
,
3490 gdb::optional
<block_enum
> block_index
,
3493 iter
->per_objfile
= per_objfile
;
3494 iter
->block_index
= block_index
;
3495 iter
->domain
= domain
;
3497 iter
->global_seen
= 0;
3502 /* Initialize the index symtab iterator ITER, const char *NAME variant. */
3505 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3506 dwarf2_per_objfile
*per_objfile
,
3507 gdb::optional
<block_enum
> block_index
,
3511 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3513 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3514 /* index is NULL if OBJF_READNOW. */
3518 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3519 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3522 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3525 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3526 dwarf2_per_objfile
*per_objfile
,
3527 gdb::optional
<block_enum
> block_index
,
3528 domain_enum domain
, offset_type namei
)
3530 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3532 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3533 /* index is NULL if OBJF_READNOW. */
3537 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3538 const auto &bucket
= index
->symbol_table
[namei
];
3540 iter
->vec
= (offset_type
*) (index
->constant_pool
3541 + MAYBE_SWAP (bucket
.vec
));
3542 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3545 /* Return the next matching CU or NULL if there are no more. */
3547 static struct dwarf2_per_cu_data
*
3548 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3550 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3552 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3554 offset_type cu_index_and_attrs
=
3555 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3556 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3557 gdb_index_symbol_kind symbol_kind
=
3558 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3559 /* Only check the symbol attributes if they're present.
3560 Indices prior to version 7 don't record them,
3561 and indices >= 7 may elide them for certain symbols
3562 (gold does this). */
3564 (per_objfile
->per_bfd
->index_table
->version
>= 7
3565 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3567 /* Don't crash on bad data. */
3568 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
3569 + per_objfile
->per_bfd
->all_type_units
.size ()))
3571 complaint (_(".gdb_index entry has bad CU index"
3572 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3576 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
3578 /* Skip if already read in. */
3579 if (per_objfile
->symtab_set_p (per_cu
))
3582 /* Check static vs global. */
3585 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3587 if (iter
->block_index
.has_value ())
3589 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3591 if (is_static
!= want_static
)
3595 /* Work around gold/15646. */
3597 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3599 if (iter
->global_seen
)
3602 iter
->global_seen
= 1;
3606 /* Only check the symbol's kind if it has one. */
3609 switch (iter
->domain
)
3612 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3613 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3614 /* Some types are also in VAR_DOMAIN. */
3615 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3619 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3623 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3627 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3642 struct compunit_symtab
*
3643 dwarf2_gdb_index::lookup_symbol (struct objfile
*objfile
,
3644 block_enum block_index
,
3645 const char *name
, domain_enum domain
)
3647 struct compunit_symtab
*stab_best
= NULL
;
3648 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3650 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3652 struct dw2_symtab_iterator iter
;
3653 struct dwarf2_per_cu_data
*per_cu
;
3655 dw2_symtab_iter_init (&iter
, per_objfile
, block_index
, domain
, name
);
3657 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3659 struct symbol
*sym
, *with_opaque
= NULL
;
3660 struct compunit_symtab
*stab
3661 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3662 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3663 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3665 sym
= block_find_symbol (block
, name
, domain
,
3666 block_find_non_opaque_type_preferred
,
3669 /* Some caution must be observed with overloaded functions
3670 and methods, since the index will not contain any overload
3671 information (but NAME might contain it). */
3674 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3676 if (with_opaque
!= NULL
3677 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3680 /* Keep looking through other CUs. */
3687 dwarf2_base_index_functions::print_stats (struct objfile
*objfile
)
3689 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3690 int total
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3691 + per_objfile
->per_bfd
->all_type_units
.size ());
3694 for (int i
= 0; i
< total
; ++i
)
3696 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3698 if (!per_objfile
->symtab_set_p (per_cu
))
3701 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3702 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3705 /* This dumps minimal information about the index.
3706 It is called via "mt print objfiles".
3707 One use is to verify .gdb_index has been loaded by the
3708 gdb.dwarf2/gdb-index.exp testcase. */
3711 dwarf2_gdb_index::dump (struct objfile
*objfile
)
3713 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3715 gdb_assert (per_objfile
->per_bfd
->using_index
);
3716 printf_filtered (".gdb_index:");
3717 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3719 printf_filtered (" version %d\n",
3720 per_objfile
->per_bfd
->index_table
->version
);
3723 printf_filtered (" faked for \"readnow\"\n");
3724 printf_filtered ("\n");
3728 dwarf2_gdb_index::expand_symtabs_for_function (struct objfile
*objfile
,
3729 const char *func_name
)
3731 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3733 struct dw2_symtab_iterator iter
;
3734 struct dwarf2_per_cu_data
*per_cu
;
3736 dw2_symtab_iter_init (&iter
, per_objfile
, {}, VAR_DOMAIN
, func_name
);
3738 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3739 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3744 dwarf2_base_index_functions::expand_all_symtabs (struct objfile
*objfile
)
3746 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3747 int total_units
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3748 + per_objfile
->per_bfd
->all_type_units
.size ());
3750 for (int i
= 0; i
< total_units
; ++i
)
3752 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3754 /* We don't want to directly expand a partial CU, because if we
3755 read it with the wrong language, then assertion failures can
3756 be triggered later on. See PR symtab/23010. So, tell
3757 dw2_instantiate_symtab to skip partial CUs -- any important
3758 partial CU will be read via DW_TAG_imported_unit anyway. */
3759 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3764 dwarf2_base_index_functions::expand_symtabs_with_fullname
3765 (struct objfile
*objfile
, const char *fullname
)
3767 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3769 /* We don't need to consider type units here.
3770 This is only called for examining code, e.g. expand_line_sal.
3771 There can be an order of magnitude (or more) more type units
3772 than comp units, and we avoid them if we can. */
3774 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3776 /* We only need to look at symtabs not already expanded. */
3777 if (per_objfile
->symtab_set_p (per_cu
))
3780 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3781 if (file_data
== NULL
)
3784 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3786 const char *this_fullname
= file_data
->file_names
[j
];
3788 if (filename_cmp (this_fullname
, fullname
) == 0)
3790 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3798 dw2_expand_symtabs_matching_symbol
3799 (mapped_index_base
&index
,
3800 const lookup_name_info
&lookup_name_in
,
3801 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3802 enum search_domain kind
,
3803 gdb::function_view
<bool (offset_type
)> match_callback
,
3804 dwarf2_per_objfile
*per_objfile
);
3807 dw2_expand_symtabs_matching_one
3808 (dwarf2_per_cu_data
*per_cu
,
3809 dwarf2_per_objfile
*per_objfile
,
3810 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3811 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3814 dw2_map_matching_symbols
3815 (struct objfile
*objfile
,
3816 const lookup_name_info
&name
, domain_enum domain
,
3818 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3819 symbol_compare_ftype
*ordered_compare
)
3822 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3824 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3826 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3828 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3830 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3831 auto matcher
= [&] (const char *symname
)
3833 if (ordered_compare
== nullptr)
3835 return ordered_compare (symname
, match_name
) == 0;
3838 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3839 [&] (offset_type namei
)
3841 struct dw2_symtab_iterator iter
;
3842 struct dwarf2_per_cu_data
*per_cu
;
3844 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3846 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3847 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3854 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3855 proceed assuming all symtabs have been read in. */
3858 for (compunit_symtab
*cust
: objfile
->compunits ())
3860 const struct block
*block
;
3864 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3865 if (!iterate_over_symbols_terminated (block
, name
,
3872 dwarf2_gdb_index::map_matching_symbols
3873 (struct objfile
*objfile
,
3874 const lookup_name_info
&name
, domain_enum domain
,
3876 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3877 symbol_compare_ftype
*ordered_compare
)
3879 dw2_map_matching_symbols (objfile
, name
, domain
, global
, callback
,
3883 /* Starting from a search name, return the string that finds the upper
3884 bound of all strings that start with SEARCH_NAME in a sorted name
3885 list. Returns the empty string to indicate that the upper bound is
3886 the end of the list. */
3889 make_sort_after_prefix_name (const char *search_name
)
3891 /* When looking to complete "func", we find the upper bound of all
3892 symbols that start with "func" by looking for where we'd insert
3893 the closest string that would follow "func" in lexicographical
3894 order. Usually, that's "func"-with-last-character-incremented,
3895 i.e. "fund". Mind non-ASCII characters, though. Usually those
3896 will be UTF-8 multi-byte sequences, but we can't be certain.
3897 Especially mind the 0xff character, which is a valid character in
3898 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3899 rule out compilers allowing it in identifiers. Note that
3900 conveniently, strcmp/strcasecmp are specified to compare
3901 characters interpreted as unsigned char. So what we do is treat
3902 the whole string as a base 256 number composed of a sequence of
3903 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3904 to 0, and carries 1 to the following more-significant position.
3905 If the very first character in SEARCH_NAME ends up incremented
3906 and carries/overflows, then the upper bound is the end of the
3907 list. The string after the empty string is also the empty
3910 Some examples of this operation:
3912 SEARCH_NAME => "+1" RESULT
3916 "\xff" "a" "\xff" => "\xff" "b"
3921 Then, with these symbols for example:
3927 completing "func" looks for symbols between "func" and
3928 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3929 which finds "func" and "func1", but not "fund".
3933 funcÿ (Latin1 'ÿ' [0xff])
3937 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3938 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3942 ÿÿ (Latin1 'ÿ' [0xff])
3945 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3946 the end of the list.
3948 std::string after
= search_name
;
3949 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3951 if (!after
.empty ())
3952 after
.back () = (unsigned char) after
.back () + 1;
3956 /* See declaration. */
3958 std::pair
<std::vector
<name_component
>::const_iterator
,
3959 std::vector
<name_component
>::const_iterator
>
3960 mapped_index_base::find_name_components_bounds
3961 (const lookup_name_info
&lookup_name_without_params
, language lang
,
3962 dwarf2_per_objfile
*per_objfile
) const
3965 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3967 const char *lang_name
3968 = lookup_name_without_params
.language_lookup_name (lang
);
3970 /* Comparison function object for lower_bound that matches against a
3971 given symbol name. */
3972 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3975 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3976 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3977 return name_cmp (elem_name
, name
) < 0;
3980 /* Comparison function object for upper_bound that matches against a
3981 given symbol name. */
3982 auto lookup_compare_upper
= [&] (const char *name
,
3983 const name_component
&elem
)
3985 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
3986 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3987 return name_cmp (name
, elem_name
) < 0;
3990 auto begin
= this->name_components
.begin ();
3991 auto end
= this->name_components
.end ();
3993 /* Find the lower bound. */
3996 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3999 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4002 /* Find the upper bound. */
4005 if (lookup_name_without_params
.completion_mode ())
4007 /* In completion mode, we want UPPER to point past all
4008 symbols names that have the same prefix. I.e., with
4009 these symbols, and completing "func":
4011 function << lower bound
4013 other_function << upper bound
4015 We find the upper bound by looking for the insertion
4016 point of "func"-with-last-character-incremented,
4018 std::string after
= make_sort_after_prefix_name (lang_name
);
4021 return std::lower_bound (lower
, end
, after
.c_str (),
4022 lookup_compare_lower
);
4025 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4028 return {lower
, upper
};
4031 /* See declaration. */
4034 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
4036 if (!this->name_components
.empty ())
4039 this->name_components_casing
= case_sensitivity
;
4041 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4043 /* The code below only knows how to break apart components of C++
4044 symbol names (and other languages that use '::' as
4045 namespace/module separator) and Ada symbol names. */
4046 auto count
= this->symbol_name_count ();
4047 for (offset_type idx
= 0; idx
< count
; idx
++)
4049 if (this->symbol_name_slot_invalid (idx
))
4052 const char *name
= this->symbol_name_at (idx
, per_objfile
);
4054 /* Add each name component to the name component table. */
4055 unsigned int previous_len
= 0;
4057 if (strstr (name
, "::") != nullptr)
4059 for (unsigned int current_len
= cp_find_first_component (name
);
4060 name
[current_len
] != '\0';
4061 current_len
+= cp_find_first_component (name
+ current_len
))
4063 gdb_assert (name
[current_len
] == ':');
4064 this->name_components
.push_back ({previous_len
, idx
});
4065 /* Skip the '::'. */
4067 previous_len
= current_len
;
4072 /* Handle the Ada encoded (aka mangled) form here. */
4073 for (const char *iter
= strstr (name
, "__");
4075 iter
= strstr (iter
, "__"))
4077 this->name_components
.push_back ({previous_len
, idx
});
4079 previous_len
= iter
- name
;
4083 this->name_components
.push_back ({previous_len
, idx
});
4086 /* Sort name_components elements by name. */
4087 auto name_comp_compare
= [&] (const name_component
&left
,
4088 const name_component
&right
)
4090 const char *left_qualified
4091 = this->symbol_name_at (left
.idx
, per_objfile
);
4092 const char *right_qualified
4093 = this->symbol_name_at (right
.idx
, per_objfile
);
4095 const char *left_name
= left_qualified
+ left
.name_offset
;
4096 const char *right_name
= right_qualified
+ right
.name_offset
;
4098 return name_cmp (left_name
, right_name
) < 0;
4101 std::sort (this->name_components
.begin (),
4102 this->name_components
.end (),
4106 /* Helper for dw2_expand_symtabs_matching that works with a
4107 mapped_index_base instead of the containing objfile. This is split
4108 to a separate function in order to be able to unit test the
4109 name_components matching using a mock mapped_index_base. For each
4110 symbol name that matches, calls MATCH_CALLBACK, passing it the
4111 symbol's index in the mapped_index_base symbol table. */
4114 dw2_expand_symtabs_matching_symbol
4115 (mapped_index_base
&index
,
4116 const lookup_name_info
&lookup_name_in
,
4117 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4118 enum search_domain kind
,
4119 gdb::function_view
<bool (offset_type
)> match_callback
,
4120 dwarf2_per_objfile
*per_objfile
)
4122 lookup_name_info lookup_name_without_params
4123 = lookup_name_in
.make_ignore_params ();
4125 /* Build the symbol name component sorted vector, if we haven't
4127 index
.build_name_components (per_objfile
);
4129 /* The same symbol may appear more than once in the range though.
4130 E.g., if we're looking for symbols that complete "w", and we have
4131 a symbol named "w1::w2", we'll find the two name components for
4132 that same symbol in the range. To be sure we only call the
4133 callback once per symbol, we first collect the symbol name
4134 indexes that matched in a temporary vector and ignore
4136 std::vector
<offset_type
> matches
;
4138 struct name_and_matcher
4140 symbol_name_matcher_ftype
*matcher
;
4143 bool operator== (const name_and_matcher
&other
) const
4145 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4149 /* A vector holding all the different symbol name matchers, for all
4151 std::vector
<name_and_matcher
> matchers
;
4153 for (int i
= 0; i
< nr_languages
; i
++)
4155 enum language lang_e
= (enum language
) i
;
4157 const language_defn
*lang
= language_def (lang_e
);
4158 symbol_name_matcher_ftype
*name_matcher
4159 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
4161 name_and_matcher key
{
4163 lookup_name_without_params
.language_lookup_name (lang_e
)
4166 /* Don't insert the same comparison routine more than once.
4167 Note that we do this linear walk. This is not a problem in
4168 practice because the number of supported languages is
4170 if (std::find (matchers
.begin (), matchers
.end (), key
)
4173 matchers
.push_back (std::move (key
));
4176 = index
.find_name_components_bounds (lookup_name_without_params
,
4177 lang_e
, per_objfile
);
4179 /* Now for each symbol name in range, check to see if we have a name
4180 match, and if so, call the MATCH_CALLBACK callback. */
4182 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4184 const char *qualified
4185 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4187 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4188 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4191 matches
.push_back (bounds
.first
->idx
);
4195 std::sort (matches
.begin (), matches
.end ());
4197 /* Finally call the callback, once per match. */
4199 for (offset_type idx
: matches
)
4203 if (!match_callback (idx
))
4209 /* Above we use a type wider than idx's for 'prev', since 0 and
4210 (offset_type)-1 are both possible values. */
4211 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4216 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4218 /* A mock .gdb_index/.debug_names-like name index table, enough to
4219 exercise dw2_expand_symtabs_matching_symbol, which works with the
4220 mapped_index_base interface. Builds an index from the symbol list
4221 passed as parameter to the constructor. */
4222 class mock_mapped_index
: public mapped_index_base
4225 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4226 : m_symbol_table (symbols
)
4229 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4231 /* Return the number of names in the symbol table. */
4232 size_t symbol_name_count () const override
4234 return m_symbol_table
.size ();
4237 /* Get the name of the symbol at IDX in the symbol table. */
4238 const char *symbol_name_at
4239 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4241 return m_symbol_table
[idx
];
4245 gdb::array_view
<const char *> m_symbol_table
;
4248 /* Convenience function that converts a NULL pointer to a "<null>"
4249 string, to pass to print routines. */
4252 string_or_null (const char *str
)
4254 return str
!= NULL
? str
: "<null>";
4257 /* Check if a lookup_name_info built from
4258 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4259 index. EXPECTED_LIST is the list of expected matches, in expected
4260 matching order. If no match expected, then an empty list is
4261 specified. Returns true on success. On failure prints a warning
4262 indicating the file:line that failed, and returns false. */
4265 check_match (const char *file
, int line
,
4266 mock_mapped_index
&mock_index
,
4267 const char *name
, symbol_name_match_type match_type
,
4268 bool completion_mode
,
4269 std::initializer_list
<const char *> expected_list
,
4270 dwarf2_per_objfile
*per_objfile
)
4272 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4274 bool matched
= true;
4276 auto mismatch
= [&] (const char *expected_str
,
4279 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4280 "expected=\"%s\", got=\"%s\"\n"),
4282 (match_type
== symbol_name_match_type::FULL
4284 name
, string_or_null (expected_str
), string_or_null (got
));
4288 auto expected_it
= expected_list
.begin ();
4289 auto expected_end
= expected_list
.end ();
4291 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4293 [&] (offset_type idx
)
4295 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4296 const char *expected_str
4297 = expected_it
== expected_end
? NULL
: *expected_it
++;
4299 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4300 mismatch (expected_str
, matched_name
);
4304 const char *expected_str
4305 = expected_it
== expected_end
? NULL
: *expected_it
++;
4306 if (expected_str
!= NULL
)
4307 mismatch (expected_str
, NULL
);
4312 /* The symbols added to the mock mapped_index for testing (in
4314 static const char *test_symbols
[] = {
4323 "ns2::tmpl<int>::foo2",
4324 "(anonymous namespace)::A::B::C",
4326 /* These are used to check that the increment-last-char in the
4327 matching algorithm for completion doesn't match "t1_fund" when
4328 completing "t1_func". */
4334 /* A UTF-8 name with multi-byte sequences to make sure that
4335 cp-name-parser understands this as a single identifier ("função"
4336 is "function" in PT). */
4339 /* \377 (0xff) is Latin1 'ÿ'. */
4342 /* \377 (0xff) is Latin1 'ÿ'. */
4346 /* A name with all sorts of complications. Starts with "z" to make
4347 it easier for the completion tests below. */
4348 #define Z_SYM_NAME \
4349 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4350 "::tuple<(anonymous namespace)::ui*, " \
4351 "std::default_delete<(anonymous namespace)::ui>, void>"
4356 /* Returns true if the mapped_index_base::find_name_component_bounds
4357 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4358 in completion mode. */
4361 check_find_bounds_finds (mapped_index_base
&index
,
4362 const char *search_name
,
4363 gdb::array_view
<const char *> expected_syms
,
4364 dwarf2_per_objfile
*per_objfile
)
4366 lookup_name_info
lookup_name (search_name
,
4367 symbol_name_match_type::FULL
, true);
4369 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4373 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4374 if (distance
!= expected_syms
.size ())
4377 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4379 auto nc_elem
= bounds
.first
+ exp_elem
;
4380 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4381 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4388 /* Test the lower-level mapped_index::find_name_component_bounds
4392 test_mapped_index_find_name_component_bounds ()
4394 mock_mapped_index
mock_index (test_symbols
);
4396 mock_index
.build_name_components (NULL
/* per_objfile */);
4398 /* Test the lower-level mapped_index::find_name_component_bounds
4399 method in completion mode. */
4401 static const char *expected_syms
[] = {
4406 SELF_CHECK (check_find_bounds_finds
4407 (mock_index
, "t1_func", expected_syms
,
4408 NULL
/* per_objfile */));
4411 /* Check that the increment-last-char in the name matching algorithm
4412 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4414 static const char *expected_syms1
[] = {
4418 SELF_CHECK (check_find_bounds_finds
4419 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4421 static const char *expected_syms2
[] = {
4424 SELF_CHECK (check_find_bounds_finds
4425 (mock_index
, "\377\377", expected_syms2
,
4426 NULL
/* per_objfile */));
4430 /* Test dw2_expand_symtabs_matching_symbol. */
4433 test_dw2_expand_symtabs_matching_symbol ()
4435 mock_mapped_index
mock_index (test_symbols
);
4437 /* We let all tests run until the end even if some fails, for debug
4439 bool any_mismatch
= false;
4441 /* Create the expected symbols list (an initializer_list). Needed
4442 because lists have commas, and we need to pass them to CHECK,
4443 which is a macro. */
4444 #define EXPECT(...) { __VA_ARGS__ }
4446 /* Wrapper for check_match that passes down the current
4447 __FILE__/__LINE__. */
4448 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4449 any_mismatch |= !check_match (__FILE__, __LINE__, \
4451 NAME, MATCH_TYPE, COMPLETION_MODE, \
4452 EXPECTED_LIST, NULL)
4454 /* Identity checks. */
4455 for (const char *sym
: test_symbols
)
4457 /* Should be able to match all existing symbols. */
4458 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4461 /* Should be able to match all existing symbols with
4463 std::string with_params
= std::string (sym
) + "(int)";
4464 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4467 /* Should be able to match all existing symbols with
4468 parameters and qualifiers. */
4469 with_params
= std::string (sym
) + " ( int ) const";
4470 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4473 /* This should really find sym, but cp-name-parser.y doesn't
4474 know about lvalue/rvalue qualifiers yet. */
4475 with_params
= std::string (sym
) + " ( int ) &&";
4476 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4480 /* Check that the name matching algorithm for completion doesn't get
4481 confused with Latin1 'ÿ' / 0xff. */
4483 static const char str
[] = "\377";
4484 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4485 EXPECT ("\377", "\377\377123"));
4488 /* Check that the increment-last-char in the matching algorithm for
4489 completion doesn't match "t1_fund" when completing "t1_func". */
4491 static const char str
[] = "t1_func";
4492 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4493 EXPECT ("t1_func", "t1_func1"));
4496 /* Check that completion mode works at each prefix of the expected
4499 static const char str
[] = "function(int)";
4500 size_t len
= strlen (str
);
4503 for (size_t i
= 1; i
< len
; i
++)
4505 lookup
.assign (str
, i
);
4506 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4507 EXPECT ("function"));
4511 /* While "w" is a prefix of both components, the match function
4512 should still only be called once. */
4514 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4516 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4520 /* Same, with a "complicated" symbol. */
4522 static const char str
[] = Z_SYM_NAME
;
4523 size_t len
= strlen (str
);
4526 for (size_t i
= 1; i
< len
; i
++)
4528 lookup
.assign (str
, i
);
4529 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4530 EXPECT (Z_SYM_NAME
));
4534 /* In FULL mode, an incomplete symbol doesn't match. */
4536 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4540 /* A complete symbol with parameters matches any overload, since the
4541 index has no overload info. */
4543 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4544 EXPECT ("std::zfunction", "std::zfunction2"));
4545 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4546 EXPECT ("std::zfunction", "std::zfunction2"));
4547 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4548 EXPECT ("std::zfunction", "std::zfunction2"));
4551 /* Check that whitespace is ignored appropriately. A symbol with a
4552 template argument list. */
4554 static const char expected
[] = "ns::foo<int>";
4555 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4557 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4561 /* Check that whitespace is ignored appropriately. A symbol with a
4562 template argument list that includes a pointer. */
4564 static const char expected
[] = "ns::foo<char*>";
4565 /* Try both completion and non-completion modes. */
4566 static const bool completion_mode
[2] = {false, true};
4567 for (size_t i
= 0; i
< 2; i
++)
4569 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4570 completion_mode
[i
], EXPECT (expected
));
4571 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4572 completion_mode
[i
], EXPECT (expected
));
4574 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4575 completion_mode
[i
], EXPECT (expected
));
4576 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4577 completion_mode
[i
], EXPECT (expected
));
4582 /* Check method qualifiers are ignored. */
4583 static const char expected
[] = "ns::foo<char*>";
4584 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4585 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4586 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4587 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4588 CHECK_MATCH ("foo < char * > ( int ) const",
4589 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4590 CHECK_MATCH ("foo < char * > ( int ) &&",
4591 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4594 /* Test lookup names that don't match anything. */
4596 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4599 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4603 /* Some wild matching tests, exercising "(anonymous namespace)",
4604 which should not be confused with a parameter list. */
4606 static const char *syms
[] = {
4610 "A :: B :: C ( int )",
4615 for (const char *s
: syms
)
4617 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4618 EXPECT ("(anonymous namespace)::A::B::C"));
4623 static const char expected
[] = "ns2::tmpl<int>::foo2";
4624 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4626 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4630 SELF_CHECK (!any_mismatch
);
4639 test_mapped_index_find_name_component_bounds ();
4640 test_dw2_expand_symtabs_matching_symbol ();
4643 }} // namespace selftests::dw2_expand_symtabs_matching
4645 #endif /* GDB_SELF_TEST */
4647 /* If FILE_MATCHER is NULL or if PER_CU has
4648 dwarf2_per_cu_quick_data::MARK set (see
4649 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4650 EXPANSION_NOTIFY on it. */
4653 dw2_expand_symtabs_matching_one
4654 (dwarf2_per_cu_data
*per_cu
,
4655 dwarf2_per_objfile
*per_objfile
,
4656 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4657 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4659 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4661 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4663 compunit_symtab
*symtab
4664 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4665 gdb_assert (symtab
!= nullptr);
4667 if (expansion_notify
!= NULL
&& symtab_was_null
)
4668 expansion_notify (symtab
);
4672 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4673 matched, to expand corresponding CUs that were marked. IDX is the
4674 index of the symbol name that matched. */
4677 dw2_expand_marked_cus
4678 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4679 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4680 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4683 offset_type
*vec
, vec_len
, vec_idx
;
4684 bool global_seen
= false;
4685 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4687 vec
= (offset_type
*) (index
.constant_pool
4688 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4689 vec_len
= MAYBE_SWAP (vec
[0]);
4690 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4692 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4693 /* This value is only valid for index versions >= 7. */
4694 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4695 gdb_index_symbol_kind symbol_kind
=
4696 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4697 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4698 /* Only check the symbol attributes if they're present.
4699 Indices prior to version 7 don't record them,
4700 and indices >= 7 may elide them for certain symbols
4701 (gold does this). */
4704 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4706 /* Work around gold/15646. */
4709 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4717 /* Only check the symbol's kind if it has one. */
4722 case VARIABLES_DOMAIN
:
4723 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4726 case FUNCTIONS_DOMAIN
:
4727 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4731 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4734 case MODULES_DOMAIN
:
4735 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4743 /* Don't crash on bad data. */
4744 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
4745 + per_objfile
->per_bfd
->all_type_units
.size ()))
4747 complaint (_(".gdb_index entry has bad CU index"
4748 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4752 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
4753 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4758 /* If FILE_MATCHER is non-NULL, set all the
4759 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4760 that match FILE_MATCHER. */
4763 dw_expand_symtabs_matching_file_matcher
4764 (dwarf2_per_objfile
*per_objfile
,
4765 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4767 if (file_matcher
== NULL
)
4770 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4772 NULL
, xcalloc
, xfree
));
4773 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4775 NULL
, xcalloc
, xfree
));
4777 /* The rule is CUs specify all the files, including those used by
4778 any TU, so there's no need to scan TUs here. */
4780 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4784 per_cu
->v
.quick
->mark
= 0;
4786 /* We only need to look at symtabs not already expanded. */
4787 if (per_objfile
->symtab_set_p (per_cu
))
4790 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4791 if (file_data
== NULL
)
4794 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4796 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4798 per_cu
->v
.quick
->mark
= 1;
4802 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4804 const char *this_real_name
;
4806 if (file_matcher (file_data
->file_names
[j
], false))
4808 per_cu
->v
.quick
->mark
= 1;
4812 /* Before we invoke realpath, which can get expensive when many
4813 files are involved, do a quick comparison of the basenames. */
4814 if (!basenames_may_differ
4815 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4819 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4820 if (file_matcher (this_real_name
, false))
4822 per_cu
->v
.quick
->mark
= 1;
4827 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4828 ? visited_found
.get ()
4829 : visited_not_found
.get (),
4836 dw2_expand_symtabs_matching
4837 (struct objfile
*objfile
,
4838 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4839 const lookup_name_info
*lookup_name
,
4840 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4841 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4842 enum search_domain kind
)
4844 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4846 /* index_table is NULL if OBJF_READNOW. */
4847 if (!per_objfile
->per_bfd
->index_table
)
4850 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4852 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4854 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4858 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4859 file_matcher
, expansion_notify
);
4864 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4866 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4868 kind
, [&] (offset_type idx
)
4870 dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
, expansion_notify
,
4877 dwarf2_gdb_index::expand_symtabs_matching
4878 (struct objfile
*objfile
,
4879 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4880 const lookup_name_info
*lookup_name
,
4881 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4882 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4883 enum search_domain kind
)
4885 dw2_expand_symtabs_matching (objfile
, file_matcher
, lookup_name
,
4886 symbol_matcher
, expansion_notify
, kind
);
4889 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4892 static struct compunit_symtab
*
4893 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4898 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4899 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4902 if (cust
->includes
== NULL
)
4905 for (i
= 0; cust
->includes
[i
]; ++i
)
4907 struct compunit_symtab
*s
= cust
->includes
[i
];
4909 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4917 struct compunit_symtab
*
4918 dwarf2_base_index_functions::find_pc_sect_compunit_symtab
4919 (struct objfile
*objfile
,
4920 struct bound_minimal_symbol msymbol
,
4922 struct obj_section
*section
,
4925 struct dwarf2_per_cu_data
*data
;
4926 struct compunit_symtab
*result
;
4928 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4931 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4932 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4933 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4937 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
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 ());
5348 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
5349 objfiles using the same BFD. */
5350 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
5351 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
5356 /* Type used to manage iterating over all CUs looking for a symbol for
5359 class dw2_debug_names_iterator
5362 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5363 gdb::optional
<block_enum
> block_index
,
5365 const char *name
, dwarf2_per_objfile
*per_objfile
)
5366 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5367 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5368 m_per_objfile (per_objfile
)
5371 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5372 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5375 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5376 m_per_objfile (per_objfile
)
5379 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5380 block_enum block_index
, domain_enum domain
,
5381 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5382 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5383 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5384 m_per_objfile (per_objfile
)
5387 /* Return the next matching CU or NULL if there are no more. */
5388 dwarf2_per_cu_data
*next ();
5391 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5393 dwarf2_per_objfile
*per_objfile
);
5394 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5396 dwarf2_per_objfile
*per_objfile
);
5398 /* The internalized form of .debug_names. */
5399 const mapped_debug_names
&m_map
;
5401 /* If set, only look for symbols that match that block. Valid values are
5402 GLOBAL_BLOCK and STATIC_BLOCK. */
5403 const gdb::optional
<block_enum
> m_block_index
;
5405 /* The kind of symbol we're looking for. */
5406 const domain_enum m_domain
= UNDEF_DOMAIN
;
5407 const search_domain m_search
= ALL_DOMAIN
;
5409 /* The list of CUs from the index entry of the symbol, or NULL if
5411 const gdb_byte
*m_addr
;
5413 dwarf2_per_objfile
*m_per_objfile
;
5417 mapped_debug_names::namei_to_name
5418 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5420 const ULONGEST namei_string_offs
5421 = extract_unsigned_integer ((name_table_string_offs_reordered
5422 + namei
* offset_size
),
5425 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5428 /* Find a slot in .debug_names for the object named NAME. If NAME is
5429 found, return pointer to its pool data. If NAME cannot be found,
5433 dw2_debug_names_iterator::find_vec_in_debug_names
5434 (const mapped_debug_names
&map
, const char *name
,
5435 dwarf2_per_objfile
*per_objfile
)
5437 int (*cmp
) (const char *, const char *);
5439 gdb::unique_xmalloc_ptr
<char> without_params
;
5440 if (current_language
->la_language
== language_cplus
5441 || current_language
->la_language
== language_fortran
5442 || current_language
->la_language
== language_d
)
5444 /* NAME is already canonical. Drop any qualifiers as
5445 .debug_names does not contain any. */
5447 if (strchr (name
, '(') != NULL
)
5449 without_params
= cp_remove_params (name
);
5450 if (without_params
!= NULL
)
5451 name
= without_params
.get ();
5455 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5457 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5459 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5460 (map
.bucket_table_reordered
5461 + (full_hash
% map
.bucket_count
)), 4,
5462 map
.dwarf5_byte_order
);
5466 if (namei
>= map
.name_count
)
5468 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5470 namei
, map
.name_count
,
5471 objfile_name (per_objfile
->objfile
));
5477 const uint32_t namei_full_hash
5478 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5479 (map
.hash_table_reordered
+ namei
), 4,
5480 map
.dwarf5_byte_order
);
5481 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5484 if (full_hash
== namei_full_hash
)
5486 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5488 #if 0 /* An expensive sanity check. */
5489 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5491 complaint (_("Wrong .debug_names hash for string at index %u "
5493 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5498 if (cmp (namei_string
, name
) == 0)
5500 const ULONGEST namei_entry_offs
5501 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5502 + namei
* map
.offset_size
),
5503 map
.offset_size
, map
.dwarf5_byte_order
);
5504 return map
.entry_pool
+ namei_entry_offs
;
5509 if (namei
>= map
.name_count
)
5515 dw2_debug_names_iterator::find_vec_in_debug_names
5516 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5518 if (namei
>= map
.name_count
)
5520 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5522 namei
, map
.name_count
,
5523 objfile_name (per_objfile
->objfile
));
5527 const ULONGEST namei_entry_offs
5528 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5529 + namei
* map
.offset_size
),
5530 map
.offset_size
, map
.dwarf5_byte_order
);
5531 return map
.entry_pool
+ namei_entry_offs
;
5534 /* See dw2_debug_names_iterator. */
5536 dwarf2_per_cu_data
*
5537 dw2_debug_names_iterator::next ()
5542 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5543 struct objfile
*objfile
= m_per_objfile
->objfile
;
5544 bfd
*const abfd
= objfile
->obfd
;
5548 unsigned int bytes_read
;
5549 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5550 m_addr
+= bytes_read
;
5554 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5555 if (indexval_it
== m_map
.abbrev_map
.cend ())
5557 complaint (_("Wrong .debug_names undefined abbrev code %s "
5559 pulongest (abbrev
), objfile_name (objfile
));
5562 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5563 enum class symbol_linkage
{
5567 } symbol_linkage_
= symbol_linkage::unknown
;
5568 dwarf2_per_cu_data
*per_cu
= NULL
;
5569 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5574 case DW_FORM_implicit_const
:
5575 ull
= attr
.implicit_const
;
5577 case DW_FORM_flag_present
:
5581 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5582 m_addr
+= bytes_read
;
5585 ull
= read_4_bytes (abfd
, m_addr
);
5589 ull
= read_8_bytes (abfd
, m_addr
);
5592 case DW_FORM_ref_sig8
:
5593 ull
= read_8_bytes (abfd
, m_addr
);
5597 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5598 dwarf_form_name (attr
.form
),
5599 objfile_name (objfile
));
5602 switch (attr
.dw_idx
)
5604 case DW_IDX_compile_unit
:
5605 /* Don't crash on bad data. */
5606 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5608 complaint (_(".debug_names entry has bad CU index %s"
5611 objfile_name (objfile
));
5614 per_cu
= per_bfd
->get_cutu (ull
);
5616 case DW_IDX_type_unit
:
5617 /* Don't crash on bad data. */
5618 if (ull
>= per_bfd
->all_type_units
.size ())
5620 complaint (_(".debug_names entry has bad TU index %s"
5623 objfile_name (objfile
));
5626 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5628 case DW_IDX_die_offset
:
5629 /* In a per-CU index (as opposed to a per-module index), index
5630 entries without CU attribute implicitly refer to the single CU. */
5632 per_cu
= per_bfd
->get_cu (0);
5634 case DW_IDX_GNU_internal
:
5635 if (!m_map
.augmentation_is_gdb
)
5637 symbol_linkage_
= symbol_linkage::static_
;
5639 case DW_IDX_GNU_external
:
5640 if (!m_map
.augmentation_is_gdb
)
5642 symbol_linkage_
= symbol_linkage::extern_
;
5647 /* Skip if already read in. */
5648 if (m_per_objfile
->symtab_set_p (per_cu
))
5651 /* Check static vs global. */
5652 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5654 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5655 const bool symbol_is_static
=
5656 symbol_linkage_
== symbol_linkage::static_
;
5657 if (want_static
!= symbol_is_static
)
5661 /* Match dw2_symtab_iter_next, symbol_kind
5662 and debug_names::psymbol_tag. */
5666 switch (indexval
.dwarf_tag
)
5668 case DW_TAG_variable
:
5669 case DW_TAG_subprogram
:
5670 /* Some types are also in VAR_DOMAIN. */
5671 case DW_TAG_typedef
:
5672 case DW_TAG_structure_type
:
5679 switch (indexval
.dwarf_tag
)
5681 case DW_TAG_typedef
:
5682 case DW_TAG_structure_type
:
5689 switch (indexval
.dwarf_tag
)
5692 case DW_TAG_variable
:
5699 switch (indexval
.dwarf_tag
)
5711 /* Match dw2_expand_symtabs_matching, symbol_kind and
5712 debug_names::psymbol_tag. */
5715 case VARIABLES_DOMAIN
:
5716 switch (indexval
.dwarf_tag
)
5718 case DW_TAG_variable
:
5724 case FUNCTIONS_DOMAIN
:
5725 switch (indexval
.dwarf_tag
)
5727 case DW_TAG_subprogram
:
5734 switch (indexval
.dwarf_tag
)
5736 case DW_TAG_typedef
:
5737 case DW_TAG_structure_type
:
5743 case MODULES_DOMAIN
:
5744 switch (indexval
.dwarf_tag
)
5758 struct compunit_symtab
*
5759 dwarf2_debug_names_index::lookup_symbol
5760 (struct objfile
*objfile
, block_enum block_index
,
5761 const char *name
, domain_enum domain
)
5763 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5765 const auto &mapp
= per_objfile
->per_bfd
->debug_names_table
;
5768 /* index is NULL if OBJF_READNOW. */
5771 const auto &map
= *mapp
;
5773 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
, per_objfile
);
5775 struct compunit_symtab
*stab_best
= NULL
;
5776 struct dwarf2_per_cu_data
*per_cu
;
5777 while ((per_cu
= iter
.next ()) != NULL
)
5779 struct symbol
*sym
, *with_opaque
= NULL
;
5780 compunit_symtab
*stab
5781 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5782 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5783 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5785 sym
= block_find_symbol (block
, name
, domain
,
5786 block_find_non_opaque_type_preferred
,
5789 /* Some caution must be observed with overloaded functions and
5790 methods, since the index will not contain any overload
5791 information (but NAME might contain it). */
5794 && strcmp_iw (sym
->search_name (), name
) == 0)
5796 if (with_opaque
!= NULL
5797 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5800 /* Keep looking through other CUs. */
5806 /* This dumps minimal information about .debug_names. It is called
5807 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5808 uses this to verify that .debug_names has been loaded. */
5811 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
5813 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5815 gdb_assert (per_objfile
->per_bfd
->using_index
);
5816 printf_filtered (".debug_names:");
5817 if (per_objfile
->per_bfd
->debug_names_table
)
5818 printf_filtered (" exists\n");
5820 printf_filtered (" faked for \"readnow\"\n");
5821 printf_filtered ("\n");
5825 dwarf2_debug_names_index::expand_symtabs_for_function
5826 (struct objfile
*objfile
, const char *func_name
)
5828 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5830 /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5831 if (per_objfile
->per_bfd
->debug_names_table
)
5833 const mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5835 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5838 struct dwarf2_per_cu_data
*per_cu
;
5839 while ((per_cu
= iter
.next ()) != NULL
)
5840 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5845 dwarf2_debug_names_index::map_matching_symbols
5846 (struct objfile
*objfile
,
5847 const lookup_name_info
&name
, domain_enum domain
,
5849 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5850 symbol_compare_ftype
*ordered_compare
)
5852 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5854 /* debug_names_table is NULL if OBJF_READNOW. */
5855 if (!per_objfile
->per_bfd
->debug_names_table
)
5858 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5859 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5861 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5862 auto matcher
= [&] (const char *symname
)
5864 if (ordered_compare
== nullptr)
5866 return ordered_compare (symname
, match_name
) == 0;
5869 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5870 [&] (offset_type namei
)
5872 /* The name was matched, now expand corresponding CUs that were
5874 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5877 struct dwarf2_per_cu_data
*per_cu
;
5878 while ((per_cu
= iter
.next ()) != NULL
)
5879 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5884 /* It's a shame we couldn't do this inside the
5885 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5886 that have already been expanded. Instead, this loop matches what
5887 the psymtab code does. */
5888 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5890 compunit_symtab
*symtab
= per_objfile
->get_symtab (per_cu
);
5891 if (symtab
!= nullptr)
5893 const struct block
*block
5894 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
5895 if (!iterate_over_symbols_terminated (block
, name
,
5903 dwarf2_debug_names_index::expand_symtabs_matching
5904 (struct objfile
*objfile
,
5905 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5906 const lookup_name_info
*lookup_name
,
5907 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5908 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5909 enum search_domain kind
)
5911 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5913 /* debug_names_table is NULL if OBJF_READNOW. */
5914 if (!per_objfile
->per_bfd
->debug_names_table
)
5917 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
5919 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
5921 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5925 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5931 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5933 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
5935 kind
, [&] (offset_type namei
)
5937 /* The name was matched, now expand corresponding CUs that were
5939 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
);
5941 struct dwarf2_per_cu_data
*per_cu
;
5942 while ((per_cu
= iter
.next ()) != NULL
)
5943 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
5949 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5950 to either a dwarf2_per_bfd or dwz_file object. */
5952 template <typename T
>
5953 static gdb::array_view
<const gdb_byte
>
5954 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5956 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5958 if (section
->empty ())
5961 /* Older elfutils strip versions could keep the section in the main
5962 executable while splitting it for the separate debug info file. */
5963 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5966 section
->read (obj
);
5968 /* dwarf2_section_info::size is a bfd_size_type, while
5969 gdb::array_view works with size_t. On 32-bit hosts, with
5970 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5971 is 32-bit. So we need an explicit narrowing conversion here.
5972 This is fine, because it's impossible to allocate or mmap an
5973 array/buffer larger than what size_t can represent. */
5974 return gdb::make_array_view (section
->buffer
, section
->size
);
5977 /* Lookup the index cache for the contents of the index associated to
5980 static gdb::array_view
<const gdb_byte
>
5981 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
5983 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5984 if (build_id
== nullptr)
5987 return global_index_cache
.lookup_gdb_index (build_id
,
5988 &dwarf2_per_bfd
->index_cache_res
);
5991 /* Same as the above, but for DWZ. */
5993 static gdb::array_view
<const gdb_byte
>
5994 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5996 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5997 if (build_id
== nullptr)
6000 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6003 /* See symfile.h. */
6006 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6008 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6009 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6011 dwarf_read_debug_printf ("called");
6013 /* If we're about to read full symbols, don't bother with the
6014 indices. In this case we also don't care if some other debug
6015 format is making psymtabs, because they are all about to be
6017 if ((objfile
->flags
& OBJF_READNOW
))
6019 dwarf_read_debug_printf ("readnow requested");
6021 /* When using READNOW, the using_index flag (set below) indicates that
6022 PER_BFD was already initialized, when we loaded some other objfile. */
6023 if (per_bfd
->using_index
)
6025 dwarf_read_debug_printf ("using_index already set");
6026 *index_kind
= dw_index_kind::GDB_INDEX
;
6027 per_objfile
->resize_symtabs ();
6031 per_bfd
->using_index
= 1;
6032 create_all_comp_units (per_objfile
);
6033 create_all_type_units (per_objfile
);
6034 per_bfd
->quick_file_names_table
6035 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
6036 per_objfile
->resize_symtabs ();
6038 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
6039 + per_bfd
->all_type_units
.size ()); ++i
)
6041 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
6043 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6044 struct dwarf2_per_cu_quick_data
);
6047 /* Return 1 so that gdb sees the "quick" functions. However,
6048 these functions will be no-ops because we will have expanded
6050 *index_kind
= dw_index_kind::GDB_INDEX
;
6054 /* Was a debug names index already read when we processed an objfile sharing
6056 if (per_bfd
->debug_names_table
!= nullptr)
6058 dwarf_read_debug_printf ("re-using shared debug names table");
6059 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6060 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6061 per_objfile
->resize_symtabs ();
6065 /* Was a GDB index already read when we processed an objfile sharing
6067 if (per_bfd
->index_table
!= nullptr)
6069 dwarf_read_debug_printf ("re-using shared index table");
6070 *index_kind
= dw_index_kind::GDB_INDEX
;
6071 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6072 per_objfile
->resize_symtabs ();
6076 /* There might already be partial symtabs built for this BFD. This happens
6077 when loading the same binary twice with the index-cache enabled. If so,
6078 don't try to read an index. The objfile / per_objfile initialization will
6079 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
6081 if (per_bfd
->partial_symtabs
!= nullptr)
6083 dwarf_read_debug_printf ("re-using shared partial symtabs");
6087 if (dwarf2_read_debug_names (per_objfile
))
6089 dwarf_read_debug_printf ("found debug names");
6090 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6091 per_objfile
->resize_symtabs ();
6095 if (dwarf2_read_gdb_index (per_objfile
,
6096 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
6097 get_gdb_index_contents_from_section
<dwz_file
>))
6099 dwarf_read_debug_printf ("found gdb index from file");
6100 *index_kind
= dw_index_kind::GDB_INDEX
;
6101 per_objfile
->resize_symtabs ();
6105 /* ... otherwise, try to find the index in the index cache. */
6106 if (dwarf2_read_gdb_index (per_objfile
,
6107 get_gdb_index_contents_from_cache
,
6108 get_gdb_index_contents_from_cache_dwz
))
6110 dwarf_read_debug_printf ("found gdb index from cache");
6111 global_index_cache
.hit ();
6112 *index_kind
= dw_index_kind::GDB_INDEX
;
6113 per_objfile
->resize_symtabs ();
6117 global_index_cache
.miss ();
6123 /* Build a partial symbol table. */
6126 dwarf2_build_psymtabs (struct objfile
*objfile
)
6128 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6129 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6131 if (per_bfd
->partial_symtabs
!= nullptr)
6133 /* Partial symbols were already read, so now we can simply
6135 objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6136 per_objfile
->resize_symtabs ();
6142 /* This isn't really ideal: all the data we allocate on the
6143 objfile's obstack is still uselessly kept around. However,
6144 freeing it seems unsafe. */
6145 psymtab_discarder
psymtabs (objfile
);
6146 dwarf2_build_psymtabs_hard (per_objfile
);
6149 per_objfile
->resize_symtabs ();
6151 /* (maybe) store an index in the cache. */
6152 global_index_cache
.store (per_objfile
);
6154 catch (const gdb_exception_error
&except
)
6156 exception_print (gdb_stderr
, except
);
6159 /* Finish by setting the local reference to partial symtabs, so that
6160 we don't try to read them again if reading another objfile with the same
6161 BFD. If we can't in fact share, this won't make a difference anyway as
6162 the dwarf2_per_bfd object won't be shared. */
6163 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
6166 /* Find the base address of the compilation unit for range lists and
6167 location lists. It will normally be specified by DW_AT_low_pc.
6168 In DWARF-3 draft 4, the base address could be overridden by
6169 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6170 compilation units with discontinuous ranges. */
6173 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6175 struct attribute
*attr
;
6177 cu
->base_address
.reset ();
6179 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6180 if (attr
!= nullptr)
6181 cu
->base_address
= attr
->as_address ();
6184 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6185 if (attr
!= nullptr)
6186 cu
->base_address
= attr
->as_address ();
6190 /* Helper function that returns the proper abbrev section for
6193 static struct dwarf2_section_info
*
6194 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6196 struct dwarf2_section_info
*abbrev
;
6197 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6199 if (this_cu
->is_dwz
)
6200 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
6202 abbrev
= &per_bfd
->abbrev
;
6207 /* Fetch the abbreviation table offset from a comp or type unit header. */
6210 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
6211 struct dwarf2_section_info
*section
,
6212 sect_offset sect_off
)
6214 bfd
*abfd
= section
->get_bfd_owner ();
6215 const gdb_byte
*info_ptr
;
6216 unsigned int initial_length_size
, offset_size
;
6219 section
->read (per_objfile
->objfile
);
6220 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6221 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6222 offset_size
= initial_length_size
== 4 ? 4 : 8;
6223 info_ptr
+= initial_length_size
;
6225 version
= read_2_bytes (abfd
, info_ptr
);
6229 /* Skip unit type and address size. */
6233 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6236 /* A partial symtab that is used only for include files. */
6237 struct dwarf2_include_psymtab
: public partial_symtab
6239 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6240 : partial_symtab (filename
, objfile
)
6244 void read_symtab (struct objfile
*objfile
) override
6246 /* It's an include file, no symbols to read for it.
6247 Everything is in the includer symtab. */
6249 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6250 expansion of the includer psymtab. We use the dependencies[0] field to
6251 model the includer. But if we go the regular route of calling
6252 expand_psymtab here, and having expand_psymtab call expand_dependencies
6253 to expand the includer, we'll only use expand_psymtab on the includer
6254 (making it a non-toplevel psymtab), while if we expand the includer via
6255 another path, we'll use read_symtab (making it a toplevel psymtab).
6256 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6257 psymtab, and trigger read_symtab on the includer here directly. */
6258 includer ()->read_symtab (objfile
);
6261 void expand_psymtab (struct objfile
*objfile
) override
6263 /* This is not called by read_symtab, and should not be called by any
6264 expand_dependencies. */
6268 bool readin_p (struct objfile
*objfile
) const override
6270 return includer ()->readin_p (objfile
);
6273 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6279 partial_symtab
*includer () const
6281 /* An include psymtab has exactly one dependency: the psymtab that
6283 gdb_assert (this->number_of_dependencies
== 1);
6284 return this->dependencies
[0];
6288 /* Allocate a new partial symtab for file named NAME and mark this new
6289 partial symtab as being an include of PST. */
6292 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6293 struct objfile
*objfile
)
6295 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6297 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6298 subpst
->dirname
= pst
->dirname
;
6300 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6301 subpst
->dependencies
[0] = pst
;
6302 subpst
->number_of_dependencies
= 1;
6305 /* Read the Line Number Program data and extract the list of files
6306 included by the source file represented by PST. Build an include
6307 partial symtab for each of these included files. */
6310 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6311 struct die_info
*die
,
6312 dwarf2_psymtab
*pst
)
6315 struct attribute
*attr
;
6317 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6318 if (attr
!= nullptr && attr
->form_is_unsigned ())
6319 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
6321 return; /* No linetable, so no includes. */
6323 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6324 that we pass in the raw text_low here; that is ok because we're
6325 only decoding the line table to make include partial symtabs, and
6326 so the addresses aren't really used. */
6327 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6328 pst
->raw_text_low (), 1);
6332 hash_signatured_type (const void *item
)
6334 const struct signatured_type
*sig_type
6335 = (const struct signatured_type
*) item
;
6337 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6338 return sig_type
->signature
;
6342 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6344 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6345 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6347 return lhs
->signature
== rhs
->signature
;
6350 /* Allocate a hash table for signatured types. */
6353 allocate_signatured_type_table ()
6355 return htab_up (htab_create_alloc (41,
6356 hash_signatured_type
,
6358 NULL
, xcalloc
, xfree
));
6361 /* A helper function to add a signatured type CU to a table. */
6364 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6366 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6367 std::vector
<signatured_type
*> *all_type_units
6368 = (std::vector
<signatured_type
*> *) datum
;
6370 all_type_units
->push_back (sigt
);
6375 /* A helper for create_debug_types_hash_table. Read types from SECTION
6376 and fill them into TYPES_HTAB. It will process only type units,
6377 therefore DW_UT_type. */
6380 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6381 struct dwo_file
*dwo_file
,
6382 dwarf2_section_info
*section
, htab_up
&types_htab
,
6383 rcuh_kind section_kind
)
6385 struct objfile
*objfile
= per_objfile
->objfile
;
6386 struct dwarf2_section_info
*abbrev_section
;
6388 const gdb_byte
*info_ptr
, *end_ptr
;
6390 abbrev_section
= (dwo_file
!= NULL
6391 ? &dwo_file
->sections
.abbrev
6392 : &per_objfile
->per_bfd
->abbrev
);
6394 dwarf_read_debug_printf ("Reading %s for %s",
6395 section
->get_name (),
6396 abbrev_section
->get_file_name ());
6398 section
->read (objfile
);
6399 info_ptr
= section
->buffer
;
6401 if (info_ptr
== NULL
)
6404 /* We can't set abfd until now because the section may be empty or
6405 not present, in which case the bfd is unknown. */
6406 abfd
= section
->get_bfd_owner ();
6408 /* We don't use cutu_reader here because we don't need to read
6409 any dies: the signature is in the header. */
6411 end_ptr
= info_ptr
+ section
->size
;
6412 while (info_ptr
< end_ptr
)
6414 struct signatured_type
*sig_type
;
6415 struct dwo_unit
*dwo_tu
;
6417 const gdb_byte
*ptr
= info_ptr
;
6418 struct comp_unit_head header
;
6419 unsigned int length
;
6421 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6423 /* Initialize it due to a false compiler warning. */
6424 header
.signature
= -1;
6425 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6427 /* We need to read the type's signature in order to build the hash
6428 table, but we don't need anything else just yet. */
6430 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6431 abbrev_section
, ptr
, section_kind
);
6433 length
= header
.get_length ();
6435 /* Skip dummy type units. */
6436 if (ptr
>= info_ptr
+ length
6437 || peek_abbrev_code (abfd
, ptr
) == 0
6438 || (header
.unit_type
!= DW_UT_type
6439 && header
.unit_type
!= DW_UT_split_type
))
6445 if (types_htab
== NULL
)
6448 types_htab
= allocate_dwo_unit_table ();
6450 types_htab
= allocate_signatured_type_table ();
6456 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6457 dwo_tu
->dwo_file
= dwo_file
;
6458 dwo_tu
->signature
= header
.signature
;
6459 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6460 dwo_tu
->section
= section
;
6461 dwo_tu
->sect_off
= sect_off
;
6462 dwo_tu
->length
= length
;
6466 /* N.B.: type_offset is not usable if this type uses a DWO file.
6467 The real type_offset is in the DWO file. */
6469 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6470 sig_type
->signature
= header
.signature
;
6471 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6472 sig_type
->per_cu
.is_debug_types
= 1;
6473 sig_type
->per_cu
.section
= section
;
6474 sig_type
->per_cu
.sect_off
= sect_off
;
6475 sig_type
->per_cu
.length
= length
;
6478 slot
= htab_find_slot (types_htab
.get (),
6479 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6481 gdb_assert (slot
!= NULL
);
6484 sect_offset dup_sect_off
;
6488 const struct dwo_unit
*dup_tu
6489 = (const struct dwo_unit
*) *slot
;
6491 dup_sect_off
= dup_tu
->sect_off
;
6495 const struct signatured_type
*dup_tu
6496 = (const struct signatured_type
*) *slot
;
6498 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6501 complaint (_("debug type entry at offset %s is duplicate to"
6502 " the entry at offset %s, signature %s"),
6503 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6504 hex_string (header
.signature
));
6506 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6508 dwarf_read_debug_printf_v (" offset %s, signature %s",
6509 sect_offset_str (sect_off
),
6510 hex_string (header
.signature
));
6516 /* Create the hash table of all entries in the .debug_types
6517 (or .debug_types.dwo) section(s).
6518 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6519 otherwise it is NULL.
6521 The result is a pointer to the hash table or NULL if there are no types.
6523 Note: This function processes DWO files only, not DWP files. */
6526 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6527 struct dwo_file
*dwo_file
,
6528 gdb::array_view
<dwarf2_section_info
> type_sections
,
6529 htab_up
&types_htab
)
6531 for (dwarf2_section_info
§ion
: type_sections
)
6532 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6536 /* Create the hash table of all entries in the .debug_types section,
6537 and initialize all_type_units.
6538 The result is zero if there is an error (e.g. missing .debug_types section),
6539 otherwise non-zero. */
6542 create_all_type_units (dwarf2_per_objfile
*per_objfile
)
6546 create_debug_type_hash_table (per_objfile
, NULL
, &per_objfile
->per_bfd
->info
,
6547 types_htab
, rcuh_kind::COMPILE
);
6548 create_debug_types_hash_table (per_objfile
, NULL
, per_objfile
->per_bfd
->types
,
6550 if (types_htab
== NULL
)
6552 per_objfile
->per_bfd
->signatured_types
= NULL
;
6556 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6558 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
6559 per_objfile
->per_bfd
->all_type_units
.reserve
6560 (htab_elements (per_objfile
->per_bfd
->signatured_types
.get ()));
6562 htab_traverse_noresize (per_objfile
->per_bfd
->signatured_types
.get (),
6563 add_signatured_type_cu_to_table
,
6564 &per_objfile
->per_bfd
->all_type_units
);
6569 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6570 If SLOT is non-NULL, it is the entry to use in the hash table.
6571 Otherwise we find one. */
6573 static struct signatured_type
*
6574 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6576 if (per_objfile
->per_bfd
->all_type_units
.size ()
6577 == per_objfile
->per_bfd
->all_type_units
.capacity ())
6578 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6580 signatured_type
*sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6582 per_objfile
->resize_symtabs ();
6584 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6585 sig_type
->signature
= sig
;
6586 sig_type
->per_cu
.is_debug_types
= 1;
6587 if (per_objfile
->per_bfd
->using_index
)
6589 sig_type
->per_cu
.v
.quick
=
6590 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6591 struct dwarf2_per_cu_quick_data
);
6596 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6599 gdb_assert (*slot
== NULL
);
6601 /* The rest of sig_type must be filled in by the caller. */
6605 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6606 Fill in SIG_ENTRY with DWO_ENTRY. */
6609 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6610 struct signatured_type
*sig_entry
,
6611 struct dwo_unit
*dwo_entry
)
6613 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6615 /* Make sure we're not clobbering something we don't expect to. */
6616 gdb_assert (! sig_entry
->per_cu
.queued
);
6617 gdb_assert (per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6618 if (per_bfd
->using_index
)
6620 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6621 gdb_assert (!per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6624 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6625 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6626 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6627 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6628 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6630 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6631 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6632 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6633 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6634 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6635 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6636 sig_entry
->dwo_unit
= dwo_entry
;
6639 /* Subroutine of lookup_signatured_type.
6640 If we haven't read the TU yet, create the signatured_type data structure
6641 for a TU to be read in directly from a DWO file, bypassing the stub.
6642 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6643 using .gdb_index, then when reading a CU we want to stay in the DWO file
6644 containing that CU. Otherwise we could end up reading several other DWO
6645 files (due to comdat folding) to process the transitive closure of all the
6646 mentioned TUs, and that can be slow. The current DWO file will have every
6647 type signature that it needs.
6648 We only do this for .gdb_index because in the psymtab case we already have
6649 to read all the DWOs to build the type unit groups. */
6651 static struct signatured_type
*
6652 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6654 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6655 struct dwo_file
*dwo_file
;
6656 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6657 struct signatured_type find_sig_entry
, *sig_entry
;
6660 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6662 /* If TU skeletons have been removed then we may not have read in any
6664 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6665 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6667 /* We only ever need to read in one copy of a signatured type.
6668 Use the global signatured_types array to do our own comdat-folding
6669 of types. If this is the first time we're reading this TU, and
6670 the TU has an entry in .gdb_index, replace the recorded data from
6671 .gdb_index with this TU. */
6673 find_sig_entry
.signature
= sig
;
6674 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6675 &find_sig_entry
, INSERT
);
6676 sig_entry
= (struct signatured_type
*) *slot
;
6678 /* We can get here with the TU already read, *or* in the process of being
6679 read. Don't reassign the global entry to point to this DWO if that's
6680 the case. Also note that if the TU is already being read, it may not
6681 have come from a DWO, the program may be a mix of Fission-compiled
6682 code and non-Fission-compiled code. */
6684 /* Have we already tried to read this TU?
6685 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6686 needn't exist in the global table yet). */
6687 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6690 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6691 dwo_unit of the TU itself. */
6692 dwo_file
= cu
->dwo_unit
->dwo_file
;
6694 /* Ok, this is the first time we're reading this TU. */
6695 if (dwo_file
->tus
== NULL
)
6697 find_dwo_entry
.signature
= sig
;
6698 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6700 if (dwo_entry
== NULL
)
6703 /* If the global table doesn't have an entry for this TU, add one. */
6704 if (sig_entry
== NULL
)
6705 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6707 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6708 sig_entry
->per_cu
.tu_read
= 1;
6712 /* Subroutine of lookup_signatured_type.
6713 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6714 then try the DWP file. If the TU stub (skeleton) has been removed then
6715 it won't be in .gdb_index. */
6717 static struct signatured_type
*
6718 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6720 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6721 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6722 struct dwo_unit
*dwo_entry
;
6723 struct signatured_type find_sig_entry
, *sig_entry
;
6726 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6727 gdb_assert (dwp_file
!= NULL
);
6729 /* If TU skeletons have been removed then we may not have read in any
6731 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6732 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6734 find_sig_entry
.signature
= sig
;
6735 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6736 &find_sig_entry
, INSERT
);
6737 sig_entry
= (struct signatured_type
*) *slot
;
6739 /* Have we already tried to read this TU?
6740 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6741 needn't exist in the global table yet). */
6742 if (sig_entry
!= NULL
)
6745 if (dwp_file
->tus
== NULL
)
6747 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6748 1 /* is_debug_types */);
6749 if (dwo_entry
== NULL
)
6752 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6753 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6758 /* Lookup a signature based type for DW_FORM_ref_sig8.
6759 Returns NULL if signature SIG is not present in the table.
6760 It is up to the caller to complain about this. */
6762 static struct signatured_type
*
6763 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6765 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6767 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6769 /* We're in a DWO/DWP file, and we're using .gdb_index.
6770 These cases require special processing. */
6771 if (get_dwp_file (per_objfile
) == NULL
)
6772 return lookup_dwo_signatured_type (cu
, sig
);
6774 return lookup_dwp_signatured_type (cu
, sig
);
6778 struct signatured_type find_entry
, *entry
;
6780 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6782 find_entry
.signature
= sig
;
6783 entry
= ((struct signatured_type
*)
6784 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6790 /* Low level DIE reading support. */
6792 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6795 init_cu_die_reader (struct die_reader_specs
*reader
,
6796 struct dwarf2_cu
*cu
,
6797 struct dwarf2_section_info
*section
,
6798 struct dwo_file
*dwo_file
,
6799 struct abbrev_table
*abbrev_table
)
6801 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6802 reader
->abfd
= section
->get_bfd_owner ();
6804 reader
->dwo_file
= dwo_file
;
6805 reader
->die_section
= section
;
6806 reader
->buffer
= section
->buffer
;
6807 reader
->buffer_end
= section
->buffer
+ section
->size
;
6808 reader
->abbrev_table
= abbrev_table
;
6811 /* Subroutine of cutu_reader to simplify it.
6812 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6813 There's just a lot of work to do, and cutu_reader is big enough
6816 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6817 from it to the DIE in the DWO. If NULL we are skipping the stub.
6818 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6819 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6820 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6821 STUB_COMP_DIR may be non-NULL.
6822 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6823 are filled in with the info of the DIE from the DWO file.
6824 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6825 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6826 kept around for at least as long as *RESULT_READER.
6828 The result is non-zero if a valid (non-dummy) DIE was found. */
6831 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6832 struct dwo_unit
*dwo_unit
,
6833 struct die_info
*stub_comp_unit_die
,
6834 const char *stub_comp_dir
,
6835 struct die_reader_specs
*result_reader
,
6836 const gdb_byte
**result_info_ptr
,
6837 struct die_info
**result_comp_unit_die
,
6838 abbrev_table_up
*result_dwo_abbrev_table
)
6840 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6841 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6842 struct objfile
*objfile
= per_objfile
->objfile
;
6844 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6845 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6846 int i
,num_extra_attrs
;
6847 struct dwarf2_section_info
*dwo_abbrev_section
;
6848 struct die_info
*comp_unit_die
;
6850 /* At most one of these may be provided. */
6851 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6853 /* These attributes aren't processed until later:
6854 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6855 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6856 referenced later. However, these attributes are found in the stub
6857 which we won't have later. In order to not impose this complication
6858 on the rest of the code, we read them here and copy them to the
6867 if (stub_comp_unit_die
!= NULL
)
6869 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6871 if (!per_cu
->is_debug_types
)
6872 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6873 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6874 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6875 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6876 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6878 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6880 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6881 We need the value before we can process DW_AT_ranges values from the
6883 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
6885 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
6886 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
6887 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
6888 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
6890 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
6892 else if (stub_comp_dir
!= NULL
)
6894 /* Reconstruct the comp_dir attribute to simplify the code below. */
6895 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
6896 comp_dir
->name
= DW_AT_comp_dir
;
6897 comp_dir
->form
= DW_FORM_string
;
6898 comp_dir
->set_string_noncanonical (stub_comp_dir
);
6901 /* Set up for reading the DWO CU/TU. */
6902 cu
->dwo_unit
= dwo_unit
;
6903 dwarf2_section_info
*section
= dwo_unit
->section
;
6904 section
->read (objfile
);
6905 abfd
= section
->get_bfd_owner ();
6906 begin_info_ptr
= info_ptr
= (section
->buffer
6907 + to_underlying (dwo_unit
->sect_off
));
6908 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6910 if (per_cu
->is_debug_types
)
6912 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
6914 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6915 section
, dwo_abbrev_section
,
6916 info_ptr
, rcuh_kind::TYPE
);
6917 /* This is not an assert because it can be caused by bad debug info. */
6918 if (sig_type
->signature
!= cu
->header
.signature
)
6920 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6921 " TU at offset %s [in module %s]"),
6922 hex_string (sig_type
->signature
),
6923 hex_string (cu
->header
.signature
),
6924 sect_offset_str (dwo_unit
->sect_off
),
6925 bfd_get_filename (abfd
));
6927 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6928 /* For DWOs coming from DWP files, we don't know the CU length
6929 nor the type's offset in the TU until now. */
6930 dwo_unit
->length
= cu
->header
.get_length ();
6931 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6933 /* Establish the type offset that can be used to lookup the type.
6934 For DWO files, we don't know it until now. */
6935 sig_type
->type_offset_in_section
6936 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6940 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
6941 section
, dwo_abbrev_section
,
6942 info_ptr
, rcuh_kind::COMPILE
);
6943 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6944 /* For DWOs coming from DWP files, we don't know the CU length
6946 dwo_unit
->length
= cu
->header
.get_length ();
6949 dwo_abbrev_section
->read (objfile
);
6950 *result_dwo_abbrev_table
6951 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
6952 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6953 result_dwo_abbrev_table
->get ());
6955 /* Read in the die, but leave space to copy over the attributes
6956 from the stub. This has the benefit of simplifying the rest of
6957 the code - all the work to maintain the illusion of a single
6958 DW_TAG_{compile,type}_unit DIE is done here. */
6959 num_extra_attrs
= ((stmt_list
!= NULL
)
6963 + (comp_dir
!= NULL
));
6964 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6967 /* Copy over the attributes from the stub to the DIE we just read in. */
6968 comp_unit_die
= *result_comp_unit_die
;
6969 i
= comp_unit_die
->num_attrs
;
6970 if (stmt_list
!= NULL
)
6971 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6973 comp_unit_die
->attrs
[i
++] = *low_pc
;
6974 if (high_pc
!= NULL
)
6975 comp_unit_die
->attrs
[i
++] = *high_pc
;
6977 comp_unit_die
->attrs
[i
++] = *ranges
;
6978 if (comp_dir
!= NULL
)
6979 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6980 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6982 if (dwarf_die_debug
)
6984 fprintf_unfiltered (gdb_stdlog
,
6985 "Read die from %s@0x%x of %s:\n",
6986 section
->get_name (),
6987 (unsigned) (begin_info_ptr
- section
->buffer
),
6988 bfd_get_filename (abfd
));
6989 dump_die (comp_unit_die
, dwarf_die_debug
);
6992 /* Skip dummy compilation units. */
6993 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6994 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6997 *result_info_ptr
= info_ptr
;
7001 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7002 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7003 signature is part of the header. */
7004 static gdb::optional
<ULONGEST
>
7005 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7007 if (cu
->header
.version
>= 5)
7008 return cu
->header
.signature
;
7009 struct attribute
*attr
;
7010 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7011 if (attr
== nullptr || !attr
->form_is_unsigned ())
7012 return gdb::optional
<ULONGEST
> ();
7013 return attr
->as_unsigned ();
7016 /* Subroutine of cutu_reader to simplify it.
7017 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7018 Returns NULL if the specified DWO unit cannot be found. */
7020 static struct dwo_unit
*
7021 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
7023 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7024 struct dwo_unit
*dwo_unit
;
7025 const char *comp_dir
;
7027 gdb_assert (cu
!= NULL
);
7029 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7030 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7031 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7033 if (per_cu
->is_debug_types
)
7034 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
7037 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7039 if (!signature
.has_value ())
7040 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7042 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
7044 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
7050 /* Subroutine of cutu_reader to simplify it.
7051 See it for a description of the parameters.
7052 Read a TU directly from a DWO file, bypassing the stub. */
7055 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
7056 dwarf2_per_objfile
*per_objfile
,
7057 dwarf2_cu
*existing_cu
)
7059 struct signatured_type
*sig_type
;
7061 /* Verify we can do the following downcast, and that we have the
7063 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7064 sig_type
= (struct signatured_type
*) this_cu
;
7065 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7069 if (existing_cu
!= nullptr)
7072 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
7073 /* There's no need to do the rereading_dwo_cu handling that
7074 cutu_reader does since we don't read the stub. */
7078 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7079 in per_objfile yet. */
7080 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7081 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7082 cu
= m_new_cu
.get ();
7085 /* A future optimization, if needed, would be to use an existing
7086 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7087 could share abbrev tables. */
7089 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
7090 NULL
/* stub_comp_unit_die */,
7091 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7094 &m_dwo_abbrev_table
) == 0)
7101 /* Initialize a CU (or TU) and read its DIEs.
7102 If the CU defers to a DWO file, read the DWO file as well.
7104 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7105 Otherwise the table specified in the comp unit header is read in and used.
7106 This is an optimization for when we already have the abbrev table.
7108 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7111 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7112 dwarf2_per_objfile
*per_objfile
,
7113 struct abbrev_table
*abbrev_table
,
7114 dwarf2_cu
*existing_cu
,
7116 : die_reader_specs
{},
7119 struct objfile
*objfile
= per_objfile
->objfile
;
7120 struct dwarf2_section_info
*section
= this_cu
->section
;
7121 bfd
*abfd
= section
->get_bfd_owner ();
7122 const gdb_byte
*begin_info_ptr
;
7123 struct signatured_type
*sig_type
= NULL
;
7124 struct dwarf2_section_info
*abbrev_section
;
7125 /* Non-zero if CU currently points to a DWO file and we need to
7126 reread it. When this happens we need to reread the skeleton die
7127 before we can reread the DWO file (this only applies to CUs, not TUs). */
7128 int rereading_dwo_cu
= 0;
7130 if (dwarf_die_debug
)
7131 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7132 this_cu
->is_debug_types
? "type" : "comp",
7133 sect_offset_str (this_cu
->sect_off
));
7135 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7136 file (instead of going through the stub), short-circuit all of this. */
7137 if (this_cu
->reading_dwo_directly
)
7139 /* Narrow down the scope of possibilities to have to understand. */
7140 gdb_assert (this_cu
->is_debug_types
);
7141 gdb_assert (abbrev_table
== NULL
);
7142 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
7146 /* This is cheap if the section is already read in. */
7147 section
->read (objfile
);
7149 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7151 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7155 if (existing_cu
!= nullptr)
7158 /* If this CU is from a DWO file we need to start over, we need to
7159 refetch the attributes from the skeleton CU.
7160 This could be optimized by retrieving those attributes from when we
7161 were here the first time: the previous comp_unit_die was stored in
7162 comp_unit_obstack. But there's no data yet that we need this
7164 if (cu
->dwo_unit
!= NULL
)
7165 rereading_dwo_cu
= 1;
7169 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7170 in per_objfile yet. */
7171 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7172 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7173 cu
= m_new_cu
.get ();
7176 /* Get the header. */
7177 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7179 /* We already have the header, there's no need to read it in again. */
7180 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7184 if (this_cu
->is_debug_types
)
7186 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7187 section
, abbrev_section
,
7188 info_ptr
, rcuh_kind::TYPE
);
7190 /* Since per_cu is the first member of struct signatured_type,
7191 we can go from a pointer to one to a pointer to the other. */
7192 sig_type
= (struct signatured_type
*) this_cu
;
7193 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7194 gdb_assert (sig_type
->type_offset_in_tu
7195 == cu
->header
.type_cu_offset_in_tu
);
7196 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7198 /* LENGTH has not been set yet for type units if we're
7199 using .gdb_index. */
7200 this_cu
->length
= cu
->header
.get_length ();
7202 /* Establish the type offset that can be used to lookup the type. */
7203 sig_type
->type_offset_in_section
=
7204 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7206 this_cu
->dwarf_version
= cu
->header
.version
;
7210 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7211 section
, abbrev_section
,
7213 rcuh_kind::COMPILE
);
7215 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7216 if (this_cu
->length
== 0)
7217 this_cu
->length
= cu
->header
.get_length ();
7219 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7220 this_cu
->dwarf_version
= cu
->header
.version
;
7224 /* Skip dummy compilation units. */
7225 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7226 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7232 /* If we don't have them yet, read the abbrevs for this compilation unit.
7233 And if we need to read them now, make sure they're freed when we're
7235 if (abbrev_table
!= NULL
)
7236 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7239 abbrev_section
->read (objfile
);
7240 m_abbrev_table_holder
7241 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
7242 abbrev_table
= m_abbrev_table_holder
.get ();
7245 /* Read the top level CU/TU die. */
7246 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7247 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7249 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7255 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7256 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7257 table from the DWO file and pass the ownership over to us. It will be
7258 referenced from READER, so we must make sure to free it after we're done
7261 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7262 DWO CU, that this test will fail (the attribute will not be present). */
7263 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7264 if (dwo_name
!= nullptr)
7266 struct dwo_unit
*dwo_unit
;
7267 struct die_info
*dwo_comp_unit_die
;
7269 if (comp_unit_die
->has_children
)
7271 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7272 " has children (offset %s) [in module %s]"),
7273 sect_offset_str (this_cu
->sect_off
),
7274 bfd_get_filename (abfd
));
7276 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7277 if (dwo_unit
!= NULL
)
7279 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7280 comp_unit_die
, NULL
,
7283 &m_dwo_abbrev_table
) == 0)
7289 comp_unit_die
= dwo_comp_unit_die
;
7293 /* Yikes, we couldn't find the rest of the DIE, we only have
7294 the stub. A complaint has already been logged. There's
7295 not much more we can do except pass on the stub DIE to
7296 die_reader_func. We don't want to throw an error on bad
7303 cutu_reader::keep ()
7305 /* Done, clean up. */
7306 gdb_assert (!dummy_p
);
7307 if (m_new_cu
!= NULL
)
7309 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7311 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7312 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7316 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7317 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7318 assumed to have already done the lookup to find the DWO file).
7320 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7321 THIS_CU->is_debug_types, but nothing else.
7323 We fill in THIS_CU->length.
7325 THIS_CU->cu is always freed when done.
7326 This is done in order to not leave THIS_CU->cu in a state where we have
7327 to care whether it refers to the "main" CU or the DWO CU.
7329 When parent_cu is passed, it is used to provide a default value for
7330 str_offsets_base and addr_base from the parent. */
7332 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7333 dwarf2_per_objfile
*per_objfile
,
7334 struct dwarf2_cu
*parent_cu
,
7335 struct dwo_file
*dwo_file
)
7336 : die_reader_specs
{},
7339 struct objfile
*objfile
= per_objfile
->objfile
;
7340 struct dwarf2_section_info
*section
= this_cu
->section
;
7341 bfd
*abfd
= section
->get_bfd_owner ();
7342 struct dwarf2_section_info
*abbrev_section
;
7343 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7345 if (dwarf_die_debug
)
7346 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7347 this_cu
->is_debug_types
? "type" : "comp",
7348 sect_offset_str (this_cu
->sect_off
));
7350 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7352 abbrev_section
= (dwo_file
!= NULL
7353 ? &dwo_file
->sections
.abbrev
7354 : get_abbrev_section_for_cu (this_cu
));
7356 /* This is cheap if the section is already read in. */
7357 section
->read (objfile
);
7359 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7361 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7362 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
7363 section
, abbrev_section
, info_ptr
,
7364 (this_cu
->is_debug_types
7366 : rcuh_kind::COMPILE
));
7368 if (parent_cu
!= nullptr)
7370 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7371 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7373 this_cu
->length
= m_new_cu
->header
.get_length ();
7375 /* Skip dummy compilation units. */
7376 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7377 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7383 abbrev_section
->read (objfile
);
7384 m_abbrev_table_holder
7385 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
7387 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7388 m_abbrev_table_holder
.get ());
7389 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7393 /* Type Unit Groups.
7395 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7396 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7397 so that all types coming from the same compilation (.o file) are grouped
7398 together. A future step could be to put the types in the same symtab as
7399 the CU the types ultimately came from. */
7402 hash_type_unit_group (const void *item
)
7404 const struct type_unit_group
*tu_group
7405 = (const struct type_unit_group
*) item
;
7407 return hash_stmt_list_entry (&tu_group
->hash
);
7411 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7413 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7414 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7416 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7419 /* Allocate a hash table for type unit groups. */
7422 allocate_type_unit_groups_table ()
7424 return htab_up (htab_create_alloc (3,
7425 hash_type_unit_group
,
7427 NULL
, xcalloc
, xfree
));
7430 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7431 partial symtabs. We combine several TUs per psymtab to not let the size
7432 of any one psymtab grow too big. */
7433 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7434 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7436 /* Helper routine for get_type_unit_group.
7437 Create the type_unit_group object used to hold one or more TUs. */
7439 static struct type_unit_group
*
7440 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7442 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7443 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7444 struct dwarf2_per_cu_data
*per_cu
;
7445 struct type_unit_group
*tu_group
;
7447 tu_group
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, type_unit_group
);
7448 per_cu
= &tu_group
->per_cu
;
7449 per_cu
->per_bfd
= per_bfd
;
7451 if (per_bfd
->using_index
)
7453 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7454 struct dwarf2_per_cu_quick_data
);
7458 unsigned int line_offset
= to_underlying (line_offset_struct
);
7459 dwarf2_psymtab
*pst
;
7462 /* Give the symtab a useful name for debug purposes. */
7463 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7464 name
= string_printf ("<type_units_%d>",
7465 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7467 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7469 pst
= create_partial_symtab (per_cu
, per_objfile
, name
.c_str ());
7470 pst
->anonymous
= true;
7473 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7474 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7479 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7480 STMT_LIST is a DW_AT_stmt_list attribute. */
7482 static struct type_unit_group
*
7483 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7485 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7486 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7487 struct type_unit_group
*tu_group
;
7489 unsigned int line_offset
;
7490 struct type_unit_group type_unit_group_for_lookup
;
7492 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7493 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7495 /* Do we need to create a new group, or can we use an existing one? */
7497 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
7499 line_offset
= stmt_list
->as_unsigned ();
7500 ++tu_stats
->nr_symtab_sharers
;
7504 /* Ugh, no stmt_list. Rare, but we have to handle it.
7505 We can do various things here like create one group per TU or
7506 spread them over multiple groups to split up the expansion work.
7507 To avoid worst case scenarios (too many groups or too large groups)
7508 we, umm, group them in bunches. */
7509 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7510 | (tu_stats
->nr_stmt_less_type_units
7511 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7512 ++tu_stats
->nr_stmt_less_type_units
;
7515 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7516 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7517 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7518 &type_unit_group_for_lookup
, INSERT
);
7521 tu_group
= (struct type_unit_group
*) *slot
;
7522 gdb_assert (tu_group
!= NULL
);
7526 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7527 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7529 ++tu_stats
->nr_symtabs
;
7535 /* Partial symbol tables. */
7537 /* Create a psymtab named NAME and assign it to PER_CU.
7539 The caller must fill in the following details:
7540 dirname, textlow, texthigh. */
7542 static dwarf2_psymtab
*
7543 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7544 dwarf2_per_objfile
*per_objfile
,
7547 struct objfile
*objfile
= per_objfile
->objfile
;
7548 dwarf2_psymtab
*pst
;
7550 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7552 pst
->psymtabs_addrmap_supported
= true;
7554 /* This is the glue that links PST into GDB's symbol API. */
7555 per_cu
->v
.psymtab
= pst
;
7560 /* DIE reader function for process_psymtab_comp_unit. */
7563 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7564 const gdb_byte
*info_ptr
,
7565 struct die_info
*comp_unit_die
,
7566 enum language pretend_language
)
7568 struct dwarf2_cu
*cu
= reader
->cu
;
7569 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7570 struct objfile
*objfile
= per_objfile
->objfile
;
7571 struct gdbarch
*gdbarch
= objfile
->arch ();
7572 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7574 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7575 dwarf2_psymtab
*pst
;
7576 enum pc_bounds_kind cu_bounds_kind
;
7577 const char *filename
;
7579 gdb_assert (! per_cu
->is_debug_types
);
7581 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7583 /* Allocate a new partial symbol table structure. */
7584 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7585 static const char artificial
[] = "<artificial>";
7586 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7587 if (filename
== NULL
)
7589 else if (strcmp (filename
, artificial
) == 0)
7591 debug_filename
.reset (concat (artificial
, "@",
7592 sect_offset_str (per_cu
->sect_off
),
7594 filename
= debug_filename
.get ();
7597 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7599 /* This must be done before calling dwarf2_build_include_psymtabs. */
7600 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7602 baseaddr
= objfile
->text_section_offset ();
7604 dwarf2_find_base_address (comp_unit_die
, cu
);
7606 /* Possibly set the default values of LOWPC and HIGHPC from
7608 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7609 &best_highpc
, cu
, pst
);
7610 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7613 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7616 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7618 /* Store the contiguous range if it is not empty; it can be
7619 empty for CUs with no code. */
7620 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7624 /* Check if comp unit has_children.
7625 If so, read the rest of the partial symbols from this comp unit.
7626 If not, there's no more debug_info for this comp unit. */
7627 if (comp_unit_die
->has_children
)
7629 struct partial_die_info
*first_die
;
7630 CORE_ADDR lowpc
, highpc
;
7632 lowpc
= ((CORE_ADDR
) -1);
7633 highpc
= ((CORE_ADDR
) 0);
7635 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7637 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7638 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7640 /* If we didn't find a lowpc, set it to highpc to avoid
7641 complaints from `maint check'. */
7642 if (lowpc
== ((CORE_ADDR
) -1))
7645 /* If the compilation unit didn't have an explicit address range,
7646 then use the information extracted from its child dies. */
7647 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7650 best_highpc
= highpc
;
7653 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7654 best_lowpc
+ baseaddr
)
7656 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7657 best_highpc
+ baseaddr
)
7662 if (!cu
->per_cu
->imported_symtabs_empty ())
7665 int len
= cu
->per_cu
->imported_symtabs_size ();
7667 /* Fill in 'dependencies' here; we fill in 'users' in a
7669 pst
->number_of_dependencies
= len
;
7671 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7672 for (i
= 0; i
< len
; ++i
)
7674 pst
->dependencies
[i
]
7675 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7678 cu
->per_cu
->imported_symtabs_free ();
7681 /* Get the list of files included in the current compilation unit,
7682 and build a psymtab for each of them. */
7683 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7685 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7686 ", %d global, %d static syms",
7687 per_cu
->is_debug_types
? "type" : "comp",
7688 sect_offset_str (per_cu
->sect_off
),
7689 paddress (gdbarch
, pst
->text_low (objfile
)),
7690 paddress (gdbarch
, pst
->text_high (objfile
)),
7691 (int) pst
->global_psymbols
.size (),
7692 (int) pst
->static_psymbols
.size ());
7695 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7696 Process compilation unit THIS_CU for a psymtab. */
7699 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7700 dwarf2_per_objfile
*per_objfile
,
7701 bool want_partial_unit
,
7702 enum language pretend_language
)
7704 /* If this compilation unit was already read in, free the
7705 cached copy in order to read it in again. This is
7706 necessary because we skipped some symbols when we first
7707 read in the compilation unit (see load_partial_dies).
7708 This problem could be avoided, but the benefit is unclear. */
7709 per_objfile
->remove_cu (this_cu
);
7711 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7713 switch (reader
.comp_unit_die
->tag
)
7715 case DW_TAG_compile_unit
:
7716 this_cu
->unit_type
= DW_UT_compile
;
7718 case DW_TAG_partial_unit
:
7719 this_cu
->unit_type
= DW_UT_partial
;
7721 case DW_TAG_type_unit
:
7722 this_cu
->unit_type
= DW_UT_type
;
7732 else if (this_cu
->is_debug_types
)
7733 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7734 reader
.comp_unit_die
);
7735 else if (want_partial_unit
7736 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7737 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7738 reader
.comp_unit_die
,
7741 this_cu
->lang
= reader
.cu
->language
;
7743 /* Age out any secondary CUs. */
7744 per_objfile
->age_comp_units ();
7747 /* Reader function for build_type_psymtabs. */
7750 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7751 const gdb_byte
*info_ptr
,
7752 struct die_info
*type_unit_die
)
7754 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7755 struct dwarf2_cu
*cu
= reader
->cu
;
7756 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7757 struct signatured_type
*sig_type
;
7758 struct type_unit_group
*tu_group
;
7759 struct attribute
*attr
;
7760 struct partial_die_info
*first_die
;
7761 CORE_ADDR lowpc
, highpc
;
7762 dwarf2_psymtab
*pst
;
7764 gdb_assert (per_cu
->is_debug_types
);
7765 sig_type
= (struct signatured_type
*) per_cu
;
7767 if (! type_unit_die
->has_children
)
7770 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7771 tu_group
= get_type_unit_group (cu
, attr
);
7773 if (tu_group
->tus
== nullptr)
7774 tu_group
->tus
= new std::vector
<signatured_type
*>;
7775 tu_group
->tus
->push_back (sig_type
);
7777 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7778 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7779 pst
->anonymous
= true;
7781 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7783 lowpc
= (CORE_ADDR
) -1;
7784 highpc
= (CORE_ADDR
) 0;
7785 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7790 /* Struct used to sort TUs by their abbreviation table offset. */
7792 struct tu_abbrev_offset
7794 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7795 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7798 signatured_type
*sig_type
;
7799 sect_offset abbrev_offset
;
7802 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7805 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7806 const struct tu_abbrev_offset
&b
)
7808 return a
.abbrev_offset
< b
.abbrev_offset
;
7811 /* Efficiently read all the type units.
7812 This does the bulk of the work for build_type_psymtabs.
7814 The efficiency is because we sort TUs by the abbrev table they use and
7815 only read each abbrev table once. In one program there are 200K TUs
7816 sharing 8K abbrev tables.
7818 The main purpose of this function is to support building the
7819 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7820 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7821 can collapse the search space by grouping them by stmt_list.
7822 The savings can be significant, in the same program from above the 200K TUs
7823 share 8K stmt_list tables.
7825 FUNC is expected to call get_type_unit_group, which will create the
7826 struct type_unit_group if necessary and add it to
7827 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7830 build_type_psymtabs_1 (dwarf2_per_objfile
*per_objfile
)
7832 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7833 abbrev_table_up abbrev_table
;
7834 sect_offset abbrev_offset
;
7836 /* It's up to the caller to not call us multiple times. */
7837 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7839 if (per_objfile
->per_bfd
->all_type_units
.empty ())
7842 /* TUs typically share abbrev tables, and there can be way more TUs than
7843 abbrev tables. Sort by abbrev table to reduce the number of times we
7844 read each abbrev table in.
7845 Alternatives are to punt or to maintain a cache of abbrev tables.
7846 This is simpler and efficient enough for now.
7848 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7849 symtab to use). Typically TUs with the same abbrev offset have the same
7850 stmt_list value too so in practice this should work well.
7852 The basic algorithm here is:
7854 sort TUs by abbrev table
7855 for each TU with same abbrev table:
7856 read abbrev table if first user
7857 read TU top level DIE
7858 [IWBN if DWO skeletons had DW_AT_stmt_list]
7861 dwarf_read_debug_printf ("Building type unit groups ...");
7863 /* Sort in a separate table to maintain the order of all_type_units
7864 for .gdb_index: TU indices directly index all_type_units. */
7865 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7866 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
7868 for (signatured_type
*sig_type
: per_objfile
->per_bfd
->all_type_units
)
7869 sorted_by_abbrev
.emplace_back
7870 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->per_cu
.section
,
7871 sig_type
->per_cu
.sect_off
));
7873 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7874 sort_tu_by_abbrev_offset
);
7876 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7878 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7880 /* Switch to the next abbrev table if necessary. */
7881 if (abbrev_table
== NULL
7882 || tu
.abbrev_offset
!= abbrev_offset
)
7884 abbrev_offset
= tu
.abbrev_offset
;
7885 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
7887 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
7888 ++tu_stats
->nr_uniq_abbrev_tables
;
7891 cutu_reader
reader (&tu
.sig_type
->per_cu
, per_objfile
,
7892 abbrev_table
.get (), nullptr, false);
7893 if (!reader
.dummy_p
)
7894 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7895 reader
.comp_unit_die
);
7899 /* Print collected type unit statistics. */
7902 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
7904 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7906 dwarf_read_debug_printf ("Type unit statistics:");
7907 dwarf_read_debug_printf (" %zu TUs",
7908 per_objfile
->per_bfd
->all_type_units
.size ());
7909 dwarf_read_debug_printf (" %d uniq abbrev tables",
7910 tu_stats
->nr_uniq_abbrev_tables
);
7911 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
7912 tu_stats
->nr_symtabs
);
7913 dwarf_read_debug_printf (" %d symtab sharers",
7914 tu_stats
->nr_symtab_sharers
);
7915 dwarf_read_debug_printf (" %d type units without a stmt_list",
7916 tu_stats
->nr_stmt_less_type_units
);
7917 dwarf_read_debug_printf (" %d all_type_units reallocs",
7918 tu_stats
->nr_all_type_units_reallocs
);
7921 /* Traversal function for build_type_psymtabs. */
7924 build_type_psymtab_dependencies (void **slot
, void *info
)
7926 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7927 struct objfile
*objfile
= per_objfile
->objfile
;
7928 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7929 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7930 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7931 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7934 gdb_assert (len
> 0);
7935 gdb_assert (per_cu
->type_unit_group_p ());
7937 pst
->number_of_dependencies
= len
;
7938 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7939 for (i
= 0; i
< len
; ++i
)
7941 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7942 gdb_assert (iter
->per_cu
.is_debug_types
);
7943 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7944 iter
->type_unit_group
= tu_group
;
7947 delete tu_group
->tus
;
7948 tu_group
->tus
= nullptr;
7953 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7954 Build partial symbol tables for the .debug_types comp-units. */
7957 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
7959 if (! create_all_type_units (per_objfile
))
7962 build_type_psymtabs_1 (per_objfile
);
7965 /* Traversal function for process_skeletonless_type_unit.
7966 Read a TU in a DWO file and build partial symbols for it. */
7969 process_skeletonless_type_unit (void **slot
, void *info
)
7971 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7972 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
7973 struct signatured_type find_entry
, *entry
;
7975 /* If this TU doesn't exist in the global table, add it and read it in. */
7977 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
7978 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
7980 find_entry
.signature
= dwo_unit
->signature
;
7981 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
7982 &find_entry
, INSERT
);
7983 /* If we've already seen this type there's nothing to do. What's happening
7984 is we're doing our own version of comdat-folding here. */
7988 /* This does the job that create_all_type_units would have done for
7990 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
7991 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
7994 /* This does the job that build_type_psymtabs_1 would have done. */
7995 cutu_reader
reader (&entry
->per_cu
, per_objfile
, nullptr, nullptr, false);
7996 if (!reader
.dummy_p
)
7997 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7998 reader
.comp_unit_die
);
8003 /* Traversal function for process_skeletonless_type_units. */
8006 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8008 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8010 if (dwo_file
->tus
!= NULL
)
8011 htab_traverse_noresize (dwo_file
->tus
.get (),
8012 process_skeletonless_type_unit
, info
);
8017 /* Scan all TUs of DWO files, verifying we've processed them.
8018 This is needed in case a TU was emitted without its skeleton.
8019 Note: This can't be done until we know what all the DWO files are. */
8022 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
8024 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8025 if (get_dwp_file (per_objfile
) == NULL
8026 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
8028 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
8029 process_dwo_file_for_skeletonless_type_units
,
8034 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8037 set_partial_user (dwarf2_per_objfile
*per_objfile
)
8039 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8041 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8046 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8048 /* Set the 'user' field only if it is not already set. */
8049 if (pst
->dependencies
[j
]->user
== NULL
)
8050 pst
->dependencies
[j
]->user
= pst
;
8055 /* Build the partial symbol table by doing a quick pass through the
8056 .debug_info and .debug_abbrev sections. */
8059 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
8061 struct objfile
*objfile
= per_objfile
->objfile
;
8063 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
8064 objfile_name (objfile
));
8066 scoped_restore restore_reading_psyms
8067 = make_scoped_restore (&per_objfile
->per_bfd
->reading_partial_symbols
,
8070 per_objfile
->per_bfd
->info
.read (objfile
);
8072 /* Any cached compilation units will be linked by the per-objfile
8073 read_in_chain. Make sure to free them when we're done. */
8074 free_cached_comp_units
freer (per_objfile
);
8076 build_type_psymtabs (per_objfile
);
8078 create_all_comp_units (per_objfile
);
8080 /* Create a temporary address map on a temporary obstack. We later
8081 copy this to the final obstack. */
8082 auto_obstack temp_obstack
;
8084 scoped_restore save_psymtabs_addrmap
8085 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8086 addrmap_create_mutable (&temp_obstack
));
8088 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8090 if (per_cu
->v
.psymtab
!= NULL
)
8091 /* In case a forward DW_TAG_imported_unit has read the CU already. */
8093 process_psymtab_comp_unit (per_cu
, per_objfile
, false,
8097 /* This has to wait until we read the CUs, we need the list of DWOs. */
8098 process_skeletonless_type_units (per_objfile
);
8100 /* Now that all TUs have been processed we can fill in the dependencies. */
8101 if (per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
8103 htab_traverse_noresize (per_objfile
->per_bfd
->type_unit_groups
.get (),
8104 build_type_psymtab_dependencies
, per_objfile
);
8107 if (dwarf_read_debug
> 0)
8108 print_tu_stats (per_objfile
);
8110 set_partial_user (per_objfile
);
8112 objfile
->partial_symtabs
->psymtabs_addrmap
8113 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8114 objfile
->partial_symtabs
->obstack ());
8115 /* At this point we want to keep the address map. */
8116 save_psymtabs_addrmap
.release ();
8118 dwarf_read_debug_printf ("Done building psymtabs of %s",
8119 objfile_name (objfile
));
8122 /* Load the partial DIEs for a secondary CU into memory.
8123 This is also used when rereading a primary CU with load_all_dies. */
8126 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8127 dwarf2_per_objfile
*per_objfile
,
8128 dwarf2_cu
*existing_cu
)
8130 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8132 if (!reader
.dummy_p
)
8134 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8137 /* Check if comp unit has_children.
8138 If so, read the rest of the partial symbols from this comp unit.
8139 If not, there's no more debug_info for this comp unit. */
8140 if (reader
.comp_unit_die
->has_children
)
8141 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8148 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
8149 struct dwarf2_section_info
*section
,
8150 struct dwarf2_section_info
*abbrev_section
,
8151 unsigned int is_dwz
)
8153 const gdb_byte
*info_ptr
;
8154 struct objfile
*objfile
= per_objfile
->objfile
;
8156 dwarf_read_debug_printf ("Reading %s for %s",
8157 section
->get_name (),
8158 section
->get_file_name ());
8160 section
->read (objfile
);
8162 info_ptr
= section
->buffer
;
8164 while (info_ptr
< section
->buffer
+ section
->size
)
8166 struct dwarf2_per_cu_data
*this_cu
;
8168 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8170 comp_unit_head cu_header
;
8171 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
8172 abbrev_section
, info_ptr
,
8173 rcuh_kind::COMPILE
);
8175 /* Save the compilation unit for later lookup. */
8176 if (cu_header
.unit_type
!= DW_UT_type
)
8177 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
8180 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
8181 sig_type
->signature
= cu_header
.signature
;
8182 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8183 this_cu
= &sig_type
->per_cu
;
8185 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8186 this_cu
->sect_off
= sect_off
;
8187 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8188 this_cu
->is_dwz
= is_dwz
;
8189 this_cu
->section
= section
;
8191 per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8193 info_ptr
= info_ptr
+ this_cu
->length
;
8197 /* Create a list of all compilation units in OBJFILE.
8198 This is only done for -readnow and building partial symtabs. */
8201 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
8203 gdb_assert (per_objfile
->per_bfd
->all_comp_units
.empty ());
8204 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
8205 &per_objfile
->per_bfd
->abbrev
, 0);
8207 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
8209 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1);
8212 /* Process all loaded DIEs for compilation unit CU, starting at
8213 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8214 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8215 DW_AT_ranges). See the comments of add_partial_subprogram on how
8216 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8219 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8220 CORE_ADDR
*highpc
, int set_addrmap
,
8221 struct dwarf2_cu
*cu
)
8223 struct partial_die_info
*pdi
;
8225 /* Now, march along the PDI's, descending into ones which have
8226 interesting children but skipping the children of the other ones,
8227 until we reach the end of the compilation unit. */
8235 /* Anonymous namespaces or modules have no name but have interesting
8236 children, so we need to look at them. Ditto for anonymous
8239 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8240 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8241 || pdi
->tag
== DW_TAG_imported_unit
8242 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8246 case DW_TAG_subprogram
:
8247 case DW_TAG_inlined_subroutine
:
8248 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8249 if (cu
->language
== language_cplus
)
8250 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8253 case DW_TAG_constant
:
8254 case DW_TAG_variable
:
8255 case DW_TAG_typedef
:
8256 case DW_TAG_union_type
:
8257 if (!pdi
->is_declaration
8258 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8260 add_partial_symbol (pdi
, cu
);
8263 case DW_TAG_class_type
:
8264 case DW_TAG_interface_type
:
8265 case DW_TAG_structure_type
:
8266 if (!pdi
->is_declaration
)
8268 add_partial_symbol (pdi
, cu
);
8270 if ((cu
->language
== language_rust
8271 || cu
->language
== language_cplus
) && pdi
->has_children
)
8272 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8275 case DW_TAG_enumeration_type
:
8276 if (!pdi
->is_declaration
)
8277 add_partial_enumeration (pdi
, cu
);
8279 case DW_TAG_base_type
:
8280 case DW_TAG_subrange_type
:
8281 /* File scope base type definitions are added to the partial
8283 add_partial_symbol (pdi
, cu
);
8285 case DW_TAG_namespace
:
8286 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8289 if (!pdi
->is_declaration
)
8290 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8292 case DW_TAG_imported_unit
:
8294 struct dwarf2_per_cu_data
*per_cu
;
8296 /* For now we don't handle imported units in type units. */
8297 if (cu
->per_cu
->is_debug_types
)
8299 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8300 " supported in type units [in module %s]"),
8301 objfile_name (cu
->per_objfile
->objfile
));
8304 per_cu
= dwarf2_find_containing_comp_unit
8305 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8307 /* Go read the partial unit, if needed. */
8308 if (per_cu
->v
.psymtab
== NULL
)
8309 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8312 cu
->per_cu
->imported_symtabs_push (per_cu
);
8315 case DW_TAG_imported_declaration
:
8316 add_partial_symbol (pdi
, cu
);
8323 /* If the die has a sibling, skip to the sibling. */
8325 pdi
= pdi
->die_sibling
;
8329 /* Functions used to compute the fully scoped name of a partial DIE.
8331 Normally, this is simple. For C++, the parent DIE's fully scoped
8332 name is concatenated with "::" and the partial DIE's name.
8333 Enumerators are an exception; they use the scope of their parent
8334 enumeration type, i.e. the name of the enumeration type is not
8335 prepended to the enumerator.
8337 There are two complexities. One is DW_AT_specification; in this
8338 case "parent" means the parent of the target of the specification,
8339 instead of the direct parent of the DIE. The other is compilers
8340 which do not emit DW_TAG_namespace; in this case we try to guess
8341 the fully qualified name of structure types from their members'
8342 linkage names. This must be done using the DIE's children rather
8343 than the children of any DW_AT_specification target. We only need
8344 to do this for structures at the top level, i.e. if the target of
8345 any DW_AT_specification (if any; otherwise the DIE itself) does not
8348 /* Compute the scope prefix associated with PDI's parent, in
8349 compilation unit CU. The result will be allocated on CU's
8350 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8351 field. NULL is returned if no prefix is necessary. */
8353 partial_die_parent_scope (struct partial_die_info
*pdi
,
8354 struct dwarf2_cu
*cu
)
8356 const char *grandparent_scope
;
8357 struct partial_die_info
*parent
, *real_pdi
;
8359 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8360 then this means the parent of the specification DIE. */
8363 while (real_pdi
->has_specification
)
8365 auto res
= find_partial_die (real_pdi
->spec_offset
,
8366 real_pdi
->spec_is_dwz
, cu
);
8371 parent
= real_pdi
->die_parent
;
8375 if (parent
->scope_set
)
8376 return parent
->scope
;
8380 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8382 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8383 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8384 Work around this problem here. */
8385 if (cu
->language
== language_cplus
8386 && parent
->tag
== DW_TAG_namespace
8387 && strcmp (parent
->name (cu
), "::") == 0
8388 && grandparent_scope
== NULL
)
8390 parent
->scope
= NULL
;
8391 parent
->scope_set
= 1;
8395 /* Nested subroutines in Fortran get a prefix. */
8396 if (pdi
->tag
== DW_TAG_enumerator
)
8397 /* Enumerators should not get the name of the enumeration as a prefix. */
8398 parent
->scope
= grandparent_scope
;
8399 else if (parent
->tag
== DW_TAG_namespace
8400 || parent
->tag
== DW_TAG_module
8401 || parent
->tag
== DW_TAG_structure_type
8402 || parent
->tag
== DW_TAG_class_type
8403 || parent
->tag
== DW_TAG_interface_type
8404 || parent
->tag
== DW_TAG_union_type
8405 || parent
->tag
== DW_TAG_enumeration_type
8406 || (cu
->language
== language_fortran
8407 && parent
->tag
== DW_TAG_subprogram
8408 && pdi
->tag
== DW_TAG_subprogram
))
8410 if (grandparent_scope
== NULL
)
8411 parent
->scope
= parent
->name (cu
);
8413 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8415 parent
->name (cu
), 0, cu
);
8419 /* FIXME drow/2004-04-01: What should we be doing with
8420 function-local names? For partial symbols, we should probably be
8422 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8423 dwarf_tag_name (parent
->tag
),
8424 sect_offset_str (pdi
->sect_off
));
8425 parent
->scope
= grandparent_scope
;
8428 parent
->scope_set
= 1;
8429 return parent
->scope
;
8432 /* Return the fully scoped name associated with PDI, from compilation unit
8433 CU. The result will be allocated with malloc. */
8435 static gdb::unique_xmalloc_ptr
<char>
8436 partial_die_full_name (struct partial_die_info
*pdi
,
8437 struct dwarf2_cu
*cu
)
8439 const char *parent_scope
;
8441 /* If this is a template instantiation, we can not work out the
8442 template arguments from partial DIEs. So, unfortunately, we have
8443 to go through the full DIEs. At least any work we do building
8444 types here will be reused if full symbols are loaded later. */
8445 if (pdi
->has_template_arguments
)
8449 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8451 struct die_info
*die
;
8452 struct attribute attr
;
8453 struct dwarf2_cu
*ref_cu
= cu
;
8455 /* DW_FORM_ref_addr is using section offset. */
8456 attr
.name
= (enum dwarf_attribute
) 0;
8457 attr
.form
= DW_FORM_ref_addr
;
8458 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8459 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8461 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8465 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8466 if (parent_scope
== NULL
)
8469 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8475 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8477 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8478 struct objfile
*objfile
= per_objfile
->objfile
;
8479 struct gdbarch
*gdbarch
= objfile
->arch ();
8481 const char *actual_name
= NULL
;
8484 baseaddr
= objfile
->text_section_offset ();
8486 gdb::unique_xmalloc_ptr
<char> built_actual_name
8487 = partial_die_full_name (pdi
, cu
);
8488 if (built_actual_name
!= NULL
)
8489 actual_name
= built_actual_name
.get ();
8491 if (actual_name
== NULL
)
8492 actual_name
= pdi
->name (cu
);
8494 partial_symbol psymbol
;
8495 memset (&psymbol
, 0, sizeof (psymbol
));
8496 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8497 psymbol
.ginfo
.set_section_index (-1);
8499 /* The code below indicates that the psymbol should be installed by
8501 gdb::optional
<psymbol_placement
> where
;
8505 case DW_TAG_inlined_subroutine
:
8506 case DW_TAG_subprogram
:
8507 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8509 if (pdi
->is_external
8510 || cu
->language
== language_ada
8511 || (cu
->language
== language_fortran
8512 && pdi
->die_parent
!= NULL
8513 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8515 /* Normally, only "external" DIEs are part of the global scope.
8516 But in Ada and Fortran, we want to be able to access nested
8517 procedures globally. So all Ada and Fortran subprograms are
8518 stored in the global scope. */
8519 where
= psymbol_placement::GLOBAL
;
8522 where
= psymbol_placement::STATIC
;
8524 psymbol
.domain
= VAR_DOMAIN
;
8525 psymbol
.aclass
= LOC_BLOCK
;
8526 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8527 psymbol
.ginfo
.value
.address
= addr
;
8529 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8530 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8532 case DW_TAG_constant
:
8533 psymbol
.domain
= VAR_DOMAIN
;
8534 psymbol
.aclass
= LOC_STATIC
;
8535 where
= (pdi
->is_external
8536 ? psymbol_placement::GLOBAL
8537 : psymbol_placement::STATIC
);
8539 case DW_TAG_variable
:
8541 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8545 && !per_objfile
->per_bfd
->has_section_at_zero
)
8547 /* A global or static variable may also have been stripped
8548 out by the linker if unused, in which case its address
8549 will be nullified; do not add such variables into partial
8550 symbol table then. */
8552 else if (pdi
->is_external
)
8555 Don't enter into the minimal symbol tables as there is
8556 a minimal symbol table entry from the ELF symbols already.
8557 Enter into partial symbol table if it has a location
8558 descriptor or a type.
8559 If the location descriptor is missing, new_symbol will create
8560 a LOC_UNRESOLVED symbol, the address of the variable will then
8561 be determined from the minimal symbol table whenever the variable
8563 The address for the partial symbol table entry is not
8564 used by GDB, but it comes in handy for debugging partial symbol
8567 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8569 psymbol
.domain
= VAR_DOMAIN
;
8570 psymbol
.aclass
= LOC_STATIC
;
8571 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8572 psymbol
.ginfo
.value
.address
= addr
;
8573 where
= psymbol_placement::GLOBAL
;
8578 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8580 /* Static Variable. Skip symbols whose value we cannot know (those
8581 without location descriptors or constant values). */
8582 if (!has_loc
&& !pdi
->has_const_value
)
8585 psymbol
.domain
= VAR_DOMAIN
;
8586 psymbol
.aclass
= LOC_STATIC
;
8587 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8589 psymbol
.ginfo
.value
.address
= addr
;
8590 where
= psymbol_placement::STATIC
;
8593 case DW_TAG_array_type
:
8594 case DW_TAG_typedef
:
8595 case DW_TAG_base_type
:
8596 case DW_TAG_subrange_type
:
8597 psymbol
.domain
= VAR_DOMAIN
;
8598 psymbol
.aclass
= LOC_TYPEDEF
;
8599 where
= psymbol_placement::STATIC
;
8601 case DW_TAG_imported_declaration
:
8602 case DW_TAG_namespace
:
8603 psymbol
.domain
= VAR_DOMAIN
;
8604 psymbol
.aclass
= LOC_TYPEDEF
;
8605 where
= psymbol_placement::GLOBAL
;
8608 /* With Fortran 77 there might be a "BLOCK DATA" module
8609 available without any name. If so, we skip the module as it
8610 doesn't bring any value. */
8611 if (actual_name
!= nullptr)
8613 psymbol
.domain
= MODULE_DOMAIN
;
8614 psymbol
.aclass
= LOC_TYPEDEF
;
8615 where
= psymbol_placement::GLOBAL
;
8618 case DW_TAG_class_type
:
8619 case DW_TAG_interface_type
:
8620 case DW_TAG_structure_type
:
8621 case DW_TAG_union_type
:
8622 case DW_TAG_enumeration_type
:
8623 /* Skip external references. The DWARF standard says in the section
8624 about "Structure, Union, and Class Type Entries": "An incomplete
8625 structure, union or class type is represented by a structure,
8626 union or class entry that does not have a byte size attribute
8627 and that has a DW_AT_declaration attribute." */
8628 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8631 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8632 static vs. global. */
8633 psymbol
.domain
= STRUCT_DOMAIN
;
8634 psymbol
.aclass
= LOC_TYPEDEF
;
8635 where
= (cu
->language
== language_cplus
8636 ? psymbol_placement::GLOBAL
8637 : psymbol_placement::STATIC
);
8639 case DW_TAG_enumerator
:
8640 psymbol
.domain
= VAR_DOMAIN
;
8641 psymbol
.aclass
= LOC_CONST
;
8642 where
= (cu
->language
== language_cplus
8643 ? psymbol_placement::GLOBAL
8644 : psymbol_placement::STATIC
);
8650 if (where
.has_value ())
8652 if (built_actual_name
!= nullptr)
8653 actual_name
= objfile
->intern (actual_name
);
8654 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8655 psymbol
.ginfo
.set_linkage_name (actual_name
);
8658 psymbol
.ginfo
.set_demangled_name (actual_name
,
8659 &objfile
->objfile_obstack
);
8660 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8662 cu
->per_cu
->v
.psymtab
->add_psymbol (psymbol
, *where
, objfile
);
8666 /* Read a partial die corresponding to a namespace; also, add a symbol
8667 corresponding to that namespace to the symbol table. NAMESPACE is
8668 the name of the enclosing namespace. */
8671 add_partial_namespace (struct partial_die_info
*pdi
,
8672 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8673 int set_addrmap
, struct dwarf2_cu
*cu
)
8675 /* Add a symbol for the namespace. */
8677 add_partial_symbol (pdi
, cu
);
8679 /* Now scan partial symbols in that namespace. */
8681 if (pdi
->has_children
)
8682 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8685 /* Read a partial die corresponding to a Fortran module. */
8688 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8689 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8691 /* Add a symbol for the namespace. */
8693 add_partial_symbol (pdi
, cu
);
8695 /* Now scan partial symbols in that module. */
8697 if (pdi
->has_children
)
8698 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8701 /* Read a partial die corresponding to a subprogram or an inlined
8702 subprogram and create a partial symbol for that subprogram.
8703 When the CU language allows it, this routine also defines a partial
8704 symbol for each nested subprogram that this subprogram contains.
8705 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8706 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8708 PDI may also be a lexical block, in which case we simply search
8709 recursively for subprograms defined inside that lexical block.
8710 Again, this is only performed when the CU language allows this
8711 type of definitions. */
8714 add_partial_subprogram (struct partial_die_info
*pdi
,
8715 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8716 int set_addrmap
, struct dwarf2_cu
*cu
)
8718 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8720 if (pdi
->has_pc_info
)
8722 if (pdi
->lowpc
< *lowpc
)
8723 *lowpc
= pdi
->lowpc
;
8724 if (pdi
->highpc
> *highpc
)
8725 *highpc
= pdi
->highpc
;
8728 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8729 struct gdbarch
*gdbarch
= objfile
->arch ();
8731 CORE_ADDR this_highpc
;
8732 CORE_ADDR this_lowpc
;
8734 baseaddr
= objfile
->text_section_offset ();
8736 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8737 pdi
->lowpc
+ baseaddr
)
8740 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8741 pdi
->highpc
+ baseaddr
)
8743 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8744 this_lowpc
, this_highpc
- 1,
8745 cu
->per_cu
->v
.psymtab
);
8749 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8751 if (!pdi
->is_declaration
)
8752 /* Ignore subprogram DIEs that do not have a name, they are
8753 illegal. Do not emit a complaint at this point, we will
8754 do so when we convert this psymtab into a symtab. */
8756 add_partial_symbol (pdi
, cu
);
8760 if (! pdi
->has_children
)
8763 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8765 pdi
= pdi
->die_child
;
8769 if (pdi
->tag
== DW_TAG_subprogram
8770 || pdi
->tag
== DW_TAG_inlined_subroutine
8771 || pdi
->tag
== DW_TAG_lexical_block
)
8772 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8773 pdi
= pdi
->die_sibling
;
8778 /* Read a partial die corresponding to an enumeration type. */
8781 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8782 struct dwarf2_cu
*cu
)
8784 struct partial_die_info
*pdi
;
8786 if (enum_pdi
->name (cu
) != NULL
)
8787 add_partial_symbol (enum_pdi
, cu
);
8789 pdi
= enum_pdi
->die_child
;
8792 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8793 complaint (_("malformed enumerator DIE ignored"));
8795 add_partial_symbol (pdi
, cu
);
8796 pdi
= pdi
->die_sibling
;
8800 /* Return the initial uleb128 in the die at INFO_PTR. */
8803 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8805 unsigned int bytes_read
;
8807 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8810 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8811 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8813 Return the corresponding abbrev, or NULL if the number is zero (indicating
8814 an empty DIE). In either case *BYTES_READ will be set to the length of
8815 the initial number. */
8817 static const struct abbrev_info
*
8818 peek_die_abbrev (const die_reader_specs
&reader
,
8819 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8821 dwarf2_cu
*cu
= reader
.cu
;
8822 bfd
*abfd
= reader
.abfd
;
8823 unsigned int abbrev_number
8824 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8826 if (abbrev_number
== 0)
8829 const abbrev_info
*abbrev
8830 = reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8833 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8834 " at offset %s [in module %s]"),
8835 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8836 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8842 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8843 Returns a pointer to the end of a series of DIEs, terminated by an empty
8844 DIE. Any children of the skipped DIEs will also be skipped. */
8846 static const gdb_byte
*
8847 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8851 unsigned int bytes_read
;
8852 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
8856 return info_ptr
+ bytes_read
;
8858 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8862 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8863 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8864 abbrev corresponding to that skipped uleb128 should be passed in
8865 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8868 static const gdb_byte
*
8869 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8870 const struct abbrev_info
*abbrev
)
8872 unsigned int bytes_read
;
8873 struct attribute attr
;
8874 bfd
*abfd
= reader
->abfd
;
8875 struct dwarf2_cu
*cu
= reader
->cu
;
8876 const gdb_byte
*buffer
= reader
->buffer
;
8877 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8878 unsigned int form
, i
;
8880 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8882 /* The only abbrev we care about is DW_AT_sibling. */
8883 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8885 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8886 if (attr
.form
== DW_FORM_ref_addr
)
8887 complaint (_("ignoring absolute DW_AT_sibling"));
8890 sect_offset off
= attr
.get_ref_die_offset ();
8891 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8893 if (sibling_ptr
< info_ptr
)
8894 complaint (_("DW_AT_sibling points backwards"));
8895 else if (sibling_ptr
> reader
->buffer_end
)
8896 reader
->die_section
->overflow_complaint ();
8902 /* If it isn't DW_AT_sibling, skip this attribute. */
8903 form
= abbrev
->attrs
[i
].form
;
8907 case DW_FORM_ref_addr
:
8908 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8909 and later it is offset sized. */
8910 if (cu
->header
.version
== 2)
8911 info_ptr
+= cu
->header
.addr_size
;
8913 info_ptr
+= cu
->header
.offset_size
;
8915 case DW_FORM_GNU_ref_alt
:
8916 info_ptr
+= cu
->header
.offset_size
;
8919 info_ptr
+= cu
->header
.addr_size
;
8927 case DW_FORM_flag_present
:
8928 case DW_FORM_implicit_const
:
8945 case DW_FORM_ref_sig8
:
8948 case DW_FORM_data16
:
8951 case DW_FORM_string
:
8952 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8953 info_ptr
+= bytes_read
;
8955 case DW_FORM_sec_offset
:
8957 case DW_FORM_GNU_strp_alt
:
8958 info_ptr
+= cu
->header
.offset_size
;
8960 case DW_FORM_exprloc
:
8962 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8963 info_ptr
+= bytes_read
;
8965 case DW_FORM_block1
:
8966 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8968 case DW_FORM_block2
:
8969 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8971 case DW_FORM_block4
:
8972 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8978 case DW_FORM_ref_udata
:
8979 case DW_FORM_GNU_addr_index
:
8980 case DW_FORM_GNU_str_index
:
8981 case DW_FORM_rnglistx
:
8982 case DW_FORM_loclistx
:
8983 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8985 case DW_FORM_indirect
:
8986 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8987 info_ptr
+= bytes_read
;
8988 /* We need to continue parsing from here, so just go back to
8990 goto skip_attribute
;
8993 error (_("Dwarf Error: Cannot handle %s "
8994 "in DWARF reader [in module %s]"),
8995 dwarf_form_name (form
),
8996 bfd_get_filename (abfd
));
9000 if (abbrev
->has_children
)
9001 return skip_children (reader
, info_ptr
);
9006 /* Locate ORIG_PDI's sibling.
9007 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9009 static const gdb_byte
*
9010 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9011 struct partial_die_info
*orig_pdi
,
9012 const gdb_byte
*info_ptr
)
9014 /* Do we know the sibling already? */
9016 if (orig_pdi
->sibling
)
9017 return orig_pdi
->sibling
;
9019 /* Are there any children to deal with? */
9021 if (!orig_pdi
->has_children
)
9024 /* Skip the children the long way. */
9026 return skip_children (reader
, info_ptr
);
9029 /* Expand this partial symbol table into a full symbol table. SELF is
9033 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
9035 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9037 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
9039 /* If this psymtab is constructed from a debug-only objfile, the
9040 has_section_at_zero flag will not necessarily be correct. We
9041 can get the correct value for this flag by looking at the data
9042 associated with the (presumably stripped) associated objfile. */
9043 if (objfile
->separate_debug_objfile_backlink
)
9045 dwarf2_per_objfile
*per_objfile_backlink
9046 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9048 per_objfile
->per_bfd
->has_section_at_zero
9049 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
9052 expand_psymtab (objfile
);
9054 process_cu_includes (per_objfile
);
9057 /* Reading in full CUs. */
9059 /* Add PER_CU to the queue. */
9062 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
9063 dwarf2_per_objfile
*per_objfile
,
9064 enum language pretend_language
)
9068 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
9069 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
9072 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
9074 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9077 Return true if maybe_queue_comp_unit requires the caller to load the CU's
9078 DIEs, false otherwise.
9080 Explanation: there is an invariant that if a CU is queued for expansion
9081 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
9082 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
9083 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
9084 are not yet loaded, the the caller must load the CU's DIEs to ensure the
9085 invariant is respected.
9087 The caller is therefore not required to load the CU's DIEs (we return false)
9090 - the CU is already expanded, and therefore does not get enqueued
9091 - the CU gets enqueued for expansion, but its DIEs are already loaded
9093 Note that the caller should not use this function's return value as an
9094 indicator of whether the CU's DIEs are loaded right now, it should check
9095 that by calling `dwarf2_per_objfile::get_cu` instead. */
9098 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9099 dwarf2_per_cu_data
*per_cu
,
9100 dwarf2_per_objfile
*per_objfile
,
9101 enum language pretend_language
)
9103 /* We may arrive here during partial symbol reading, if we need full
9104 DIEs to process an unusual case (e.g. template arguments). Do
9105 not queue PER_CU, just tell our caller to load its DIEs. */
9106 if (per_cu
->per_bfd
->reading_partial_symbols
)
9108 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9110 if (cu
== NULL
|| cu
->dies
== NULL
)
9115 /* Mark the dependence relation so that we don't flush PER_CU
9117 if (dependent_cu
!= NULL
)
9118 dwarf2_add_dependence (dependent_cu
, per_cu
);
9120 /* If it's already on the queue, we have nothing to do. */
9123 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
9125 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
9127 /* If the CU is queued for expansion, it should not already be
9129 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
9131 /* The DIEs are already loaded, the caller doesn't need to do it. */
9135 bool queued
= false;
9136 if (!per_objfile
->symtab_set_p (per_cu
))
9138 /* Add it to the queue. */
9139 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9143 /* If the compilation unit is already loaded, just mark it as
9145 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9149 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
9150 and the DIEs are not already loaded. */
9151 return queued
&& cu
== nullptr;
9154 /* Process the queue. */
9157 process_queue (dwarf2_per_objfile
*per_objfile
)
9159 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
9160 objfile_name (per_objfile
->objfile
));
9162 /* The queue starts out with one item, but following a DIE reference
9163 may load a new CU, adding it to the end of the queue. */
9164 while (!per_objfile
->per_bfd
->queue
->empty ())
9166 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
9167 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9169 if (!per_objfile
->symtab_set_p (per_cu
))
9171 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9173 /* Skip dummy CUs. */
9176 unsigned int debug_print_threshold
;
9179 if (per_cu
->is_debug_types
)
9181 struct signatured_type
*sig_type
=
9182 (struct signatured_type
*) per_cu
;
9184 sprintf (buf
, "TU %s at offset %s",
9185 hex_string (sig_type
->signature
),
9186 sect_offset_str (per_cu
->sect_off
));
9187 /* There can be 100s of TUs.
9188 Only print them in verbose mode. */
9189 debug_print_threshold
= 2;
9193 sprintf (buf
, "CU at offset %s",
9194 sect_offset_str (per_cu
->sect_off
));
9195 debug_print_threshold
= 1;
9198 if (dwarf_read_debug
>= debug_print_threshold
)
9199 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
9201 if (per_cu
->is_debug_types
)
9202 process_full_type_unit (cu
, item
.pretend_language
);
9204 process_full_comp_unit (cu
, item
.pretend_language
);
9206 if (dwarf_read_debug
>= debug_print_threshold
)
9207 dwarf_read_debug_printf ("Done expanding %s", buf
);
9212 per_objfile
->per_bfd
->queue
->pop ();
9215 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
9216 objfile_name (per_objfile
->objfile
));
9219 /* Read in full symbols for PST, and anything it depends on. */
9222 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9224 gdb_assert (!readin_p (objfile
));
9226 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9227 free_cached_comp_units
freer (per_objfile
);
9228 expand_dependencies (objfile
);
9230 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9231 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9234 /* See psympriv.h. */
9237 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9239 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9240 return per_objfile
->symtab_set_p (per_cu_data
);
9243 /* See psympriv.h. */
9246 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9248 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9249 return per_objfile
->get_symtab (per_cu_data
);
9252 /* Trivial hash function for die_info: the hash value of a DIE
9253 is its offset in .debug_info for this objfile. */
9256 die_hash (const void *item
)
9258 const struct die_info
*die
= (const struct die_info
*) item
;
9260 return to_underlying (die
->sect_off
);
9263 /* Trivial comparison function for die_info structures: two DIEs
9264 are equal if they have the same offset. */
9267 die_eq (const void *item_lhs
, const void *item_rhs
)
9269 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9270 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9272 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9275 /* Load the DIEs associated with PER_CU into memory.
9277 In some cases, the caller, while reading partial symbols, will need to load
9278 the full symbols for the CU for some reason. It will already have a
9279 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
9280 rather than creating a new one. */
9283 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9284 dwarf2_per_objfile
*per_objfile
,
9285 dwarf2_cu
*existing_cu
,
9287 enum language pretend_language
)
9289 gdb_assert (! this_cu
->is_debug_types
);
9291 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9295 struct dwarf2_cu
*cu
= reader
.cu
;
9296 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9298 gdb_assert (cu
->die_hash
== NULL
);
9300 htab_create_alloc_ex (cu
->header
.length
/ 12,
9304 &cu
->comp_unit_obstack
,
9305 hashtab_obstack_allocate
,
9306 dummy_obstack_deallocate
);
9308 if (reader
.comp_unit_die
->has_children
)
9309 reader
.comp_unit_die
->child
9310 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9311 &info_ptr
, reader
.comp_unit_die
);
9312 cu
->dies
= reader
.comp_unit_die
;
9313 /* comp_unit_die is not stored in die_hash, no need. */
9315 /* We try not to read any attributes in this function, because not
9316 all CUs needed for references have been loaded yet, and symbol
9317 table processing isn't initialized. But we have to set the CU language,
9318 or we won't be able to build types correctly.
9319 Similarly, if we do not read the producer, we can not apply
9320 producer-specific interpretation. */
9321 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9326 /* Add a DIE to the delayed physname list. */
9329 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9330 const char *name
, struct die_info
*die
,
9331 struct dwarf2_cu
*cu
)
9333 struct delayed_method_info mi
;
9335 mi
.fnfield_index
= fnfield_index
;
9339 cu
->method_list
.push_back (mi
);
9342 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9343 "const" / "volatile". If so, decrements LEN by the length of the
9344 modifier and return true. Otherwise return false. */
9348 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9350 size_t mod_len
= sizeof (mod
) - 1;
9351 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9359 /* Compute the physnames of any methods on the CU's method list.
9361 The computation of method physnames is delayed in order to avoid the
9362 (bad) condition that one of the method's formal parameters is of an as yet
9366 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9368 /* Only C++ delays computing physnames. */
9369 if (cu
->method_list
.empty ())
9371 gdb_assert (cu
->language
== language_cplus
);
9373 for (const delayed_method_info
&mi
: cu
->method_list
)
9375 const char *physname
;
9376 struct fn_fieldlist
*fn_flp
9377 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9378 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9379 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9380 = physname
? physname
: "";
9382 /* Since there's no tag to indicate whether a method is a
9383 const/volatile overload, extract that information out of the
9385 if (physname
!= NULL
)
9387 size_t len
= strlen (physname
);
9391 if (physname
[len
] == ')') /* shortcut */
9393 else if (check_modifier (physname
, len
, " const"))
9394 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9395 else if (check_modifier (physname
, len
, " volatile"))
9396 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9403 /* The list is no longer needed. */
9404 cu
->method_list
.clear ();
9407 /* Go objects should be embedded in a DW_TAG_module DIE,
9408 and it's not clear if/how imported objects will appear.
9409 To keep Go support simple until that's worked out,
9410 go back through what we've read and create something usable.
9411 We could do this while processing each DIE, and feels kinda cleaner,
9412 but that way is more invasive.
9413 This is to, for example, allow the user to type "p var" or "b main"
9414 without having to specify the package name, and allow lookups
9415 of module.object to work in contexts that use the expression
9419 fixup_go_packaging (struct dwarf2_cu
*cu
)
9421 gdb::unique_xmalloc_ptr
<char> package_name
;
9422 struct pending
*list
;
9425 for (list
= *cu
->get_builder ()->get_global_symbols ();
9429 for (i
= 0; i
< list
->nsyms
; ++i
)
9431 struct symbol
*sym
= list
->symbol
[i
];
9433 if (sym
->language () == language_go
9434 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9436 gdb::unique_xmalloc_ptr
<char> this_package_name
9437 (go_symbol_package_name (sym
));
9439 if (this_package_name
== NULL
)
9441 if (package_name
== NULL
)
9442 package_name
= std::move (this_package_name
);
9445 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9446 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9447 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9448 (symbol_symtab (sym
) != NULL
9449 ? symtab_to_filename_for_display
9450 (symbol_symtab (sym
))
9451 : objfile_name (objfile
)),
9452 this_package_name
.get (), package_name
.get ());
9458 if (package_name
!= NULL
)
9460 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9461 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9462 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9463 saved_package_name
);
9466 sym
= new (&objfile
->objfile_obstack
) symbol
;
9467 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9468 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9469 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9470 e.g., "main" finds the "main" module and not C's main(). */
9471 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9472 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9473 SYMBOL_TYPE (sym
) = type
;
9475 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9479 /* Allocate a fully-qualified name consisting of the two parts on the
9483 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9485 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9488 /* A helper that allocates a variant part to attach to a Rust enum
9489 type. OBSTACK is where the results should be allocated. TYPE is
9490 the type we're processing. DISCRIMINANT_INDEX is the index of the
9491 discriminant. It must be the index of one of the fields of TYPE,
9492 or -1 to mean there is no discriminant (univariant enum).
9493 DEFAULT_INDEX is the index of the default field; or -1 if there is
9494 no default. RANGES is indexed by "effective" field number (the
9495 field index, but omitting the discriminant and default fields) and
9496 must hold the discriminant values used by the variants. Note that
9497 RANGES must have a lifetime at least as long as OBSTACK -- either
9498 already allocated on it, or static. */
9501 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9502 int discriminant_index
, int default_index
,
9503 gdb::array_view
<discriminant_range
> ranges
)
9505 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
9506 gdb_assert (discriminant_index
== -1
9507 || (discriminant_index
>= 0
9508 && discriminant_index
< type
->num_fields ()));
9509 gdb_assert (default_index
== -1
9510 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9512 /* We have one variant for each non-discriminant field. */
9513 int n_variants
= type
->num_fields ();
9514 if (discriminant_index
!= -1)
9517 variant
*variants
= new (obstack
) variant
[n_variants
];
9520 for (int i
= 0; i
< type
->num_fields (); ++i
)
9522 if (i
== discriminant_index
)
9525 variants
[var_idx
].first_field
= i
;
9526 variants
[var_idx
].last_field
= i
+ 1;
9528 /* The default field does not need a range, but other fields do.
9529 We skipped the discriminant above. */
9530 if (i
!= default_index
)
9532 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9539 gdb_assert (range_idx
== ranges
.size ());
9540 gdb_assert (var_idx
== n_variants
);
9542 variant_part
*part
= new (obstack
) variant_part
;
9543 part
->discriminant_index
= discriminant_index
;
9544 /* If there is no discriminant, then whether it is signed is of no
9547 = (discriminant_index
== -1
9549 : type
->field (discriminant_index
).type ()->is_unsigned ());
9550 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9552 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9553 gdb::array_view
<variant_part
> *prop_value
9554 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9556 struct dynamic_prop prop
;
9557 prop
.set_variant_parts (prop_value
);
9559 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9562 /* Some versions of rustc emitted enums in an unusual way.
9564 Ordinary enums were emitted as unions. The first element of each
9565 structure in the union was named "RUST$ENUM$DISR". This element
9566 held the discriminant.
9568 These versions of Rust also implemented the "non-zero"
9569 optimization. When the enum had two values, and one is empty and
9570 the other holds a pointer that cannot be zero, the pointer is used
9571 as the discriminant, with a zero value meaning the empty variant.
9572 Here, the union's first member is of the form
9573 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9574 where the fieldnos are the indices of the fields that should be
9575 traversed in order to find the field (which may be several fields deep)
9576 and the variantname is the name of the variant of the case when the
9579 This function recognizes whether TYPE is of one of these forms,
9580 and, if so, smashes it to be a variant type. */
9583 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9585 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9587 /* We don't need to deal with empty enums. */
9588 if (type
->num_fields () == 0)
9591 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9592 if (type
->num_fields () == 1
9593 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9595 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9597 /* Decode the field name to find the offset of the
9599 ULONGEST bit_offset
= 0;
9600 struct type
*field_type
= type
->field (0).type ();
9601 while (name
[0] >= '0' && name
[0] <= '9')
9604 unsigned long index
= strtoul (name
, &tail
, 10);
9607 || index
>= field_type
->num_fields ()
9608 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9609 != FIELD_LOC_KIND_BITPOS
))
9611 complaint (_("Could not parse Rust enum encoding string \"%s\""
9613 TYPE_FIELD_NAME (type
, 0),
9614 objfile_name (objfile
));
9619 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9620 field_type
= field_type
->field (index
).type ();
9623 /* Smash this type to be a structure type. We have to do this
9624 because the type has already been recorded. */
9625 type
->set_code (TYPE_CODE_STRUCT
);
9626 type
->set_num_fields (3);
9627 /* Save the field we care about. */
9628 struct field saved_field
= type
->field (0);
9630 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9632 /* Put the discriminant at index 0. */
9633 type
->field (0).set_type (field_type
);
9634 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9635 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9636 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9638 /* The order of fields doesn't really matter, so put the real
9639 field at index 1 and the data-less field at index 2. */
9640 type
->field (1) = saved_field
;
9641 TYPE_FIELD_NAME (type
, 1)
9642 = rust_last_path_segment (type
->field (1).type ()->name ());
9643 type
->field (1).type ()->set_name
9644 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9645 TYPE_FIELD_NAME (type
, 1)));
9647 const char *dataless_name
9648 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9650 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9652 type
->field (2).set_type (dataless_type
);
9653 /* NAME points into the original discriminant name, which
9654 already has the correct lifetime. */
9655 TYPE_FIELD_NAME (type
, 2) = name
;
9656 SET_FIELD_BITPOS (type
->field (2), 0);
9658 /* Indicate that this is a variant type. */
9659 static discriminant_range ranges
[1] = { { 0, 0 } };
9660 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9662 /* A union with a single anonymous field is probably an old-style
9664 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9666 /* Smash this type to be a structure type. We have to do this
9667 because the type has already been recorded. */
9668 type
->set_code (TYPE_CODE_STRUCT
);
9670 struct type
*field_type
= type
->field (0).type ();
9671 const char *variant_name
9672 = rust_last_path_segment (field_type
->name ());
9673 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9674 field_type
->set_name
9675 (rust_fully_qualify (&objfile
->objfile_obstack
,
9676 type
->name (), variant_name
));
9678 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9682 struct type
*disr_type
= nullptr;
9683 for (int i
= 0; i
< type
->num_fields (); ++i
)
9685 disr_type
= type
->field (i
).type ();
9687 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9689 /* All fields of a true enum will be structs. */
9692 else if (disr_type
->num_fields () == 0)
9694 /* Could be data-less variant, so keep going. */
9695 disr_type
= nullptr;
9697 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9698 "RUST$ENUM$DISR") != 0)
9700 /* Not a Rust enum. */
9710 /* If we got here without a discriminant, then it's probably
9712 if (disr_type
== nullptr)
9715 /* Smash this type to be a structure type. We have to do this
9716 because the type has already been recorded. */
9717 type
->set_code (TYPE_CODE_STRUCT
);
9719 /* Make space for the discriminant field. */
9720 struct field
*disr_field
= &disr_type
->field (0);
9722 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9723 * sizeof (struct field
)));
9724 memcpy (new_fields
+ 1, type
->fields (),
9725 type
->num_fields () * sizeof (struct field
));
9726 type
->set_fields (new_fields
);
9727 type
->set_num_fields (type
->num_fields () + 1);
9729 /* Install the discriminant at index 0 in the union. */
9730 type
->field (0) = *disr_field
;
9731 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9732 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9734 /* We need a way to find the correct discriminant given a
9735 variant name. For convenience we build a map here. */
9736 struct type
*enum_type
= disr_field
->type ();
9737 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9738 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9740 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9743 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9744 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9748 int n_fields
= type
->num_fields ();
9749 /* We don't need a range entry for the discriminant, but we do
9750 need one for every other field, as there is no default
9752 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9755 /* Skip the discriminant here. */
9756 for (int i
= 1; i
< n_fields
; ++i
)
9758 /* Find the final word in the name of this variant's type.
9759 That name can be used to look up the correct
9761 const char *variant_name
9762 = rust_last_path_segment (type
->field (i
).type ()->name ());
9764 auto iter
= discriminant_map
.find (variant_name
);
9765 if (iter
!= discriminant_map
.end ())
9767 ranges
[i
- 1].low
= iter
->second
;
9768 ranges
[i
- 1].high
= iter
->second
;
9771 /* In Rust, each element should have the size of the
9773 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9775 /* Remove the discriminant field, if it exists. */
9776 struct type
*sub_type
= type
->field (i
).type ();
9777 if (sub_type
->num_fields () > 0)
9779 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9780 sub_type
->set_fields (sub_type
->fields () + 1);
9782 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9784 (rust_fully_qualify (&objfile
->objfile_obstack
,
9785 type
->name (), variant_name
));
9788 /* Indicate that this is a variant type. */
9789 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9790 gdb::array_view
<discriminant_range
> (ranges
,
9795 /* Rewrite some Rust unions to be structures with variants parts. */
9798 rust_union_quirks (struct dwarf2_cu
*cu
)
9800 gdb_assert (cu
->language
== language_rust
);
9801 for (type
*type_
: cu
->rust_unions
)
9802 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9803 /* We don't need this any more. */
9804 cu
->rust_unions
.clear ();
9809 type_unit_group_unshareable
*
9810 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9812 auto iter
= this->m_type_units
.find (tu_group
);
9813 if (iter
!= this->m_type_units
.end ())
9814 return iter
->second
.get ();
9816 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9817 type_unit_group_unshareable
*result
= uniq
.get ();
9818 this->m_type_units
[tu_group
] = std::move (uniq
);
9823 dwarf2_per_objfile::get_type_for_signatured_type
9824 (signatured_type
*sig_type
) const
9826 auto iter
= this->m_type_map
.find (sig_type
);
9827 if (iter
== this->m_type_map
.end ())
9830 return iter
->second
;
9833 void dwarf2_per_objfile::set_type_for_signatured_type
9834 (signatured_type
*sig_type
, struct type
*type
)
9836 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9838 this->m_type_map
[sig_type
] = type
;
9841 /* A helper function for computing the list of all symbol tables
9842 included by PER_CU. */
9845 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9846 htab_t all_children
, htab_t all_type_symtabs
,
9847 dwarf2_per_cu_data
*per_cu
,
9848 dwarf2_per_objfile
*per_objfile
,
9849 struct compunit_symtab
*immediate_parent
)
9851 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9854 /* This inclusion and its children have been processed. */
9860 /* Only add a CU if it has a symbol table. */
9861 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9864 /* If this is a type unit only add its symbol table if we haven't
9865 seen it yet (type unit per_cu's can share symtabs). */
9866 if (per_cu
->is_debug_types
)
9868 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9872 result
->push_back (cust
);
9873 if (cust
->user
== NULL
)
9874 cust
->user
= immediate_parent
;
9879 result
->push_back (cust
);
9880 if (cust
->user
== NULL
)
9881 cust
->user
= immediate_parent
;
9885 if (!per_cu
->imported_symtabs_empty ())
9886 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9888 recursively_compute_inclusions (result
, all_children
,
9889 all_type_symtabs
, ptr
, per_objfile
,
9894 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9898 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
9899 dwarf2_per_objfile
*per_objfile
)
9901 gdb_assert (! per_cu
->is_debug_types
);
9903 if (!per_cu
->imported_symtabs_empty ())
9906 std::vector
<compunit_symtab
*> result_symtabs
;
9907 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9909 /* If we don't have a symtab, we can just skip this case. */
9913 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
9915 NULL
, xcalloc
, xfree
));
9916 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
9918 NULL
, xcalloc
, xfree
));
9920 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9922 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
9923 all_type_symtabs
.get (), ptr
,
9927 /* Now we have a transitive closure of all the included symtabs. */
9928 len
= result_symtabs
.size ();
9930 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
9931 struct compunit_symtab
*, len
+ 1);
9932 memcpy (cust
->includes
, result_symtabs
.data (),
9933 len
* sizeof (compunit_symtab
*));
9934 cust
->includes
[len
] = NULL
;
9938 /* Compute the 'includes' field for the symtabs of all the CUs we just
9942 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
9944 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
9946 if (! iter
->is_debug_types
)
9947 compute_compunit_symtab_includes (iter
, per_objfile
);
9950 per_objfile
->per_bfd
->just_read_cus
.clear ();
9953 /* Generate full symbol information for CU, whose DIEs have
9954 already been loaded into memory. */
9957 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
9959 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
9960 struct objfile
*objfile
= per_objfile
->objfile
;
9961 struct gdbarch
*gdbarch
= objfile
->arch ();
9962 CORE_ADDR lowpc
, highpc
;
9963 struct compunit_symtab
*cust
;
9965 struct block
*static_block
;
9968 baseaddr
= objfile
->text_section_offset ();
9970 /* Clear the list here in case something was left over. */
9971 cu
->method_list
.clear ();
9973 cu
->language
= pretend_language
;
9974 cu
->language_defn
= language_def (cu
->language
);
9976 dwarf2_find_base_address (cu
->dies
, cu
);
9978 /* Do line number decoding in read_file_scope () */
9979 process_die (cu
->dies
, cu
);
9981 /* For now fudge the Go package. */
9982 if (cu
->language
== language_go
)
9983 fixup_go_packaging (cu
);
9985 /* Now that we have processed all the DIEs in the CU, all the types
9986 should be complete, and it should now be safe to compute all of the
9988 compute_delayed_physnames (cu
);
9990 if (cu
->language
== language_rust
)
9991 rust_union_quirks (cu
);
9993 /* Some compilers don't define a DW_AT_high_pc attribute for the
9994 compilation unit. If the DW_AT_high_pc is missing, synthesize
9995 it, by scanning the DIE's below the compilation unit. */
9996 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9998 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9999 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10001 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10002 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10003 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10004 addrmap to help ensure it has an accurate map of pc values belonging to
10006 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10008 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10009 SECT_OFF_TEXT (objfile
),
10014 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10016 /* Set symtab language to language from DW_AT_language. If the
10017 compilation is from a C file generated by language preprocessors, do
10018 not set the language if it was already deduced by start_subfile. */
10019 if (!(cu
->language
== language_c
10020 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10021 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10023 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10024 produce DW_AT_location with location lists but it can be possibly
10025 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10026 there were bugs in prologue debug info, fixed later in GCC-4.5
10027 by "unwind info for epilogues" patch (which is not directly related).
10029 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10030 needed, it would be wrong due to missing DW_AT_producer there.
10032 Still one can confuse GDB by using non-standard GCC compilation
10033 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10035 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10036 cust
->locations_valid
= 1;
10038 if (gcc_4_minor
>= 5)
10039 cust
->epilogue_unwind_valid
= 1;
10041 cust
->call_site_htab
= cu
->call_site_htab
;
10044 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10046 /* Push it for inclusion processing later. */
10047 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
10049 /* Not needed any more. */
10050 cu
->reset_builder ();
10053 /* Generate full symbol information for type unit CU, whose DIEs have
10054 already been loaded into memory. */
10057 process_full_type_unit (dwarf2_cu
*cu
,
10058 enum language pretend_language
)
10060 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10061 struct objfile
*objfile
= per_objfile
->objfile
;
10062 struct compunit_symtab
*cust
;
10063 struct signatured_type
*sig_type
;
10065 gdb_assert (cu
->per_cu
->is_debug_types
);
10066 sig_type
= (struct signatured_type
*) cu
->per_cu
;
10068 /* Clear the list here in case something was left over. */
10069 cu
->method_list
.clear ();
10071 cu
->language
= pretend_language
;
10072 cu
->language_defn
= language_def (cu
->language
);
10074 /* The symbol tables are set up in read_type_unit_scope. */
10075 process_die (cu
->dies
, cu
);
10077 /* For now fudge the Go package. */
10078 if (cu
->language
== language_go
)
10079 fixup_go_packaging (cu
);
10081 /* Now that we have processed all the DIEs in the CU, all the types
10082 should be complete, and it should now be safe to compute all of the
10084 compute_delayed_physnames (cu
);
10086 if (cu
->language
== language_rust
)
10087 rust_union_quirks (cu
);
10089 /* TUs share symbol tables.
10090 If this is the first TU to use this symtab, complete the construction
10091 of it with end_expandable_symtab. Otherwise, complete the addition of
10092 this TU's symbols to the existing symtab. */
10093 type_unit_group_unshareable
*tug_unshare
=
10094 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
10095 if (tug_unshare
->compunit_symtab
== NULL
)
10097 buildsym_compunit
*builder
= cu
->get_builder ();
10098 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10099 tug_unshare
->compunit_symtab
= cust
;
10103 /* Set symtab language to language from DW_AT_language. If the
10104 compilation is from a C file generated by language preprocessors,
10105 do not set the language if it was already deduced by
10107 if (!(cu
->language
== language_c
10108 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10109 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10114 cu
->get_builder ()->augment_type_symtab ();
10115 cust
= tug_unshare
->compunit_symtab
;
10118 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10120 /* Not needed any more. */
10121 cu
->reset_builder ();
10124 /* Process an imported unit DIE. */
10127 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10129 struct attribute
*attr
;
10131 /* For now we don't handle imported units in type units. */
10132 if (cu
->per_cu
->is_debug_types
)
10134 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10135 " supported in type units [in module %s]"),
10136 objfile_name (cu
->per_objfile
->objfile
));
10139 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10142 sect_offset sect_off
= attr
->get_ref_die_offset ();
10143 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10144 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10145 dwarf2_per_cu_data
*per_cu
10146 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10148 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10149 into another compilation unit, at root level. Regard this as a hint,
10151 if (die
->parent
&& die
->parent
->parent
== NULL
10152 && per_cu
->unit_type
== DW_UT_compile
10153 && per_cu
->lang
== language_cplus
)
10156 /* If necessary, add it to the queue and load its DIEs. */
10157 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10158 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
10159 false, cu
->language
);
10161 cu
->per_cu
->imported_symtabs_push (per_cu
);
10165 /* RAII object that represents a process_die scope: i.e.,
10166 starts/finishes processing a DIE. */
10167 class process_die_scope
10170 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10171 : m_die (die
), m_cu (cu
)
10173 /* We should only be processing DIEs not already in process. */
10174 gdb_assert (!m_die
->in_process
);
10175 m_die
->in_process
= true;
10178 ~process_die_scope ()
10180 m_die
->in_process
= false;
10182 /* If we're done processing the DIE for the CU that owns the line
10183 header, we don't need the line header anymore. */
10184 if (m_cu
->line_header_die_owner
== m_die
)
10186 delete m_cu
->line_header
;
10187 m_cu
->line_header
= NULL
;
10188 m_cu
->line_header_die_owner
= NULL
;
10197 /* Process a die and its children. */
10200 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10202 process_die_scope
scope (die
, cu
);
10206 case DW_TAG_padding
:
10208 case DW_TAG_compile_unit
:
10209 case DW_TAG_partial_unit
:
10210 read_file_scope (die
, cu
);
10212 case DW_TAG_type_unit
:
10213 read_type_unit_scope (die
, cu
);
10215 case DW_TAG_subprogram
:
10216 /* Nested subprograms in Fortran get a prefix. */
10217 if (cu
->language
== language_fortran
10218 && die
->parent
!= NULL
10219 && die
->parent
->tag
== DW_TAG_subprogram
)
10220 cu
->processing_has_namespace_info
= true;
10221 /* Fall through. */
10222 case DW_TAG_inlined_subroutine
:
10223 read_func_scope (die
, cu
);
10225 case DW_TAG_lexical_block
:
10226 case DW_TAG_try_block
:
10227 case DW_TAG_catch_block
:
10228 read_lexical_block_scope (die
, cu
);
10230 case DW_TAG_call_site
:
10231 case DW_TAG_GNU_call_site
:
10232 read_call_site_scope (die
, cu
);
10234 case DW_TAG_class_type
:
10235 case DW_TAG_interface_type
:
10236 case DW_TAG_structure_type
:
10237 case DW_TAG_union_type
:
10238 process_structure_scope (die
, cu
);
10240 case DW_TAG_enumeration_type
:
10241 process_enumeration_scope (die
, cu
);
10244 /* These dies have a type, but processing them does not create
10245 a symbol or recurse to process the children. Therefore we can
10246 read them on-demand through read_type_die. */
10247 case DW_TAG_subroutine_type
:
10248 case DW_TAG_set_type
:
10249 case DW_TAG_pointer_type
:
10250 case DW_TAG_ptr_to_member_type
:
10251 case DW_TAG_reference_type
:
10252 case DW_TAG_rvalue_reference_type
:
10253 case DW_TAG_string_type
:
10256 case DW_TAG_array_type
:
10257 /* We only need to handle this case for Ada -- in other
10258 languages, it's normal for the compiler to emit a typedef
10260 if (cu
->language
!= language_ada
)
10263 case DW_TAG_base_type
:
10264 case DW_TAG_subrange_type
:
10265 case DW_TAG_typedef
:
10266 /* Add a typedef symbol for the type definition, if it has a
10268 new_symbol (die
, read_type_die (die
, cu
), cu
);
10270 case DW_TAG_common_block
:
10271 read_common_block (die
, cu
);
10273 case DW_TAG_common_inclusion
:
10275 case DW_TAG_namespace
:
10276 cu
->processing_has_namespace_info
= true;
10277 read_namespace (die
, cu
);
10279 case DW_TAG_module
:
10280 cu
->processing_has_namespace_info
= true;
10281 read_module (die
, cu
);
10283 case DW_TAG_imported_declaration
:
10284 cu
->processing_has_namespace_info
= true;
10285 if (read_namespace_alias (die
, cu
))
10287 /* The declaration is not a global namespace alias. */
10288 /* Fall through. */
10289 case DW_TAG_imported_module
:
10290 cu
->processing_has_namespace_info
= true;
10291 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10292 || cu
->language
!= language_fortran
))
10293 complaint (_("Tag '%s' has unexpected children"),
10294 dwarf_tag_name (die
->tag
));
10295 read_import_statement (die
, cu
);
10298 case DW_TAG_imported_unit
:
10299 process_imported_unit_die (die
, cu
);
10302 case DW_TAG_variable
:
10303 read_variable (die
, cu
);
10307 new_symbol (die
, NULL
, cu
);
10312 /* DWARF name computation. */
10314 /* A helper function for dwarf2_compute_name which determines whether DIE
10315 needs to have the name of the scope prepended to the name listed in the
10319 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10321 struct attribute
*attr
;
10325 case DW_TAG_namespace
:
10326 case DW_TAG_typedef
:
10327 case DW_TAG_class_type
:
10328 case DW_TAG_interface_type
:
10329 case DW_TAG_structure_type
:
10330 case DW_TAG_union_type
:
10331 case DW_TAG_enumeration_type
:
10332 case DW_TAG_enumerator
:
10333 case DW_TAG_subprogram
:
10334 case DW_TAG_inlined_subroutine
:
10335 case DW_TAG_member
:
10336 case DW_TAG_imported_declaration
:
10339 case DW_TAG_variable
:
10340 case DW_TAG_constant
:
10341 /* We only need to prefix "globally" visible variables. These include
10342 any variable marked with DW_AT_external or any variable that
10343 lives in a namespace. [Variables in anonymous namespaces
10344 require prefixing, but they are not DW_AT_external.] */
10346 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10348 struct dwarf2_cu
*spec_cu
= cu
;
10350 return die_needs_namespace (die_specification (die
, &spec_cu
),
10354 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10355 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10356 && die
->parent
->tag
!= DW_TAG_module
)
10358 /* A variable in a lexical block of some kind does not need a
10359 namespace, even though in C++ such variables may be external
10360 and have a mangled name. */
10361 if (die
->parent
->tag
== DW_TAG_lexical_block
10362 || die
->parent
->tag
== DW_TAG_try_block
10363 || die
->parent
->tag
== DW_TAG_catch_block
10364 || die
->parent
->tag
== DW_TAG_subprogram
)
10373 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10374 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10375 defined for the given DIE. */
10377 static struct attribute
*
10378 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10380 struct attribute
*attr
;
10382 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10384 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10389 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10390 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10391 defined for the given DIE. */
10393 static const char *
10394 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10396 const char *linkage_name
;
10398 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10399 if (linkage_name
== NULL
)
10400 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10402 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10403 See https://github.com/rust-lang/rust/issues/32925. */
10404 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10405 && strchr (linkage_name
, '{') != NULL
)
10406 linkage_name
= NULL
;
10408 return linkage_name
;
10411 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10412 compute the physname for the object, which include a method's:
10413 - formal parameters (C++),
10414 - receiver type (Go),
10416 The term "physname" is a bit confusing.
10417 For C++, for example, it is the demangled name.
10418 For Go, for example, it's the mangled name.
10420 For Ada, return the DIE's linkage name rather than the fully qualified
10421 name. PHYSNAME is ignored..
10423 The result is allocated on the objfile->per_bfd's obstack and
10426 static const char *
10427 dwarf2_compute_name (const char *name
,
10428 struct die_info
*die
, struct dwarf2_cu
*cu
,
10431 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10434 name
= dwarf2_name (die
, cu
);
10436 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10437 but otherwise compute it by typename_concat inside GDB.
10438 FIXME: Actually this is not really true, or at least not always true.
10439 It's all very confusing. compute_and_set_names doesn't try to demangle
10440 Fortran names because there is no mangling standard. So new_symbol
10441 will set the demangled name to the result of dwarf2_full_name, and it is
10442 the demangled name that GDB uses if it exists. */
10443 if (cu
->language
== language_ada
10444 || (cu
->language
== language_fortran
&& physname
))
10446 /* For Ada unit, we prefer the linkage name over the name, as
10447 the former contains the exported name, which the user expects
10448 to be able to reference. Ideally, we want the user to be able
10449 to reference this entity using either natural or linkage name,
10450 but we haven't started looking at this enhancement yet. */
10451 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10453 if (linkage_name
!= NULL
)
10454 return linkage_name
;
10457 /* These are the only languages we know how to qualify names in. */
10459 && (cu
->language
== language_cplus
10460 || cu
->language
== language_fortran
|| cu
->language
== language_d
10461 || cu
->language
== language_rust
))
10463 if (die_needs_namespace (die
, cu
))
10465 const char *prefix
;
10466 const char *canonical_name
= NULL
;
10470 prefix
= determine_prefix (die
, cu
);
10471 if (*prefix
!= '\0')
10473 gdb::unique_xmalloc_ptr
<char> prefixed_name
10474 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10476 buf
.puts (prefixed_name
.get ());
10481 /* Template parameters may be specified in the DIE's DW_AT_name, or
10482 as children with DW_TAG_template_type_param or
10483 DW_TAG_value_type_param. If the latter, add them to the name
10484 here. If the name already has template parameters, then
10485 skip this step; some versions of GCC emit both, and
10486 it is more efficient to use the pre-computed name.
10488 Something to keep in mind about this process: it is very
10489 unlikely, or in some cases downright impossible, to produce
10490 something that will match the mangled name of a function.
10491 If the definition of the function has the same debug info,
10492 we should be able to match up with it anyway. But fallbacks
10493 using the minimal symbol, for instance to find a method
10494 implemented in a stripped copy of libstdc++, will not work.
10495 If we do not have debug info for the definition, we will have to
10496 match them up some other way.
10498 When we do name matching there is a related problem with function
10499 templates; two instantiated function templates are allowed to
10500 differ only by their return types, which we do not add here. */
10502 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10504 struct attribute
*attr
;
10505 struct die_info
*child
;
10507 const language_defn
*cplus_lang
= language_def (cu
->language
);
10509 die
->building_fullname
= 1;
10511 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10515 const gdb_byte
*bytes
;
10516 struct dwarf2_locexpr_baton
*baton
;
10519 if (child
->tag
!= DW_TAG_template_type_param
10520 && child
->tag
!= DW_TAG_template_value_param
)
10531 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10534 complaint (_("template parameter missing DW_AT_type"));
10535 buf
.puts ("UNKNOWN_TYPE");
10538 type
= die_type (child
, cu
);
10540 if (child
->tag
== DW_TAG_template_type_param
)
10542 cplus_lang
->print_type (type
, "", &buf
, -1, 0,
10543 &type_print_raw_options
);
10547 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10550 complaint (_("template parameter missing "
10551 "DW_AT_const_value"));
10552 buf
.puts ("UNKNOWN_VALUE");
10556 dwarf2_const_value_attr (attr
, type
, name
,
10557 &cu
->comp_unit_obstack
, cu
,
10558 &value
, &bytes
, &baton
);
10560 if (type
->has_no_signedness ())
10561 /* GDB prints characters as NUMBER 'CHAR'. If that's
10562 changed, this can use value_print instead. */
10563 cplus_lang
->printchar (value
, type
, &buf
);
10566 struct value_print_options opts
;
10569 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10573 baton
->per_objfile
);
10574 else if (bytes
!= NULL
)
10576 v
= allocate_value (type
);
10577 memcpy (value_contents_writeable (v
), bytes
,
10578 TYPE_LENGTH (type
));
10581 v
= value_from_longest (type
, value
);
10583 /* Specify decimal so that we do not depend on
10585 get_formatted_print_options (&opts
, 'd');
10587 value_print (v
, &buf
, &opts
);
10592 die
->building_fullname
= 0;
10596 /* Close the argument list, with a space if necessary
10597 (nested templates). */
10598 if (!buf
.empty () && buf
.string ().back () == '>')
10605 /* For C++ methods, append formal parameter type
10606 information, if PHYSNAME. */
10608 if (physname
&& die
->tag
== DW_TAG_subprogram
10609 && cu
->language
== language_cplus
)
10611 struct type
*type
= read_type_die (die
, cu
);
10613 c_type_print_args (type
, &buf
, 1, cu
->language
,
10614 &type_print_raw_options
);
10616 if (cu
->language
== language_cplus
)
10618 /* Assume that an artificial first parameter is
10619 "this", but do not crash if it is not. RealView
10620 marks unnamed (and thus unused) parameters as
10621 artificial; there is no way to differentiate
10623 if (type
->num_fields () > 0
10624 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10625 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10626 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10627 buf
.puts (" const");
10631 const std::string
&intermediate_name
= buf
.string ();
10633 if (cu
->language
== language_cplus
)
10635 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10638 /* If we only computed INTERMEDIATE_NAME, or if
10639 INTERMEDIATE_NAME is already canonical, then we need to
10641 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10642 name
= objfile
->intern (intermediate_name
);
10644 name
= canonical_name
;
10651 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10652 If scope qualifiers are appropriate they will be added. The result
10653 will be allocated on the storage_obstack, or NULL if the DIE does
10654 not have a name. NAME may either be from a previous call to
10655 dwarf2_name or NULL.
10657 The output string will be canonicalized (if C++). */
10659 static const char *
10660 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10662 return dwarf2_compute_name (name
, die
, cu
, 0);
10665 /* Construct a physname for the given DIE in CU. NAME may either be
10666 from a previous call to dwarf2_name or NULL. The result will be
10667 allocated on the objfile_objstack or NULL if the DIE does not have a
10670 The output string will be canonicalized (if C++). */
10672 static const char *
10673 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10675 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10676 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10679 /* In this case dwarf2_compute_name is just a shortcut not building anything
10681 if (!die_needs_namespace (die
, cu
))
10682 return dwarf2_compute_name (name
, die
, cu
, 1);
10684 if (cu
->language
!= language_rust
)
10685 mangled
= dw2_linkage_name (die
, cu
);
10687 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10689 gdb::unique_xmalloc_ptr
<char> demangled
;
10690 if (mangled
!= NULL
)
10693 if (language_def (cu
->language
)->store_sym_names_in_linkage_form_p ())
10695 /* Do nothing (do not demangle the symbol name). */
10699 /* Use DMGL_RET_DROP for C++ template functions to suppress
10700 their return type. It is easier for GDB users to search
10701 for such functions as `name(params)' than `long name(params)'.
10702 In such case the minimal symbol names do not match the full
10703 symbol names but for template functions there is never a need
10704 to look up their definition from their declaration so
10705 the only disadvantage remains the minimal symbol variant
10706 `long name(params)' does not have the proper inferior type. */
10707 demangled
.reset (gdb_demangle (mangled
,
10708 (DMGL_PARAMS
| DMGL_ANSI
10709 | DMGL_RET_DROP
)));
10712 canon
= demangled
.get ();
10720 if (canon
== NULL
|| check_physname
)
10722 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10724 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10726 /* It may not mean a bug in GDB. The compiler could also
10727 compute DW_AT_linkage_name incorrectly. But in such case
10728 GDB would need to be bug-to-bug compatible. */
10730 complaint (_("Computed physname <%s> does not match demangled <%s> "
10731 "(from linkage <%s>) - DIE at %s [in module %s]"),
10732 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10733 objfile_name (objfile
));
10735 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10736 is available here - over computed PHYSNAME. It is safer
10737 against both buggy GDB and buggy compilers. */
10751 retval
= objfile
->intern (retval
);
10756 /* Inspect DIE in CU for a namespace alias. If one exists, record
10757 a new symbol for it.
10759 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10762 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10764 struct attribute
*attr
;
10766 /* If the die does not have a name, this is not a namespace
10768 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10772 struct die_info
*d
= die
;
10773 struct dwarf2_cu
*imported_cu
= cu
;
10775 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10776 keep inspecting DIEs until we hit the underlying import. */
10777 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10778 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10780 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10784 d
= follow_die_ref (d
, attr
, &imported_cu
);
10785 if (d
->tag
!= DW_TAG_imported_declaration
)
10789 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10791 complaint (_("DIE at %s has too many recursively imported "
10792 "declarations"), sect_offset_str (d
->sect_off
));
10799 sect_offset sect_off
= attr
->get_ref_die_offset ();
10801 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10802 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10804 /* This declaration is a global namespace alias. Add
10805 a symbol for it whose type is the aliased namespace. */
10806 new_symbol (die
, type
, cu
);
10815 /* Return the using directives repository (global or local?) to use in the
10816 current context for CU.
10818 For Ada, imported declarations can materialize renamings, which *may* be
10819 global. However it is impossible (for now?) in DWARF to distinguish
10820 "external" imported declarations and "static" ones. As all imported
10821 declarations seem to be static in all other languages, make them all CU-wide
10822 global only in Ada. */
10824 static struct using_direct
**
10825 using_directives (struct dwarf2_cu
*cu
)
10827 if (cu
->language
== language_ada
10828 && cu
->get_builder ()->outermost_context_p ())
10829 return cu
->get_builder ()->get_global_using_directives ();
10831 return cu
->get_builder ()->get_local_using_directives ();
10834 /* Read the import statement specified by the given die and record it. */
10837 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10839 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10840 struct attribute
*import_attr
;
10841 struct die_info
*imported_die
, *child_die
;
10842 struct dwarf2_cu
*imported_cu
;
10843 const char *imported_name
;
10844 const char *imported_name_prefix
;
10845 const char *canonical_name
;
10846 const char *import_alias
;
10847 const char *imported_declaration
= NULL
;
10848 const char *import_prefix
;
10849 std::vector
<const char *> excludes
;
10851 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10852 if (import_attr
== NULL
)
10854 complaint (_("Tag '%s' has no DW_AT_import"),
10855 dwarf_tag_name (die
->tag
));
10860 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10861 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10862 if (imported_name
== NULL
)
10864 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10866 The import in the following code:
10880 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10881 <52> DW_AT_decl_file : 1
10882 <53> DW_AT_decl_line : 6
10883 <54> DW_AT_import : <0x75>
10884 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10885 <59> DW_AT_name : B
10886 <5b> DW_AT_decl_file : 1
10887 <5c> DW_AT_decl_line : 2
10888 <5d> DW_AT_type : <0x6e>
10890 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10891 <76> DW_AT_byte_size : 4
10892 <77> DW_AT_encoding : 5 (signed)
10894 imports the wrong die ( 0x75 instead of 0x58 ).
10895 This case will be ignored until the gcc bug is fixed. */
10899 /* Figure out the local name after import. */
10900 import_alias
= dwarf2_name (die
, cu
);
10902 /* Figure out where the statement is being imported to. */
10903 import_prefix
= determine_prefix (die
, cu
);
10905 /* Figure out what the scope of the imported die is and prepend it
10906 to the name of the imported die. */
10907 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10909 if (imported_die
->tag
!= DW_TAG_namespace
10910 && imported_die
->tag
!= DW_TAG_module
)
10912 imported_declaration
= imported_name
;
10913 canonical_name
= imported_name_prefix
;
10915 else if (strlen (imported_name_prefix
) > 0)
10916 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10917 imported_name_prefix
,
10918 (cu
->language
== language_d
? "." : "::"),
10919 imported_name
, (char *) NULL
);
10921 canonical_name
= imported_name
;
10923 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10924 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10925 child_die
= child_die
->sibling
)
10927 /* DWARF-4: A Fortran use statement with a “rename list” may be
10928 represented by an imported module entry with an import attribute
10929 referring to the module and owned entries corresponding to those
10930 entities that are renamed as part of being imported. */
10932 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10934 complaint (_("child DW_TAG_imported_declaration expected "
10935 "- DIE at %s [in module %s]"),
10936 sect_offset_str (child_die
->sect_off
),
10937 objfile_name (objfile
));
10941 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10942 if (import_attr
== NULL
)
10944 complaint (_("Tag '%s' has no DW_AT_import"),
10945 dwarf_tag_name (child_die
->tag
));
10950 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10952 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10953 if (imported_name
== NULL
)
10955 complaint (_("child DW_TAG_imported_declaration has unknown "
10956 "imported name - DIE at %s [in module %s]"),
10957 sect_offset_str (child_die
->sect_off
),
10958 objfile_name (objfile
));
10962 excludes
.push_back (imported_name
);
10964 process_die (child_die
, cu
);
10967 add_using_directive (using_directives (cu
),
10971 imported_declaration
,
10974 &objfile
->objfile_obstack
);
10977 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10978 types, but gives them a size of zero. Starting with version 14,
10979 ICC is compatible with GCC. */
10982 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10984 if (!cu
->checked_producer
)
10985 check_producer (cu
);
10987 return cu
->producer_is_icc_lt_14
;
10990 /* ICC generates a DW_AT_type for C void functions. This was observed on
10991 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10992 which says that void functions should not have a DW_AT_type. */
10995 producer_is_icc (struct dwarf2_cu
*cu
)
10997 if (!cu
->checked_producer
)
10998 check_producer (cu
);
11000 return cu
->producer_is_icc
;
11003 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11004 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11005 this, it was first present in GCC release 4.3.0. */
11008 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11010 if (!cu
->checked_producer
)
11011 check_producer (cu
);
11013 return cu
->producer_is_gcc_lt_4_3
;
11016 static file_and_directory
11017 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11019 file_and_directory res
;
11021 /* Find the filename. Do not use dwarf2_name here, since the filename
11022 is not a source language identifier. */
11023 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11024 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11026 if (res
.comp_dir
== NULL
11027 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11028 && IS_ABSOLUTE_PATH (res
.name
))
11030 res
.comp_dir_storage
= ldirname (res
.name
);
11031 if (!res
.comp_dir_storage
.empty ())
11032 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11034 if (res
.comp_dir
!= NULL
)
11036 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11037 directory, get rid of it. */
11038 const char *cp
= strchr (res
.comp_dir
, ':');
11040 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11041 res
.comp_dir
= cp
+ 1;
11044 if (res
.name
== NULL
)
11045 res
.name
= "<unknown>";
11050 /* Handle DW_AT_stmt_list for a compilation unit.
11051 DIE is the DW_TAG_compile_unit die for CU.
11052 COMP_DIR is the compilation directory. LOWPC is passed to
11053 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11056 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11057 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11059 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11060 struct attribute
*attr
;
11061 struct line_header line_header_local
;
11062 hashval_t line_header_local_hash
;
11064 int decode_mapping
;
11066 gdb_assert (! cu
->per_cu
->is_debug_types
);
11068 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11069 if (attr
== NULL
|| !attr
->form_is_unsigned ())
11072 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11074 /* The line header hash table is only created if needed (it exists to
11075 prevent redundant reading of the line table for partial_units).
11076 If we're given a partial_unit, we'll need it. If we're given a
11077 compile_unit, then use the line header hash table if it's already
11078 created, but don't create one just yet. */
11080 if (per_objfile
->line_header_hash
== NULL
11081 && die
->tag
== DW_TAG_partial_unit
)
11083 per_objfile
->line_header_hash
11084 .reset (htab_create_alloc (127, line_header_hash_voidp
,
11085 line_header_eq_voidp
,
11086 free_line_header_voidp
,
11090 line_header_local
.sect_off
= line_offset
;
11091 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11092 line_header_local_hash
= line_header_hash (&line_header_local
);
11093 if (per_objfile
->line_header_hash
!= NULL
)
11095 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11096 &line_header_local
,
11097 line_header_local_hash
, NO_INSERT
);
11099 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11100 is not present in *SLOT (since if there is something in *SLOT then
11101 it will be for a partial_unit). */
11102 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11104 gdb_assert (*slot
!= NULL
);
11105 cu
->line_header
= (struct line_header
*) *slot
;
11110 /* dwarf_decode_line_header does not yet provide sufficient information.
11111 We always have to call also dwarf_decode_lines for it. */
11112 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11116 cu
->line_header
= lh
.release ();
11117 cu
->line_header_die_owner
= die
;
11119 if (per_objfile
->line_header_hash
== NULL
)
11123 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11124 &line_header_local
,
11125 line_header_local_hash
, INSERT
);
11126 gdb_assert (slot
!= NULL
);
11128 if (slot
!= NULL
&& *slot
== NULL
)
11130 /* This newly decoded line number information unit will be owned
11131 by line_header_hash hash table. */
11132 *slot
= cu
->line_header
;
11133 cu
->line_header_die_owner
= NULL
;
11137 /* We cannot free any current entry in (*slot) as that struct line_header
11138 may be already used by multiple CUs. Create only temporary decoded
11139 line_header for this CU - it may happen at most once for each line
11140 number information unit. And if we're not using line_header_hash
11141 then this is what we want as well. */
11142 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11144 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11145 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11150 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11153 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11155 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11156 struct objfile
*objfile
= per_objfile
->objfile
;
11157 struct gdbarch
*gdbarch
= objfile
->arch ();
11158 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11159 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11160 struct attribute
*attr
;
11161 struct die_info
*child_die
;
11162 CORE_ADDR baseaddr
;
11164 prepare_one_comp_unit (cu
, die
, cu
->language
);
11165 baseaddr
= objfile
->text_section_offset ();
11167 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11169 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11170 from finish_block. */
11171 if (lowpc
== ((CORE_ADDR
) -1))
11173 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11175 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11177 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11178 standardised yet. As a workaround for the language detection we fall
11179 back to the DW_AT_producer string. */
11180 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11181 cu
->language
= language_opencl
;
11183 /* Similar hack for Go. */
11184 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11185 set_cu_language (DW_LANG_Go
, cu
);
11187 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11189 /* Decode line number information if present. We do this before
11190 processing child DIEs, so that the line header table is available
11191 for DW_AT_decl_file. */
11192 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11194 /* Process all dies in compilation unit. */
11195 if (die
->child
!= NULL
)
11197 child_die
= die
->child
;
11198 while (child_die
&& child_die
->tag
)
11200 process_die (child_die
, cu
);
11201 child_die
= child_die
->sibling
;
11205 /* Decode macro information, if present. Dwarf 2 macro information
11206 refers to information in the line number info statement program
11207 header, so we can only read it if we've read the header
11209 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11211 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11212 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11214 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11215 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11217 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
11221 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11222 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11224 unsigned int macro_offset
= attr
->as_unsigned ();
11226 dwarf_decode_macros (cu
, macro_offset
, 0);
11232 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11234 struct type_unit_group
*tu_group
;
11236 struct attribute
*attr
;
11238 struct signatured_type
*sig_type
;
11240 gdb_assert (per_cu
->is_debug_types
);
11241 sig_type
= (struct signatured_type
*) per_cu
;
11243 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11245 /* If we're using .gdb_index (includes -readnow) then
11246 per_cu->type_unit_group may not have been set up yet. */
11247 if (sig_type
->type_unit_group
== NULL
)
11248 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11249 tu_group
= sig_type
->type_unit_group
;
11251 /* If we've already processed this stmt_list there's no real need to
11252 do it again, we could fake it and just recreate the part we need
11253 (file name,index -> symtab mapping). If data shows this optimization
11254 is useful we can do it then. */
11255 type_unit_group_unshareable
*tug_unshare
11256 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11257 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11259 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11262 if (attr
!= NULL
&& attr
->form_is_unsigned ())
11264 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11265 lh
= dwarf_decode_line_header (line_offset
, this);
11270 start_symtab ("", NULL
, 0);
11273 gdb_assert (tug_unshare
->symtabs
== NULL
);
11274 gdb_assert (m_builder
== nullptr);
11275 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11276 m_builder
.reset (new struct buildsym_compunit
11277 (COMPUNIT_OBJFILE (cust
), "",
11278 COMPUNIT_DIRNAME (cust
),
11279 compunit_language (cust
),
11281 list_in_scope
= get_builder ()->get_file_symbols ();
11286 line_header
= lh
.release ();
11287 line_header_die_owner
= die
;
11291 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11293 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11294 still initializing it, and our caller (a few levels up)
11295 process_full_type_unit still needs to know if this is the first
11298 tug_unshare
->symtabs
11299 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11300 struct symtab
*, line_header
->file_names_size ());
11302 auto &file_names
= line_header
->file_names ();
11303 for (i
= 0; i
< file_names
.size (); ++i
)
11305 file_entry
&fe
= file_names
[i
];
11306 dwarf2_start_subfile (this, fe
.name
,
11307 fe
.include_dir (line_header
));
11308 buildsym_compunit
*b
= get_builder ();
11309 if (b
->get_current_subfile ()->symtab
== NULL
)
11311 /* NOTE: start_subfile will recognize when it's been
11312 passed a file it has already seen. So we can't
11313 assume there's a simple mapping from
11314 cu->line_header->file_names to subfiles, plus
11315 cu->line_header->file_names may contain dups. */
11316 b
->get_current_subfile ()->symtab
11317 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11320 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11321 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11326 gdb_assert (m_builder
== nullptr);
11327 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11328 m_builder
.reset (new struct buildsym_compunit
11329 (COMPUNIT_OBJFILE (cust
), "",
11330 COMPUNIT_DIRNAME (cust
),
11331 compunit_language (cust
),
11333 list_in_scope
= get_builder ()->get_file_symbols ();
11335 auto &file_names
= line_header
->file_names ();
11336 for (i
= 0; i
< file_names
.size (); ++i
)
11338 file_entry
&fe
= file_names
[i
];
11339 fe
.symtab
= tug_unshare
->symtabs
[i
];
11343 /* The main symtab is allocated last. Type units don't have DW_AT_name
11344 so they don't have a "real" (so to speak) symtab anyway.
11345 There is later code that will assign the main symtab to all symbols
11346 that don't have one. We need to handle the case of a symbol with a
11347 missing symtab (DW_AT_decl_file) anyway. */
11350 /* Process DW_TAG_type_unit.
11351 For TUs we want to skip the first top level sibling if it's not the
11352 actual type being defined by this TU. In this case the first top
11353 level sibling is there to provide context only. */
11356 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11358 struct die_info
*child_die
;
11360 prepare_one_comp_unit (cu
, die
, language_minimal
);
11362 /* Initialize (or reinitialize) the machinery for building symtabs.
11363 We do this before processing child DIEs, so that the line header table
11364 is available for DW_AT_decl_file. */
11365 cu
->setup_type_unit_groups (die
);
11367 if (die
->child
!= NULL
)
11369 child_die
= die
->child
;
11370 while (child_die
&& child_die
->tag
)
11372 process_die (child_die
, cu
);
11373 child_die
= child_die
->sibling
;
11380 http://gcc.gnu.org/wiki/DebugFission
11381 http://gcc.gnu.org/wiki/DebugFissionDWP
11383 To simplify handling of both DWO files ("object" files with the DWARF info)
11384 and DWP files (a file with the DWOs packaged up into one file), we treat
11385 DWP files as having a collection of virtual DWO files. */
11388 hash_dwo_file (const void *item
)
11390 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11393 hash
= htab_hash_string (dwo_file
->dwo_name
);
11394 if (dwo_file
->comp_dir
!= NULL
)
11395 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11400 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11402 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11403 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11405 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11407 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11408 return lhs
->comp_dir
== rhs
->comp_dir
;
11409 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11412 /* Allocate a hash table for DWO files. */
11415 allocate_dwo_file_hash_table ()
11417 auto delete_dwo_file
= [] (void *item
)
11419 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11424 return htab_up (htab_create_alloc (41,
11431 /* Lookup DWO file DWO_NAME. */
11434 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11435 const char *dwo_name
,
11436 const char *comp_dir
)
11438 struct dwo_file find_entry
;
11441 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11442 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11444 find_entry
.dwo_name
= dwo_name
;
11445 find_entry
.comp_dir
= comp_dir
;
11446 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11453 hash_dwo_unit (const void *item
)
11455 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11457 /* This drops the top 32 bits of the id, but is ok for a hash. */
11458 return dwo_unit
->signature
;
11462 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11464 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11465 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11467 /* The signature is assumed to be unique within the DWO file.
11468 So while object file CU dwo_id's always have the value zero,
11469 that's OK, assuming each object file DWO file has only one CU,
11470 and that's the rule for now. */
11471 return lhs
->signature
== rhs
->signature
;
11474 /* Allocate a hash table for DWO CUs,TUs.
11475 There is one of these tables for each of CUs,TUs for each DWO file. */
11478 allocate_dwo_unit_table ()
11480 /* Start out with a pretty small number.
11481 Generally DWO files contain only one CU and maybe some TUs. */
11482 return htab_up (htab_create_alloc (3,
11485 NULL
, xcalloc
, xfree
));
11488 /* die_reader_func for create_dwo_cu. */
11491 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11492 const gdb_byte
*info_ptr
,
11493 struct die_info
*comp_unit_die
,
11494 struct dwo_file
*dwo_file
,
11495 struct dwo_unit
*dwo_unit
)
11497 struct dwarf2_cu
*cu
= reader
->cu
;
11498 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11499 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11501 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11502 if (!signature
.has_value ())
11504 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11505 " its dwo_id [in module %s]"),
11506 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11510 dwo_unit
->dwo_file
= dwo_file
;
11511 dwo_unit
->signature
= *signature
;
11512 dwo_unit
->section
= section
;
11513 dwo_unit
->sect_off
= sect_off
;
11514 dwo_unit
->length
= cu
->per_cu
->length
;
11516 dwarf_read_debug_printf (" offset %s, dwo_id %s",
11517 sect_offset_str (sect_off
),
11518 hex_string (dwo_unit
->signature
));
11521 /* Create the dwo_units for the CUs in a DWO_FILE.
11522 Note: This function processes DWO files only, not DWP files. */
11525 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11526 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11527 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11529 struct objfile
*objfile
= per_objfile
->objfile
;
11530 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11531 const gdb_byte
*info_ptr
, *end_ptr
;
11533 section
.read (objfile
);
11534 info_ptr
= section
.buffer
;
11536 if (info_ptr
== NULL
)
11539 dwarf_read_debug_printf ("Reading %s for %s:",
11540 section
.get_name (),
11541 section
.get_file_name ());
11543 end_ptr
= info_ptr
+ section
.size
;
11544 while (info_ptr
< end_ptr
)
11546 struct dwarf2_per_cu_data per_cu
;
11547 struct dwo_unit read_unit
{};
11548 struct dwo_unit
*dwo_unit
;
11550 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11552 memset (&per_cu
, 0, sizeof (per_cu
));
11553 per_cu
.per_bfd
= per_bfd
;
11554 per_cu
.is_debug_types
= 0;
11555 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11556 per_cu
.section
= §ion
;
11558 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11559 if (!reader
.dummy_p
)
11560 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11561 &dwo_file
, &read_unit
);
11562 info_ptr
+= per_cu
.length
;
11564 // If the unit could not be parsed, skip it.
11565 if (read_unit
.dwo_file
== NULL
)
11568 if (cus_htab
== NULL
)
11569 cus_htab
= allocate_dwo_unit_table ();
11571 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11573 *dwo_unit
= read_unit
;
11574 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11575 gdb_assert (slot
!= NULL
);
11578 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11579 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11581 complaint (_("debug cu entry at offset %s is duplicate to"
11582 " the entry at offset %s, signature %s"),
11583 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11584 hex_string (dwo_unit
->signature
));
11586 *slot
= (void *)dwo_unit
;
11590 /* DWP file .debug_{cu,tu}_index section format:
11591 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11592 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11594 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11595 officially standard DWP format was published with DWARF v5 and is called
11596 Version 5. There are no versions 3 or 4.
11600 Both index sections have the same format, and serve to map a 64-bit
11601 signature to a set of section numbers. Each section begins with a header,
11602 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11603 indexes, and a pool of 32-bit section numbers. The index sections will be
11604 aligned at 8-byte boundaries in the file.
11606 The index section header consists of:
11608 V, 32 bit version number
11610 N, 32 bit number of compilation units or type units in the index
11611 M, 32 bit number of slots in the hash table
11613 Numbers are recorded using the byte order of the application binary.
11615 The hash table begins at offset 16 in the section, and consists of an array
11616 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11617 order of the application binary). Unused slots in the hash table are 0.
11618 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11620 The parallel table begins immediately after the hash table
11621 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11622 array of 32-bit indexes (using the byte order of the application binary),
11623 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11624 table contains a 32-bit index into the pool of section numbers. For unused
11625 hash table slots, the corresponding entry in the parallel table will be 0.
11627 The pool of section numbers begins immediately following the hash table
11628 (at offset 16 + 12 * M from the beginning of the section). The pool of
11629 section numbers consists of an array of 32-bit words (using the byte order
11630 of the application binary). Each item in the array is indexed starting
11631 from 0. The hash table entry provides the index of the first section
11632 number in the set. Additional section numbers in the set follow, and the
11633 set is terminated by a 0 entry (section number 0 is not used in ELF).
11635 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11636 section must be the first entry in the set, and the .debug_abbrev.dwo must
11637 be the second entry. Other members of the set may follow in any order.
11641 DWP Versions 2 and 5:
11643 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11644 and the entries in the index tables are now offsets into these sections.
11645 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11648 Index Section Contents:
11650 Hash Table of Signatures dwp_hash_table.hash_table
11651 Parallel Table of Indices dwp_hash_table.unit_table
11652 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11653 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11655 The index section header consists of:
11657 V, 32 bit version number
11658 L, 32 bit number of columns in the table of section offsets
11659 N, 32 bit number of compilation units or type units in the index
11660 M, 32 bit number of slots in the hash table
11662 Numbers are recorded using the byte order of the application binary.
11664 The hash table has the same format as version 1.
11665 The parallel table of indices has the same format as version 1,
11666 except that the entries are origin-1 indices into the table of sections
11667 offsets and the table of section sizes.
11669 The table of offsets begins immediately following the parallel table
11670 (at offset 16 + 12 * M from the beginning of the section). The table is
11671 a two-dimensional array of 32-bit words (using the byte order of the
11672 application binary), with L columns and N+1 rows, in row-major order.
11673 Each row in the array is indexed starting from 0. The first row provides
11674 a key to the remaining rows: each column in this row provides an identifier
11675 for a debug section, and the offsets in the same column of subsequent rows
11676 refer to that section. The section identifiers for Version 2 are:
11678 DW_SECT_INFO 1 .debug_info.dwo
11679 DW_SECT_TYPES 2 .debug_types.dwo
11680 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11681 DW_SECT_LINE 4 .debug_line.dwo
11682 DW_SECT_LOC 5 .debug_loc.dwo
11683 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11684 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11685 DW_SECT_MACRO 8 .debug_macro.dwo
11687 The section identifiers for Version 5 are:
11689 DW_SECT_INFO_V5 1 .debug_info.dwo
11690 DW_SECT_RESERVED_V5 2 --
11691 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11692 DW_SECT_LINE_V5 4 .debug_line.dwo
11693 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11694 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11695 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11696 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11698 The offsets provided by the CU and TU index sections are the base offsets
11699 for the contributions made by each CU or TU to the corresponding section
11700 in the package file. Each CU and TU header contains an abbrev_offset
11701 field, used to find the abbreviations table for that CU or TU within the
11702 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11703 be interpreted as relative to the base offset given in the index section.
11704 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11705 should be interpreted as relative to the base offset for .debug_line.dwo,
11706 and offsets into other debug sections obtained from DWARF attributes should
11707 also be interpreted as relative to the corresponding base offset.
11709 The table of sizes begins immediately following the table of offsets.
11710 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11711 with L columns and N rows, in row-major order. Each row in the array is
11712 indexed starting from 1 (row 0 is shared by the two tables).
11716 Hash table lookup is handled the same in version 1 and 2:
11718 We assume that N and M will not exceed 2^32 - 1.
11719 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11721 Given a 64-bit compilation unit signature or a type signature S, an entry
11722 in the hash table is located as follows:
11724 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11725 the low-order k bits all set to 1.
11727 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11729 3) If the hash table entry at index H matches the signature, use that
11730 entry. If the hash table entry at index H is unused (all zeroes),
11731 terminate the search: the signature is not present in the table.
11733 4) Let H = (H + H') modulo M. Repeat at Step 3.
11735 Because M > N and H' and M are relatively prime, the search is guaranteed
11736 to stop at an unused slot or find the match. */
11738 /* Create a hash table to map DWO IDs to their CU/TU entry in
11739 .debug_{info,types}.dwo in DWP_FILE.
11740 Returns NULL if there isn't one.
11741 Note: This function processes DWP files only, not DWO files. */
11743 static struct dwp_hash_table
*
11744 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11745 struct dwp_file
*dwp_file
, int is_debug_types
)
11747 struct objfile
*objfile
= per_objfile
->objfile
;
11748 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11749 const gdb_byte
*index_ptr
, *index_end
;
11750 struct dwarf2_section_info
*index
;
11751 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11752 struct dwp_hash_table
*htab
;
11754 if (is_debug_types
)
11755 index
= &dwp_file
->sections
.tu_index
;
11757 index
= &dwp_file
->sections
.cu_index
;
11759 if (index
->empty ())
11761 index
->read (objfile
);
11763 index_ptr
= index
->buffer
;
11764 index_end
= index_ptr
+ index
->size
;
11766 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11767 For now it's safe to just read 4 bytes (particularly as it's difficult to
11768 tell if you're dealing with Version 5 before you've read the version). */
11769 version
= read_4_bytes (dbfd
, index_ptr
);
11771 if (version
== 2 || version
== 5)
11772 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11776 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11778 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11781 if (version
!= 1 && version
!= 2 && version
!= 5)
11783 error (_("Dwarf Error: unsupported DWP file version (%s)"
11784 " [in module %s]"),
11785 pulongest (version
), dwp_file
->name
);
11787 if (nr_slots
!= (nr_slots
& -nr_slots
))
11789 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11790 " is not power of 2 [in module %s]"),
11791 pulongest (nr_slots
), dwp_file
->name
);
11794 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11795 htab
->version
= version
;
11796 htab
->nr_columns
= nr_columns
;
11797 htab
->nr_units
= nr_units
;
11798 htab
->nr_slots
= nr_slots
;
11799 htab
->hash_table
= index_ptr
;
11800 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11802 /* Exit early if the table is empty. */
11803 if (nr_slots
== 0 || nr_units
== 0
11804 || (version
== 2 && nr_columns
== 0)
11805 || (version
== 5 && nr_columns
== 0))
11807 /* All must be zero. */
11808 if (nr_slots
!= 0 || nr_units
!= 0
11809 || (version
== 2 && nr_columns
!= 0)
11810 || (version
== 5 && nr_columns
!= 0))
11812 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11813 " all zero [in modules %s]"),
11821 htab
->section_pool
.v1
.indices
=
11822 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11823 /* It's harder to decide whether the section is too small in v1.
11824 V1 is deprecated anyway so we punt. */
11826 else if (version
== 2)
11828 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11829 int *ids
= htab
->section_pool
.v2
.section_ids
;
11830 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11831 /* Reverse map for error checking. */
11832 int ids_seen
[DW_SECT_MAX
+ 1];
11835 if (nr_columns
< 2)
11837 error (_("Dwarf Error: bad DWP hash table, too few columns"
11838 " in section table [in module %s]"),
11841 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11843 error (_("Dwarf Error: bad DWP hash table, too many columns"
11844 " in section table [in module %s]"),
11847 memset (ids
, 255, sizeof_ids
);
11848 memset (ids_seen
, 255, sizeof (ids_seen
));
11849 for (i
= 0; i
< nr_columns
; ++i
)
11851 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11853 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11855 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11856 " in section table [in module %s]"),
11857 id
, dwp_file
->name
);
11859 if (ids_seen
[id
] != -1)
11861 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11862 " id %d in section table [in module %s]"),
11863 id
, dwp_file
->name
);
11868 /* Must have exactly one info or types section. */
11869 if (((ids_seen
[DW_SECT_INFO
] != -1)
11870 + (ids_seen
[DW_SECT_TYPES
] != -1))
11873 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11874 " DWO info/types section [in module %s]"),
11877 /* Must have an abbrev section. */
11878 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11880 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11881 " section [in module %s]"),
11884 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11885 htab
->section_pool
.v2
.sizes
=
11886 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11887 * nr_units
* nr_columns
);
11888 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11889 * nr_units
* nr_columns
))
11892 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11893 " [in module %s]"),
11897 else /* version == 5 */
11899 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11900 int *ids
= htab
->section_pool
.v5
.section_ids
;
11901 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
11902 /* Reverse map for error checking. */
11903 int ids_seen
[DW_SECT_MAX_V5
+ 1];
11905 if (nr_columns
< 2)
11907 error (_("Dwarf Error: bad DWP hash table, too few columns"
11908 " in section table [in module %s]"),
11911 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
11913 error (_("Dwarf Error: bad DWP hash table, too many columns"
11914 " in section table [in module %s]"),
11917 memset (ids
, 255, sizeof_ids
);
11918 memset (ids_seen
, 255, sizeof (ids_seen
));
11919 for (int i
= 0; i
< nr_columns
; ++i
)
11921 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11923 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
11925 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11926 " in section table [in module %s]"),
11927 id
, dwp_file
->name
);
11929 if (ids_seen
[id
] != -1)
11931 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11932 " id %d in section table [in module %s]"),
11933 id
, dwp_file
->name
);
11938 /* Must have seen an info section. */
11939 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
11941 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11942 " DWO info/types section [in module %s]"),
11945 /* Must have an abbrev section. */
11946 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
11948 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11949 " section [in module %s]"),
11952 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11953 htab
->section_pool
.v5
.sizes
11954 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
11955 * nr_units
* nr_columns
);
11956 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
11957 * nr_units
* nr_columns
))
11960 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11961 " [in module %s]"),
11969 /* Update SECTIONS with the data from SECTP.
11971 This function is like the other "locate" section routines, but in
11972 this context the sections to read comes from the DWP V1 hash table,
11973 not the full ELF section table.
11975 The result is non-zero for success, or zero if an error was found. */
11978 locate_v1_virtual_dwo_sections (asection
*sectp
,
11979 struct virtual_v1_dwo_sections
*sections
)
11981 const struct dwop_section_names
*names
= &dwop_section_names
;
11983 if (names
->abbrev_dwo
.matches (sectp
->name
))
11985 /* There can be only one. */
11986 if (sections
->abbrev
.s
.section
!= NULL
)
11988 sections
->abbrev
.s
.section
= sectp
;
11989 sections
->abbrev
.size
= bfd_section_size (sectp
);
11991 else if (names
->info_dwo
.matches (sectp
->name
)
11992 || names
->types_dwo
.matches (sectp
->name
))
11994 /* There can be only one. */
11995 if (sections
->info_or_types
.s
.section
!= NULL
)
11997 sections
->info_or_types
.s
.section
= sectp
;
11998 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12000 else if (names
->line_dwo
.matches (sectp
->name
))
12002 /* There can be only one. */
12003 if (sections
->line
.s
.section
!= NULL
)
12005 sections
->line
.s
.section
= sectp
;
12006 sections
->line
.size
= bfd_section_size (sectp
);
12008 else if (names
->loc_dwo
.matches (sectp
->name
))
12010 /* There can be only one. */
12011 if (sections
->loc
.s
.section
!= NULL
)
12013 sections
->loc
.s
.section
= sectp
;
12014 sections
->loc
.size
= bfd_section_size (sectp
);
12016 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12018 /* There can be only one. */
12019 if (sections
->macinfo
.s
.section
!= NULL
)
12021 sections
->macinfo
.s
.section
= sectp
;
12022 sections
->macinfo
.size
= bfd_section_size (sectp
);
12024 else if (names
->macro_dwo
.matches (sectp
->name
))
12026 /* There can be only one. */
12027 if (sections
->macro
.s
.section
!= NULL
)
12029 sections
->macro
.s
.section
= sectp
;
12030 sections
->macro
.size
= bfd_section_size (sectp
);
12032 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12034 /* There can be only one. */
12035 if (sections
->str_offsets
.s
.section
!= NULL
)
12037 sections
->str_offsets
.s
.section
= sectp
;
12038 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12042 /* No other kind of section is valid. */
12049 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12050 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12051 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12052 This is for DWP version 1 files. */
12054 static struct dwo_unit
*
12055 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
12056 struct dwp_file
*dwp_file
,
12057 uint32_t unit_index
,
12058 const char *comp_dir
,
12059 ULONGEST signature
, int is_debug_types
)
12061 const struct dwp_hash_table
*dwp_htab
=
12062 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12063 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12064 const char *kind
= is_debug_types
? "TU" : "CU";
12065 struct dwo_file
*dwo_file
;
12066 struct dwo_unit
*dwo_unit
;
12067 struct virtual_v1_dwo_sections sections
;
12068 void **dwo_file_slot
;
12071 gdb_assert (dwp_file
->version
== 1);
12073 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
12074 kind
, pulongest (unit_index
), hex_string (signature
),
12077 /* Fetch the sections of this DWO unit.
12078 Put a limit on the number of sections we look for so that bad data
12079 doesn't cause us to loop forever. */
12081 #define MAX_NR_V1_DWO_SECTIONS \
12082 (1 /* .debug_info or .debug_types */ \
12083 + 1 /* .debug_abbrev */ \
12084 + 1 /* .debug_line */ \
12085 + 1 /* .debug_loc */ \
12086 + 1 /* .debug_str_offsets */ \
12087 + 1 /* .debug_macro or .debug_macinfo */ \
12088 + 1 /* trailing zero */)
12090 memset (§ions
, 0, sizeof (sections
));
12092 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12095 uint32_t section_nr
=
12096 read_4_bytes (dbfd
,
12097 dwp_htab
->section_pool
.v1
.indices
12098 + (unit_index
+ i
) * sizeof (uint32_t));
12100 if (section_nr
== 0)
12102 if (section_nr
>= dwp_file
->num_sections
)
12104 error (_("Dwarf Error: bad DWP hash table, section number too large"
12105 " [in module %s]"),
12109 sectp
= dwp_file
->elf_sections
[section_nr
];
12110 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12112 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12113 " [in module %s]"),
12119 || sections
.info_or_types
.empty ()
12120 || sections
.abbrev
.empty ())
12122 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12123 " [in module %s]"),
12126 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12128 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12129 " [in module %s]"),
12133 /* It's easier for the rest of the code if we fake a struct dwo_file and
12134 have dwo_unit "live" in that. At least for now.
12136 The DWP file can be made up of a random collection of CUs and TUs.
12137 However, for each CU + set of TUs that came from the same original DWO
12138 file, we can combine them back into a virtual DWO file to save space
12139 (fewer struct dwo_file objects to allocate). Remember that for really
12140 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12142 std::string virtual_dwo_name
=
12143 string_printf ("virtual-dwo/%d-%d-%d-%d",
12144 sections
.abbrev
.get_id (),
12145 sections
.line
.get_id (),
12146 sections
.loc
.get_id (),
12147 sections
.str_offsets
.get_id ());
12148 /* Can we use an existing virtual DWO file? */
12149 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12151 /* Create one if necessary. */
12152 if (*dwo_file_slot
== NULL
)
12154 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12155 virtual_dwo_name
.c_str ());
12157 dwo_file
= new struct dwo_file
;
12158 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12159 dwo_file
->comp_dir
= comp_dir
;
12160 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12161 dwo_file
->sections
.line
= sections
.line
;
12162 dwo_file
->sections
.loc
= sections
.loc
;
12163 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12164 dwo_file
->sections
.macro
= sections
.macro
;
12165 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12166 /* The "str" section is global to the entire DWP file. */
12167 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12168 /* The info or types section is assigned below to dwo_unit,
12169 there's no need to record it in dwo_file.
12170 Also, we can't simply record type sections in dwo_file because
12171 we record a pointer into the vector in dwo_unit. As we collect more
12172 types we'll grow the vector and eventually have to reallocate space
12173 for it, invalidating all copies of pointers into the previous
12175 *dwo_file_slot
= dwo_file
;
12179 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12180 virtual_dwo_name
.c_str ());
12182 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12185 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12186 dwo_unit
->dwo_file
= dwo_file
;
12187 dwo_unit
->signature
= signature
;
12188 dwo_unit
->section
=
12189 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12190 *dwo_unit
->section
= sections
.info_or_types
;
12191 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12196 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
12197 simplify them. Given a pointer to the containing section SECTION, and
12198 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
12199 virtual section of just that piece. */
12201 static struct dwarf2_section_info
12202 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
12203 struct dwarf2_section_info
*section
,
12204 bfd_size_type offset
, bfd_size_type size
)
12206 struct dwarf2_section_info result
;
12209 gdb_assert (section
!= NULL
);
12210 gdb_assert (!section
->is_virtual
);
12212 memset (&result
, 0, sizeof (result
));
12213 result
.s
.containing_section
= section
;
12214 result
.is_virtual
= true;
12219 sectp
= section
->get_bfd_section ();
12221 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12222 bounds of the real section. This is a pretty-rare event, so just
12223 flag an error (easier) instead of a warning and trying to cope. */
12225 || offset
+ size
> bfd_section_size (sectp
))
12227 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
12228 " in section %s [in module %s]"),
12229 sectp
? bfd_section_name (sectp
) : "<unknown>",
12230 objfile_name (per_objfile
->objfile
));
12233 result
.virtual_offset
= offset
;
12234 result
.size
= size
;
12238 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12239 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12240 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12241 This is for DWP version 2 files. */
12243 static struct dwo_unit
*
12244 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
12245 struct dwp_file
*dwp_file
,
12246 uint32_t unit_index
,
12247 const char *comp_dir
,
12248 ULONGEST signature
, int is_debug_types
)
12250 const struct dwp_hash_table
*dwp_htab
=
12251 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12252 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12253 const char *kind
= is_debug_types
? "TU" : "CU";
12254 struct dwo_file
*dwo_file
;
12255 struct dwo_unit
*dwo_unit
;
12256 struct virtual_v2_or_v5_dwo_sections sections
;
12257 void **dwo_file_slot
;
12260 gdb_assert (dwp_file
->version
== 2);
12262 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
12263 kind
, pulongest (unit_index
), hex_string (signature
),
12266 /* Fetch the section offsets of this DWO unit. */
12268 memset (§ions
, 0, sizeof (sections
));
12270 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12272 uint32_t offset
= read_4_bytes (dbfd
,
12273 dwp_htab
->section_pool
.v2
.offsets
12274 + (((unit_index
- 1) * dwp_htab
->nr_columns
12276 * sizeof (uint32_t)));
12277 uint32_t size
= read_4_bytes (dbfd
,
12278 dwp_htab
->section_pool
.v2
.sizes
12279 + (((unit_index
- 1) * dwp_htab
->nr_columns
12281 * sizeof (uint32_t)));
12283 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12286 case DW_SECT_TYPES
:
12287 sections
.info_or_types_offset
= offset
;
12288 sections
.info_or_types_size
= size
;
12290 case DW_SECT_ABBREV
:
12291 sections
.abbrev_offset
= offset
;
12292 sections
.abbrev_size
= size
;
12295 sections
.line_offset
= offset
;
12296 sections
.line_size
= size
;
12299 sections
.loc_offset
= offset
;
12300 sections
.loc_size
= size
;
12302 case DW_SECT_STR_OFFSETS
:
12303 sections
.str_offsets_offset
= offset
;
12304 sections
.str_offsets_size
= size
;
12306 case DW_SECT_MACINFO
:
12307 sections
.macinfo_offset
= offset
;
12308 sections
.macinfo_size
= size
;
12310 case DW_SECT_MACRO
:
12311 sections
.macro_offset
= offset
;
12312 sections
.macro_size
= size
;
12317 /* It's easier for the rest of the code if we fake a struct dwo_file and
12318 have dwo_unit "live" in that. At least for now.
12320 The DWP file can be made up of a random collection of CUs and TUs.
12321 However, for each CU + set of TUs that came from the same original DWO
12322 file, we can combine them back into a virtual DWO file to save space
12323 (fewer struct dwo_file objects to allocate). Remember that for really
12324 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12326 std::string virtual_dwo_name
=
12327 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12328 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12329 (long) (sections
.line_size
? sections
.line_offset
: 0),
12330 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12331 (long) (sections
.str_offsets_size
12332 ? sections
.str_offsets_offset
: 0));
12333 /* Can we use an existing virtual DWO file? */
12334 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12336 /* Create one if necessary. */
12337 if (*dwo_file_slot
== NULL
)
12339 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12340 virtual_dwo_name
.c_str ());
12342 dwo_file
= new struct dwo_file
;
12343 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12344 dwo_file
->comp_dir
= comp_dir
;
12345 dwo_file
->sections
.abbrev
=
12346 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12347 sections
.abbrev_offset
,
12348 sections
.abbrev_size
);
12349 dwo_file
->sections
.line
=
12350 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
12351 sections
.line_offset
,
12352 sections
.line_size
);
12353 dwo_file
->sections
.loc
=
12354 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
12355 sections
.loc_offset
, sections
.loc_size
);
12356 dwo_file
->sections
.macinfo
=
12357 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12358 sections
.macinfo_offset
,
12359 sections
.macinfo_size
);
12360 dwo_file
->sections
.macro
=
12361 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
12362 sections
.macro_offset
,
12363 sections
.macro_size
);
12364 dwo_file
->sections
.str_offsets
=
12365 create_dwp_v2_or_v5_section (per_objfile
,
12366 &dwp_file
->sections
.str_offsets
,
12367 sections
.str_offsets_offset
,
12368 sections
.str_offsets_size
);
12369 /* The "str" section is global to the entire DWP file. */
12370 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12371 /* The info or types section is assigned below to dwo_unit,
12372 there's no need to record it in dwo_file.
12373 Also, we can't simply record type sections in dwo_file because
12374 we record a pointer into the vector in dwo_unit. As we collect more
12375 types we'll grow the vector and eventually have to reallocate space
12376 for it, invalidating all copies of pointers into the previous
12378 *dwo_file_slot
= dwo_file
;
12382 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12383 virtual_dwo_name
.c_str ());
12385 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12388 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12389 dwo_unit
->dwo_file
= dwo_file
;
12390 dwo_unit
->signature
= signature
;
12391 dwo_unit
->section
=
12392 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12393 *dwo_unit
->section
= create_dwp_v2_or_v5_section
12396 ? &dwp_file
->sections
.types
12397 : &dwp_file
->sections
.info
,
12398 sections
.info_or_types_offset
,
12399 sections
.info_or_types_size
);
12400 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12405 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12406 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12407 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12408 This is for DWP version 5 files. */
12410 static struct dwo_unit
*
12411 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
12412 struct dwp_file
*dwp_file
,
12413 uint32_t unit_index
,
12414 const char *comp_dir
,
12415 ULONGEST signature
, int is_debug_types
)
12417 const struct dwp_hash_table
*dwp_htab
12418 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12419 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12420 const char *kind
= is_debug_types
? "TU" : "CU";
12421 struct dwo_file
*dwo_file
;
12422 struct dwo_unit
*dwo_unit
;
12423 struct virtual_v2_or_v5_dwo_sections sections
{};
12424 void **dwo_file_slot
;
12426 gdb_assert (dwp_file
->version
== 5);
12428 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
12429 kind
, pulongest (unit_index
), hex_string (signature
),
12432 /* Fetch the section offsets of this DWO unit. */
12434 /* memset (§ions, 0, sizeof (sections)); */
12436 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12438 uint32_t offset
= read_4_bytes (dbfd
,
12439 dwp_htab
->section_pool
.v5
.offsets
12440 + (((unit_index
- 1)
12441 * dwp_htab
->nr_columns
12443 * sizeof (uint32_t)));
12444 uint32_t size
= read_4_bytes (dbfd
,
12445 dwp_htab
->section_pool
.v5
.sizes
12446 + (((unit_index
- 1) * dwp_htab
->nr_columns
12448 * sizeof (uint32_t)));
12450 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
12452 case DW_SECT_ABBREV_V5
:
12453 sections
.abbrev_offset
= offset
;
12454 sections
.abbrev_size
= size
;
12456 case DW_SECT_INFO_V5
:
12457 sections
.info_or_types_offset
= offset
;
12458 sections
.info_or_types_size
= size
;
12460 case DW_SECT_LINE_V5
:
12461 sections
.line_offset
= offset
;
12462 sections
.line_size
= size
;
12464 case DW_SECT_LOCLISTS_V5
:
12465 sections
.loclists_offset
= offset
;
12466 sections
.loclists_size
= size
;
12468 case DW_SECT_MACRO_V5
:
12469 sections
.macro_offset
= offset
;
12470 sections
.macro_size
= size
;
12472 case DW_SECT_RNGLISTS_V5
:
12473 sections
.rnglists_offset
= offset
;
12474 sections
.rnglists_size
= size
;
12476 case DW_SECT_STR_OFFSETS_V5
:
12477 sections
.str_offsets_offset
= offset
;
12478 sections
.str_offsets_size
= size
;
12480 case DW_SECT_RESERVED_V5
:
12486 /* It's easier for the rest of the code if we fake a struct dwo_file and
12487 have dwo_unit "live" in that. At least for now.
12489 The DWP file can be made up of a random collection of CUs and TUs.
12490 However, for each CU + set of TUs that came from the same original DWO
12491 file, we can combine them back into a virtual DWO file to save space
12492 (fewer struct dwo_file objects to allocate). Remember that for really
12493 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12495 std::string virtual_dwo_name
=
12496 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
12497 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12498 (long) (sections
.line_size
? sections
.line_offset
: 0),
12499 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
12500 (long) (sections
.str_offsets_size
12501 ? sections
.str_offsets_offset
: 0),
12502 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
12503 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
12504 /* Can we use an existing virtual DWO file? */
12505 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
12506 virtual_dwo_name
.c_str (),
12508 /* Create one if necessary. */
12509 if (*dwo_file_slot
== NULL
)
12511 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12512 virtual_dwo_name
.c_str ());
12514 dwo_file
= new struct dwo_file
;
12515 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12516 dwo_file
->comp_dir
= comp_dir
;
12517 dwo_file
->sections
.abbrev
=
12518 create_dwp_v2_or_v5_section (per_objfile
,
12519 &dwp_file
->sections
.abbrev
,
12520 sections
.abbrev_offset
,
12521 sections
.abbrev_size
);
12522 dwo_file
->sections
.line
=
12523 create_dwp_v2_or_v5_section (per_objfile
,
12524 &dwp_file
->sections
.line
,
12525 sections
.line_offset
, sections
.line_size
);
12526 dwo_file
->sections
.macro
=
12527 create_dwp_v2_or_v5_section (per_objfile
,
12528 &dwp_file
->sections
.macro
,
12529 sections
.macro_offset
,
12530 sections
.macro_size
);
12531 dwo_file
->sections
.loclists
=
12532 create_dwp_v2_or_v5_section (per_objfile
,
12533 &dwp_file
->sections
.loclists
,
12534 sections
.loclists_offset
,
12535 sections
.loclists_size
);
12536 dwo_file
->sections
.rnglists
=
12537 create_dwp_v2_or_v5_section (per_objfile
,
12538 &dwp_file
->sections
.rnglists
,
12539 sections
.rnglists_offset
,
12540 sections
.rnglists_size
);
12541 dwo_file
->sections
.str_offsets
=
12542 create_dwp_v2_or_v5_section (per_objfile
,
12543 &dwp_file
->sections
.str_offsets
,
12544 sections
.str_offsets_offset
,
12545 sections
.str_offsets_size
);
12546 /* The "str" section is global to the entire DWP file. */
12547 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12548 /* The info or types section is assigned below to dwo_unit,
12549 there's no need to record it in dwo_file.
12550 Also, we can't simply record type sections in dwo_file because
12551 we record a pointer into the vector in dwo_unit. As we collect more
12552 types we'll grow the vector and eventually have to reallocate space
12553 for it, invalidating all copies of pointers into the previous
12555 *dwo_file_slot
= dwo_file
;
12559 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12560 virtual_dwo_name
.c_str ());
12562 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12565 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12566 dwo_unit
->dwo_file
= dwo_file
;
12567 dwo_unit
->signature
= signature
;
12569 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12570 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12571 &dwp_file
->sections
.info
,
12572 sections
.info_or_types_offset
,
12573 sections
.info_or_types_size
);
12574 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12579 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12580 Returns NULL if the signature isn't found. */
12582 static struct dwo_unit
*
12583 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12584 struct dwp_file
*dwp_file
, const char *comp_dir
,
12585 ULONGEST signature
, int is_debug_types
)
12587 const struct dwp_hash_table
*dwp_htab
=
12588 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12589 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12590 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12591 uint32_t hash
= signature
& mask
;
12592 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12595 struct dwo_unit find_dwo_cu
;
12597 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12598 find_dwo_cu
.signature
= signature
;
12599 slot
= htab_find_slot (is_debug_types
12600 ? dwp_file
->loaded_tus
.get ()
12601 : dwp_file
->loaded_cus
.get (),
12602 &find_dwo_cu
, INSERT
);
12605 return (struct dwo_unit
*) *slot
;
12607 /* Use a for loop so that we don't loop forever on bad debug info. */
12608 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12610 ULONGEST signature_in_table
;
12612 signature_in_table
=
12613 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12614 if (signature_in_table
== signature
)
12616 uint32_t unit_index
=
12617 read_4_bytes (dbfd
,
12618 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12620 if (dwp_file
->version
== 1)
12622 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12623 unit_index
, comp_dir
,
12624 signature
, is_debug_types
);
12626 else if (dwp_file
->version
== 2)
12628 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12629 unit_index
, comp_dir
,
12630 signature
, is_debug_types
);
12632 else /* version == 5 */
12634 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12635 unit_index
, comp_dir
,
12636 signature
, is_debug_types
);
12638 return (struct dwo_unit
*) *slot
;
12640 if (signature_in_table
== 0)
12642 hash
= (hash
+ hash2
) & mask
;
12645 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12646 " [in module %s]"),
12650 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12651 Open the file specified by FILE_NAME and hand it off to BFD for
12652 preliminary analysis. Return a newly initialized bfd *, which
12653 includes a canonicalized copy of FILE_NAME.
12654 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12655 SEARCH_CWD is true if the current directory is to be searched.
12656 It will be searched before debug-file-directory.
12657 If successful, the file is added to the bfd include table of the
12658 objfile's bfd (see gdb_bfd_record_inclusion).
12659 If unable to find/open the file, return NULL.
12660 NOTE: This function is derived from symfile_bfd_open. */
12662 static gdb_bfd_ref_ptr
12663 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12664 const char *file_name
, int is_dwp
, int search_cwd
)
12667 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12668 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12669 to debug_file_directory. */
12670 const char *search_path
;
12671 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12673 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12676 if (*debug_file_directory
!= '\0')
12678 search_path_holder
.reset (concat (".", dirname_separator_string
,
12679 debug_file_directory
,
12681 search_path
= search_path_holder
.get ();
12687 search_path
= debug_file_directory
;
12689 openp_flags flags
= OPF_RETURN_REALPATH
;
12691 flags
|= OPF_SEARCH_IN_PATH
;
12693 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12694 desc
= openp (search_path
, flags
, file_name
,
12695 O_RDONLY
| O_BINARY
, &absolute_name
);
12699 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12701 if (sym_bfd
== NULL
)
12703 bfd_set_cacheable (sym_bfd
.get (), 1);
12705 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12708 /* Success. Record the bfd as having been included by the objfile's bfd.
12709 This is important because things like demangled_names_hash lives in the
12710 objfile's per_bfd space and may have references to things like symbol
12711 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12712 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12717 /* Try to open DWO file FILE_NAME.
12718 COMP_DIR is the DW_AT_comp_dir attribute.
12719 The result is the bfd handle of the file.
12720 If there is a problem finding or opening the file, return NULL.
12721 Upon success, the canonicalized path of the file is stored in the bfd,
12722 same as symfile_bfd_open. */
12724 static gdb_bfd_ref_ptr
12725 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12726 const char *file_name
, const char *comp_dir
)
12728 if (IS_ABSOLUTE_PATH (file_name
))
12729 return try_open_dwop_file (per_objfile
, file_name
,
12730 0 /*is_dwp*/, 0 /*search_cwd*/);
12732 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12734 if (comp_dir
!= NULL
)
12736 gdb::unique_xmalloc_ptr
<char> path_to_try
12737 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12739 /* NOTE: If comp_dir is a relative path, this will also try the
12740 search path, which seems useful. */
12741 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12743 1 /*search_cwd*/));
12748 /* That didn't work, try debug-file-directory, which, despite its name,
12749 is a list of paths. */
12751 if (*debug_file_directory
== '\0')
12754 return try_open_dwop_file (per_objfile
, file_name
,
12755 0 /*is_dwp*/, 1 /*search_cwd*/);
12758 /* This function is mapped across the sections and remembers the offset and
12759 size of each of the DWO debugging sections we are interested in. */
12762 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12763 dwo_sections
*dwo_sections
)
12765 const struct dwop_section_names
*names
= &dwop_section_names
;
12767 if (names
->abbrev_dwo
.matches (sectp
->name
))
12769 dwo_sections
->abbrev
.s
.section
= sectp
;
12770 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12772 else if (names
->info_dwo
.matches (sectp
->name
))
12774 dwo_sections
->info
.s
.section
= sectp
;
12775 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12777 else if (names
->line_dwo
.matches (sectp
->name
))
12779 dwo_sections
->line
.s
.section
= sectp
;
12780 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12782 else if (names
->loc_dwo
.matches (sectp
->name
))
12784 dwo_sections
->loc
.s
.section
= sectp
;
12785 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12787 else if (names
->loclists_dwo
.matches (sectp
->name
))
12789 dwo_sections
->loclists
.s
.section
= sectp
;
12790 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12792 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12794 dwo_sections
->macinfo
.s
.section
= sectp
;
12795 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12797 else if (names
->macro_dwo
.matches (sectp
->name
))
12799 dwo_sections
->macro
.s
.section
= sectp
;
12800 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12802 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12804 dwo_sections
->rnglists
.s
.section
= sectp
;
12805 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12807 else if (names
->str_dwo
.matches (sectp
->name
))
12809 dwo_sections
->str
.s
.section
= sectp
;
12810 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12812 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12814 dwo_sections
->str_offsets
.s
.section
= sectp
;
12815 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12817 else if (names
->types_dwo
.matches (sectp
->name
))
12819 struct dwarf2_section_info type_section
;
12821 memset (&type_section
, 0, sizeof (type_section
));
12822 type_section
.s
.section
= sectp
;
12823 type_section
.size
= bfd_section_size (sectp
);
12824 dwo_sections
->types
.push_back (type_section
);
12828 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12829 by PER_CU. This is for the non-DWP case.
12830 The result is NULL if DWO_NAME can't be found. */
12832 static struct dwo_file
*
12833 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12834 const char *comp_dir
)
12836 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12838 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12841 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12846 dwo_file_up
dwo_file (new struct dwo_file
);
12847 dwo_file
->dwo_name
= dwo_name
;
12848 dwo_file
->comp_dir
= comp_dir
;
12849 dwo_file
->dbfd
= std::move (dbfd
);
12851 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12852 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12853 &dwo_file
->sections
);
12855 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12858 if (cu
->per_cu
->dwarf_version
< 5)
12860 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12861 dwo_file
->sections
.types
, dwo_file
->tus
);
12865 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12866 &dwo_file
->sections
.info
, dwo_file
->tus
,
12867 rcuh_kind::COMPILE
);
12870 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12872 return dwo_file
.release ();
12875 /* This function is mapped across the sections and remembers the offset and
12876 size of each of the DWP debugging sections common to version 1 and 2 that
12877 we are interested in. */
12880 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12881 dwp_file
*dwp_file
)
12883 const struct dwop_section_names
*names
= &dwop_section_names
;
12884 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12886 /* Record the ELF section number for later lookup: this is what the
12887 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12888 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12889 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12891 /* Look for specific sections that we need. */
12892 if (names
->str_dwo
.matches (sectp
->name
))
12894 dwp_file
->sections
.str
.s
.section
= sectp
;
12895 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12897 else if (names
->cu_index
.matches (sectp
->name
))
12899 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12900 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12902 else if (names
->tu_index
.matches (sectp
->name
))
12904 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12905 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12909 /* This function is mapped across the sections and remembers the offset and
12910 size of each of the DWP version 2 debugging sections that we are interested
12911 in. This is split into a separate function because we don't know if we
12912 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12915 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12917 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12918 const struct dwop_section_names
*names
= &dwop_section_names
;
12919 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12921 /* Record the ELF section number for later lookup: this is what the
12922 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12923 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12924 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12926 /* Look for specific sections that we need. */
12927 if (names
->abbrev_dwo
.matches (sectp
->name
))
12929 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12930 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12932 else if (names
->info_dwo
.matches (sectp
->name
))
12934 dwp_file
->sections
.info
.s
.section
= sectp
;
12935 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12937 else if (names
->line_dwo
.matches (sectp
->name
))
12939 dwp_file
->sections
.line
.s
.section
= sectp
;
12940 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12942 else if (names
->loc_dwo
.matches (sectp
->name
))
12944 dwp_file
->sections
.loc
.s
.section
= sectp
;
12945 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12947 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12949 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12950 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12952 else if (names
->macro_dwo
.matches (sectp
->name
))
12954 dwp_file
->sections
.macro
.s
.section
= sectp
;
12955 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12957 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12959 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12960 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12962 else if (names
->types_dwo
.matches (sectp
->name
))
12964 dwp_file
->sections
.types
.s
.section
= sectp
;
12965 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12969 /* This function is mapped across the sections and remembers the offset and
12970 size of each of the DWP version 5 debugging sections that we are interested
12971 in. This is split into a separate function because we don't know if we
12972 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
12975 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12977 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12978 const struct dwop_section_names
*names
= &dwop_section_names
;
12979 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12981 /* Record the ELF section number for later lookup: this is what the
12982 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12983 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12984 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12986 /* Look for specific sections that we need. */
12987 if (names
->abbrev_dwo
.matches (sectp
->name
))
12989 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12990 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12992 else if (names
->info_dwo
.matches (sectp
->name
))
12994 dwp_file
->sections
.info
.s
.section
= sectp
;
12995 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12997 else if (names
->line_dwo
.matches (sectp
->name
))
12999 dwp_file
->sections
.line
.s
.section
= sectp
;
13000 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13002 else if (names
->loclists_dwo
.matches (sectp
->name
))
13004 dwp_file
->sections
.loclists
.s
.section
= sectp
;
13005 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
13007 else if (names
->macro_dwo
.matches (sectp
->name
))
13009 dwp_file
->sections
.macro
.s
.section
= sectp
;
13010 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13012 else if (names
->rnglists_dwo
.matches (sectp
->name
))
13014 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
13015 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
13017 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
13019 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13020 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13024 /* Hash function for dwp_file loaded CUs/TUs. */
13027 hash_dwp_loaded_cutus (const void *item
)
13029 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13031 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13032 return dwo_unit
->signature
;
13035 /* Equality function for dwp_file loaded CUs/TUs. */
13038 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13040 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13041 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13043 return dua
->signature
== dub
->signature
;
13046 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13049 allocate_dwp_loaded_cutus_table ()
13051 return htab_up (htab_create_alloc (3,
13052 hash_dwp_loaded_cutus
,
13053 eq_dwp_loaded_cutus
,
13054 NULL
, xcalloc
, xfree
));
13057 /* Try to open DWP file FILE_NAME.
13058 The result is the bfd handle of the file.
13059 If there is a problem finding or opening the file, return NULL.
13060 Upon success, the canonicalized path of the file is stored in the bfd,
13061 same as symfile_bfd_open. */
13063 static gdb_bfd_ref_ptr
13064 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
13066 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
13068 1 /*search_cwd*/));
13072 /* Work around upstream bug 15652.
13073 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13074 [Whether that's a "bug" is debatable, but it is getting in our way.]
13075 We have no real idea where the dwp file is, because gdb's realpath-ing
13076 of the executable's path may have discarded the needed info.
13077 [IWBN if the dwp file name was recorded in the executable, akin to
13078 .gnu_debuglink, but that doesn't exist yet.]
13079 Strip the directory from FILE_NAME and search again. */
13080 if (*debug_file_directory
!= '\0')
13082 /* Don't implicitly search the current directory here.
13083 If the user wants to search "." to handle this case,
13084 it must be added to debug-file-directory. */
13085 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
13093 /* Initialize the use of the DWP file for the current objfile.
13094 By convention the name of the DWP file is ${objfile}.dwp.
13095 The result is NULL if it can't be found. */
13097 static std::unique_ptr
<struct dwp_file
>
13098 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
13100 struct objfile
*objfile
= per_objfile
->objfile
;
13102 /* Try to find first .dwp for the binary file before any symbolic links
13105 /* If the objfile is a debug file, find the name of the real binary
13106 file and get the name of dwp file from there. */
13107 std::string dwp_name
;
13108 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13110 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13111 const char *backlink_basename
= lbasename (backlink
->original_name
);
13113 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13116 dwp_name
= objfile
->original_name
;
13118 dwp_name
+= ".dwp";
13120 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
13122 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13124 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13125 dwp_name
= objfile_name (objfile
);
13126 dwp_name
+= ".dwp";
13127 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
13132 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
13134 return std::unique_ptr
<dwp_file
> ();
13137 const char *name
= bfd_get_filename (dbfd
.get ());
13138 std::unique_ptr
<struct dwp_file
> dwp_file
13139 (new struct dwp_file (name
, std::move (dbfd
)));
13141 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13142 dwp_file
->elf_sections
=
13143 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
13144 dwp_file
->num_sections
, asection
*);
13146 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13147 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13150 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
13152 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
13154 /* The DWP file version is stored in the hash table. Oh well. */
13155 if (dwp_file
->cus
&& dwp_file
->tus
13156 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13158 /* Technically speaking, we should try to limp along, but this is
13159 pretty bizarre. We use pulongest here because that's the established
13160 portability solution (e.g, we cannot use %u for uint32_t). */
13161 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13162 " TU version %s [in DWP file %s]"),
13163 pulongest (dwp_file
->cus
->version
),
13164 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13168 dwp_file
->version
= dwp_file
->cus
->version
;
13169 else if (dwp_file
->tus
)
13170 dwp_file
->version
= dwp_file
->tus
->version
;
13172 dwp_file
->version
= 2;
13174 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13176 if (dwp_file
->version
== 2)
13177 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13180 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13184 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
13185 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
13187 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
13188 dwarf_read_debug_printf (" %s CUs, %s TUs",
13189 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13190 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13195 /* Wrapper around open_and_init_dwp_file, only open it once. */
13197 static struct dwp_file
*
13198 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
13200 if (!per_objfile
->per_bfd
->dwp_checked
)
13202 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
13203 per_objfile
->per_bfd
->dwp_checked
= 1;
13205 return per_objfile
->per_bfd
->dwp_file
.get ();
13208 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13209 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13210 or in the DWP file for the objfile, referenced by THIS_UNIT.
13211 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13212 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13214 This is called, for example, when wanting to read a variable with a
13215 complex location. Therefore we don't want to do file i/o for every call.
13216 Therefore we don't want to look for a DWO file on every call.
13217 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13218 then we check if we've already seen DWO_NAME, and only THEN do we check
13221 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13222 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13224 static struct dwo_unit
*
13225 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13226 ULONGEST signature
, int is_debug_types
)
13228 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13229 struct objfile
*objfile
= per_objfile
->objfile
;
13230 const char *kind
= is_debug_types
? "TU" : "CU";
13231 void **dwo_file_slot
;
13232 struct dwo_file
*dwo_file
;
13233 struct dwp_file
*dwp_file
;
13235 /* First see if there's a DWP file.
13236 If we have a DWP file but didn't find the DWO inside it, don't
13237 look for the original DWO file. It makes gdb behave differently
13238 depending on whether one is debugging in the build tree. */
13240 dwp_file
= get_dwp_file (per_objfile
);
13241 if (dwp_file
!= NULL
)
13243 const struct dwp_hash_table
*dwp_htab
=
13244 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13246 if (dwp_htab
!= NULL
)
13248 struct dwo_unit
*dwo_cutu
=
13249 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
13252 if (dwo_cutu
!= NULL
)
13254 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
13255 kind
, hex_string (signature
),
13256 host_address_to_string (dwo_cutu
));
13264 /* No DWP file, look for the DWO file. */
13266 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
13267 if (*dwo_file_slot
== NULL
)
13269 /* Read in the file and build a table of the CUs/TUs it contains. */
13270 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
13272 /* NOTE: This will be NULL if unable to open the file. */
13273 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13275 if (dwo_file
!= NULL
)
13277 struct dwo_unit
*dwo_cutu
= NULL
;
13279 if (is_debug_types
&& dwo_file
->tus
)
13281 struct dwo_unit find_dwo_cutu
;
13283 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13284 find_dwo_cutu
.signature
= signature
;
13286 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
13289 else if (!is_debug_types
&& dwo_file
->cus
)
13291 struct dwo_unit find_dwo_cutu
;
13293 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13294 find_dwo_cutu
.signature
= signature
;
13295 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
13299 if (dwo_cutu
!= NULL
)
13301 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
13302 kind
, dwo_name
, hex_string (signature
),
13303 host_address_to_string (dwo_cutu
));
13310 /* We didn't find it. This could mean a dwo_id mismatch, or
13311 someone deleted the DWO/DWP file, or the search path isn't set up
13312 correctly to find the file. */
13314 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
13315 kind
, dwo_name
, hex_string (signature
));
13317 /* This is a warning and not a complaint because it can be caused by
13318 pilot error (e.g., user accidentally deleting the DWO). */
13320 /* Print the name of the DWP file if we looked there, helps the user
13321 better diagnose the problem. */
13322 std::string dwp_text
;
13324 if (dwp_file
!= NULL
)
13325 dwp_text
= string_printf (" [in DWP file %s]",
13326 lbasename (dwp_file
->name
));
13328 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13329 " [in module %s]"),
13330 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
13331 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
13336 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13337 See lookup_dwo_cutu_unit for details. */
13339 static struct dwo_unit
*
13340 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13341 ULONGEST signature
)
13343 gdb_assert (!cu
->per_cu
->is_debug_types
);
13345 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
13348 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13349 See lookup_dwo_cutu_unit for details. */
13351 static struct dwo_unit
*
13352 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
13354 gdb_assert (cu
->per_cu
->is_debug_types
);
13356 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
13358 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
13361 /* Traversal function for queue_and_load_all_dwo_tus. */
13364 queue_and_load_dwo_tu (void **slot
, void *info
)
13366 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13367 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
13368 ULONGEST signature
= dwo_unit
->signature
;
13369 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
13371 if (sig_type
!= NULL
)
13373 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13375 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13376 a real dependency of PER_CU on SIG_TYPE. That is detected later
13377 while processing PER_CU. */
13378 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
13379 load_full_type_unit (sig_cu
, cu
->per_objfile
);
13380 cu
->per_cu
->imported_symtabs_push (sig_cu
);
13386 /* Queue all TUs contained in the DWO of CU to be read in.
13387 The DWO may have the only definition of the type, though it may not be
13388 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13389 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13392 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
13394 struct dwo_unit
*dwo_unit
;
13395 struct dwo_file
*dwo_file
;
13397 gdb_assert (cu
!= nullptr);
13398 gdb_assert (!cu
->per_cu
->is_debug_types
);
13399 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
13401 dwo_unit
= cu
->dwo_unit
;
13402 gdb_assert (dwo_unit
!= NULL
);
13404 dwo_file
= dwo_unit
->dwo_file
;
13405 if (dwo_file
->tus
!= NULL
)
13406 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
13409 /* Read in various DIEs. */
13411 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13412 Inherit only the children of the DW_AT_abstract_origin DIE not being
13413 already referenced by DW_AT_abstract_origin from the children of the
13417 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13419 struct die_info
*child_die
;
13420 sect_offset
*offsetp
;
13421 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13422 struct die_info
*origin_die
;
13423 /* Iterator of the ORIGIN_DIE children. */
13424 struct die_info
*origin_child_die
;
13425 struct attribute
*attr
;
13426 struct dwarf2_cu
*origin_cu
;
13427 struct pending
**origin_previous_list_in_scope
;
13429 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13433 /* Note that following die references may follow to a die in a
13437 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13439 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13441 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13442 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13444 if (die
->tag
!= origin_die
->tag
13445 && !(die
->tag
== DW_TAG_inlined_subroutine
13446 && origin_die
->tag
== DW_TAG_subprogram
))
13447 complaint (_("DIE %s and its abstract origin %s have different tags"),
13448 sect_offset_str (die
->sect_off
),
13449 sect_offset_str (origin_die
->sect_off
));
13451 std::vector
<sect_offset
> offsets
;
13453 for (child_die
= die
->child
;
13454 child_die
&& child_die
->tag
;
13455 child_die
= child_die
->sibling
)
13457 struct die_info
*child_origin_die
;
13458 struct dwarf2_cu
*child_origin_cu
;
13460 /* We are trying to process concrete instance entries:
13461 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13462 it's not relevant to our analysis here. i.e. detecting DIEs that are
13463 present in the abstract instance but not referenced in the concrete
13465 if (child_die
->tag
== DW_TAG_call_site
13466 || child_die
->tag
== DW_TAG_GNU_call_site
)
13469 /* For each CHILD_DIE, find the corresponding child of
13470 ORIGIN_DIE. If there is more than one layer of
13471 DW_AT_abstract_origin, follow them all; there shouldn't be,
13472 but GCC versions at least through 4.4 generate this (GCC PR
13474 child_origin_die
= child_die
;
13475 child_origin_cu
= cu
;
13478 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13482 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13486 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13487 counterpart may exist. */
13488 if (child_origin_die
!= child_die
)
13490 if (child_die
->tag
!= child_origin_die
->tag
13491 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13492 && child_origin_die
->tag
== DW_TAG_subprogram
))
13493 complaint (_("Child DIE %s and its abstract origin %s have "
13495 sect_offset_str (child_die
->sect_off
),
13496 sect_offset_str (child_origin_die
->sect_off
));
13497 if (child_origin_die
->parent
!= origin_die
)
13498 complaint (_("Child DIE %s and its abstract origin %s have "
13499 "different parents"),
13500 sect_offset_str (child_die
->sect_off
),
13501 sect_offset_str (child_origin_die
->sect_off
));
13503 offsets
.push_back (child_origin_die
->sect_off
);
13506 std::sort (offsets
.begin (), offsets
.end ());
13507 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13508 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13509 if (offsetp
[-1] == *offsetp
)
13510 complaint (_("Multiple children of DIE %s refer "
13511 "to DIE %s as their abstract origin"),
13512 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13514 offsetp
= offsets
.data ();
13515 origin_child_die
= origin_die
->child
;
13516 while (origin_child_die
&& origin_child_die
->tag
)
13518 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13519 while (offsetp
< offsets_end
13520 && *offsetp
< origin_child_die
->sect_off
)
13522 if (offsetp
>= offsets_end
13523 || *offsetp
> origin_child_die
->sect_off
)
13525 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13526 Check whether we're already processing ORIGIN_CHILD_DIE.
13527 This can happen with mutually referenced abstract_origins.
13529 if (!origin_child_die
->in_process
)
13530 process_die (origin_child_die
, origin_cu
);
13532 origin_child_die
= origin_child_die
->sibling
;
13534 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13536 if (cu
!= origin_cu
)
13537 compute_delayed_physnames (origin_cu
);
13541 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13543 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13544 struct gdbarch
*gdbarch
= objfile
->arch ();
13545 struct context_stack
*newobj
;
13548 struct die_info
*child_die
;
13549 struct attribute
*attr
, *call_line
, *call_file
;
13551 CORE_ADDR baseaddr
;
13552 struct block
*block
;
13553 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13554 std::vector
<struct symbol
*> template_args
;
13555 struct template_symbol
*templ_func
= NULL
;
13559 /* If we do not have call site information, we can't show the
13560 caller of this inlined function. That's too confusing, so
13561 only use the scope for local variables. */
13562 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13563 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13564 if (call_line
== NULL
|| call_file
== NULL
)
13566 read_lexical_block_scope (die
, cu
);
13571 baseaddr
= objfile
->text_section_offset ();
13573 name
= dwarf2_name (die
, cu
);
13575 /* Ignore functions with missing or empty names. These are actually
13576 illegal according to the DWARF standard. */
13579 complaint (_("missing name for subprogram DIE at %s"),
13580 sect_offset_str (die
->sect_off
));
13584 /* Ignore functions with missing or invalid low and high pc attributes. */
13585 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13586 <= PC_BOUNDS_INVALID
)
13588 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13589 if (attr
== nullptr || !attr
->as_boolean ())
13590 complaint (_("cannot get low and high bounds "
13591 "for subprogram DIE at %s"),
13592 sect_offset_str (die
->sect_off
));
13596 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13597 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13599 /* If we have any template arguments, then we must allocate a
13600 different sort of symbol. */
13601 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13603 if (child_die
->tag
== DW_TAG_template_type_param
13604 || child_die
->tag
== DW_TAG_template_value_param
)
13606 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13607 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13612 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13613 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13614 (struct symbol
*) templ_func
);
13616 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13617 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13620 /* If there is a location expression for DW_AT_frame_base, record
13622 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13623 if (attr
!= nullptr)
13624 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13626 /* If there is a location for the static link, record it. */
13627 newobj
->static_link
= NULL
;
13628 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13629 if (attr
!= nullptr)
13631 newobj
->static_link
13632 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13633 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13637 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13639 if (die
->child
!= NULL
)
13641 child_die
= die
->child
;
13642 while (child_die
&& child_die
->tag
)
13644 if (child_die
->tag
== DW_TAG_template_type_param
13645 || child_die
->tag
== DW_TAG_template_value_param
)
13647 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13650 template_args
.push_back (arg
);
13653 process_die (child_die
, cu
);
13654 child_die
= child_die
->sibling
;
13658 inherit_abstract_dies (die
, cu
);
13660 /* If we have a DW_AT_specification, we might need to import using
13661 directives from the context of the specification DIE. See the
13662 comment in determine_prefix. */
13663 if (cu
->language
== language_cplus
13664 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13666 struct dwarf2_cu
*spec_cu
= cu
;
13667 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13671 child_die
= spec_die
->child
;
13672 while (child_die
&& child_die
->tag
)
13674 if (child_die
->tag
== DW_TAG_imported_module
)
13675 process_die (child_die
, spec_cu
);
13676 child_die
= child_die
->sibling
;
13679 /* In some cases, GCC generates specification DIEs that
13680 themselves contain DW_AT_specification attributes. */
13681 spec_die
= die_specification (spec_die
, &spec_cu
);
13685 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13686 /* Make a block for the local symbols within. */
13687 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13688 cstk
.static_link
, lowpc
, highpc
);
13690 /* For C++, set the block's scope. */
13691 if ((cu
->language
== language_cplus
13692 || cu
->language
== language_fortran
13693 || cu
->language
== language_d
13694 || cu
->language
== language_rust
)
13695 && cu
->processing_has_namespace_info
)
13696 block_set_scope (block
, determine_prefix (die
, cu
),
13697 &objfile
->objfile_obstack
);
13699 /* If we have address ranges, record them. */
13700 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13702 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13704 /* Attach template arguments to function. */
13705 if (!template_args
.empty ())
13707 gdb_assert (templ_func
!= NULL
);
13709 templ_func
->n_template_arguments
= template_args
.size ();
13710 templ_func
->template_arguments
13711 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13712 templ_func
->n_template_arguments
);
13713 memcpy (templ_func
->template_arguments
,
13714 template_args
.data (),
13715 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13717 /* Make sure that the symtab is set on the new symbols. Even
13718 though they don't appear in this symtab directly, other parts
13719 of gdb assume that symbols do, and this is reasonably
13721 for (symbol
*sym
: template_args
)
13722 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13725 /* In C++, we can have functions nested inside functions (e.g., when
13726 a function declares a class that has methods). This means that
13727 when we finish processing a function scope, we may need to go
13728 back to building a containing block's symbol lists. */
13729 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13730 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13732 /* If we've finished processing a top-level function, subsequent
13733 symbols go in the file symbol list. */
13734 if (cu
->get_builder ()->outermost_context_p ())
13735 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13738 /* Process all the DIES contained within a lexical block scope. Start
13739 a new scope, process the dies, and then close the scope. */
13742 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13744 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13745 struct gdbarch
*gdbarch
= objfile
->arch ();
13746 CORE_ADDR lowpc
, highpc
;
13747 struct die_info
*child_die
;
13748 CORE_ADDR baseaddr
;
13750 baseaddr
= objfile
->text_section_offset ();
13752 /* Ignore blocks with missing or invalid low and high pc attributes. */
13753 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13754 as multiple lexical blocks? Handling children in a sane way would
13755 be nasty. Might be easier to properly extend generic blocks to
13756 describe ranges. */
13757 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13759 case PC_BOUNDS_NOT_PRESENT
:
13760 /* DW_TAG_lexical_block has no attributes, process its children as if
13761 there was no wrapping by that DW_TAG_lexical_block.
13762 GCC does no longer produces such DWARF since GCC r224161. */
13763 for (child_die
= die
->child
;
13764 child_die
!= NULL
&& child_die
->tag
;
13765 child_die
= child_die
->sibling
)
13767 /* We might already be processing this DIE. This can happen
13768 in an unusual circumstance -- where a subroutine A
13769 appears lexically in another subroutine B, but A actually
13770 inlines B. The recursion is broken here, rather than in
13771 inherit_abstract_dies, because it seems better to simply
13772 drop concrete children here. */
13773 if (!child_die
->in_process
)
13774 process_die (child_die
, cu
);
13777 case PC_BOUNDS_INVALID
:
13780 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13781 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13783 cu
->get_builder ()->push_context (0, lowpc
);
13784 if (die
->child
!= NULL
)
13786 child_die
= die
->child
;
13787 while (child_die
&& child_die
->tag
)
13789 process_die (child_die
, cu
);
13790 child_die
= child_die
->sibling
;
13793 inherit_abstract_dies (die
, cu
);
13794 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13796 if (*cu
->get_builder ()->get_local_symbols () != NULL
13797 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13799 struct block
*block
13800 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13801 cstk
.start_addr
, highpc
);
13803 /* Note that recording ranges after traversing children, as we
13804 do here, means that recording a parent's ranges entails
13805 walking across all its children's ranges as they appear in
13806 the address map, which is quadratic behavior.
13808 It would be nicer to record the parent's ranges before
13809 traversing its children, simply overriding whatever you find
13810 there. But since we don't even decide whether to create a
13811 block until after we've traversed its children, that's hard
13813 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13815 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13816 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13819 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13822 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13824 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13825 struct objfile
*objfile
= per_objfile
->objfile
;
13826 struct gdbarch
*gdbarch
= objfile
->arch ();
13827 CORE_ADDR pc
, baseaddr
;
13828 struct attribute
*attr
;
13829 struct call_site
*call_site
, call_site_local
;
13832 struct die_info
*child_die
;
13834 baseaddr
= objfile
->text_section_offset ();
13836 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13839 /* This was a pre-DWARF-5 GNU extension alias
13840 for DW_AT_call_return_pc. */
13841 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13845 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13846 "DIE %s [in module %s]"),
13847 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13850 pc
= attr
->as_address () + baseaddr
;
13851 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13853 if (cu
->call_site_htab
== NULL
)
13854 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13855 NULL
, &objfile
->objfile_obstack
,
13856 hashtab_obstack_allocate
, NULL
);
13857 call_site_local
.pc
= pc
;
13858 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13861 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13862 "DIE %s [in module %s]"),
13863 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13864 objfile_name (objfile
));
13868 /* Count parameters at the caller. */
13871 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13872 child_die
= child_die
->sibling
)
13874 if (child_die
->tag
!= DW_TAG_call_site_parameter
13875 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13877 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13878 "DW_TAG_call_site child DIE %s [in module %s]"),
13879 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13880 objfile_name (objfile
));
13888 = ((struct call_site
*)
13889 obstack_alloc (&objfile
->objfile_obstack
,
13890 sizeof (*call_site
)
13891 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13893 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13894 call_site
->pc
= pc
;
13896 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13897 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13899 struct die_info
*func_die
;
13901 /* Skip also over DW_TAG_inlined_subroutine. */
13902 for (func_die
= die
->parent
;
13903 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13904 && func_die
->tag
!= DW_TAG_subroutine_type
;
13905 func_die
= func_die
->parent
);
13907 /* DW_AT_call_all_calls is a superset
13908 of DW_AT_call_all_tail_calls. */
13910 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13911 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13912 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13913 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13915 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13916 not complete. But keep CALL_SITE for look ups via call_site_htab,
13917 both the initial caller containing the real return address PC and
13918 the final callee containing the current PC of a chain of tail
13919 calls do not need to have the tail call list complete. But any
13920 function candidate for a virtual tail call frame searched via
13921 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13922 determined unambiguously. */
13926 struct type
*func_type
= NULL
;
13929 func_type
= get_die_type (func_die
, cu
);
13930 if (func_type
!= NULL
)
13932 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
13934 /* Enlist this call site to the function. */
13935 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13936 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13939 complaint (_("Cannot find function owning DW_TAG_call_site "
13940 "DIE %s [in module %s]"),
13941 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13945 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13947 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13949 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13952 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13953 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13955 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13956 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
13957 /* Keep NULL DWARF_BLOCK. */;
13958 else if (attr
->form_is_block ())
13960 struct dwarf2_locexpr_baton
*dlbaton
;
13961 struct dwarf_block
*block
= attr
->as_block ();
13963 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13964 dlbaton
->data
= block
->data
;
13965 dlbaton
->size
= block
->size
;
13966 dlbaton
->per_objfile
= per_objfile
;
13967 dlbaton
->per_cu
= cu
->per_cu
;
13969 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13971 else if (attr
->form_is_ref ())
13973 struct dwarf2_cu
*target_cu
= cu
;
13974 struct die_info
*target_die
;
13976 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13977 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
13978 if (die_is_declaration (target_die
, target_cu
))
13980 const char *target_physname
;
13982 /* Prefer the mangled name; otherwise compute the demangled one. */
13983 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13984 if (target_physname
== NULL
)
13985 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13986 if (target_physname
== NULL
)
13987 complaint (_("DW_AT_call_target target DIE has invalid "
13988 "physname, for referencing DIE %s [in module %s]"),
13989 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13991 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13997 /* DW_AT_entry_pc should be preferred. */
13998 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13999 <= PC_BOUNDS_INVALID
)
14000 complaint (_("DW_AT_call_target target DIE has invalid "
14001 "low pc, for referencing DIE %s [in module %s]"),
14002 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14005 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14006 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14011 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14012 "block nor reference, for DIE %s [in module %s]"),
14013 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14015 call_site
->per_cu
= cu
->per_cu
;
14016 call_site
->per_objfile
= per_objfile
;
14018 for (child_die
= die
->child
;
14019 child_die
&& child_die
->tag
;
14020 child_die
= child_die
->sibling
)
14022 struct call_site_parameter
*parameter
;
14023 struct attribute
*loc
, *origin
;
14025 if (child_die
->tag
!= DW_TAG_call_site_parameter
14026 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14028 /* Already printed the complaint above. */
14032 gdb_assert (call_site
->parameter_count
< nparams
);
14033 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14035 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14036 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14037 register is contained in DW_AT_call_value. */
14039 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14040 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14041 if (origin
== NULL
)
14043 /* This was a pre-DWARF-5 GNU extension alias
14044 for DW_AT_call_parameter. */
14045 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14047 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
14049 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14051 sect_offset sect_off
= origin
->get_ref_die_offset ();
14052 if (!cu
->header
.offset_in_cu_p (sect_off
))
14054 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14055 binding can be done only inside one CU. Such referenced DIE
14056 therefore cannot be even moved to DW_TAG_partial_unit. */
14057 complaint (_("DW_AT_call_parameter offset is not in CU for "
14058 "DW_TAG_call_site child DIE %s [in module %s]"),
14059 sect_offset_str (child_die
->sect_off
),
14060 objfile_name (objfile
));
14063 parameter
->u
.param_cu_off
14064 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14066 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
14068 complaint (_("No DW_FORM_block* DW_AT_location for "
14069 "DW_TAG_call_site child DIE %s [in module %s]"),
14070 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14075 struct dwarf_block
*block
= loc
->as_block ();
14077 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14078 (block
->data
, &block
->data
[block
->size
]);
14079 if (parameter
->u
.dwarf_reg
!= -1)
14080 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14081 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
14082 &block
->data
[block
->size
],
14083 ¶meter
->u
.fb_offset
))
14084 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14087 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14088 "for DW_FORM_block* DW_AT_location is supported for "
14089 "DW_TAG_call_site child DIE %s "
14091 sect_offset_str (child_die
->sect_off
),
14092 objfile_name (objfile
));
14097 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14099 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14100 if (attr
== NULL
|| !attr
->form_is_block ())
14102 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14103 "DW_TAG_call_site child DIE %s [in module %s]"),
14104 sect_offset_str (child_die
->sect_off
),
14105 objfile_name (objfile
));
14109 struct dwarf_block
*block
= attr
->as_block ();
14110 parameter
->value
= block
->data
;
14111 parameter
->value_size
= block
->size
;
14113 /* Parameters are not pre-cleared by memset above. */
14114 parameter
->data_value
= NULL
;
14115 parameter
->data_value_size
= 0;
14116 call_site
->parameter_count
++;
14118 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14120 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14121 if (attr
!= nullptr)
14123 if (!attr
->form_is_block ())
14124 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14125 "DW_TAG_call_site child DIE %s [in module %s]"),
14126 sect_offset_str (child_die
->sect_off
),
14127 objfile_name (objfile
));
14130 block
= attr
->as_block ();
14131 parameter
->data_value
= block
->data
;
14132 parameter
->data_value_size
= block
->size
;
14138 /* Helper function for read_variable. If DIE represents a virtual
14139 table, then return the type of the concrete object that is
14140 associated with the virtual table. Otherwise, return NULL. */
14142 static struct type
*
14143 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14145 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14149 /* Find the type DIE. */
14150 struct die_info
*type_die
= NULL
;
14151 struct dwarf2_cu
*type_cu
= cu
;
14153 if (attr
->form_is_ref ())
14154 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14155 if (type_die
== NULL
)
14158 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14160 return die_containing_type (type_die
, type_cu
);
14163 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14166 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14168 struct rust_vtable_symbol
*storage
= NULL
;
14170 if (cu
->language
== language_rust
)
14172 struct type
*containing_type
= rust_containing_type (die
, cu
);
14174 if (containing_type
!= NULL
)
14176 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14178 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
14179 storage
->concrete_type
= containing_type
;
14180 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14184 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14185 struct attribute
*abstract_origin
14186 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14187 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14188 if (res
== NULL
&& loc
&& abstract_origin
)
14190 /* We have a variable without a name, but with a location and an abstract
14191 origin. This may be a concrete instance of an abstract variable
14192 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14194 struct dwarf2_cu
*origin_cu
= cu
;
14195 struct die_info
*origin_die
14196 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14197 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14198 per_objfile
->per_bfd
->abstract_to_concrete
14199 [origin_die
->sect_off
].push_back (die
->sect_off
);
14203 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14204 reading .debug_rnglists.
14205 Callback's type should be:
14206 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14207 Return true if the attributes are present and valid, otherwise,
14210 template <typename Callback
>
14212 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14213 dwarf_tag tag
, Callback
&&callback
)
14215 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14216 struct objfile
*objfile
= per_objfile
->objfile
;
14217 bfd
*obfd
= objfile
->obfd
;
14218 /* Base address selection entry. */
14219 gdb::optional
<CORE_ADDR
> base
;
14220 const gdb_byte
*buffer
;
14221 CORE_ADDR baseaddr
;
14222 bool overflow
= false;
14223 ULONGEST addr_index
;
14224 struct dwarf2_section_info
*rnglists_section
;
14226 base
= cu
->base_address
;
14227 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
14228 rnglists_section
->read (objfile
);
14230 if (offset
>= rnglists_section
->size
)
14232 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14236 buffer
= rnglists_section
->buffer
+ offset
;
14238 baseaddr
= objfile
->text_section_offset ();
14242 /* Initialize it due to a false compiler warning. */
14243 CORE_ADDR range_beginning
= 0, range_end
= 0;
14244 const gdb_byte
*buf_end
= (rnglists_section
->buffer
14245 + rnglists_section
->size
);
14246 unsigned int bytes_read
;
14248 if (buffer
== buf_end
)
14253 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14256 case DW_RLE_end_of_list
:
14258 case DW_RLE_base_address
:
14259 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14264 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14265 buffer
+= bytes_read
;
14267 case DW_RLE_base_addressx
:
14268 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14269 buffer
+= bytes_read
;
14270 base
= read_addr_index (cu
, addr_index
);
14272 case DW_RLE_start_length
:
14273 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14278 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14280 buffer
+= bytes_read
;
14281 range_end
= (range_beginning
14282 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14283 buffer
+= bytes_read
;
14284 if (buffer
> buf_end
)
14290 case DW_RLE_startx_length
:
14291 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14292 buffer
+= bytes_read
;
14293 range_beginning
= read_addr_index (cu
, addr_index
);
14294 if (buffer
> buf_end
)
14299 range_end
= (range_beginning
14300 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14301 buffer
+= bytes_read
;
14303 case DW_RLE_offset_pair
:
14304 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14305 buffer
+= bytes_read
;
14306 if (buffer
> buf_end
)
14311 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14312 buffer
+= bytes_read
;
14313 if (buffer
> buf_end
)
14319 case DW_RLE_start_end
:
14320 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14325 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14327 buffer
+= bytes_read
;
14328 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14329 buffer
+= bytes_read
;
14331 case DW_RLE_startx_endx
:
14332 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14333 buffer
+= bytes_read
;
14334 range_beginning
= read_addr_index (cu
, addr_index
);
14335 if (buffer
> buf_end
)
14340 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14341 buffer
+= bytes_read
;
14342 range_end
= read_addr_index (cu
, addr_index
);
14345 complaint (_("Invalid .debug_rnglists data (no base address)"));
14348 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14350 if (rlet
== DW_RLE_base_address
)
14353 if (range_beginning
> range_end
)
14355 /* Inverted range entries are invalid. */
14356 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14360 /* Empty range entries have no effect. */
14361 if (range_beginning
== range_end
)
14364 /* Only DW_RLE_offset_pair needs the base address added. */
14365 if (rlet
== DW_RLE_offset_pair
)
14367 if (!base
.has_value ())
14369 /* We have no valid base address for the DW_RLE_offset_pair. */
14370 complaint (_("Invalid .debug_rnglists data (no base address for "
14371 "DW_RLE_offset_pair)"));
14375 range_beginning
+= *base
;
14376 range_end
+= *base
;
14379 /* A not-uncommon case of bad debug info.
14380 Don't pollute the addrmap with bad data. */
14381 if (range_beginning
+ baseaddr
== 0
14382 && !per_objfile
->per_bfd
->has_section_at_zero
)
14384 complaint (_(".debug_rnglists entry has start address of zero"
14385 " [in module %s]"), objfile_name (objfile
));
14389 callback (range_beginning
, range_end
);
14394 complaint (_("Offset %d is not terminated "
14395 "for DW_AT_ranges attribute"),
14403 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14404 Callback's type should be:
14405 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14406 Return 1 if the attributes are present and valid, otherwise, return 0. */
14408 template <typename Callback
>
14410 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
14411 Callback
&&callback
)
14413 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14414 struct objfile
*objfile
= per_objfile
->objfile
;
14415 struct comp_unit_head
*cu_header
= &cu
->header
;
14416 bfd
*obfd
= objfile
->obfd
;
14417 unsigned int addr_size
= cu_header
->addr_size
;
14418 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14419 /* Base address selection entry. */
14420 gdb::optional
<CORE_ADDR
> base
;
14421 unsigned int dummy
;
14422 const gdb_byte
*buffer
;
14423 CORE_ADDR baseaddr
;
14425 if (cu_header
->version
>= 5)
14426 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
14428 base
= cu
->base_address
;
14430 per_objfile
->per_bfd
->ranges
.read (objfile
);
14431 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
14433 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14437 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
14439 baseaddr
= objfile
->text_section_offset ();
14443 CORE_ADDR range_beginning
, range_end
;
14445 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14446 buffer
+= addr_size
;
14447 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14448 buffer
+= addr_size
;
14449 offset
+= 2 * addr_size
;
14451 /* An end of list marker is a pair of zero addresses. */
14452 if (range_beginning
== 0 && range_end
== 0)
14453 /* Found the end of list entry. */
14456 /* Each base address selection entry is a pair of 2 values.
14457 The first is the largest possible address, the second is
14458 the base address. Check for a base address here. */
14459 if ((range_beginning
& mask
) == mask
)
14461 /* If we found the largest possible address, then we already
14462 have the base address in range_end. */
14467 if (!base
.has_value ())
14469 /* We have no valid base address for the ranges
14471 complaint (_("Invalid .debug_ranges data (no base address)"));
14475 if (range_beginning
> range_end
)
14477 /* Inverted range entries are invalid. */
14478 complaint (_("Invalid .debug_ranges data (inverted range)"));
14482 /* Empty range entries have no effect. */
14483 if (range_beginning
== range_end
)
14486 range_beginning
+= *base
;
14487 range_end
+= *base
;
14489 /* A not-uncommon case of bad debug info.
14490 Don't pollute the addrmap with bad data. */
14491 if (range_beginning
+ baseaddr
== 0
14492 && !per_objfile
->per_bfd
->has_section_at_zero
)
14494 complaint (_(".debug_ranges entry has start address of zero"
14495 " [in module %s]"), objfile_name (objfile
));
14499 callback (range_beginning
, range_end
);
14505 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14506 Return 1 if the attributes are present and valid, otherwise, return 0.
14507 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14510 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14511 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14512 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
14514 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14515 struct gdbarch
*gdbarch
= objfile
->arch ();
14516 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14519 CORE_ADDR high
= 0;
14522 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14523 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14525 if (ranges_pst
!= NULL
)
14530 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14531 range_beginning
+ baseaddr
)
14533 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14534 range_end
+ baseaddr
)
14536 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14537 lowpc
, highpc
- 1, ranges_pst
);
14540 /* FIXME: This is recording everything as a low-high
14541 segment of consecutive addresses. We should have a
14542 data structure for discontiguous block ranges
14546 low
= range_beginning
;
14552 if (range_beginning
< low
)
14553 low
= range_beginning
;
14554 if (range_end
> high
)
14562 /* If the first entry is an end-of-list marker, the range
14563 describes an empty scope, i.e. no instructions. */
14569 *high_return
= high
;
14573 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14574 definition for the return value. *LOWPC and *HIGHPC are set iff
14575 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14577 static enum pc_bounds_kind
14578 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14579 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14580 dwarf2_psymtab
*pst
)
14582 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14583 struct attribute
*attr
;
14584 struct attribute
*attr_high
;
14586 CORE_ADDR high
= 0;
14587 enum pc_bounds_kind ret
;
14589 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14592 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14593 if (attr
!= nullptr)
14595 low
= attr
->as_address ();
14596 high
= attr_high
->as_address ();
14597 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14601 /* Found high w/o low attribute. */
14602 return PC_BOUNDS_INVALID
;
14604 /* Found consecutive range of addresses. */
14605 ret
= PC_BOUNDS_HIGH_LOW
;
14609 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14610 if (attr
!= nullptr && attr
->form_is_unsigned ())
14612 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14613 on DWARF version). */
14614 ULONGEST ranges_offset
= attr
->as_unsigned ();
14616 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14618 if (die
->tag
!= DW_TAG_compile_unit
)
14619 ranges_offset
+= cu
->gnu_ranges_base
;
14621 /* Value of the DW_AT_ranges attribute is the offset in the
14622 .debug_ranges section. */
14623 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14625 return PC_BOUNDS_INVALID
;
14626 /* Found discontinuous range of addresses. */
14627 ret
= PC_BOUNDS_RANGES
;
14630 return PC_BOUNDS_NOT_PRESENT
;
14633 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14635 return PC_BOUNDS_INVALID
;
14637 /* When using the GNU linker, .gnu.linkonce. sections are used to
14638 eliminate duplicate copies of functions and vtables and such.
14639 The linker will arbitrarily choose one and discard the others.
14640 The AT_*_pc values for such functions refer to local labels in
14641 these sections. If the section from that file was discarded, the
14642 labels are not in the output, so the relocs get a value of 0.
14643 If this is a discarded function, mark the pc bounds as invalid,
14644 so that GDB will ignore it. */
14645 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14646 return PC_BOUNDS_INVALID
;
14654 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14655 its low and high PC addresses. Do nothing if these addresses could not
14656 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14657 and HIGHPC to the high address if greater than HIGHPC. */
14660 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14661 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14662 struct dwarf2_cu
*cu
)
14664 CORE_ADDR low
, high
;
14665 struct die_info
*child
= die
->child
;
14667 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14669 *lowpc
= std::min (*lowpc
, low
);
14670 *highpc
= std::max (*highpc
, high
);
14673 /* If the language does not allow nested subprograms (either inside
14674 subprograms or lexical blocks), we're done. */
14675 if (cu
->language
!= language_ada
)
14678 /* Check all the children of the given DIE. If it contains nested
14679 subprograms, then check their pc bounds. Likewise, we need to
14680 check lexical blocks as well, as they may also contain subprogram
14682 while (child
&& child
->tag
)
14684 if (child
->tag
== DW_TAG_subprogram
14685 || child
->tag
== DW_TAG_lexical_block
)
14686 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14687 child
= child
->sibling
;
14691 /* Get the low and high pc's represented by the scope DIE, and store
14692 them in *LOWPC and *HIGHPC. If the correct values can't be
14693 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14696 get_scope_pc_bounds (struct die_info
*die
,
14697 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14698 struct dwarf2_cu
*cu
)
14700 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14701 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14702 CORE_ADDR current_low
, current_high
;
14704 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14705 >= PC_BOUNDS_RANGES
)
14707 best_low
= current_low
;
14708 best_high
= current_high
;
14712 struct die_info
*child
= die
->child
;
14714 while (child
&& child
->tag
)
14716 switch (child
->tag
) {
14717 case DW_TAG_subprogram
:
14718 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14720 case DW_TAG_namespace
:
14721 case DW_TAG_module
:
14722 /* FIXME: carlton/2004-01-16: Should we do this for
14723 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14724 that current GCC's always emit the DIEs corresponding
14725 to definitions of methods of classes as children of a
14726 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14727 the DIEs giving the declarations, which could be
14728 anywhere). But I don't see any reason why the
14729 standards says that they have to be there. */
14730 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14732 if (current_low
!= ((CORE_ADDR
) -1))
14734 best_low
= std::min (best_low
, current_low
);
14735 best_high
= std::max (best_high
, current_high
);
14743 child
= child
->sibling
;
14748 *highpc
= best_high
;
14751 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14755 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14756 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14758 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14759 struct gdbarch
*gdbarch
= objfile
->arch ();
14760 struct attribute
*attr
;
14761 struct attribute
*attr_high
;
14763 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14766 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14767 if (attr
!= nullptr)
14769 CORE_ADDR low
= attr
->as_address ();
14770 CORE_ADDR high
= attr_high
->as_address ();
14772 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14775 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14776 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14777 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14781 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14782 if (attr
!= nullptr && attr
->form_is_unsigned ())
14784 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14785 on DWARF version). */
14786 ULONGEST ranges_offset
= attr
->as_unsigned ();
14788 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14790 if (die
->tag
!= DW_TAG_compile_unit
)
14791 ranges_offset
+= cu
->gnu_ranges_base
;
14793 std::vector
<blockrange
> blockvec
;
14794 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14795 [&] (CORE_ADDR start
, CORE_ADDR end
)
14799 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14800 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14801 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14802 blockvec
.emplace_back (start
, end
);
14805 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14809 /* Check whether the producer field indicates either of GCC < 4.6, or the
14810 Intel C/C++ compiler, and cache the result in CU. */
14813 check_producer (struct dwarf2_cu
*cu
)
14817 if (cu
->producer
== NULL
)
14819 /* For unknown compilers expect their behavior is DWARF version
14822 GCC started to support .debug_types sections by -gdwarf-4 since
14823 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14824 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14825 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14826 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14828 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14830 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14831 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14833 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14835 cu
->producer_is_icc
= true;
14836 cu
->producer_is_icc_lt_14
= major
< 14;
14838 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14839 cu
->producer_is_codewarrior
= true;
14842 /* For other non-GCC compilers, expect their behavior is DWARF version
14846 cu
->checked_producer
= true;
14849 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14850 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14851 during 4.6.0 experimental. */
14854 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14856 if (!cu
->checked_producer
)
14857 check_producer (cu
);
14859 return cu
->producer_is_gxx_lt_4_6
;
14863 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14864 with incorrect is_stmt attributes. */
14867 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14869 if (!cu
->checked_producer
)
14870 check_producer (cu
);
14872 return cu
->producer_is_codewarrior
;
14875 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14876 If that attribute is not available, return the appropriate
14879 static enum dwarf_access_attribute
14880 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14882 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14883 if (attr
!= nullptr)
14885 LONGEST value
= attr
->constant_value (-1);
14886 if (value
== DW_ACCESS_public
14887 || value
== DW_ACCESS_protected
14888 || value
== DW_ACCESS_private
)
14889 return (dwarf_access_attribute
) value
;
14890 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
14894 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14896 /* The default DWARF 2 accessibility for members is public, the default
14897 accessibility for inheritance is private. */
14899 if (die
->tag
!= DW_TAG_inheritance
)
14900 return DW_ACCESS_public
;
14902 return DW_ACCESS_private
;
14906 /* DWARF 3+ defines the default accessibility a different way. The same
14907 rules apply now for DW_TAG_inheritance as for the members and it only
14908 depends on the container kind. */
14910 if (die
->parent
->tag
== DW_TAG_class_type
)
14911 return DW_ACCESS_private
;
14913 return DW_ACCESS_public
;
14917 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14918 offset. If the attribute was not found return 0, otherwise return
14919 1. If it was found but could not properly be handled, set *OFFSET
14923 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14926 struct attribute
*attr
;
14928 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14933 /* Note that we do not check for a section offset first here.
14934 This is because DW_AT_data_member_location is new in DWARF 4,
14935 so if we see it, we can assume that a constant form is really
14936 a constant and not a section offset. */
14937 if (attr
->form_is_constant ())
14938 *offset
= attr
->constant_value (0);
14939 else if (attr
->form_is_section_offset ())
14940 dwarf2_complex_location_expr_complaint ();
14941 else if (attr
->form_is_block ())
14942 *offset
= decode_locdesc (attr
->as_block (), cu
);
14944 dwarf2_complex_location_expr_complaint ();
14952 /* Look for DW_AT_data_member_location and store the results in FIELD. */
14955 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14956 struct field
*field
)
14958 struct attribute
*attr
;
14960 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14963 if (attr
->form_is_constant ())
14965 LONGEST offset
= attr
->constant_value (0);
14966 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14968 else if (attr
->form_is_section_offset ())
14969 dwarf2_complex_location_expr_complaint ();
14970 else if (attr
->form_is_block ())
14973 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
14975 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
14978 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14979 struct objfile
*objfile
= per_objfile
->objfile
;
14980 struct dwarf2_locexpr_baton
*dlbaton
14981 = XOBNEW (&objfile
->objfile_obstack
,
14982 struct dwarf2_locexpr_baton
);
14983 dlbaton
->data
= attr
->as_block ()->data
;
14984 dlbaton
->size
= attr
->as_block ()->size
;
14985 /* When using this baton, we want to compute the address
14986 of the field, not the value. This is why
14987 is_reference is set to false here. */
14988 dlbaton
->is_reference
= false;
14989 dlbaton
->per_objfile
= per_objfile
;
14990 dlbaton
->per_cu
= cu
->per_cu
;
14992 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
14996 dwarf2_complex_location_expr_complaint ();
15000 /* Add an aggregate field to the field list. */
15003 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15004 struct dwarf2_cu
*cu
)
15006 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15007 struct gdbarch
*gdbarch
= objfile
->arch ();
15008 struct nextfield
*new_field
;
15009 struct attribute
*attr
;
15011 const char *fieldname
= "";
15013 if (die
->tag
== DW_TAG_inheritance
)
15015 fip
->baseclasses
.emplace_back ();
15016 new_field
= &fip
->baseclasses
.back ();
15020 fip
->fields
.emplace_back ();
15021 new_field
= &fip
->fields
.back ();
15024 new_field
->offset
= die
->sect_off
;
15026 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
15027 if (new_field
->accessibility
!= DW_ACCESS_public
)
15028 fip
->non_public_fields
= true;
15030 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15031 if (attr
!= nullptr)
15032 new_field
->virtuality
= attr
->as_virtuality ();
15034 new_field
->virtuality
= DW_VIRTUALITY_none
;
15036 fp
= &new_field
->field
;
15038 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15040 /* Data member other than a C++ static data member. */
15042 /* Get type of field. */
15043 fp
->set_type (die_type (die
, cu
));
15045 SET_FIELD_BITPOS (*fp
, 0);
15047 /* Get bit size of field (zero if none). */
15048 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15049 if (attr
!= nullptr)
15051 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
15055 FIELD_BITSIZE (*fp
) = 0;
15058 /* Get bit offset of field. */
15059 handle_data_member_location (die
, cu
, fp
);
15060 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15061 if (attr
!= nullptr && attr
->form_is_constant ())
15063 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15065 /* For big endian bits, the DW_AT_bit_offset gives the
15066 additional bit offset from the MSB of the containing
15067 anonymous object to the MSB of the field. We don't
15068 have to do anything special since we don't need to
15069 know the size of the anonymous object. */
15070 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15071 + attr
->constant_value (0)));
15075 /* For little endian bits, compute the bit offset to the
15076 MSB of the anonymous object, subtract off the number of
15077 bits from the MSB of the field to the MSB of the
15078 object, and then subtract off the number of bits of
15079 the field itself. The result is the bit offset of
15080 the LSB of the field. */
15081 int anonymous_size
;
15082 int bit_offset
= attr
->constant_value (0);
15084 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15085 if (attr
!= nullptr && attr
->form_is_constant ())
15087 /* The size of the anonymous object containing
15088 the bit field is explicit, so use the
15089 indicated size (in bytes). */
15090 anonymous_size
= attr
->constant_value (0);
15094 /* The size of the anonymous object containing
15095 the bit field must be inferred from the type
15096 attribute of the data member containing the
15098 anonymous_size
= TYPE_LENGTH (fp
->type ());
15100 SET_FIELD_BITPOS (*fp
,
15101 (FIELD_BITPOS (*fp
)
15102 + anonymous_size
* bits_per_byte
15103 - bit_offset
- FIELD_BITSIZE (*fp
)));
15106 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15108 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15109 + attr
->constant_value (0)));
15111 /* Get name of field. */
15112 fieldname
= dwarf2_name (die
, cu
);
15113 if (fieldname
== NULL
)
15116 /* The name is already allocated along with this objfile, so we don't
15117 need to duplicate it for the type. */
15118 fp
->name
= fieldname
;
15120 /* Change accessibility for artificial fields (e.g. virtual table
15121 pointer or virtual base class pointer) to private. */
15122 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15124 FIELD_ARTIFICIAL (*fp
) = 1;
15125 new_field
->accessibility
= DW_ACCESS_private
;
15126 fip
->non_public_fields
= true;
15129 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15131 /* C++ static member. */
15133 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15134 is a declaration, but all versions of G++ as of this writing
15135 (so through at least 3.2.1) incorrectly generate
15136 DW_TAG_variable tags. */
15138 const char *physname
;
15140 /* Get name of field. */
15141 fieldname
= dwarf2_name (die
, cu
);
15142 if (fieldname
== NULL
)
15145 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15147 /* Only create a symbol if this is an external value.
15148 new_symbol checks this and puts the value in the global symbol
15149 table, which we want. If it is not external, new_symbol
15150 will try to put the value in cu->list_in_scope which is wrong. */
15151 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15153 /* A static const member, not much different than an enum as far as
15154 we're concerned, except that we can support more types. */
15155 new_symbol (die
, NULL
, cu
);
15158 /* Get physical name. */
15159 physname
= dwarf2_physname (fieldname
, die
, cu
);
15161 /* The name is already allocated along with this objfile, so we don't
15162 need to duplicate it for the type. */
15163 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15164 fp
->set_type (die_type (die
, cu
));
15165 FIELD_NAME (*fp
) = fieldname
;
15167 else if (die
->tag
== DW_TAG_inheritance
)
15169 /* C++ base class field. */
15170 handle_data_member_location (die
, cu
, fp
);
15171 FIELD_BITSIZE (*fp
) = 0;
15172 fp
->set_type (die_type (die
, cu
));
15173 FIELD_NAME (*fp
) = fp
->type ()->name ();
15176 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15179 /* Can the type given by DIE define another type? */
15182 type_can_define_types (const struct die_info
*die
)
15186 case DW_TAG_typedef
:
15187 case DW_TAG_class_type
:
15188 case DW_TAG_structure_type
:
15189 case DW_TAG_union_type
:
15190 case DW_TAG_enumeration_type
:
15198 /* Add a type definition defined in the scope of the FIP's class. */
15201 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15202 struct dwarf2_cu
*cu
)
15204 struct decl_field fp
;
15205 memset (&fp
, 0, sizeof (fp
));
15207 gdb_assert (type_can_define_types (die
));
15209 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15210 fp
.name
= dwarf2_name (die
, cu
);
15211 fp
.type
= read_type_die (die
, cu
);
15213 /* Save accessibility. */
15214 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15215 switch (accessibility
)
15217 case DW_ACCESS_public
:
15218 /* The assumed value if neither private nor protected. */
15220 case DW_ACCESS_private
:
15223 case DW_ACCESS_protected
:
15224 fp
.is_protected
= 1;
15228 if (die
->tag
== DW_TAG_typedef
)
15229 fip
->typedef_field_list
.push_back (fp
);
15231 fip
->nested_types_list
.push_back (fp
);
15234 /* A convenience typedef that's used when finding the discriminant
15235 field for a variant part. */
15236 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
15239 /* Compute the discriminant range for a given variant. OBSTACK is
15240 where the results will be stored. VARIANT is the variant to
15241 process. IS_UNSIGNED indicates whether the discriminant is signed
15244 static const gdb::array_view
<discriminant_range
>
15245 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
15248 std::vector
<discriminant_range
> ranges
;
15250 if (variant
.default_branch
)
15253 if (variant
.discr_list_data
== nullptr)
15255 discriminant_range r
15256 = {variant
.discriminant_value
, variant
.discriminant_value
};
15257 ranges
.push_back (r
);
15261 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
15262 variant
.discr_list_data
->size
);
15263 while (!data
.empty ())
15265 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
15267 complaint (_("invalid discriminant marker: %d"), data
[0]);
15270 bool is_range
= data
[0] == DW_DSC_range
;
15271 data
= data
.slice (1);
15273 ULONGEST low
, high
;
15274 unsigned int bytes_read
;
15278 complaint (_("DW_AT_discr_list missing low value"));
15282 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
15284 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
15286 data
= data
.slice (bytes_read
);
15292 complaint (_("DW_AT_discr_list missing high value"));
15296 high
= read_unsigned_leb128 (nullptr, data
.data (),
15299 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
15301 data
= data
.slice (bytes_read
);
15306 ranges
.push_back ({ low
, high
});
15310 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
15312 std::copy (ranges
.begin (), ranges
.end (), result
);
15313 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
15316 static const gdb::array_view
<variant_part
> create_variant_parts
15317 (struct obstack
*obstack
,
15318 const offset_map_type
&offset_map
,
15319 struct field_info
*fi
,
15320 const std::vector
<variant_part_builder
> &variant_parts
);
15322 /* Fill in a "struct variant" for a given variant field. RESULT is
15323 the variant to fill in. OBSTACK is where any needed allocations
15324 will be done. OFFSET_MAP holds the mapping from section offsets to
15325 fields for the type. FI describes the fields of the type we're
15326 processing. FIELD is the variant field we're converting. */
15329 create_one_variant (variant
&result
, struct obstack
*obstack
,
15330 const offset_map_type
&offset_map
,
15331 struct field_info
*fi
, const variant_field
&field
)
15333 result
.discriminants
= convert_variant_range (obstack
, field
, false);
15334 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
15335 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
15336 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
15337 field
.variant_parts
);
15340 /* Fill in a "struct variant_part" for a given variant part. RESULT
15341 is the variant part to fill in. OBSTACK is where any needed
15342 allocations will be done. OFFSET_MAP holds the mapping from
15343 section offsets to fields for the type. FI describes the fields of
15344 the type we're processing. BUILDER is the variant part to be
15348 create_one_variant_part (variant_part
&result
,
15349 struct obstack
*obstack
,
15350 const offset_map_type
&offset_map
,
15351 struct field_info
*fi
,
15352 const variant_part_builder
&builder
)
15354 auto iter
= offset_map
.find (builder
.discriminant_offset
);
15355 if (iter
== offset_map
.end ())
15357 result
.discriminant_index
= -1;
15358 /* Doesn't matter. */
15359 result
.is_unsigned
= false;
15363 result
.discriminant_index
= iter
->second
;
15365 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
15368 size_t n
= builder
.variants
.size ();
15369 variant
*output
= new (obstack
) variant
[n
];
15370 for (size_t i
= 0; i
< n
; ++i
)
15371 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
15372 builder
.variants
[i
]);
15374 result
.variants
= gdb::array_view
<variant
> (output
, n
);
15377 /* Create a vector of variant parts that can be attached to a type.
15378 OBSTACK is where any needed allocations will be done. OFFSET_MAP
15379 holds the mapping from section offsets to fields for the type. FI
15380 describes the fields of the type we're processing. VARIANT_PARTS
15381 is the vector to convert. */
15383 static const gdb::array_view
<variant_part
>
15384 create_variant_parts (struct obstack
*obstack
,
15385 const offset_map_type
&offset_map
,
15386 struct field_info
*fi
,
15387 const std::vector
<variant_part_builder
> &variant_parts
)
15389 if (variant_parts
.empty ())
15392 size_t n
= variant_parts
.size ();
15393 variant_part
*result
= new (obstack
) variant_part
[n
];
15394 for (size_t i
= 0; i
< n
; ++i
)
15395 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
15398 return gdb::array_view
<variant_part
> (result
, n
);
15401 /* Compute the variant part vector for FIP, attaching it to TYPE when
15405 add_variant_property (struct field_info
*fip
, struct type
*type
,
15406 struct dwarf2_cu
*cu
)
15408 /* Map section offsets of fields to their field index. Note the
15409 field index here does not take the number of baseclasses into
15411 offset_map_type offset_map
;
15412 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
15413 offset_map
[fip
->fields
[i
].offset
] = i
;
15415 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15416 gdb::array_view
<variant_part
> parts
15417 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
15418 fip
->variant_parts
);
15420 struct dynamic_prop prop
;
15421 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
15422 obstack_copy (&objfile
->objfile_obstack
, &parts
,
15425 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
15428 /* Create the vector of fields, and attach it to the type. */
15431 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15432 struct dwarf2_cu
*cu
)
15434 int nfields
= fip
->nfields ();
15436 /* Record the field count, allocate space for the array of fields,
15437 and create blank accessibility bitfields if necessary. */
15438 type
->set_num_fields (nfields
);
15440 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
15442 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15444 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15446 TYPE_FIELD_PRIVATE_BITS (type
) =
15447 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15448 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15450 TYPE_FIELD_PROTECTED_BITS (type
) =
15451 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15452 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15454 TYPE_FIELD_IGNORE_BITS (type
) =
15455 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15456 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15459 /* If the type has baseclasses, allocate and clear a bit vector for
15460 TYPE_FIELD_VIRTUAL_BITS. */
15461 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15463 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15464 unsigned char *pointer
;
15466 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15467 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15468 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15469 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15470 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15473 if (!fip
->variant_parts
.empty ())
15474 add_variant_property (fip
, type
, cu
);
15476 /* Copy the saved-up fields into the field vector. */
15477 for (int i
= 0; i
< nfields
; ++i
)
15479 struct nextfield
&field
15480 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15481 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15483 type
->field (i
) = field
.field
;
15484 switch (field
.accessibility
)
15486 case DW_ACCESS_private
:
15487 if (cu
->language
!= language_ada
)
15488 SET_TYPE_FIELD_PRIVATE (type
, i
);
15491 case DW_ACCESS_protected
:
15492 if (cu
->language
!= language_ada
)
15493 SET_TYPE_FIELD_PROTECTED (type
, i
);
15496 case DW_ACCESS_public
:
15500 /* Unknown accessibility. Complain and treat it as public. */
15502 complaint (_("unsupported accessibility %d"),
15503 field
.accessibility
);
15507 if (i
< fip
->baseclasses
.size ())
15509 switch (field
.virtuality
)
15511 case DW_VIRTUALITY_virtual
:
15512 case DW_VIRTUALITY_pure_virtual
:
15513 if (cu
->language
== language_ada
)
15514 error (_("unexpected virtuality in component of Ada type"));
15515 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15522 /* Return true if this member function is a constructor, false
15526 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15528 const char *fieldname
;
15529 const char *type_name
;
15532 if (die
->parent
== NULL
)
15535 if (die
->parent
->tag
!= DW_TAG_structure_type
15536 && die
->parent
->tag
!= DW_TAG_union_type
15537 && die
->parent
->tag
!= DW_TAG_class_type
)
15540 fieldname
= dwarf2_name (die
, cu
);
15541 type_name
= dwarf2_name (die
->parent
, cu
);
15542 if (fieldname
== NULL
|| type_name
== NULL
)
15545 len
= strlen (fieldname
);
15546 return (strncmp (fieldname
, type_name
, len
) == 0
15547 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15550 /* Add a member function to the proper fieldlist. */
15553 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15554 struct type
*type
, struct dwarf2_cu
*cu
)
15556 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15557 struct attribute
*attr
;
15559 struct fnfieldlist
*flp
= nullptr;
15560 struct fn_field
*fnp
;
15561 const char *fieldname
;
15562 struct type
*this_type
;
15564 if (cu
->language
== language_ada
)
15565 error (_("unexpected member function in Ada type"));
15567 /* Get name of member function. */
15568 fieldname
= dwarf2_name (die
, cu
);
15569 if (fieldname
== NULL
)
15572 /* Look up member function name in fieldlist. */
15573 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15575 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15577 flp
= &fip
->fnfieldlists
[i
];
15582 /* Create a new fnfieldlist if necessary. */
15583 if (flp
== nullptr)
15585 fip
->fnfieldlists
.emplace_back ();
15586 flp
= &fip
->fnfieldlists
.back ();
15587 flp
->name
= fieldname
;
15588 i
= fip
->fnfieldlists
.size () - 1;
15591 /* Create a new member function field and add it to the vector of
15593 flp
->fnfields
.emplace_back ();
15594 fnp
= &flp
->fnfields
.back ();
15596 /* Delay processing of the physname until later. */
15597 if (cu
->language
== language_cplus
)
15598 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15602 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15603 fnp
->physname
= physname
? physname
: "";
15606 fnp
->type
= alloc_type (objfile
);
15607 this_type
= read_type_die (die
, cu
);
15608 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15610 int nparams
= this_type
->num_fields ();
15612 /* TYPE is the domain of this method, and THIS_TYPE is the type
15613 of the method itself (TYPE_CODE_METHOD). */
15614 smash_to_method_type (fnp
->type
, type
,
15615 TYPE_TARGET_TYPE (this_type
),
15616 this_type
->fields (),
15617 this_type
->num_fields (),
15618 this_type
->has_varargs ());
15620 /* Handle static member functions.
15621 Dwarf2 has no clean way to discern C++ static and non-static
15622 member functions. G++ helps GDB by marking the first
15623 parameter for non-static member functions (which is the this
15624 pointer) as artificial. We obtain this information from
15625 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15626 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15627 fnp
->voffset
= VOFFSET_STATIC
;
15630 complaint (_("member function type missing for '%s'"),
15631 dwarf2_full_name (fieldname
, die
, cu
));
15633 /* Get fcontext from DW_AT_containing_type if present. */
15634 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15635 fnp
->fcontext
= die_containing_type (die
, cu
);
15637 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15638 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15640 /* Get accessibility. */
15641 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15642 switch (accessibility
)
15644 case DW_ACCESS_private
:
15645 fnp
->is_private
= 1;
15647 case DW_ACCESS_protected
:
15648 fnp
->is_protected
= 1;
15652 /* Check for artificial methods. */
15653 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15654 if (attr
&& attr
->as_boolean ())
15655 fnp
->is_artificial
= 1;
15657 /* Check for defaulted methods. */
15658 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15659 if (attr
!= nullptr)
15660 fnp
->defaulted
= attr
->defaulted ();
15662 /* Check for deleted methods. */
15663 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15664 if (attr
!= nullptr && attr
->as_boolean ())
15665 fnp
->is_deleted
= 1;
15667 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15669 /* Get index in virtual function table if it is a virtual member
15670 function. For older versions of GCC, this is an offset in the
15671 appropriate virtual table, as specified by DW_AT_containing_type.
15672 For everyone else, it is an expression to be evaluated relative
15673 to the object address. */
15675 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15676 if (attr
!= nullptr)
15678 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15680 struct dwarf_block
*block
= attr
->as_block ();
15682 if (block
->data
[0] == DW_OP_constu
)
15684 /* Old-style GCC. */
15685 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15687 else if (block
->data
[0] == DW_OP_deref
15688 || (block
->size
> 1
15689 && block
->data
[0] == DW_OP_deref_size
15690 && block
->data
[1] == cu
->header
.addr_size
))
15692 fnp
->voffset
= decode_locdesc (block
, cu
);
15693 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15694 dwarf2_complex_location_expr_complaint ();
15696 fnp
->voffset
/= cu
->header
.addr_size
;
15700 dwarf2_complex_location_expr_complaint ();
15702 if (!fnp
->fcontext
)
15704 /* If there is no `this' field and no DW_AT_containing_type,
15705 we cannot actually find a base class context for the
15707 if (this_type
->num_fields () == 0
15708 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15710 complaint (_("cannot determine context for virtual member "
15711 "function \"%s\" (offset %s)"),
15712 fieldname
, sect_offset_str (die
->sect_off
));
15717 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15721 else if (attr
->form_is_section_offset ())
15723 dwarf2_complex_location_expr_complaint ();
15727 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15733 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15734 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15736 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15737 complaint (_("Member function \"%s\" (offset %s) is virtual "
15738 "but the vtable offset is not specified"),
15739 fieldname
, sect_offset_str (die
->sect_off
));
15740 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15741 TYPE_CPLUS_DYNAMIC (type
) = 1;
15746 /* Create the vector of member function fields, and attach it to the type. */
15749 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15750 struct dwarf2_cu
*cu
)
15752 if (cu
->language
== language_ada
)
15753 error (_("unexpected member functions in Ada type"));
15755 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15756 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15758 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15760 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15762 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15763 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15765 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15766 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15767 fn_flp
->fn_fields
= (struct fn_field
*)
15768 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15770 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15771 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15774 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15777 /* Returns non-zero if NAME is the name of a vtable member in CU's
15778 language, zero otherwise. */
15780 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15782 static const char vptr
[] = "_vptr";
15784 /* Look for the C++ form of the vtable. */
15785 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15791 /* GCC outputs unnamed structures that are really pointers to member
15792 functions, with the ABI-specified layout. If TYPE describes
15793 such a structure, smash it into a member function type.
15795 GCC shouldn't do this; it should just output pointer to member DIEs.
15796 This is GCC PR debug/28767. */
15799 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15801 struct type
*pfn_type
, *self_type
, *new_type
;
15803 /* Check for a structure with no name and two children. */
15804 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15807 /* Check for __pfn and __delta members. */
15808 if (TYPE_FIELD_NAME (type
, 0) == NULL
15809 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15810 || TYPE_FIELD_NAME (type
, 1) == NULL
15811 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15814 /* Find the type of the method. */
15815 pfn_type
= type
->field (0).type ();
15816 if (pfn_type
== NULL
15817 || pfn_type
->code () != TYPE_CODE_PTR
15818 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15821 /* Look for the "this" argument. */
15822 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15823 if (pfn_type
->num_fields () == 0
15824 /* || pfn_type->field (0).type () == NULL */
15825 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15828 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15829 new_type
= alloc_type (objfile
);
15830 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15831 pfn_type
->fields (), pfn_type
->num_fields (),
15832 pfn_type
->has_varargs ());
15833 smash_to_methodptr_type (type
, new_type
);
15836 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15837 requires rewriting, then copy it and return the updated copy.
15838 Otherwise return nullptr. */
15840 static struct type
*
15841 rewrite_array_type (struct type
*type
)
15843 if (type
->code () != TYPE_CODE_ARRAY
)
15846 struct type
*index_type
= type
->index_type ();
15847 range_bounds
*current_bounds
= index_type
->bounds ();
15849 /* Handle multi-dimensional arrays. */
15850 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15851 if (new_target
== nullptr)
15853 /* Maybe we don't need to rewrite this array. */
15854 if (current_bounds
->low
.kind () == PROP_CONST
15855 && current_bounds
->high
.kind () == PROP_CONST
)
15859 /* Either the target type was rewritten, or the bounds have to be
15860 updated. Either way we want to copy the type and update
15862 struct type
*copy
= copy_type (type
);
15863 int nfields
= copy
->num_fields ();
15865 = ((struct field
*) TYPE_ZALLOC (copy
,
15866 nfields
* sizeof (struct field
)));
15867 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15868 copy
->set_fields (new_fields
);
15869 if (new_target
!= nullptr)
15870 TYPE_TARGET_TYPE (copy
) = new_target
;
15872 struct type
*index_copy
= copy_type (index_type
);
15873 range_bounds
*bounds
15874 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15875 sizeof (range_bounds
));
15876 *bounds
= *current_bounds
;
15877 bounds
->low
.set_const_val (1);
15878 bounds
->high
.set_const_val (0);
15879 index_copy
->set_bounds (bounds
);
15880 copy
->set_index_type (index_copy
);
15885 /* While some versions of GCC will generate complicated DWARF for an
15886 array (see quirk_ada_thick_pointer), more recent versions were
15887 modified to emit an explicit thick pointer structure. However, in
15888 this case, the array still has DWARF expressions for its ranges,
15889 and these must be ignored. */
15892 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
15895 gdb_assert (cu
->language
== language_ada
);
15897 /* Check for a structure with two children. */
15898 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15901 /* Check for P_ARRAY and P_BOUNDS members. */
15902 if (TYPE_FIELD_NAME (type
, 0) == NULL
15903 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
15904 || TYPE_FIELD_NAME (type
, 1) == NULL
15905 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
15908 /* Make sure we're looking at a pointer to an array. */
15909 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15912 /* The Ada code already knows how to handle these types, so all that
15913 we need to do is turn the bounds into static bounds. However, we
15914 don't want to rewrite existing array or index types in-place,
15915 because those may be referenced in other contexts where this
15916 rewriting is undesirable. */
15917 struct type
*new_ary_type
15918 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
15919 if (new_ary_type
!= nullptr)
15920 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
15923 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15924 appropriate error checking and issuing complaints if there is a
15928 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15930 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15932 if (attr
== nullptr)
15935 if (!attr
->form_is_constant ())
15937 complaint (_("DW_AT_alignment must have constant form"
15938 " - DIE at %s [in module %s]"),
15939 sect_offset_str (die
->sect_off
),
15940 objfile_name (cu
->per_objfile
->objfile
));
15944 LONGEST val
= attr
->constant_value (0);
15947 complaint (_("DW_AT_alignment value must not be negative"
15948 " - DIE at %s [in module %s]"),
15949 sect_offset_str (die
->sect_off
),
15950 objfile_name (cu
->per_objfile
->objfile
));
15953 ULONGEST align
= val
;
15957 complaint (_("DW_AT_alignment value must not be zero"
15958 " - DIE at %s [in module %s]"),
15959 sect_offset_str (die
->sect_off
),
15960 objfile_name (cu
->per_objfile
->objfile
));
15963 if ((align
& (align
- 1)) != 0)
15965 complaint (_("DW_AT_alignment value must be a power of 2"
15966 " - DIE at %s [in module %s]"),
15967 sect_offset_str (die
->sect_off
),
15968 objfile_name (cu
->per_objfile
->objfile
));
15975 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15976 the alignment for TYPE. */
15979 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15982 if (!set_type_align (type
, get_alignment (cu
, die
)))
15983 complaint (_("DW_AT_alignment value too large"
15984 " - DIE at %s [in module %s]"),
15985 sect_offset_str (die
->sect_off
),
15986 objfile_name (cu
->per_objfile
->objfile
));
15989 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15990 constant for a type, according to DWARF5 spec, Table 5.5. */
15993 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15998 case DW_CC_pass_by_reference
:
15999 case DW_CC_pass_by_value
:
16003 complaint (_("unrecognized DW_AT_calling_convention value "
16004 "(%s) for a type"), pulongest (value
));
16009 /* Check if the given VALUE is a valid enum dwarf_calling_convention
16010 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
16011 also according to GNU-specific values (see include/dwarf2.h). */
16014 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
16019 case DW_CC_program
:
16023 case DW_CC_GNU_renesas_sh
:
16024 case DW_CC_GNU_borland_fastcall_i386
:
16025 case DW_CC_GDB_IBM_OpenCL
:
16029 complaint (_("unrecognized DW_AT_calling_convention value "
16030 "(%s) for a subroutine"), pulongest (value
));
16035 /* Called when we find the DIE that starts a structure or union scope
16036 (definition) to create a type for the structure or union. Fill in
16037 the type's name and general properties; the members will not be
16038 processed until process_structure_scope. A symbol table entry for
16039 the type will also not be done until process_structure_scope (assuming
16040 the type has a name).
16042 NOTE: we need to call these functions regardless of whether or not the
16043 DIE has a DW_AT_name attribute, since it might be an anonymous
16044 structure or union. This gets the type entered into our set of
16045 user defined types. */
16047 static struct type
*
16048 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16050 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16052 struct attribute
*attr
;
16055 /* If the definition of this type lives in .debug_types, read that type.
16056 Don't follow DW_AT_specification though, that will take us back up
16057 the chain and we want to go down. */
16058 attr
= die
->attr (DW_AT_signature
);
16059 if (attr
!= nullptr)
16061 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16063 /* The type's CU may not be the same as CU.
16064 Ensure TYPE is recorded with CU in die_type_hash. */
16065 return set_die_type (die
, type
, cu
);
16068 type
= alloc_type (objfile
);
16069 INIT_CPLUS_SPECIFIC (type
);
16071 name
= dwarf2_name (die
, cu
);
16074 if (cu
->language
== language_cplus
16075 || cu
->language
== language_d
16076 || cu
->language
== language_rust
)
16078 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
16080 /* dwarf2_full_name might have already finished building the DIE's
16081 type. If so, there is no need to continue. */
16082 if (get_die_type (die
, cu
) != NULL
)
16083 return get_die_type (die
, cu
);
16085 type
->set_name (full_name
);
16089 /* The name is already allocated along with this objfile, so
16090 we don't need to duplicate it for the type. */
16091 type
->set_name (name
);
16095 if (die
->tag
== DW_TAG_structure_type
)
16097 type
->set_code (TYPE_CODE_STRUCT
);
16099 else if (die
->tag
== DW_TAG_union_type
)
16101 type
->set_code (TYPE_CODE_UNION
);
16105 type
->set_code (TYPE_CODE_STRUCT
);
16108 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
16109 TYPE_DECLARED_CLASS (type
) = 1;
16111 /* Store the calling convention in the type if it's available in
16112 the die. Otherwise the calling convention remains set to
16113 the default value DW_CC_normal. */
16114 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16115 if (attr
!= nullptr
16116 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
16118 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16119 TYPE_CPLUS_CALLING_CONVENTION (type
)
16120 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
16123 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16124 if (attr
!= nullptr)
16126 if (attr
->form_is_constant ())
16127 TYPE_LENGTH (type
) = attr
->constant_value (0);
16130 struct dynamic_prop prop
;
16131 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
16132 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
16133 TYPE_LENGTH (type
) = 0;
16138 TYPE_LENGTH (type
) = 0;
16141 maybe_set_alignment (cu
, die
, type
);
16143 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16145 /* ICC<14 does not output the required DW_AT_declaration on
16146 incomplete types, but gives them a size of zero. */
16147 type
->set_is_stub (true);
16150 type
->set_stub_is_supported (true);
16152 if (die_is_declaration (die
, cu
))
16153 type
->set_is_stub (true);
16154 else if (attr
== NULL
&& die
->child
== NULL
16155 && producer_is_realview (cu
->producer
))
16156 /* RealView does not output the required DW_AT_declaration
16157 on incomplete types. */
16158 type
->set_is_stub (true);
16160 /* We need to add the type field to the die immediately so we don't
16161 infinitely recurse when dealing with pointers to the structure
16162 type within the structure itself. */
16163 set_die_type (die
, type
, cu
);
16165 /* set_die_type should be already done. */
16166 set_descriptive_type (type
, die
, cu
);
16171 static void handle_struct_member_die
16172 (struct die_info
*child_die
,
16174 struct field_info
*fi
,
16175 std::vector
<struct symbol
*> *template_args
,
16176 struct dwarf2_cu
*cu
);
16178 /* A helper for handle_struct_member_die that handles
16179 DW_TAG_variant_part. */
16182 handle_variant_part (struct die_info
*die
, struct type
*type
,
16183 struct field_info
*fi
,
16184 std::vector
<struct symbol
*> *template_args
,
16185 struct dwarf2_cu
*cu
)
16187 variant_part_builder
*new_part
;
16188 if (fi
->current_variant_part
== nullptr)
16190 fi
->variant_parts
.emplace_back ();
16191 new_part
= &fi
->variant_parts
.back ();
16193 else if (!fi
->current_variant_part
->processing_variant
)
16195 complaint (_("nested DW_TAG_variant_part seen "
16196 "- DIE at %s [in module %s]"),
16197 sect_offset_str (die
->sect_off
),
16198 objfile_name (cu
->per_objfile
->objfile
));
16203 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
16204 current
.variant_parts
.emplace_back ();
16205 new_part
= ¤t
.variant_parts
.back ();
16208 /* When we recurse, we want callees to add to this new variant
16210 scoped_restore save_current_variant_part
16211 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
16213 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16216 /* It's a univariant form, an extension we support. */
16218 else if (discr
->form_is_ref ())
16220 struct dwarf2_cu
*target_cu
= cu
;
16221 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16223 new_part
->discriminant_offset
= target_die
->sect_off
;
16227 complaint (_("DW_AT_discr does not have DIE reference form"
16228 " - DIE at %s [in module %s]"),
16229 sect_offset_str (die
->sect_off
),
16230 objfile_name (cu
->per_objfile
->objfile
));
16233 for (die_info
*child_die
= die
->child
;
16235 child_die
= child_die
->sibling
)
16236 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
16239 /* A helper for handle_struct_member_die that handles
16243 handle_variant (struct die_info
*die
, struct type
*type
,
16244 struct field_info
*fi
,
16245 std::vector
<struct symbol
*> *template_args
,
16246 struct dwarf2_cu
*cu
)
16248 if (fi
->current_variant_part
== nullptr)
16250 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
16251 "- DIE at %s [in module %s]"),
16252 sect_offset_str (die
->sect_off
),
16253 objfile_name (cu
->per_objfile
->objfile
));
16256 if (fi
->current_variant_part
->processing_variant
)
16258 complaint (_("nested DW_TAG_variant seen "
16259 "- DIE at %s [in module %s]"),
16260 sect_offset_str (die
->sect_off
),
16261 objfile_name (cu
->per_objfile
->objfile
));
16265 scoped_restore save_processing_variant
16266 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
16269 fi
->current_variant_part
->variants
.emplace_back ();
16270 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
16271 variant
.first_field
= fi
->fields
.size ();
16273 /* In a variant we want to get the discriminant and also add a
16274 field for our sole member child. */
16275 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
16276 if (discr
== nullptr || !discr
->form_is_constant ())
16278 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
16279 if (discr
== nullptr || discr
->as_block ()->size
== 0)
16280 variant
.default_branch
= true;
16282 variant
.discr_list_data
= discr
->as_block ();
16285 variant
.discriminant_value
= discr
->constant_value (0);
16287 for (die_info
*variant_child
= die
->child
;
16288 variant_child
!= NULL
;
16289 variant_child
= variant_child
->sibling
)
16290 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
16292 variant
.last_field
= fi
->fields
.size ();
16295 /* A helper for process_structure_scope that handles a single member
16299 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16300 struct field_info
*fi
,
16301 std::vector
<struct symbol
*> *template_args
,
16302 struct dwarf2_cu
*cu
)
16304 if (child_die
->tag
== DW_TAG_member
16305 || child_die
->tag
== DW_TAG_variable
)
16307 /* NOTE: carlton/2002-11-05: A C++ static data member
16308 should be a DW_TAG_member that is a declaration, but
16309 all versions of G++ as of this writing (so through at
16310 least 3.2.1) incorrectly generate DW_TAG_variable
16311 tags for them instead. */
16312 dwarf2_add_field (fi
, child_die
, cu
);
16314 else if (child_die
->tag
== DW_TAG_subprogram
)
16316 /* Rust doesn't have member functions in the C++ sense.
16317 However, it does emit ordinary functions as children
16318 of a struct DIE. */
16319 if (cu
->language
== language_rust
)
16320 read_func_scope (child_die
, cu
);
16323 /* C++ member function. */
16324 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16327 else if (child_die
->tag
== DW_TAG_inheritance
)
16329 /* C++ base class field. */
16330 dwarf2_add_field (fi
, child_die
, cu
);
16332 else if (type_can_define_types (child_die
))
16333 dwarf2_add_type_defn (fi
, child_die
, cu
);
16334 else if (child_die
->tag
== DW_TAG_template_type_param
16335 || child_die
->tag
== DW_TAG_template_value_param
)
16337 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16340 template_args
->push_back (arg
);
16342 else if (child_die
->tag
== DW_TAG_variant_part
)
16343 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
16344 else if (child_die
->tag
== DW_TAG_variant
)
16345 handle_variant (child_die
, type
, fi
, template_args
, cu
);
16348 /* Finish creating a structure or union type, including filling in
16349 its members and creating a symbol for it. */
16352 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16354 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16355 struct die_info
*child_die
;
16358 type
= get_die_type (die
, cu
);
16360 type
= read_structure_type (die
, cu
);
16362 bool has_template_parameters
= false;
16363 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16365 struct field_info fi
;
16366 std::vector
<struct symbol
*> template_args
;
16368 child_die
= die
->child
;
16370 while (child_die
&& child_die
->tag
)
16372 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16373 child_die
= child_die
->sibling
;
16376 /* Attach template arguments to type. */
16377 if (!template_args
.empty ())
16379 has_template_parameters
= true;
16380 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16381 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16382 TYPE_TEMPLATE_ARGUMENTS (type
)
16383 = XOBNEWVEC (&objfile
->objfile_obstack
,
16385 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16386 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16387 template_args
.data (),
16388 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16389 * sizeof (struct symbol
*)));
16392 /* Attach fields and member functions to the type. */
16393 if (fi
.nfields () > 0)
16394 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16395 if (!fi
.fnfieldlists
.empty ())
16397 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16399 /* Get the type which refers to the base class (possibly this
16400 class itself) which contains the vtable pointer for the current
16401 class from the DW_AT_containing_type attribute. This use of
16402 DW_AT_containing_type is a GNU extension. */
16404 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16406 struct type
*t
= die_containing_type (die
, cu
);
16408 set_type_vptr_basetype (type
, t
);
16413 /* Our own class provides vtbl ptr. */
16414 for (i
= t
->num_fields () - 1;
16415 i
>= TYPE_N_BASECLASSES (t
);
16418 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16420 if (is_vtable_name (fieldname
, cu
))
16422 set_type_vptr_fieldno (type
, i
);
16427 /* Complain if virtual function table field not found. */
16428 if (i
< TYPE_N_BASECLASSES (t
))
16429 complaint (_("virtual function table pointer "
16430 "not found when defining class '%s'"),
16431 type
->name () ? type
->name () : "");
16435 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16438 else if (cu
->producer
16439 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16441 /* The IBM XLC compiler does not provide direct indication
16442 of the containing type, but the vtable pointer is
16443 always named __vfp. */
16447 for (i
= type
->num_fields () - 1;
16448 i
>= TYPE_N_BASECLASSES (type
);
16451 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16453 set_type_vptr_fieldno (type
, i
);
16454 set_type_vptr_basetype (type
, type
);
16461 /* Copy fi.typedef_field_list linked list elements content into the
16462 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16463 if (!fi
.typedef_field_list
.empty ())
16465 int count
= fi
.typedef_field_list
.size ();
16467 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16468 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16469 = ((struct decl_field
*)
16471 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16472 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16474 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16475 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16478 /* Copy fi.nested_types_list linked list elements content into the
16479 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16480 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16482 int count
= fi
.nested_types_list
.size ();
16484 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16485 TYPE_NESTED_TYPES_ARRAY (type
)
16486 = ((struct decl_field
*)
16487 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16488 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16490 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16491 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16495 quirk_gcc_member_function_pointer (type
, objfile
);
16496 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16497 cu
->rust_unions
.push_back (type
);
16498 else if (cu
->language
== language_ada
)
16499 quirk_ada_thick_pointer_struct (die
, cu
, type
);
16501 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16502 snapshots) has been known to create a die giving a declaration
16503 for a class that has, as a child, a die giving a definition for a
16504 nested class. So we have to process our children even if the
16505 current die is a declaration. Normally, of course, a declaration
16506 won't have any children at all. */
16508 child_die
= die
->child
;
16510 while (child_die
!= NULL
&& child_die
->tag
)
16512 if (child_die
->tag
== DW_TAG_member
16513 || child_die
->tag
== DW_TAG_variable
16514 || child_die
->tag
== DW_TAG_inheritance
16515 || child_die
->tag
== DW_TAG_template_value_param
16516 || child_die
->tag
== DW_TAG_template_type_param
)
16521 process_die (child_die
, cu
);
16523 child_die
= child_die
->sibling
;
16526 /* Do not consider external references. According to the DWARF standard,
16527 these DIEs are identified by the fact that they have no byte_size
16528 attribute, and a declaration attribute. */
16529 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16530 || !die_is_declaration (die
, cu
)
16531 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16533 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16535 if (has_template_parameters
)
16537 struct symtab
*symtab
;
16538 if (sym
!= nullptr)
16539 symtab
= symbol_symtab (sym
);
16540 else if (cu
->line_header
!= nullptr)
16542 /* Any related symtab will do. */
16544 = cu
->line_header
->file_names ()[0].symtab
;
16549 complaint (_("could not find suitable "
16550 "symtab for template parameter"
16551 " - DIE at %s [in module %s]"),
16552 sect_offset_str (die
->sect_off
),
16553 objfile_name (objfile
));
16556 if (symtab
!= nullptr)
16558 /* Make sure that the symtab is set on the new symbols.
16559 Even though they don't appear in this symtab directly,
16560 other parts of gdb assume that symbols do, and this is
16561 reasonably true. */
16562 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16563 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16569 /* Assuming DIE is an enumeration type, and TYPE is its associated
16570 type, update TYPE using some information only available in DIE's
16571 children. In particular, the fields are computed. */
16574 update_enumeration_type_from_children (struct die_info
*die
,
16576 struct dwarf2_cu
*cu
)
16578 struct die_info
*child_die
;
16579 int unsigned_enum
= 1;
16582 auto_obstack obstack
;
16583 std::vector
<struct field
> fields
;
16585 for (child_die
= die
->child
;
16586 child_die
!= NULL
&& child_die
->tag
;
16587 child_die
= child_die
->sibling
)
16589 struct attribute
*attr
;
16591 const gdb_byte
*bytes
;
16592 struct dwarf2_locexpr_baton
*baton
;
16595 if (child_die
->tag
!= DW_TAG_enumerator
)
16598 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16602 name
= dwarf2_name (child_die
, cu
);
16604 name
= "<anonymous enumerator>";
16606 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16607 &value
, &bytes
, &baton
);
16615 if (count_one_bits_ll (value
) >= 2)
16619 fields
.emplace_back ();
16620 struct field
&field
= fields
.back ();
16621 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16622 SET_FIELD_ENUMVAL (field
, value
);
16625 if (!fields
.empty ())
16627 type
->set_num_fields (fields
.size ());
16630 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16631 memcpy (type
->fields (), fields
.data (),
16632 sizeof (struct field
) * fields
.size ());
16636 type
->set_is_unsigned (true);
16639 TYPE_FLAG_ENUM (type
) = 1;
16642 /* Given a DW_AT_enumeration_type die, set its type. We do not
16643 complete the type's fields yet, or create any symbols. */
16645 static struct type
*
16646 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16648 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16650 struct attribute
*attr
;
16653 /* If the definition of this type lives in .debug_types, read that type.
16654 Don't follow DW_AT_specification though, that will take us back up
16655 the chain and we want to go down. */
16656 attr
= die
->attr (DW_AT_signature
);
16657 if (attr
!= nullptr)
16659 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16661 /* The type's CU may not be the same as CU.
16662 Ensure TYPE is recorded with CU in die_type_hash. */
16663 return set_die_type (die
, type
, cu
);
16666 type
= alloc_type (objfile
);
16668 type
->set_code (TYPE_CODE_ENUM
);
16669 name
= dwarf2_full_name (NULL
, die
, cu
);
16671 type
->set_name (name
);
16673 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16676 struct type
*underlying_type
= die_type (die
, cu
);
16678 TYPE_TARGET_TYPE (type
) = underlying_type
;
16681 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16682 if (attr
!= nullptr)
16684 TYPE_LENGTH (type
) = attr
->constant_value (0);
16688 TYPE_LENGTH (type
) = 0;
16691 maybe_set_alignment (cu
, die
, type
);
16693 /* The enumeration DIE can be incomplete. In Ada, any type can be
16694 declared as private in the package spec, and then defined only
16695 inside the package body. Such types are known as Taft Amendment
16696 Types. When another package uses such a type, an incomplete DIE
16697 may be generated by the compiler. */
16698 if (die_is_declaration (die
, cu
))
16699 type
->set_is_stub (true);
16701 /* If this type has an underlying type that is not a stub, then we
16702 may use its attributes. We always use the "unsigned" attribute
16703 in this situation, because ordinarily we guess whether the type
16704 is unsigned -- but the guess can be wrong and the underlying type
16705 can tell us the reality. However, we defer to a local size
16706 attribute if one exists, because this lets the compiler override
16707 the underlying type if needed. */
16708 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16710 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16711 underlying_type
= check_typedef (underlying_type
);
16713 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16715 if (TYPE_LENGTH (type
) == 0)
16716 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16718 if (TYPE_RAW_ALIGN (type
) == 0
16719 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16720 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16723 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16725 set_die_type (die
, type
, cu
);
16727 /* Finish the creation of this type by using the enum's children.
16728 Note that, as usual, this must come after set_die_type to avoid
16729 infinite recursion when trying to compute the names of the
16731 update_enumeration_type_from_children (die
, type
, cu
);
16736 /* Given a pointer to a die which begins an enumeration, process all
16737 the dies that define the members of the enumeration, and create the
16738 symbol for the enumeration type.
16740 NOTE: We reverse the order of the element list. */
16743 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16745 struct type
*this_type
;
16747 this_type
= get_die_type (die
, cu
);
16748 if (this_type
== NULL
)
16749 this_type
= read_enumeration_type (die
, cu
);
16751 if (die
->child
!= NULL
)
16753 struct die_info
*child_die
;
16756 child_die
= die
->child
;
16757 while (child_die
&& child_die
->tag
)
16759 if (child_die
->tag
!= DW_TAG_enumerator
)
16761 process_die (child_die
, cu
);
16765 name
= dwarf2_name (child_die
, cu
);
16767 new_symbol (child_die
, this_type
, cu
);
16770 child_die
= child_die
->sibling
;
16774 /* If we are reading an enum from a .debug_types unit, and the enum
16775 is a declaration, and the enum is not the signatured type in the
16776 unit, then we do not want to add a symbol for it. Adding a
16777 symbol would in some cases obscure the true definition of the
16778 enum, giving users an incomplete type when the definition is
16779 actually available. Note that we do not want to do this for all
16780 enums which are just declarations, because C++0x allows forward
16781 enum declarations. */
16782 if (cu
->per_cu
->is_debug_types
16783 && die_is_declaration (die
, cu
))
16785 struct signatured_type
*sig_type
;
16787 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16788 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16789 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16793 new_symbol (die
, this_type
, cu
);
16796 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16797 expression for an index type and finds the corresponding field
16798 offset in the hidden "P_BOUNDS" structure. Returns true on success
16799 and updates *FIELD, false if it fails to recognize an
16803 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16804 int *bounds_offset
, struct field
*field
,
16805 struct dwarf2_cu
*cu
)
16807 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16808 if (attr
== nullptr || !attr
->form_is_block ())
16811 const struct dwarf_block
*block
= attr
->as_block ();
16812 const gdb_byte
*start
= block
->data
;
16813 const gdb_byte
*end
= block
->data
+ block
->size
;
16815 /* The expression to recognize generally looks like:
16817 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16818 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16820 However, the second "plus_uconst" may be missing:
16822 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16823 DW_OP_deref_size: 4)
16825 This happens when the field is at the start of the structure.
16827 Also, the final deref may not be sized:
16829 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16832 This happens when the size of the index type happens to be the
16833 same as the architecture's word size. This can occur with or
16834 without the second plus_uconst. */
16836 if (end
- start
< 2)
16838 if (*start
++ != DW_OP_push_object_address
)
16840 if (*start
++ != DW_OP_plus_uconst
)
16843 uint64_t this_bound_off
;
16844 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16845 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16847 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16848 is consistent among all bounds. */
16849 if (*bounds_offset
== -1)
16850 *bounds_offset
= this_bound_off
;
16851 else if (*bounds_offset
!= this_bound_off
)
16854 if (start
== end
|| *start
++ != DW_OP_deref
)
16860 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16862 /* This means an offset of 0. */
16864 else if (*start
++ != DW_OP_plus_uconst
)
16868 /* The size is the parameter to DW_OP_plus_uconst. */
16870 start
= gdb_read_uleb128 (start
, end
, &val
);
16871 if (start
== nullptr)
16873 if ((int) val
!= val
)
16882 if (*start
== DW_OP_deref_size
)
16884 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16885 if (start
== nullptr)
16888 else if (*start
== DW_OP_deref
)
16890 size
= cu
->header
.addr_size
;
16896 SET_FIELD_BITPOS (*field
, 8 * offset
);
16897 if (size
!= TYPE_LENGTH (field
->type ()))
16898 FIELD_BITSIZE (*field
) = 8 * size
;
16903 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
16904 some kinds of Ada arrays:
16906 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
16907 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
16908 <11e0> DW_AT_data_location: 2 byte block: 97 6
16909 (DW_OP_push_object_address; DW_OP_deref)
16910 <11e3> DW_AT_type : <0x1173>
16911 <11e7> DW_AT_sibling : <0x1201>
16912 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
16913 <11ec> DW_AT_type : <0x1206>
16914 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
16915 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16916 DW_OP_deref_size: 4)
16917 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
16918 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16919 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16921 This actually represents a "thick pointer", which is a structure
16922 with two elements: one that is a pointer to the array data, and one
16923 that is a pointer to another structure; this second structure holds
16926 This returns a new type on success, or nullptr if this didn't
16927 recognize the type. */
16929 static struct type
*
16930 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
16933 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
16934 /* So far we've only seen this with block form. */
16935 if (attr
== nullptr || !attr
->form_is_block ())
16938 /* Note that this will fail if the structure layout is changed by
16939 the compiler. However, we have no good way to recognize some
16940 other layout, because we don't know what expression the compiler
16941 might choose to emit should this happen. */
16942 struct dwarf_block
*blk
= attr
->as_block ();
16944 || blk
->data
[0] != DW_OP_push_object_address
16945 || blk
->data
[1] != DW_OP_deref
)
16948 int bounds_offset
= -1;
16949 int max_align
= -1;
16950 std::vector
<struct field
> range_fields
;
16951 for (struct die_info
*child_die
= die
->child
;
16953 child_die
= child_die
->sibling
)
16955 if (child_die
->tag
== DW_TAG_subrange_type
)
16957 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
16959 int this_align
= type_align (underlying
);
16960 if (this_align
> max_align
)
16961 max_align
= this_align
;
16963 range_fields
.emplace_back ();
16964 range_fields
.emplace_back ();
16966 struct field
&lower
= range_fields
[range_fields
.size () - 2];
16967 struct field
&upper
= range_fields
[range_fields
.size () - 1];
16969 lower
.set_type (underlying
);
16970 FIELD_ARTIFICIAL (lower
) = 1;
16972 upper
.set_type (underlying
);
16973 FIELD_ARTIFICIAL (upper
) = 1;
16975 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
16976 &bounds_offset
, &lower
, cu
)
16977 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
16978 &bounds_offset
, &upper
, cu
))
16983 /* This shouldn't really happen, but double-check that we found
16984 where the bounds are stored. */
16985 if (bounds_offset
== -1)
16988 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16989 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
16993 /* Set the name of each field in the bounds. */
16994 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
16995 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
16996 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
16997 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
17000 struct type
*bounds
= alloc_type (objfile
);
17001 bounds
->set_code (TYPE_CODE_STRUCT
);
17003 bounds
->set_num_fields (range_fields
.size ());
17005 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
17006 * sizeof (struct field
))));
17007 memcpy (bounds
->fields (), range_fields
.data (),
17008 bounds
->num_fields () * sizeof (struct field
));
17010 int last_fieldno
= range_fields
.size () - 1;
17011 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
17012 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
17013 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
17015 /* Rewrite the existing array type in place. Specifically, we
17016 remove any dynamic properties we might have read, and we replace
17017 the index types. */
17018 struct type
*iter
= type
;
17019 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
17021 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
17022 iter
->main_type
->dyn_prop_list
= nullptr;
17023 iter
->set_index_type
17024 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
17025 iter
= TYPE_TARGET_TYPE (iter
);
17028 struct type
*result
= alloc_type (objfile
);
17029 result
->set_code (TYPE_CODE_STRUCT
);
17031 result
->set_num_fields (2);
17033 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
17034 * sizeof (struct field
))));
17036 /* The names are chosen to coincide with what the compiler does with
17037 -fgnat-encodings=all, which the Ada code in gdb already
17039 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
17040 result
->field (0).set_type (lookup_pointer_type (type
));
17042 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
17043 result
->field (1).set_type (lookup_pointer_type (bounds
));
17044 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
17046 result
->set_name (type
->name ());
17047 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
17048 + TYPE_LENGTH (result
->field (1).type ()));
17053 /* Extract all information from a DW_TAG_array_type DIE and put it in
17054 the DIE's type field. For now, this only handles one dimensional
17057 static struct type
*
17058 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17060 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17061 struct die_info
*child_die
;
17063 struct type
*element_type
, *range_type
, *index_type
;
17064 struct attribute
*attr
;
17066 struct dynamic_prop
*byte_stride_prop
= NULL
;
17067 unsigned int bit_stride
= 0;
17069 element_type
= die_type (die
, cu
);
17071 /* The die_type call above may have already set the type for this DIE. */
17072 type
= get_die_type (die
, cu
);
17076 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17080 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17083 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
17084 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
17088 complaint (_("unable to read array DW_AT_byte_stride "
17089 " - DIE at %s [in module %s]"),
17090 sect_offset_str (die
->sect_off
),
17091 objfile_name (cu
->per_objfile
->objfile
));
17092 /* Ignore this attribute. We will likely not be able to print
17093 arrays of this type correctly, but there is little we can do
17094 to help if we cannot read the attribute's value. */
17095 byte_stride_prop
= NULL
;
17099 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17101 bit_stride
= attr
->constant_value (0);
17103 /* Irix 6.2 native cc creates array types without children for
17104 arrays with unspecified length. */
17105 if (die
->child
== NULL
)
17107 index_type
= objfile_type (objfile
)->builtin_int
;
17108 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
17109 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
17110 byte_stride_prop
, bit_stride
);
17111 return set_die_type (die
, type
, cu
);
17114 std::vector
<struct type
*> range_types
;
17115 child_die
= die
->child
;
17116 while (child_die
&& child_die
->tag
)
17118 if (child_die
->tag
== DW_TAG_subrange_type
)
17120 struct type
*child_type
= read_type_die (child_die
, cu
);
17122 if (child_type
!= NULL
)
17124 /* The range type was succesfully read. Save it for the
17125 array type creation. */
17126 range_types
.push_back (child_type
);
17129 child_die
= child_die
->sibling
;
17132 if (range_types
.empty ())
17134 complaint (_("unable to find array range - DIE at %s [in module %s]"),
17135 sect_offset_str (die
->sect_off
),
17136 objfile_name (cu
->per_objfile
->objfile
));
17140 /* Dwarf2 dimensions are output from left to right, create the
17141 necessary array types in backwards order. */
17143 type
= element_type
;
17145 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
17149 while (i
< range_types
.size ())
17151 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
17152 byte_stride_prop
, bit_stride
);
17154 byte_stride_prop
= nullptr;
17159 size_t ndim
= range_types
.size ();
17162 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
17163 byte_stride_prop
, bit_stride
);
17165 byte_stride_prop
= nullptr;
17169 gdb_assert (type
!= element_type
);
17171 /* Understand Dwarf2 support for vector types (like they occur on
17172 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
17173 array type. This is not part of the Dwarf2/3 standard yet, but a
17174 custom vendor extension. The main difference between a regular
17175 array and the vector variant is that vectors are passed by value
17177 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
17178 if (attr
!= nullptr)
17179 make_vector_type (type
);
17181 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
17182 implementation may choose to implement triple vectors using this
17184 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17185 if (attr
!= nullptr && attr
->form_is_unsigned ())
17187 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
17188 TYPE_LENGTH (type
) = attr
->as_unsigned ();
17190 complaint (_("DW_AT_byte_size for array type smaller "
17191 "than the total size of elements"));
17194 name
= dwarf2_name (die
, cu
);
17196 type
->set_name (name
);
17198 maybe_set_alignment (cu
, die
, type
);
17200 struct type
*replacement_type
= nullptr;
17201 if (cu
->language
== language_ada
)
17203 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
17204 if (replacement_type
!= nullptr)
17205 type
= replacement_type
;
17208 /* Install the type in the die. */
17209 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
17211 /* set_die_type should be already done. */
17212 set_descriptive_type (type
, die
, cu
);
17217 static enum dwarf_array_dim_ordering
17218 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
17220 struct attribute
*attr
;
17222 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
17224 if (attr
!= nullptr)
17226 LONGEST val
= attr
->constant_value (-1);
17227 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
17228 return (enum dwarf_array_dim_ordering
) val
;
17231 /* GNU F77 is a special case, as at 08/2004 array type info is the
17232 opposite order to the dwarf2 specification, but data is still
17233 laid out as per normal fortran.
17235 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
17236 version checking. */
17238 if (cu
->language
== language_fortran
17239 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
17241 return DW_ORD_row_major
;
17244 switch (cu
->language_defn
->array_ordering ())
17246 case array_column_major
:
17247 return DW_ORD_col_major
;
17248 case array_row_major
:
17250 return DW_ORD_row_major
;
17254 /* Extract all information from a DW_TAG_set_type DIE and put it in
17255 the DIE's type field. */
17257 static struct type
*
17258 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17260 struct type
*domain_type
, *set_type
;
17261 struct attribute
*attr
;
17263 domain_type
= die_type (die
, cu
);
17265 /* The die_type call above may have already set the type for this DIE. */
17266 set_type
= get_die_type (die
, cu
);
17270 set_type
= create_set_type (NULL
, domain_type
);
17272 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17273 if (attr
!= nullptr && attr
->form_is_unsigned ())
17274 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
17276 maybe_set_alignment (cu
, die
, set_type
);
17278 return set_die_type (die
, set_type
, cu
);
17281 /* A helper for read_common_block that creates a locexpr baton.
17282 SYM is the symbol which we are marking as computed.
17283 COMMON_DIE is the DIE for the common block.
17284 COMMON_LOC is the location expression attribute for the common
17286 MEMBER_LOC is the location expression attribute for the particular
17287 member of the common block that we are processing.
17288 CU is the CU from which the above come. */
17291 mark_common_block_symbol_computed (struct symbol
*sym
,
17292 struct die_info
*common_die
,
17293 struct attribute
*common_loc
,
17294 struct attribute
*member_loc
,
17295 struct dwarf2_cu
*cu
)
17297 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17298 struct objfile
*objfile
= per_objfile
->objfile
;
17299 struct dwarf2_locexpr_baton
*baton
;
17301 unsigned int cu_off
;
17302 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
17303 LONGEST offset
= 0;
17305 gdb_assert (common_loc
&& member_loc
);
17306 gdb_assert (common_loc
->form_is_block ());
17307 gdb_assert (member_loc
->form_is_block ()
17308 || member_loc
->form_is_constant ());
17310 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
17311 baton
->per_objfile
= per_objfile
;
17312 baton
->per_cu
= cu
->per_cu
;
17313 gdb_assert (baton
->per_cu
);
17315 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
17317 if (member_loc
->form_is_constant ())
17319 offset
= member_loc
->constant_value (0);
17320 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
17323 baton
->size
+= member_loc
->as_block ()->size
;
17325 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
17328 *ptr
++ = DW_OP_call4
;
17329 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
17330 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
17333 if (member_loc
->form_is_constant ())
17335 *ptr
++ = DW_OP_addr
;
17336 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
17337 ptr
+= cu
->header
.addr_size
;
17341 /* We have to copy the data here, because DW_OP_call4 will only
17342 use a DW_AT_location attribute. */
17343 struct dwarf_block
*block
= member_loc
->as_block ();
17344 memcpy (ptr
, block
->data
, block
->size
);
17345 ptr
+= block
->size
;
17348 *ptr
++ = DW_OP_plus
;
17349 gdb_assert (ptr
- baton
->data
== baton
->size
);
17351 SYMBOL_LOCATION_BATON (sym
) = baton
;
17352 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
17355 /* Create appropriate locally-scoped variables for all the
17356 DW_TAG_common_block entries. Also create a struct common_block
17357 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
17358 is used to separate the common blocks name namespace from regular
17362 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
17364 struct attribute
*attr
;
17366 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17367 if (attr
!= nullptr)
17369 /* Support the .debug_loc offsets. */
17370 if (attr
->form_is_block ())
17374 else if (attr
->form_is_section_offset ())
17376 dwarf2_complex_location_expr_complaint ();
17381 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17382 "common block member");
17387 if (die
->child
!= NULL
)
17389 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17390 struct die_info
*child_die
;
17391 size_t n_entries
= 0, size
;
17392 struct common_block
*common_block
;
17393 struct symbol
*sym
;
17395 for (child_die
= die
->child
;
17396 child_die
&& child_die
->tag
;
17397 child_die
= child_die
->sibling
)
17400 size
= (sizeof (struct common_block
)
17401 + (n_entries
- 1) * sizeof (struct symbol
*));
17403 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17405 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17406 common_block
->n_entries
= 0;
17408 for (child_die
= die
->child
;
17409 child_die
&& child_die
->tag
;
17410 child_die
= child_die
->sibling
)
17412 /* Create the symbol in the DW_TAG_common_block block in the current
17414 sym
= new_symbol (child_die
, NULL
, cu
);
17417 struct attribute
*member_loc
;
17419 common_block
->contents
[common_block
->n_entries
++] = sym
;
17421 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17425 /* GDB has handled this for a long time, but it is
17426 not specified by DWARF. It seems to have been
17427 emitted by gfortran at least as recently as:
17428 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17429 complaint (_("Variable in common block has "
17430 "DW_AT_data_member_location "
17431 "- DIE at %s [in module %s]"),
17432 sect_offset_str (child_die
->sect_off
),
17433 objfile_name (objfile
));
17435 if (member_loc
->form_is_section_offset ())
17436 dwarf2_complex_location_expr_complaint ();
17437 else if (member_loc
->form_is_constant ()
17438 || member_loc
->form_is_block ())
17440 if (attr
!= nullptr)
17441 mark_common_block_symbol_computed (sym
, die
, attr
,
17445 dwarf2_complex_location_expr_complaint ();
17450 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17451 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17455 /* Create a type for a C++ namespace. */
17457 static struct type
*
17458 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17460 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17461 const char *previous_prefix
, *name
;
17465 /* For extensions, reuse the type of the original namespace. */
17466 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17468 struct die_info
*ext_die
;
17469 struct dwarf2_cu
*ext_cu
= cu
;
17471 ext_die
= dwarf2_extension (die
, &ext_cu
);
17472 type
= read_type_die (ext_die
, ext_cu
);
17474 /* EXT_CU may not be the same as CU.
17475 Ensure TYPE is recorded with CU in die_type_hash. */
17476 return set_die_type (die
, type
, cu
);
17479 name
= namespace_name (die
, &is_anonymous
, cu
);
17481 /* Now build the name of the current namespace. */
17483 previous_prefix
= determine_prefix (die
, cu
);
17484 if (previous_prefix
[0] != '\0')
17485 name
= typename_concat (&objfile
->objfile_obstack
,
17486 previous_prefix
, name
, 0, cu
);
17488 /* Create the type. */
17489 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17491 return set_die_type (die
, type
, cu
);
17494 /* Read a namespace scope. */
17497 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17499 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17502 /* Add a symbol associated to this if we haven't seen the namespace
17503 before. Also, add a using directive if it's an anonymous
17506 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17510 type
= read_type_die (die
, cu
);
17511 new_symbol (die
, type
, cu
);
17513 namespace_name (die
, &is_anonymous
, cu
);
17516 const char *previous_prefix
= determine_prefix (die
, cu
);
17518 std::vector
<const char *> excludes
;
17519 add_using_directive (using_directives (cu
),
17520 previous_prefix
, type
->name (), NULL
,
17521 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17525 if (die
->child
!= NULL
)
17527 struct die_info
*child_die
= die
->child
;
17529 while (child_die
&& child_die
->tag
)
17531 process_die (child_die
, cu
);
17532 child_die
= child_die
->sibling
;
17537 /* Read a Fortran module as type. This DIE can be only a declaration used for
17538 imported module. Still we need that type as local Fortran "use ... only"
17539 declaration imports depend on the created type in determine_prefix. */
17541 static struct type
*
17542 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17544 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17545 const char *module_name
;
17548 module_name
= dwarf2_name (die
, cu
);
17549 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17551 return set_die_type (die
, type
, cu
);
17554 /* Read a Fortran module. */
17557 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17559 struct die_info
*child_die
= die
->child
;
17562 type
= read_type_die (die
, cu
);
17563 new_symbol (die
, type
, cu
);
17565 while (child_die
&& child_die
->tag
)
17567 process_die (child_die
, cu
);
17568 child_die
= child_die
->sibling
;
17572 /* Return the name of the namespace represented by DIE. Set
17573 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17576 static const char *
17577 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17579 struct die_info
*current_die
;
17580 const char *name
= NULL
;
17582 /* Loop through the extensions until we find a name. */
17584 for (current_die
= die
;
17585 current_die
!= NULL
;
17586 current_die
= dwarf2_extension (die
, &cu
))
17588 /* We don't use dwarf2_name here so that we can detect the absence
17589 of a name -> anonymous namespace. */
17590 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17596 /* Is it an anonymous namespace? */
17598 *is_anonymous
= (name
== NULL
);
17600 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17605 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17606 the user defined type vector. */
17608 static struct type
*
17609 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17611 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17612 struct comp_unit_head
*cu_header
= &cu
->header
;
17614 struct attribute
*attr_byte_size
;
17615 struct attribute
*attr_address_class
;
17616 int byte_size
, addr_class
;
17617 struct type
*target_type
;
17619 target_type
= die_type (die
, cu
);
17621 /* The die_type call above may have already set the type for this DIE. */
17622 type
= get_die_type (die
, cu
);
17626 type
= lookup_pointer_type (target_type
);
17628 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17629 if (attr_byte_size
)
17630 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17632 byte_size
= cu_header
->addr_size
;
17634 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17635 if (attr_address_class
)
17636 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17638 addr_class
= DW_ADDR_none
;
17640 ULONGEST alignment
= get_alignment (cu
, die
);
17642 /* If the pointer size, alignment, or address class is different
17643 than the default, create a type variant marked as such and set
17644 the length accordingly. */
17645 if (TYPE_LENGTH (type
) != byte_size
17646 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17647 && alignment
!= TYPE_RAW_ALIGN (type
))
17648 || addr_class
!= DW_ADDR_none
)
17650 if (gdbarch_address_class_type_flags_p (gdbarch
))
17652 type_instance_flags type_flags
17653 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17655 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17657 type
= make_type_with_address_space (type
, type_flags
);
17659 else if (TYPE_LENGTH (type
) != byte_size
)
17661 complaint (_("invalid pointer size %d"), byte_size
);
17663 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17665 complaint (_("Invalid DW_AT_alignment"
17666 " - DIE at %s [in module %s]"),
17667 sect_offset_str (die
->sect_off
),
17668 objfile_name (cu
->per_objfile
->objfile
));
17672 /* Should we also complain about unhandled address classes? */
17676 TYPE_LENGTH (type
) = byte_size
;
17677 set_type_align (type
, alignment
);
17678 return set_die_type (die
, type
, cu
);
17681 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17682 the user defined type vector. */
17684 static struct type
*
17685 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17688 struct type
*to_type
;
17689 struct type
*domain
;
17691 to_type
= die_type (die
, cu
);
17692 domain
= die_containing_type (die
, cu
);
17694 /* The calls above may have already set the type for this DIE. */
17695 type
= get_die_type (die
, cu
);
17699 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17700 type
= lookup_methodptr_type (to_type
);
17701 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17703 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17705 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17706 to_type
->fields (), to_type
->num_fields (),
17707 to_type
->has_varargs ());
17708 type
= lookup_methodptr_type (new_type
);
17711 type
= lookup_memberptr_type (to_type
, domain
);
17713 return set_die_type (die
, type
, cu
);
17716 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17717 the user defined type vector. */
17719 static struct type
*
17720 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17721 enum type_code refcode
)
17723 struct comp_unit_head
*cu_header
= &cu
->header
;
17724 struct type
*type
, *target_type
;
17725 struct attribute
*attr
;
17727 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17729 target_type
= die_type (die
, cu
);
17731 /* The die_type call above may have already set the type for this DIE. */
17732 type
= get_die_type (die
, cu
);
17736 type
= lookup_reference_type (target_type
, refcode
);
17737 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17738 if (attr
!= nullptr)
17740 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17744 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17746 maybe_set_alignment (cu
, die
, type
);
17747 return set_die_type (die
, type
, cu
);
17750 /* Add the given cv-qualifiers to the element type of the array. GCC
17751 outputs DWARF type qualifiers that apply to an array, not the
17752 element type. But GDB relies on the array element type to carry
17753 the cv-qualifiers. This mimics section 6.7.3 of the C99
17756 static struct type
*
17757 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17758 struct type
*base_type
, int cnst
, int voltl
)
17760 struct type
*el_type
, *inner_array
;
17762 base_type
= copy_type (base_type
);
17763 inner_array
= base_type
;
17765 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17767 TYPE_TARGET_TYPE (inner_array
) =
17768 copy_type (TYPE_TARGET_TYPE (inner_array
));
17769 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17772 el_type
= TYPE_TARGET_TYPE (inner_array
);
17773 cnst
|= TYPE_CONST (el_type
);
17774 voltl
|= TYPE_VOLATILE (el_type
);
17775 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17777 return set_die_type (die
, base_type
, cu
);
17780 static struct type
*
17781 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17783 struct type
*base_type
, *cv_type
;
17785 base_type
= die_type (die
, cu
);
17787 /* The die_type call above may have already set the type for this DIE. */
17788 cv_type
= get_die_type (die
, cu
);
17792 /* In case the const qualifier is applied to an array type, the element type
17793 is so qualified, not the array type (section 6.7.3 of C99). */
17794 if (base_type
->code () == TYPE_CODE_ARRAY
)
17795 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17797 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17798 return set_die_type (die
, cv_type
, cu
);
17801 static struct type
*
17802 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17804 struct type
*base_type
, *cv_type
;
17806 base_type
= die_type (die
, cu
);
17808 /* The die_type call above may have already set the type for this DIE. */
17809 cv_type
= get_die_type (die
, cu
);
17813 /* In case the volatile qualifier is applied to an array type, the
17814 element type is so qualified, not the array type (section 6.7.3
17816 if (base_type
->code () == TYPE_CODE_ARRAY
)
17817 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17819 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17820 return set_die_type (die
, cv_type
, cu
);
17823 /* Handle DW_TAG_restrict_type. */
17825 static struct type
*
17826 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17828 struct type
*base_type
, *cv_type
;
17830 base_type
= die_type (die
, cu
);
17832 /* The die_type call above may have already set the type for this DIE. */
17833 cv_type
= get_die_type (die
, cu
);
17837 cv_type
= make_restrict_type (base_type
);
17838 return set_die_type (die
, cv_type
, cu
);
17841 /* Handle DW_TAG_atomic_type. */
17843 static struct type
*
17844 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17846 struct type
*base_type
, *cv_type
;
17848 base_type
= die_type (die
, cu
);
17850 /* The die_type call above may have already set the type for this DIE. */
17851 cv_type
= get_die_type (die
, cu
);
17855 cv_type
= make_atomic_type (base_type
);
17856 return set_die_type (die
, cv_type
, cu
);
17859 /* Extract all information from a DW_TAG_string_type DIE and add to
17860 the user defined type vector. It isn't really a user defined type,
17861 but it behaves like one, with other DIE's using an AT_user_def_type
17862 attribute to reference it. */
17864 static struct type
*
17865 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17867 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17868 struct gdbarch
*gdbarch
= objfile
->arch ();
17869 struct type
*type
, *range_type
, *index_type
, *char_type
;
17870 struct attribute
*attr
;
17871 struct dynamic_prop prop
;
17872 bool length_is_constant
= true;
17875 /* There are a couple of places where bit sizes might be made use of
17876 when parsing a DW_TAG_string_type, however, no producer that we know
17877 of make use of these. Handling bit sizes that are a multiple of the
17878 byte size is easy enough, but what about other bit sizes? Lets deal
17879 with that problem when we have to. Warn about these attributes being
17880 unsupported, then parse the type and ignore them like we always
17882 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17883 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17885 static bool warning_printed
= false;
17886 if (!warning_printed
)
17888 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17889 "currently supported on DW_TAG_string_type."));
17890 warning_printed
= true;
17894 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17895 if (attr
!= nullptr && !attr
->form_is_constant ())
17897 /* The string length describes the location at which the length of
17898 the string can be found. The size of the length field can be
17899 specified with one of the attributes below. */
17900 struct type
*prop_type
;
17901 struct attribute
*len
17902 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17903 if (len
== nullptr)
17904 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17905 if (len
!= nullptr && len
->form_is_constant ())
17907 /* Pass 0 as the default as we know this attribute is constant
17908 and the default value will not be returned. */
17909 LONGEST sz
= len
->constant_value (0);
17910 prop_type
= cu
->per_objfile
->int_type (sz
, true);
17914 /* If the size is not specified then we assume it is the size of
17915 an address on this target. */
17916 prop_type
= cu
->addr_sized_int_type (true);
17919 /* Convert the attribute into a dynamic property. */
17920 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17923 length_is_constant
= false;
17925 else if (attr
!= nullptr)
17927 /* This DW_AT_string_length just contains the length with no
17928 indirection. There's no need to create a dynamic property in this
17929 case. Pass 0 for the default value as we know it will not be
17930 returned in this case. */
17931 length
= attr
->constant_value (0);
17933 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17935 /* We don't currently support non-constant byte sizes for strings. */
17936 length
= attr
->constant_value (1);
17940 /* Use 1 as a fallback length if we have nothing else. */
17944 index_type
= objfile_type (objfile
)->builtin_int
;
17945 if (length_is_constant
)
17946 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17949 struct dynamic_prop low_bound
;
17951 low_bound
.set_const_val (1);
17952 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17954 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17955 type
= create_string_type (NULL
, char_type
, range_type
);
17957 return set_die_type (die
, type
, cu
);
17960 /* Assuming that DIE corresponds to a function, returns nonzero
17961 if the function is prototyped. */
17964 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17966 struct attribute
*attr
;
17968 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17969 if (attr
&& attr
->as_boolean ())
17972 /* The DWARF standard implies that the DW_AT_prototyped attribute
17973 is only meaningful for C, but the concept also extends to other
17974 languages that allow unprototyped functions (Eg: Objective C).
17975 For all other languages, assume that functions are always
17977 if (cu
->language
!= language_c
17978 && cu
->language
!= language_objc
17979 && cu
->language
!= language_opencl
)
17982 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17983 prototyped and unprototyped functions; default to prototyped,
17984 since that is more common in modern code (and RealView warns
17985 about unprototyped functions). */
17986 if (producer_is_realview (cu
->producer
))
17992 /* Handle DIES due to C code like:
17996 int (*funcp)(int a, long l);
18000 ('funcp' generates a DW_TAG_subroutine_type DIE). */
18002 static struct type
*
18003 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18005 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18006 struct type
*type
; /* Type that this function returns. */
18007 struct type
*ftype
; /* Function that returns above type. */
18008 struct attribute
*attr
;
18010 type
= die_type (die
, cu
);
18012 /* The die_type call above may have already set the type for this DIE. */
18013 ftype
= get_die_type (die
, cu
);
18017 ftype
= lookup_function_type (type
);
18019 if (prototyped_function_p (die
, cu
))
18020 ftype
->set_is_prototyped (true);
18022 /* Store the calling convention in the type if it's available in
18023 the subroutine die. Otherwise set the calling convention to
18024 the default value DW_CC_normal. */
18025 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
18026 if (attr
!= nullptr
18027 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
18028 TYPE_CALLING_CONVENTION (ftype
)
18029 = (enum dwarf_calling_convention
) attr
->constant_value (0);
18030 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
18031 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
18033 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
18035 /* Record whether the function returns normally to its caller or not
18036 if the DWARF producer set that information. */
18037 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
18038 if (attr
&& attr
->as_boolean ())
18039 TYPE_NO_RETURN (ftype
) = 1;
18041 /* We need to add the subroutine type to the die immediately so
18042 we don't infinitely recurse when dealing with parameters
18043 declared as the same subroutine type. */
18044 set_die_type (die
, ftype
, cu
);
18046 if (die
->child
!= NULL
)
18048 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
18049 struct die_info
*child_die
;
18050 int nparams
, iparams
;
18052 /* Count the number of parameters.
18053 FIXME: GDB currently ignores vararg functions, but knows about
18054 vararg member functions. */
18056 child_die
= die
->child
;
18057 while (child_die
&& child_die
->tag
)
18059 if (child_die
->tag
== DW_TAG_formal_parameter
)
18061 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
18062 ftype
->set_has_varargs (true);
18064 child_die
= child_die
->sibling
;
18067 /* Allocate storage for parameters and fill them in. */
18068 ftype
->set_num_fields (nparams
);
18070 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
18072 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
18073 even if we error out during the parameters reading below. */
18074 for (iparams
= 0; iparams
< nparams
; iparams
++)
18075 ftype
->field (iparams
).set_type (void_type
);
18078 child_die
= die
->child
;
18079 while (child_die
&& child_die
->tag
)
18081 if (child_die
->tag
== DW_TAG_formal_parameter
)
18083 struct type
*arg_type
;
18085 /* DWARF version 2 has no clean way to discern C++
18086 static and non-static member functions. G++ helps
18087 GDB by marking the first parameter for non-static
18088 member functions (which is the this pointer) as
18089 artificial. We pass this information to
18090 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
18092 DWARF version 3 added DW_AT_object_pointer, which GCC
18093 4.5 does not yet generate. */
18094 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
18095 if (attr
!= nullptr)
18096 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
18098 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
18099 arg_type
= die_type (child_die
, cu
);
18101 /* RealView does not mark THIS as const, which the testsuite
18102 expects. GCC marks THIS as const in method definitions,
18103 but not in the class specifications (GCC PR 43053). */
18104 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
18105 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
18108 struct dwarf2_cu
*arg_cu
= cu
;
18109 const char *name
= dwarf2_name (child_die
, cu
);
18111 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
18112 if (attr
!= nullptr)
18114 /* If the compiler emits this, use it. */
18115 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
18118 else if (name
&& strcmp (name
, "this") == 0)
18119 /* Function definitions will have the argument names. */
18121 else if (name
== NULL
&& iparams
== 0)
18122 /* Declarations may not have the names, so like
18123 elsewhere in GDB, assume an artificial first
18124 argument is "this". */
18128 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
18132 ftype
->field (iparams
).set_type (arg_type
);
18135 child_die
= child_die
->sibling
;
18142 static struct type
*
18143 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
18145 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18146 const char *name
= NULL
;
18147 struct type
*this_type
, *target_type
;
18149 name
= dwarf2_full_name (NULL
, die
, cu
);
18150 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
18151 this_type
->set_target_is_stub (true);
18152 set_die_type (die
, this_type
, cu
);
18153 target_type
= die_type (die
, cu
);
18154 if (target_type
!= this_type
)
18155 TYPE_TARGET_TYPE (this_type
) = target_type
;
18158 /* Self-referential typedefs are, it seems, not allowed by the DWARF
18159 spec and cause infinite loops in GDB. */
18160 complaint (_("Self-referential DW_TAG_typedef "
18161 "- DIE at %s [in module %s]"),
18162 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
18163 TYPE_TARGET_TYPE (this_type
) = NULL
;
18167 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
18168 anonymous typedefs, which is, strictly speaking, invalid DWARF.
18169 Handle these by just returning the target type, rather than
18170 constructing an anonymous typedef type and trying to handle this
18172 set_die_type (die
, target_type
, cu
);
18173 return target_type
;
18178 /* Helper for get_dwarf2_rational_constant that computes the value of
18179 a given gmp_mpz given an attribute. */
18182 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
18184 /* GCC will sometimes emit a 16-byte constant value as a DWARF
18185 location expression that pushes an implicit value. */
18186 if (attr
->form
== DW_FORM_exprloc
)
18188 dwarf_block
*blk
= attr
->as_block ();
18189 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
18192 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
18193 blk
->data
+ blk
->size
,
18195 if (ptr
- blk
->data
+ len
<= blk
->size
)
18197 mpz_import (value
->val
, len
,
18198 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
18204 /* On failure set it to 1. */
18205 *value
= gdb_mpz (1);
18207 else if (attr
->form_is_block ())
18209 dwarf_block
*blk
= attr
->as_block ();
18210 mpz_import (value
->val
, blk
->size
,
18211 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
18212 1, 0, 0, blk
->data
);
18215 *value
= gdb_mpz (attr
->constant_value (1));
18218 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
18219 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
18221 If the numerator and/or numerator attribute is missing,
18222 a complaint is filed, and NUMERATOR and DENOMINATOR are left
18226 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
18227 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
18229 struct attribute
*num_attr
, *denom_attr
;
18231 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
18232 if (num_attr
== nullptr)
18233 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
18234 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18236 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
18237 if (denom_attr
== nullptr)
18238 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
18239 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18241 if (num_attr
== nullptr || denom_attr
== nullptr)
18244 get_mpz (cu
, numerator
, num_attr
);
18245 get_mpz (cu
, denominator
, denom_attr
);
18248 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
18249 rational constant, rather than a signed one.
18251 If the rational constant has a negative value, a complaint
18252 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
18255 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
18256 struct dwarf2_cu
*cu
,
18257 gdb_mpz
*numerator
,
18258 gdb_mpz
*denominator
)
18263 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
18264 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
18266 mpz_neg (num
.val
, num
.val
);
18267 mpz_neg (denom
.val
, denom
.val
);
18269 else if (mpz_sgn (num
.val
) == -1)
18271 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
18273 sect_offset_str (die
->sect_off
));
18276 else if (mpz_sgn (denom
.val
) == -1)
18278 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
18280 sect_offset_str (die
->sect_off
));
18284 *numerator
= std::move (num
);
18285 *denominator
= std::move (denom
);
18288 /* Assuming that ENCODING is a string whose contents starting at the
18289 K'th character is "_nn" where "nn" is a decimal number, scan that
18290 number and set RESULT to the value. K is updated to point to the
18291 character immediately following the number.
18293 If the string does not conform to the format described above, false
18294 is returned, and K may or may not be changed. */
18297 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
18299 /* The next character should be an underscore ('_') followed
18301 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
18304 /* Skip the underscore. */
18308 /* Determine the number of digits for our number. */
18309 while (isdigit (encoding
[k
]))
18314 std::string
copy (&encoding
[start
], k
- start
);
18315 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
18321 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
18322 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
18323 DENOM, update OFFSET, and return true on success. Return false on
18327 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
18328 gdb_mpz
*num
, gdb_mpz
*denom
)
18330 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
18332 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
18335 /* Assuming DIE corresponds to a fixed point type, finish the creation
18336 of the corresponding TYPE by setting its type-specific data. CU is
18337 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
18338 encodings. It is nullptr if the GNAT encoding should be
18342 finish_fixed_point_type (struct type
*type
, const char *suffix
,
18343 struct die_info
*die
, struct dwarf2_cu
*cu
)
18345 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
18346 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
18348 /* If GNAT encodings are preferred, don't examine the
18350 struct attribute
*attr
= nullptr;
18351 if (suffix
== nullptr)
18353 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
18354 if (attr
== nullptr)
18355 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
18356 if (attr
== nullptr)
18357 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18360 /* Numerator and denominator of our fixed-point type's scaling factor.
18361 The default is a scaling factor of 1, which we use as a fallback
18362 when we are not able to decode it (problem with the debugging info,
18363 unsupported forms, bug in GDB, etc...). Using that as the default
18364 allows us to at least print the unscaled value, which might still
18365 be useful to a user. */
18366 gdb_mpz
scale_num (1);
18367 gdb_mpz
scale_denom (1);
18369 if (attr
== nullptr)
18372 if (suffix
!= nullptr
18373 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
18375 /* The number might be encoded as _nn_dd_nn_dd, where the
18376 second ratio is the 'small value. In this situation, we
18377 want the second value. */
18378 && (suffix
[offset
] != '_'
18379 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
18386 /* Scaling factor not found. Assume a scaling factor of 1,
18387 and hope for the best. At least the user will be able to
18388 see the encoded value. */
18391 complaint (_("no scale found for fixed-point type (DIE at %s)"),
18392 sect_offset_str (die
->sect_off
));
18395 else if (attr
->name
== DW_AT_binary_scale
)
18397 LONGEST scale_exp
= attr
->constant_value (0);
18398 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18400 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
18402 else if (attr
->name
== DW_AT_decimal_scale
)
18404 LONGEST scale_exp
= attr
->constant_value (0);
18405 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18407 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
18409 else if (attr
->name
== DW_AT_small
)
18411 struct die_info
*scale_die
;
18412 struct dwarf2_cu
*scale_cu
= cu
;
18414 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
18415 if (scale_die
->tag
== DW_TAG_constant
)
18416 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
18417 &scale_num
, &scale_denom
);
18419 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
18421 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18425 complaint (_("unsupported scale attribute %s for fixed-point type"
18427 dwarf_attr_name (attr
->name
),
18428 sect_offset_str (die
->sect_off
));
18431 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
18432 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
18433 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
18434 mpq_canonicalize (scaling_factor
.val
);
18437 /* The gnat-encoding suffix for fixed point. */
18439 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
18441 /* If NAME encodes an Ada fixed-point type, return a pointer to the
18442 "XF" suffix of the name. The text after this is what encodes the
18443 'small and 'delta information. Otherwise, return nullptr. */
18445 static const char *
18446 gnat_encoded_fixed_point_type_info (const char *name
)
18448 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
18451 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
18452 (which may be different from NAME) to the architecture back-end to allow
18453 it to guess the correct format if necessary. */
18455 static struct type
*
18456 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
18457 const char *name_hint
, enum bfd_endian byte_order
)
18459 struct gdbarch
*gdbarch
= objfile
->arch ();
18460 const struct floatformat
**format
;
18463 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
18465 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
18467 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18472 /* Allocate an integer type of size BITS and name NAME. */
18474 static struct type
*
18475 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
18476 int bits
, int unsigned_p
, const char *name
)
18480 /* Versions of Intel's C Compiler generate an integer type called "void"
18481 instead of using DW_TAG_unspecified_type. This has been seen on
18482 at least versions 14, 17, and 18. */
18483 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18484 && strcmp (name
, "void") == 0)
18485 type
= objfile_type (objfile
)->builtin_void
;
18487 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18492 /* Return true if DIE has a DW_AT_small attribute whose value is
18493 a constant rational, where both the numerator and denominator
18496 CU is the DIE's Compilation Unit. */
18499 has_zero_over_zero_small_attribute (struct die_info
*die
,
18500 struct dwarf2_cu
*cu
)
18502 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18503 if (attr
== nullptr)
18506 struct dwarf2_cu
*scale_cu
= cu
;
18507 struct die_info
*scale_die
18508 = follow_die_ref (die
, attr
, &scale_cu
);
18510 if (scale_die
->tag
!= DW_TAG_constant
)
18513 gdb_mpz
num (1), denom (1);
18514 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18515 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
18518 /* Initialise and return a floating point type of size BITS suitable for
18519 use as a component of a complex number. The NAME_HINT is passed through
18520 when initialising the floating point type and is the name of the complex
18523 As DWARF doesn't currently provide an explicit name for the components
18524 of a complex number, but it can be helpful to have these components
18525 named, we try to select a suitable name based on the size of the
18527 static struct type
*
18528 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18529 struct objfile
*objfile
,
18530 int bits
, const char *name_hint
,
18531 enum bfd_endian byte_order
)
18533 gdbarch
*gdbarch
= objfile
->arch ();
18534 struct type
*tt
= nullptr;
18536 /* Try to find a suitable floating point builtin type of size BITS.
18537 We're going to use the name of this type as the name for the complex
18538 target type that we are about to create. */
18539 switch (cu
->language
)
18541 case language_fortran
:
18545 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18548 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18550 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18552 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18560 tt
= builtin_type (gdbarch
)->builtin_float
;
18563 tt
= builtin_type (gdbarch
)->builtin_double
;
18565 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18567 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18573 /* If the type we found doesn't match the size we were looking for, then
18574 pretend we didn't find a type at all, the complex target type we
18575 create will then be nameless. */
18576 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18579 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18580 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18583 /* Find a representation of a given base type and install
18584 it in the TYPE field of the die. */
18586 static struct type
*
18587 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18589 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18591 struct attribute
*attr
;
18592 int encoding
= 0, bits
= 0;
18596 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18597 if (attr
!= nullptr && attr
->form_is_constant ())
18598 encoding
= attr
->constant_value (0);
18599 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18600 if (attr
!= nullptr)
18601 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18602 name
= dwarf2_name (die
, cu
);
18604 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18606 arch
= objfile
->arch ();
18607 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18609 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18610 if (attr
!= nullptr && attr
->form_is_constant ())
18612 int endianity
= attr
->constant_value (0);
18617 byte_order
= BFD_ENDIAN_BIG
;
18619 case DW_END_little
:
18620 byte_order
= BFD_ENDIAN_LITTLE
;
18623 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18628 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18629 && cu
->language
== language_ada
18630 && has_zero_over_zero_small_attribute (die
, cu
))
18632 /* brobecker/2018-02-24: This is a fixed point type for which
18633 the scaling factor is represented as fraction whose value
18634 does not make sense (zero divided by zero), so we should
18635 normally never see these. However, there is a small category
18636 of fixed point types for which GNAT is unable to provide
18637 the scaling factor via the standard DWARF mechanisms, and
18638 for which the info is provided via the GNAT encodings instead.
18639 This is likely what this DIE is about. */
18640 encoding
= (encoding
== DW_ATE_signed_fixed
18642 : DW_ATE_unsigned
);
18645 /* With GNAT encodings, fixed-point information will be encoded in
18646 the type name. Note that this can also occur with the above
18647 zero-over-zero case, which is why this is a separate "if" rather
18648 than an "else if". */
18649 const char *gnat_encoding_suffix
= nullptr;
18650 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18651 && cu
->language
== language_ada
18652 && name
!= nullptr)
18654 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18655 if (gnat_encoding_suffix
!= nullptr)
18657 gdb_assert (startswith (gnat_encoding_suffix
,
18658 GNAT_FIXED_POINT_SUFFIX
));
18659 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18660 name
, gnat_encoding_suffix
- name
);
18661 /* Use -1 here so that SUFFIX points at the "_" after the
18663 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18665 encoding
= (encoding
== DW_ATE_signed
18666 ? DW_ATE_signed_fixed
18667 : DW_ATE_unsigned_fixed
);
18673 case DW_ATE_address
:
18674 /* Turn DW_ATE_address into a void * pointer. */
18675 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18676 type
= init_pointer_type (objfile
, bits
, name
, type
);
18678 case DW_ATE_boolean
:
18679 type
= init_boolean_type (objfile
, bits
, 1, name
);
18681 case DW_ATE_complex_float
:
18682 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18684 if (type
->code () == TYPE_CODE_ERROR
)
18686 if (name
== nullptr)
18688 struct obstack
*obstack
18689 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18690 name
= obconcat (obstack
, "_Complex ", type
->name (),
18693 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18696 type
= init_complex_type (name
, type
);
18698 case DW_ATE_decimal_float
:
18699 type
= init_decfloat_type (objfile
, bits
, name
);
18702 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18704 case DW_ATE_signed
:
18705 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18707 case DW_ATE_unsigned
:
18708 if (cu
->language
== language_fortran
18710 && startswith (name
, "character("))
18711 type
= init_character_type (objfile
, bits
, 1, name
);
18713 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18715 case DW_ATE_signed_char
:
18716 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18717 || cu
->language
== language_pascal
18718 || cu
->language
== language_fortran
)
18719 type
= init_character_type (objfile
, bits
, 0, name
);
18721 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18723 case DW_ATE_unsigned_char
:
18724 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18725 || cu
->language
== language_pascal
18726 || cu
->language
== language_fortran
18727 || cu
->language
== language_rust
)
18728 type
= init_character_type (objfile
, bits
, 1, name
);
18730 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18735 type
= builtin_type (arch
)->builtin_char16
;
18736 else if (bits
== 32)
18737 type
= builtin_type (arch
)->builtin_char32
;
18740 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18742 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18744 return set_die_type (die
, type
, cu
);
18747 case DW_ATE_signed_fixed
:
18748 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18749 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18751 case DW_ATE_unsigned_fixed
:
18752 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18753 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18757 complaint (_("unsupported DW_AT_encoding: '%s'"),
18758 dwarf_type_encoding_name (encoding
));
18759 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18763 if (name
&& strcmp (name
, "char") == 0)
18764 type
->set_has_no_signedness (true);
18766 maybe_set_alignment (cu
, die
, type
);
18768 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18770 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18772 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18773 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18775 unsigned real_bit_size
= attr
->as_unsigned ();
18776 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18777 /* Only use the attributes if they make sense together. */
18778 if (attr
== nullptr
18779 || (attr
->as_unsigned () + real_bit_size
18780 <= 8 * TYPE_LENGTH (type
)))
18782 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18784 if (attr
!= nullptr)
18785 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18786 = attr
->as_unsigned ();
18791 return set_die_type (die
, type
, cu
);
18794 /* Parse dwarf attribute if it's a block, reference or constant and put the
18795 resulting value of the attribute into struct bound_prop.
18796 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18799 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18800 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18801 struct type
*default_type
)
18803 struct dwarf2_property_baton
*baton
;
18804 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18805 struct objfile
*objfile
= per_objfile
->objfile
;
18806 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18808 gdb_assert (default_type
!= NULL
);
18810 if (attr
== NULL
|| prop
== NULL
)
18813 if (attr
->form_is_block ())
18815 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18816 baton
->property_type
= default_type
;
18817 baton
->locexpr
.per_cu
= cu
->per_cu
;
18818 baton
->locexpr
.per_objfile
= per_objfile
;
18820 struct dwarf_block
*block
= attr
->as_block ();
18821 baton
->locexpr
.size
= block
->size
;
18822 baton
->locexpr
.data
= block
->data
;
18823 switch (attr
->name
)
18825 case DW_AT_string_length
:
18826 baton
->locexpr
.is_reference
= true;
18829 baton
->locexpr
.is_reference
= false;
18833 prop
->set_locexpr (baton
);
18834 gdb_assert (prop
->baton () != NULL
);
18836 else if (attr
->form_is_ref ())
18838 struct dwarf2_cu
*target_cu
= cu
;
18839 struct die_info
*target_die
;
18840 struct attribute
*target_attr
;
18842 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18843 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18844 if (target_attr
== NULL
)
18845 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18847 if (target_attr
== NULL
)
18850 switch (target_attr
->name
)
18852 case DW_AT_location
:
18853 if (target_attr
->form_is_section_offset ())
18855 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18856 baton
->property_type
= die_type (target_die
, target_cu
);
18857 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18858 prop
->set_loclist (baton
);
18859 gdb_assert (prop
->baton () != NULL
);
18861 else if (target_attr
->form_is_block ())
18863 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18864 baton
->property_type
= die_type (target_die
, target_cu
);
18865 baton
->locexpr
.per_cu
= cu
->per_cu
;
18866 baton
->locexpr
.per_objfile
= per_objfile
;
18867 struct dwarf_block
*block
= target_attr
->as_block ();
18868 baton
->locexpr
.size
= block
->size
;
18869 baton
->locexpr
.data
= block
->data
;
18870 baton
->locexpr
.is_reference
= true;
18871 prop
->set_locexpr (baton
);
18872 gdb_assert (prop
->baton () != NULL
);
18876 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18877 "dynamic property");
18881 case DW_AT_data_member_location
:
18885 if (!handle_data_member_location (target_die
, target_cu
,
18889 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18890 baton
->property_type
= read_type_die (target_die
->parent
,
18892 baton
->offset_info
.offset
= offset
;
18893 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18894 prop
->set_addr_offset (baton
);
18899 else if (attr
->form_is_constant ())
18900 prop
->set_const_val (attr
->constant_value (0));
18903 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18904 dwarf2_name (die
, cu
));
18914 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
18916 struct type
*int_type
;
18918 /* Helper macro to examine the various builtin types. */
18919 #define TRY_TYPE(F) \
18920 int_type = (unsigned_p \
18921 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18922 : objfile_type (objfile)->builtin_ ## F); \
18923 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18930 TRY_TYPE (long_long
);
18934 gdb_assert_not_reached ("unable to find suitable integer type");
18940 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
18942 int addr_size
= this->per_cu
->addr_size ();
18943 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
18946 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18947 present (which is valid) then compute the default type based on the
18948 compilation units address size. */
18950 static struct type
*
18951 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18953 struct type
*index_type
= die_type (die
, cu
);
18955 /* Dwarf-2 specifications explicitly allows to create subrange types
18956 without specifying a base type.
18957 In that case, the base type must be set to the type of
18958 the lower bound, upper bound or count, in that order, if any of these
18959 three attributes references an object that has a type.
18960 If no base type is found, the Dwarf-2 specifications say that
18961 a signed integer type of size equal to the size of an address should
18963 For the following C code: `extern char gdb_int [];'
18964 GCC produces an empty range DIE.
18965 FIXME: muller/2010-05-28: Possible references to object for low bound,
18966 high bound or count are not yet handled by this code. */
18967 if (index_type
->code () == TYPE_CODE_VOID
)
18968 index_type
= cu
->addr_sized_int_type (false);
18973 /* Read the given DW_AT_subrange DIE. */
18975 static struct type
*
18976 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18978 struct type
*base_type
, *orig_base_type
;
18979 struct type
*range_type
;
18980 struct attribute
*attr
;
18981 struct dynamic_prop low
, high
;
18982 int low_default_is_valid
;
18983 int high_bound_is_count
= 0;
18985 ULONGEST negative_mask
;
18987 orig_base_type
= read_subrange_index_type (die
, cu
);
18989 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18990 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18991 creating the range type, but we use the result of check_typedef
18992 when examining properties of the type. */
18993 base_type
= check_typedef (orig_base_type
);
18995 /* The die_type call above may have already set the type for this DIE. */
18996 range_type
= get_die_type (die
, cu
);
19000 high
.set_const_val (0);
19002 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
19003 omitting DW_AT_lower_bound. */
19004 switch (cu
->language
)
19007 case language_cplus
:
19008 low
.set_const_val (0);
19009 low_default_is_valid
= 1;
19011 case language_fortran
:
19012 low
.set_const_val (1);
19013 low_default_is_valid
= 1;
19016 case language_objc
:
19017 case language_rust
:
19018 low
.set_const_val (0);
19019 low_default_is_valid
= (cu
->header
.version
>= 4);
19023 case language_pascal
:
19024 low
.set_const_val (1);
19025 low_default_is_valid
= (cu
->header
.version
>= 4);
19028 low
.set_const_val (0);
19029 low_default_is_valid
= 0;
19033 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
19034 if (attr
!= nullptr)
19035 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
19036 else if (!low_default_is_valid
)
19037 complaint (_("Missing DW_AT_lower_bound "
19038 "- DIE at %s [in module %s]"),
19039 sect_offset_str (die
->sect_off
),
19040 objfile_name (cu
->per_objfile
->objfile
));
19042 struct attribute
*attr_ub
, *attr_count
;
19043 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
19044 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
19046 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
19047 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
19049 /* If bounds are constant do the final calculation here. */
19050 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
19051 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
19053 high_bound_is_count
= 1;
19057 if (attr_ub
!= NULL
)
19058 complaint (_("Unresolved DW_AT_upper_bound "
19059 "- DIE at %s [in module %s]"),
19060 sect_offset_str (die
->sect_off
),
19061 objfile_name (cu
->per_objfile
->objfile
));
19062 if (attr_count
!= NULL
)
19063 complaint (_("Unresolved DW_AT_count "
19064 "- DIE at %s [in module %s]"),
19065 sect_offset_str (die
->sect_off
),
19066 objfile_name (cu
->per_objfile
->objfile
));
19071 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
19072 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
19073 bias
= bias_attr
->constant_value (0);
19075 /* Normally, the DWARF producers are expected to use a signed
19076 constant form (Eg. DW_FORM_sdata) to express negative bounds.
19077 But this is unfortunately not always the case, as witnessed
19078 with GCC, for instance, where the ambiguous DW_FORM_dataN form
19079 is used instead. To work around that ambiguity, we treat
19080 the bounds as signed, and thus sign-extend their values, when
19081 the base type is signed. */
19083 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
19084 if (low
.kind () == PROP_CONST
19085 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
19086 low
.set_const_val (low
.const_val () | negative_mask
);
19087 if (high
.kind () == PROP_CONST
19088 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
19089 high
.set_const_val (high
.const_val () | negative_mask
);
19091 /* Check for bit and byte strides. */
19092 struct dynamic_prop byte_stride_prop
;
19093 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
19094 if (attr_byte_stride
!= nullptr)
19096 struct type
*prop_type
= cu
->addr_sized_int_type (false);
19097 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
19101 struct dynamic_prop bit_stride_prop
;
19102 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
19103 if (attr_bit_stride
!= nullptr)
19105 /* It only makes sense to have either a bit or byte stride. */
19106 if (attr_byte_stride
!= nullptr)
19108 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
19109 "- DIE at %s [in module %s]"),
19110 sect_offset_str (die
->sect_off
),
19111 objfile_name (cu
->per_objfile
->objfile
));
19112 attr_bit_stride
= nullptr;
19116 struct type
*prop_type
= cu
->addr_sized_int_type (false);
19117 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
19122 if (attr_byte_stride
!= nullptr
19123 || attr_bit_stride
!= nullptr)
19125 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
19126 struct dynamic_prop
*stride
19127 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
19130 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
19131 &high
, bias
, stride
, byte_stride_p
);
19134 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
19136 if (high_bound_is_count
)
19137 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
19139 /* Ada expects an empty array on no boundary attributes. */
19140 if (attr
== NULL
&& cu
->language
!= language_ada
)
19141 range_type
->bounds ()->high
.set_undefined ();
19143 name
= dwarf2_name (die
, cu
);
19145 range_type
->set_name (name
);
19147 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
19148 if (attr
!= nullptr)
19149 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
19151 maybe_set_alignment (cu
, die
, range_type
);
19153 set_die_type (die
, range_type
, cu
);
19155 /* set_die_type should be already done. */
19156 set_descriptive_type (range_type
, die
, cu
);
19161 static struct type
*
19162 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19166 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
19167 type
->set_name (dwarf2_name (die
, cu
));
19169 /* In Ada, an unspecified type is typically used when the description
19170 of the type is deferred to a different unit. When encountering
19171 such a type, we treat it as a stub, and try to resolve it later on,
19173 if (cu
->language
== language_ada
)
19174 type
->set_is_stub (true);
19176 return set_die_type (die
, type
, cu
);
19179 /* Read a single die and all its descendents. Set the die's sibling
19180 field to NULL; set other fields in the die correctly, and set all
19181 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
19182 location of the info_ptr after reading all of those dies. PARENT
19183 is the parent of the die in question. */
19185 static struct die_info
*
19186 read_die_and_children (const struct die_reader_specs
*reader
,
19187 const gdb_byte
*info_ptr
,
19188 const gdb_byte
**new_info_ptr
,
19189 struct die_info
*parent
)
19191 struct die_info
*die
;
19192 const gdb_byte
*cur_ptr
;
19194 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
19197 *new_info_ptr
= cur_ptr
;
19200 store_in_ref_table (die
, reader
->cu
);
19202 if (die
->has_children
)
19203 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
19207 *new_info_ptr
= cur_ptr
;
19210 die
->sibling
= NULL
;
19211 die
->parent
= parent
;
19215 /* Read a die, all of its descendents, and all of its siblings; set
19216 all of the fields of all of the dies correctly. Arguments are as
19217 in read_die_and_children. */
19219 static struct die_info
*
19220 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
19221 const gdb_byte
*info_ptr
,
19222 const gdb_byte
**new_info_ptr
,
19223 struct die_info
*parent
)
19225 struct die_info
*first_die
, *last_sibling
;
19226 const gdb_byte
*cur_ptr
;
19228 cur_ptr
= info_ptr
;
19229 first_die
= last_sibling
= NULL
;
19233 struct die_info
*die
19234 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
19238 *new_info_ptr
= cur_ptr
;
19245 last_sibling
->sibling
= die
;
19247 last_sibling
= die
;
19251 /* Read a die, all of its descendents, and all of its siblings; set
19252 all of the fields of all of the dies correctly. Arguments are as
19253 in read_die_and_children.
19254 This the main entry point for reading a DIE and all its children. */
19256 static struct die_info
*
19257 read_die_and_siblings (const struct die_reader_specs
*reader
,
19258 const gdb_byte
*info_ptr
,
19259 const gdb_byte
**new_info_ptr
,
19260 struct die_info
*parent
)
19262 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
19263 new_info_ptr
, parent
);
19265 if (dwarf_die_debug
)
19267 fprintf_unfiltered (gdb_stdlog
,
19268 "Read die from %s@0x%x of %s:\n",
19269 reader
->die_section
->get_name (),
19270 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19271 bfd_get_filename (reader
->abfd
));
19272 dump_die (die
, dwarf_die_debug
);
19278 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
19280 The caller is responsible for filling in the extra attributes
19281 and updating (*DIEP)->num_attrs.
19282 Set DIEP to point to a newly allocated die with its information,
19283 except for its child, sibling, and parent fields. */
19285 static const gdb_byte
*
19286 read_full_die_1 (const struct die_reader_specs
*reader
,
19287 struct die_info
**diep
, const gdb_byte
*info_ptr
,
19288 int num_extra_attrs
)
19290 unsigned int abbrev_number
, bytes_read
, i
;
19291 const struct abbrev_info
*abbrev
;
19292 struct die_info
*die
;
19293 struct dwarf2_cu
*cu
= reader
->cu
;
19294 bfd
*abfd
= reader
->abfd
;
19296 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
19297 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19298 info_ptr
+= bytes_read
;
19299 if (!abbrev_number
)
19305 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
19307 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
19309 bfd_get_filename (abfd
));
19311 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
19312 die
->sect_off
= sect_off
;
19313 die
->tag
= abbrev
->tag
;
19314 die
->abbrev
= abbrev_number
;
19315 die
->has_children
= abbrev
->has_children
;
19317 /* Make the result usable.
19318 The caller needs to update num_attrs after adding the extra
19320 die
->num_attrs
= abbrev
->num_attrs
;
19322 bool any_need_reprocess
= false;
19323 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19325 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
19327 if (die
->attrs
[i
].requires_reprocessing_p ())
19328 any_need_reprocess
= true;
19331 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
19332 if (attr
!= nullptr && attr
->form_is_unsigned ())
19333 cu
->str_offsets_base
= attr
->as_unsigned ();
19335 attr
= die
->attr (DW_AT_loclists_base
);
19336 if (attr
!= nullptr)
19337 cu
->loclist_base
= attr
->as_unsigned ();
19339 auto maybe_addr_base
= die
->addr_base ();
19340 if (maybe_addr_base
.has_value ())
19341 cu
->addr_base
= *maybe_addr_base
;
19343 attr
= die
->attr (DW_AT_rnglists_base
);
19344 if (attr
!= nullptr)
19345 cu
->rnglists_base
= attr
->as_unsigned ();
19347 if (any_need_reprocess
)
19349 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19351 if (die
->attrs
[i
].requires_reprocessing_p ())
19352 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
19359 /* Read a die and all its attributes.
19360 Set DIEP to point to a newly allocated die with its information,
19361 except for its child, sibling, and parent fields. */
19363 static const gdb_byte
*
19364 read_full_die (const struct die_reader_specs
*reader
,
19365 struct die_info
**diep
, const gdb_byte
*info_ptr
)
19367 const gdb_byte
*result
;
19369 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
19371 if (dwarf_die_debug
)
19373 fprintf_unfiltered (gdb_stdlog
,
19374 "Read die from %s@0x%x of %s:\n",
19375 reader
->die_section
->get_name (),
19376 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19377 bfd_get_filename (reader
->abfd
));
19378 dump_die (*diep
, dwarf_die_debug
);
19385 /* Returns nonzero if TAG represents a type that we might generate a partial
19389 is_type_tag_for_partial (int tag
, enum language lang
)
19394 /* Some types that would be reasonable to generate partial symbols for,
19395 that we don't at present. Note that normally this does not
19396 matter, mainly because C compilers don't give names to these
19397 types, but instead emit DW_TAG_typedef. */
19398 case DW_TAG_file_type
:
19399 case DW_TAG_ptr_to_member_type
:
19400 case DW_TAG_set_type
:
19401 case DW_TAG_string_type
:
19402 case DW_TAG_subroutine_type
:
19405 /* GNAT may emit an array with a name, but no typedef, so we
19406 need to make a symbol in this case. */
19407 case DW_TAG_array_type
:
19408 return lang
== language_ada
;
19410 case DW_TAG_base_type
:
19411 case DW_TAG_class_type
:
19412 case DW_TAG_interface_type
:
19413 case DW_TAG_enumeration_type
:
19414 case DW_TAG_structure_type
:
19415 case DW_TAG_subrange_type
:
19416 case DW_TAG_typedef
:
19417 case DW_TAG_union_type
:
19424 /* Load all DIEs that are interesting for partial symbols into memory. */
19426 static struct partial_die_info
*
19427 load_partial_dies (const struct die_reader_specs
*reader
,
19428 const gdb_byte
*info_ptr
, int building_psymtab
)
19430 struct dwarf2_cu
*cu
= reader
->cu
;
19431 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19432 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
19433 unsigned int bytes_read
;
19434 unsigned int load_all
= 0;
19435 int nesting_level
= 1;
19440 gdb_assert (cu
->per_cu
!= NULL
);
19441 if (cu
->per_cu
->load_all_dies
)
19445 = htab_create_alloc_ex (cu
->header
.length
/ 12,
19449 &cu
->comp_unit_obstack
,
19450 hashtab_obstack_allocate
,
19451 dummy_obstack_deallocate
);
19455 const abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
,
19458 /* A NULL abbrev means the end of a series of children. */
19459 if (abbrev
== NULL
)
19461 if (--nesting_level
== 0)
19464 info_ptr
+= bytes_read
;
19465 last_die
= parent_die
;
19466 parent_die
= parent_die
->die_parent
;
19470 /* Check for template arguments. We never save these; if
19471 they're seen, we just mark the parent, and go on our way. */
19472 if (parent_die
!= NULL
19473 && cu
->language
== language_cplus
19474 && (abbrev
->tag
== DW_TAG_template_type_param
19475 || abbrev
->tag
== DW_TAG_template_value_param
))
19477 parent_die
->has_template_arguments
= 1;
19481 /* We don't need a partial DIE for the template argument. */
19482 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19487 /* We only recurse into c++ subprograms looking for template arguments.
19488 Skip their other children. */
19490 && cu
->language
== language_cplus
19491 && parent_die
!= NULL
19492 && parent_die
->tag
== DW_TAG_subprogram
19493 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19495 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19499 /* Check whether this DIE is interesting enough to save. Normally
19500 we would not be interested in members here, but there may be
19501 later variables referencing them via DW_AT_specification (for
19502 static members). */
19504 && !is_type_tag_for_partial (abbrev
->tag
, cu
->language
)
19505 && abbrev
->tag
!= DW_TAG_constant
19506 && abbrev
->tag
!= DW_TAG_enumerator
19507 && abbrev
->tag
!= DW_TAG_subprogram
19508 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19509 && abbrev
->tag
!= DW_TAG_lexical_block
19510 && abbrev
->tag
!= DW_TAG_variable
19511 && abbrev
->tag
!= DW_TAG_namespace
19512 && abbrev
->tag
!= DW_TAG_module
19513 && abbrev
->tag
!= DW_TAG_member
19514 && abbrev
->tag
!= DW_TAG_imported_unit
19515 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19517 /* Otherwise we skip to the next sibling, if any. */
19518 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19522 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19525 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19527 /* This two-pass algorithm for processing partial symbols has a
19528 high cost in cache pressure. Thus, handle some simple cases
19529 here which cover the majority of C partial symbols. DIEs
19530 which neither have specification tags in them, nor could have
19531 specification tags elsewhere pointing at them, can simply be
19532 processed and discarded.
19534 This segment is also optional; scan_partial_symbols and
19535 add_partial_symbol will handle these DIEs if we chain
19536 them in normally. When compilers which do not emit large
19537 quantities of duplicate debug information are more common,
19538 this code can probably be removed. */
19540 /* Any complete simple types at the top level (pretty much all
19541 of them, for a language without namespaces), can be processed
19543 if (parent_die
== NULL
19544 && pdi
.has_specification
== 0
19545 && pdi
.is_declaration
== 0
19546 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19547 || pdi
.tag
== DW_TAG_base_type
19548 || pdi
.tag
== DW_TAG_array_type
19549 || pdi
.tag
== DW_TAG_subrange_type
))
19551 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19552 add_partial_symbol (&pdi
, cu
);
19554 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19558 /* The exception for DW_TAG_typedef with has_children above is
19559 a workaround of GCC PR debug/47510. In the case of this complaint
19560 type_name_or_error will error on such types later.
19562 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19563 it could not find the child DIEs referenced later, this is checked
19564 above. In correct DWARF DW_TAG_typedef should have no children. */
19566 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19567 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19568 "- DIE at %s [in module %s]"),
19569 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19571 /* If we're at the second level, and we're an enumerator, and
19572 our parent has no specification (meaning possibly lives in a
19573 namespace elsewhere), then we can add the partial symbol now
19574 instead of queueing it. */
19575 if (pdi
.tag
== DW_TAG_enumerator
19576 && parent_die
!= NULL
19577 && parent_die
->die_parent
== NULL
19578 && parent_die
->tag
== DW_TAG_enumeration_type
19579 && parent_die
->has_specification
== 0)
19581 if (pdi
.raw_name
== NULL
)
19582 complaint (_("malformed enumerator DIE ignored"));
19583 else if (building_psymtab
)
19584 add_partial_symbol (&pdi
, cu
);
19586 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19590 struct partial_die_info
*part_die
19591 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19593 /* We'll save this DIE so link it in. */
19594 part_die
->die_parent
= parent_die
;
19595 part_die
->die_sibling
= NULL
;
19596 part_die
->die_child
= NULL
;
19598 if (last_die
&& last_die
== parent_die
)
19599 last_die
->die_child
= part_die
;
19601 last_die
->die_sibling
= part_die
;
19603 last_die
= part_die
;
19605 if (first_die
== NULL
)
19606 first_die
= part_die
;
19608 /* Maybe add the DIE to the hash table. Not all DIEs that we
19609 find interesting need to be in the hash table, because we
19610 also have the parent/sibling/child chains; only those that we
19611 might refer to by offset later during partial symbol reading.
19613 For now this means things that might have be the target of a
19614 DW_AT_specification, DW_AT_abstract_origin, or
19615 DW_AT_extension. DW_AT_extension will refer only to
19616 namespaces; DW_AT_abstract_origin refers to functions (and
19617 many things under the function DIE, but we do not recurse
19618 into function DIEs during partial symbol reading) and
19619 possibly variables as well; DW_AT_specification refers to
19620 declarations. Declarations ought to have the DW_AT_declaration
19621 flag. It happens that GCC forgets to put it in sometimes, but
19622 only for functions, not for types.
19624 Adding more things than necessary to the hash table is harmless
19625 except for the performance cost. Adding too few will result in
19626 wasted time in find_partial_die, when we reread the compilation
19627 unit with load_all_dies set. */
19630 || abbrev
->tag
== DW_TAG_constant
19631 || abbrev
->tag
== DW_TAG_subprogram
19632 || abbrev
->tag
== DW_TAG_variable
19633 || abbrev
->tag
== DW_TAG_namespace
19634 || part_die
->is_declaration
)
19638 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19639 to_underlying (part_die
->sect_off
),
19644 /* For some DIEs we want to follow their children (if any). For C
19645 we have no reason to follow the children of structures; for other
19646 languages we have to, so that we can get at method physnames
19647 to infer fully qualified class names, for DW_AT_specification,
19648 and for C++ template arguments. For C++, we also look one level
19649 inside functions to find template arguments (if the name of the
19650 function does not already contain the template arguments).
19652 For Ada and Fortran, we need to scan the children of subprograms
19653 and lexical blocks as well because these languages allow the
19654 definition of nested entities that could be interesting for the
19655 debugger, such as nested subprograms for instance. */
19656 if (last_die
->has_children
19658 || last_die
->tag
== DW_TAG_namespace
19659 || last_die
->tag
== DW_TAG_module
19660 || last_die
->tag
== DW_TAG_enumeration_type
19661 || (cu
->language
== language_cplus
19662 && last_die
->tag
== DW_TAG_subprogram
19663 && (last_die
->raw_name
== NULL
19664 || strchr (last_die
->raw_name
, '<') == NULL
))
19665 || (cu
->language
!= language_c
19666 && (last_die
->tag
== DW_TAG_class_type
19667 || last_die
->tag
== DW_TAG_interface_type
19668 || last_die
->tag
== DW_TAG_structure_type
19669 || last_die
->tag
== DW_TAG_union_type
))
19670 || ((cu
->language
== language_ada
19671 || cu
->language
== language_fortran
)
19672 && (last_die
->tag
== DW_TAG_subprogram
19673 || last_die
->tag
== DW_TAG_lexical_block
))))
19676 parent_die
= last_die
;
19680 /* Otherwise we skip to the next sibling, if any. */
19681 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19683 /* Back to the top, do it again. */
19687 partial_die_info::partial_die_info (sect_offset sect_off_
,
19688 const struct abbrev_info
*abbrev
)
19689 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19693 /* See class definition. */
19696 partial_die_info::name (dwarf2_cu
*cu
)
19698 if (!canonical_name
&& raw_name
!= nullptr)
19700 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19701 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19702 canonical_name
= 1;
19708 /* Read a minimal amount of information into the minimal die structure.
19709 INFO_PTR should point just after the initial uleb128 of a DIE. */
19712 partial_die_info::read (const struct die_reader_specs
*reader
,
19713 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19715 struct dwarf2_cu
*cu
= reader
->cu
;
19716 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19718 int has_low_pc_attr
= 0;
19719 int has_high_pc_attr
= 0;
19720 int high_pc_relative
= 0;
19722 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19725 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19726 /* String and address offsets that need to do the reprocessing have
19727 already been read at this point, so there is no need to wait until
19728 the loop terminates to do the reprocessing. */
19729 if (attr
.requires_reprocessing_p ())
19730 read_attribute_reprocess (reader
, &attr
, tag
);
19731 /* Store the data if it is of an attribute we want to keep in a
19732 partial symbol table. */
19738 case DW_TAG_compile_unit
:
19739 case DW_TAG_partial_unit
:
19740 case DW_TAG_type_unit
:
19741 /* Compilation units have a DW_AT_name that is a filename, not
19742 a source language identifier. */
19743 case DW_TAG_enumeration_type
:
19744 case DW_TAG_enumerator
:
19745 /* These tags always have simple identifiers already; no need
19746 to canonicalize them. */
19747 canonical_name
= 1;
19748 raw_name
= attr
.as_string ();
19751 canonical_name
= 0;
19752 raw_name
= attr
.as_string ();
19756 case DW_AT_linkage_name
:
19757 case DW_AT_MIPS_linkage_name
:
19758 /* Note that both forms of linkage name might appear. We
19759 assume they will be the same, and we only store the last
19761 linkage_name
= attr
.as_string ();
19764 has_low_pc_attr
= 1;
19765 lowpc
= attr
.as_address ();
19767 case DW_AT_high_pc
:
19768 has_high_pc_attr
= 1;
19769 highpc
= attr
.as_address ();
19770 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19771 high_pc_relative
= 1;
19773 case DW_AT_location
:
19774 /* Support the .debug_loc offsets. */
19775 if (attr
.form_is_block ())
19777 d
.locdesc
= attr
.as_block ();
19779 else if (attr
.form_is_section_offset ())
19781 dwarf2_complex_location_expr_complaint ();
19785 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19786 "partial symbol information");
19789 case DW_AT_external
:
19790 is_external
= attr
.as_boolean ();
19792 case DW_AT_declaration
:
19793 is_declaration
= attr
.as_boolean ();
19798 case DW_AT_abstract_origin
:
19799 case DW_AT_specification
:
19800 case DW_AT_extension
:
19801 has_specification
= 1;
19802 spec_offset
= attr
.get_ref_die_offset ();
19803 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19804 || cu
->per_cu
->is_dwz
);
19806 case DW_AT_sibling
:
19807 /* Ignore absolute siblings, they might point outside of
19808 the current compile unit. */
19809 if (attr
.form
== DW_FORM_ref_addr
)
19810 complaint (_("ignoring absolute DW_AT_sibling"));
19813 const gdb_byte
*buffer
= reader
->buffer
;
19814 sect_offset off
= attr
.get_ref_die_offset ();
19815 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19817 if (sibling_ptr
< info_ptr
)
19818 complaint (_("DW_AT_sibling points backwards"));
19819 else if (sibling_ptr
> reader
->buffer_end
)
19820 reader
->die_section
->overflow_complaint ();
19822 sibling
= sibling_ptr
;
19825 case DW_AT_byte_size
:
19828 case DW_AT_const_value
:
19829 has_const_value
= 1;
19831 case DW_AT_calling_convention
:
19832 /* DWARF doesn't provide a way to identify a program's source-level
19833 entry point. DW_AT_calling_convention attributes are only meant
19834 to describe functions' calling conventions.
19836 However, because it's a necessary piece of information in
19837 Fortran, and before DWARF 4 DW_CC_program was the only
19838 piece of debugging information whose definition refers to
19839 a 'main program' at all, several compilers marked Fortran
19840 main programs with DW_CC_program --- even when those
19841 functions use the standard calling conventions.
19843 Although DWARF now specifies a way to provide this
19844 information, we support this practice for backward
19846 if (attr
.constant_value (0) == DW_CC_program
19847 && cu
->language
== language_fortran
)
19848 main_subprogram
= 1;
19852 LONGEST value
= attr
.constant_value (-1);
19853 if (value
== DW_INL_inlined
19854 || value
== DW_INL_declared_inlined
)
19855 may_be_inlined
= 1;
19860 if (tag
== DW_TAG_imported_unit
)
19862 d
.sect_off
= attr
.get_ref_die_offset ();
19863 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19864 || cu
->per_cu
->is_dwz
);
19868 case DW_AT_main_subprogram
:
19869 main_subprogram
= attr
.as_boolean ();
19874 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19875 on DWARF version). */
19876 ULONGEST ranges_offset
= attr
.as_unsigned ();
19878 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19880 if (tag
!= DW_TAG_compile_unit
)
19881 ranges_offset
+= cu
->gnu_ranges_base
;
19883 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19894 /* For Ada, if both the name and the linkage name appear, we prefer
19895 the latter. This lets "catch exception" work better, regardless
19896 of the order in which the name and linkage name were emitted.
19897 Really, though, this is just a workaround for the fact that gdb
19898 doesn't store both the name and the linkage name. */
19899 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19900 raw_name
= linkage_name
;
19902 if (high_pc_relative
)
19905 if (has_low_pc_attr
&& has_high_pc_attr
)
19907 /* When using the GNU linker, .gnu.linkonce. sections are used to
19908 eliminate duplicate copies of functions and vtables and such.
19909 The linker will arbitrarily choose one and discard the others.
19910 The AT_*_pc values for such functions refer to local labels in
19911 these sections. If the section from that file was discarded, the
19912 labels are not in the output, so the relocs get a value of 0.
19913 If this is a discarded function, mark the pc bounds as invalid,
19914 so that GDB will ignore it. */
19915 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
19917 struct objfile
*objfile
= per_objfile
->objfile
;
19918 struct gdbarch
*gdbarch
= objfile
->arch ();
19920 complaint (_("DW_AT_low_pc %s is zero "
19921 "for DIE at %s [in module %s]"),
19922 paddress (gdbarch
, lowpc
),
19923 sect_offset_str (sect_off
),
19924 objfile_name (objfile
));
19926 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19927 else if (lowpc
>= highpc
)
19929 struct objfile
*objfile
= per_objfile
->objfile
;
19930 struct gdbarch
*gdbarch
= objfile
->arch ();
19932 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19933 "for DIE at %s [in module %s]"),
19934 paddress (gdbarch
, lowpc
),
19935 paddress (gdbarch
, highpc
),
19936 sect_offset_str (sect_off
),
19937 objfile_name (objfile
));
19946 /* Find a cached partial DIE at OFFSET in CU. */
19948 struct partial_die_info
*
19949 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19951 struct partial_die_info
*lookup_die
= NULL
;
19952 struct partial_die_info
part_die (sect_off
);
19954 lookup_die
= ((struct partial_die_info
*)
19955 htab_find_with_hash (partial_dies
, &part_die
,
19956 to_underlying (sect_off
)));
19961 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19962 except in the case of .debug_types DIEs which do not reference
19963 outside their CU (they do however referencing other types via
19964 DW_FORM_ref_sig8). */
19966 static const struct cu_partial_die_info
19967 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19969 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19970 struct objfile
*objfile
= per_objfile
->objfile
;
19971 struct partial_die_info
*pd
= NULL
;
19973 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19974 && cu
->header
.offset_in_cu_p (sect_off
))
19976 pd
= cu
->find_partial_die (sect_off
);
19979 /* We missed recording what we needed.
19980 Load all dies and try again. */
19984 /* TUs don't reference other CUs/TUs (except via type signatures). */
19985 if (cu
->per_cu
->is_debug_types
)
19987 error (_("Dwarf Error: Type Unit at offset %s contains"
19988 " external reference to offset %s [in module %s].\n"),
19989 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19990 bfd_get_filename (objfile
->obfd
));
19992 dwarf2_per_cu_data
*per_cu
19993 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19996 cu
= per_objfile
->get_cu (per_cu
);
19997 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
19998 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
20000 cu
= per_objfile
->get_cu (per_cu
);
20003 pd
= cu
->find_partial_die (sect_off
);
20006 /* If we didn't find it, and not all dies have been loaded,
20007 load them all and try again. */
20009 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
20011 cu
->per_cu
->load_all_dies
= 1;
20013 /* This is nasty. When we reread the DIEs, somewhere up the call chain
20014 THIS_CU->cu may already be in use. So we can't just free it and
20015 replace its DIEs with the ones we read in. Instead, we leave those
20016 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
20017 and clobber THIS_CU->cu->partial_dies with the hash table for the new
20019 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
20021 pd
= cu
->find_partial_die (sect_off
);
20025 error (_("Dwarf Error: Cannot not find DIE at %s [from module %s]\n"),
20026 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
20030 /* See if we can figure out if the class lives in a namespace. We do
20031 this by looking for a member function; its demangled name will
20032 contain namespace info, if there is any. */
20035 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
20036 struct dwarf2_cu
*cu
)
20038 /* NOTE: carlton/2003-10-07: Getting the info this way changes
20039 what template types look like, because the demangler
20040 frequently doesn't give the same name as the debug info. We
20041 could fix this by only using the demangled name to get the
20042 prefix (but see comment in read_structure_type). */
20044 struct partial_die_info
*real_pdi
;
20045 struct partial_die_info
*child_pdi
;
20047 /* If this DIE (this DIE's specification, if any) has a parent, then
20048 we should not do this. We'll prepend the parent's fully qualified
20049 name when we create the partial symbol. */
20051 real_pdi
= struct_pdi
;
20052 while (real_pdi
->has_specification
)
20054 auto res
= find_partial_die (real_pdi
->spec_offset
,
20055 real_pdi
->spec_is_dwz
, cu
);
20056 real_pdi
= res
.pdi
;
20060 if (real_pdi
->die_parent
!= NULL
)
20063 for (child_pdi
= struct_pdi
->die_child
;
20065 child_pdi
= child_pdi
->die_sibling
)
20067 if (child_pdi
->tag
== DW_TAG_subprogram
20068 && child_pdi
->linkage_name
!= NULL
)
20070 gdb::unique_xmalloc_ptr
<char> actual_class_name
20071 (cu
->language_defn
->class_name_from_physname
20072 (child_pdi
->linkage_name
));
20073 if (actual_class_name
!= NULL
)
20075 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20076 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
20077 struct_pdi
->canonical_name
= 1;
20084 /* Return true if a DIE with TAG may have the DW_AT_const_value
20088 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
20092 case DW_TAG_constant
:
20093 case DW_TAG_enumerator
:
20094 case DW_TAG_formal_parameter
:
20095 case DW_TAG_template_value_param
:
20096 case DW_TAG_variable
:
20104 partial_die_info::fixup (struct dwarf2_cu
*cu
)
20106 /* Once we've fixed up a die, there's no point in doing so again.
20107 This also avoids a memory leak if we were to call
20108 guess_partial_die_structure_name multiple times. */
20112 /* If we found a reference attribute and the DIE has no name, try
20113 to find a name in the referred to DIE. */
20115 if (raw_name
== NULL
&& has_specification
)
20117 struct partial_die_info
*spec_die
;
20119 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
20120 spec_die
= res
.pdi
;
20123 spec_die
->fixup (cu
);
20125 if (spec_die
->raw_name
)
20127 raw_name
= spec_die
->raw_name
;
20128 canonical_name
= spec_die
->canonical_name
;
20130 /* Copy DW_AT_external attribute if it is set. */
20131 if (spec_die
->is_external
)
20132 is_external
= spec_die
->is_external
;
20136 if (!has_const_value
&& has_specification
20137 && can_have_DW_AT_const_value_p (tag
))
20139 struct partial_die_info
*spec_die
;
20141 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
20142 spec_die
= res
.pdi
;
20145 spec_die
->fixup (cu
);
20147 if (spec_die
->has_const_value
)
20149 /* Copy DW_AT_const_value attribute if it is set. */
20150 has_const_value
= spec_die
->has_const_value
;
20154 /* Set default names for some unnamed DIEs. */
20156 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
20158 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
20159 canonical_name
= 1;
20162 /* If there is no parent die to provide a namespace, and there are
20163 children, see if we can determine the namespace from their linkage
20165 if (cu
->language
== language_cplus
20166 && !cu
->per_objfile
->per_bfd
->types
.empty ()
20167 && die_parent
== NULL
20169 && (tag
== DW_TAG_class_type
20170 || tag
== DW_TAG_structure_type
20171 || tag
== DW_TAG_union_type
))
20172 guess_partial_die_structure_name (this, cu
);
20174 /* GCC might emit a nameless struct or union that has a linkage
20175 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20176 if (raw_name
== NULL
20177 && (tag
== DW_TAG_class_type
20178 || tag
== DW_TAG_interface_type
20179 || tag
== DW_TAG_structure_type
20180 || tag
== DW_TAG_union_type
)
20181 && linkage_name
!= NULL
)
20183 gdb::unique_xmalloc_ptr
<char> demangled
20184 (gdb_demangle (linkage_name
, DMGL_TYPES
));
20185 if (demangled
!= nullptr)
20189 /* Strip any leading namespaces/classes, keep only the base name.
20190 DW_AT_name for named DIEs does not contain the prefixes. */
20191 base
= strrchr (demangled
.get (), ':');
20192 if (base
&& base
> demangled
.get () && base
[-1] == ':')
20195 base
= demangled
.get ();
20197 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20198 raw_name
= objfile
->intern (base
);
20199 canonical_name
= 1;
20206 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
20207 contents from the given SECTION in the HEADER.
20209 HEADER_OFFSET is the offset of the header in the section. */
20211 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
20212 struct dwarf2_section_info
*section
,
20213 sect_offset header_offset
)
20215 unsigned int bytes_read
;
20216 bfd
*abfd
= section
->get_bfd_owner ();
20217 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
20219 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
20220 info_ptr
+= bytes_read
;
20222 header
->version
= read_2_bytes (abfd
, info_ptr
);
20225 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
20228 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
20231 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
20234 /* Return the DW_AT_loclists_base value for the CU. */
20236 lookup_loclist_base (struct dwarf2_cu
*cu
)
20238 /* For the .dwo unit, the loclist_base points to the first offset following
20239 the header. The header consists of the following entities-
20240 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
20242 2. version (2 bytes)
20243 3. address size (1 byte)
20244 4. segment selector size (1 byte)
20245 5. offset entry count (4 bytes)
20246 These sizes are derived as per the DWARFv5 standard. */
20247 if (cu
->dwo_unit
!= nullptr)
20249 if (cu
->header
.initial_length_size
== 4)
20250 return LOCLIST_HEADER_SIZE32
;
20251 return LOCLIST_HEADER_SIZE64
;
20253 return cu
->loclist_base
;
20256 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
20257 array of offsets in the .debug_loclists section. */
20260 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
20262 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20263 struct objfile
*objfile
= per_objfile
->objfile
;
20264 bfd
*abfd
= objfile
->obfd
;
20265 ULONGEST loclist_header_size
=
20266 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
20267 : LOCLIST_HEADER_SIZE64
);
20268 ULONGEST loclist_base
= lookup_loclist_base (cu
);
20270 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
20271 ULONGEST start_offset
=
20272 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
20274 /* Get loclists section. */
20275 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
20277 /* Read the loclists section content. */
20278 section
->read (objfile
);
20279 if (section
->buffer
== NULL
)
20280 error (_("DW_FORM_loclistx used without .debug_loclists "
20281 "section [in module %s]"), objfile_name (objfile
));
20283 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
20284 so if loclist_base is smaller than the header size, we have a problem. */
20285 if (loclist_base
< loclist_header_size
)
20286 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
20287 objfile_name (objfile
));
20289 /* Read the header of the loclists contribution. */
20290 struct loclists_rnglists_header header
;
20291 read_loclists_rnglists_header (&header
, section
,
20292 (sect_offset
) (loclist_base
- loclist_header_size
));
20294 /* Verify the loclist index is valid. */
20295 if (loclist_index
>= header
.offset_entry_count
)
20296 error (_("DW_FORM_loclistx pointing outside of "
20297 ".debug_loclists offset array [in module %s]"),
20298 objfile_name (objfile
));
20300 /* Validate that reading won't go beyond the end of the section. */
20301 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
20302 error (_("Reading DW_FORM_loclistx index beyond end of"
20303 ".debug_loclists section [in module %s]"),
20304 objfile_name (objfile
));
20306 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20308 if (cu
->header
.offset_size
== 4)
20309 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
20311 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
20314 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
20315 array of offsets in the .debug_rnglists section. */
20318 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
20321 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
20322 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20323 bfd
*abfd
= objfile
->obfd
;
20324 ULONGEST rnglist_header_size
=
20325 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
20326 : RNGLIST_HEADER_SIZE64
);
20328 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
20329 .debug_rnglists.dwo section. The rnglists base given in the skeleton
20331 ULONGEST rnglist_base
=
20332 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
20334 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
20335 ULONGEST start_offset
=
20336 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
20338 /* Get rnglists section. */
20339 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
20341 /* Read the rnglists section content. */
20342 section
->read (objfile
);
20343 if (section
->buffer
== nullptr)
20344 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
20346 objfile_name (objfile
));
20348 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
20349 so if rnglist_base is smaller than the header size, we have a problem. */
20350 if (rnglist_base
< rnglist_header_size
)
20351 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
20352 objfile_name (objfile
));
20354 /* Read the header of the rnglists contribution. */
20355 struct loclists_rnglists_header header
;
20356 read_loclists_rnglists_header (&header
, section
,
20357 (sect_offset
) (rnglist_base
- rnglist_header_size
));
20359 /* Verify the rnglist index is valid. */
20360 if (rnglist_index
>= header
.offset_entry_count
)
20361 error (_("DW_FORM_rnglistx index pointing outside of "
20362 ".debug_rnglists offset array [in module %s]"),
20363 objfile_name (objfile
));
20365 /* Validate that reading won't go beyond the end of the section. */
20366 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
20367 error (_("Reading DW_FORM_rnglistx index beyond end of"
20368 ".debug_rnglists section [in module %s]"),
20369 objfile_name (objfile
));
20371 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20373 if (cu
->header
.offset_size
== 4)
20374 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
20376 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
20379 /* Process the attributes that had to be skipped in the first round. These
20380 attributes are the ones that need str_offsets_base or addr_base attributes.
20381 They could not have been processed in the first round, because at the time
20382 the values of str_offsets_base or addr_base may not have been known. */
20384 read_attribute_reprocess (const struct die_reader_specs
*reader
,
20385 struct attribute
*attr
, dwarf_tag tag
)
20387 struct dwarf2_cu
*cu
= reader
->cu
;
20388 switch (attr
->form
)
20390 case DW_FORM_addrx
:
20391 case DW_FORM_GNU_addr_index
:
20392 attr
->set_address (read_addr_index (cu
,
20393 attr
->as_unsigned_reprocess ()));
20395 case DW_FORM_loclistx
:
20397 sect_offset loclists_sect_off
20398 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
20400 attr
->set_unsigned (to_underlying (loclists_sect_off
));
20403 case DW_FORM_rnglistx
:
20405 sect_offset rnglists_sect_off
20406 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
20408 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
20412 case DW_FORM_strx1
:
20413 case DW_FORM_strx2
:
20414 case DW_FORM_strx3
:
20415 case DW_FORM_strx4
:
20416 case DW_FORM_GNU_str_index
:
20418 unsigned int str_index
= attr
->as_unsigned_reprocess ();
20419 gdb_assert (!attr
->canonical_string_p ());
20420 if (reader
->dwo_file
!= NULL
)
20421 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
20424 attr
->set_string_noncanonical (read_stub_str_index (cu
,
20429 gdb_assert_not_reached (_("Unexpected DWARF form."));
20433 /* Read an attribute value described by an attribute form. */
20435 static const gdb_byte
*
20436 read_attribute_value (const struct die_reader_specs
*reader
,
20437 struct attribute
*attr
, unsigned form
,
20438 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
20440 struct dwarf2_cu
*cu
= reader
->cu
;
20441 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20442 struct objfile
*objfile
= per_objfile
->objfile
;
20443 bfd
*abfd
= reader
->abfd
;
20444 struct comp_unit_head
*cu_header
= &cu
->header
;
20445 unsigned int bytes_read
;
20446 struct dwarf_block
*blk
;
20448 attr
->form
= (enum dwarf_form
) form
;
20451 case DW_FORM_ref_addr
:
20452 if (cu_header
->version
== 2)
20453 attr
->set_unsigned (cu_header
->read_address (abfd
, info_ptr
,
20456 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20458 info_ptr
+= bytes_read
;
20460 case DW_FORM_GNU_ref_alt
:
20461 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20463 info_ptr
+= bytes_read
;
20467 struct gdbarch
*gdbarch
= objfile
->arch ();
20468 CORE_ADDR addr
= cu_header
->read_address (abfd
, info_ptr
, &bytes_read
);
20469 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
20470 attr
->set_address (addr
);
20471 info_ptr
+= bytes_read
;
20474 case DW_FORM_block2
:
20475 blk
= dwarf_alloc_block (cu
);
20476 blk
->size
= read_2_bytes (abfd
, info_ptr
);
20478 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20479 info_ptr
+= blk
->size
;
20480 attr
->set_block (blk
);
20482 case DW_FORM_block4
:
20483 blk
= dwarf_alloc_block (cu
);
20484 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20486 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20487 info_ptr
+= blk
->size
;
20488 attr
->set_block (blk
);
20490 case DW_FORM_data2
:
20491 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20494 case DW_FORM_data4
:
20495 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20498 case DW_FORM_data8
:
20499 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20502 case DW_FORM_data16
:
20503 blk
= dwarf_alloc_block (cu
);
20505 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20507 attr
->set_block (blk
);
20509 case DW_FORM_sec_offset
:
20510 attr
->set_unsigned (cu_header
->read_offset (abfd
, info_ptr
,
20512 info_ptr
+= bytes_read
;
20514 case DW_FORM_loclistx
:
20516 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20518 info_ptr
+= bytes_read
;
20521 case DW_FORM_string
:
20522 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20524 info_ptr
+= bytes_read
;
20527 if (!cu
->per_cu
->is_dwz
)
20529 attr
->set_string_noncanonical
20530 (read_indirect_string (per_objfile
,
20531 abfd
, info_ptr
, cu_header
,
20533 info_ptr
+= bytes_read
;
20537 case DW_FORM_line_strp
:
20538 if (!cu
->per_cu
->is_dwz
)
20540 attr
->set_string_noncanonical
20541 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20543 info_ptr
+= bytes_read
;
20547 case DW_FORM_GNU_strp_alt
:
20549 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20550 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20553 attr
->set_string_noncanonical
20554 (dwz
->read_string (objfile
, str_offset
));
20555 info_ptr
+= bytes_read
;
20558 case DW_FORM_exprloc
:
20559 case DW_FORM_block
:
20560 blk
= dwarf_alloc_block (cu
);
20561 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20562 info_ptr
+= bytes_read
;
20563 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20564 info_ptr
+= blk
->size
;
20565 attr
->set_block (blk
);
20567 case DW_FORM_block1
:
20568 blk
= dwarf_alloc_block (cu
);
20569 blk
->size
= read_1_byte (abfd
, info_ptr
);
20571 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20572 info_ptr
+= blk
->size
;
20573 attr
->set_block (blk
);
20575 case DW_FORM_data1
:
20577 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20580 case DW_FORM_flag_present
:
20581 attr
->set_unsigned (1);
20583 case DW_FORM_sdata
:
20584 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20585 info_ptr
+= bytes_read
;
20587 case DW_FORM_rnglistx
:
20589 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20591 info_ptr
+= bytes_read
;
20594 case DW_FORM_udata
:
20595 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20596 info_ptr
+= bytes_read
;
20599 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20600 + read_1_byte (abfd
, info_ptr
)));
20604 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20605 + read_2_bytes (abfd
, info_ptr
)));
20609 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20610 + read_4_bytes (abfd
, info_ptr
)));
20614 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20615 + read_8_bytes (abfd
, info_ptr
)));
20618 case DW_FORM_ref_sig8
:
20619 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20622 case DW_FORM_ref_udata
:
20623 attr
->set_unsigned ((to_underlying (cu_header
->sect_off
)
20624 + read_unsigned_leb128 (abfd
, info_ptr
,
20626 info_ptr
+= bytes_read
;
20628 case DW_FORM_indirect
:
20629 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20630 info_ptr
+= bytes_read
;
20631 if (form
== DW_FORM_implicit_const
)
20633 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20634 info_ptr
+= bytes_read
;
20636 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20639 case DW_FORM_implicit_const
:
20640 attr
->set_signed (implicit_const
);
20642 case DW_FORM_addrx
:
20643 case DW_FORM_GNU_addr_index
:
20644 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20646 info_ptr
+= bytes_read
;
20649 case DW_FORM_strx1
:
20650 case DW_FORM_strx2
:
20651 case DW_FORM_strx3
:
20652 case DW_FORM_strx4
:
20653 case DW_FORM_GNU_str_index
:
20655 ULONGEST str_index
;
20656 if (form
== DW_FORM_strx1
)
20658 str_index
= read_1_byte (abfd
, info_ptr
);
20661 else if (form
== DW_FORM_strx2
)
20663 str_index
= read_2_bytes (abfd
, info_ptr
);
20666 else if (form
== DW_FORM_strx3
)
20668 str_index
= read_3_bytes (abfd
, info_ptr
);
20671 else if (form
== DW_FORM_strx4
)
20673 str_index
= read_4_bytes (abfd
, info_ptr
);
20678 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20679 info_ptr
+= bytes_read
;
20681 attr
->set_unsigned_reprocess (str_index
);
20685 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20686 dwarf_form_name (form
),
20687 bfd_get_filename (abfd
));
20691 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20692 attr
->form
= DW_FORM_GNU_ref_alt
;
20694 /* We have seen instances where the compiler tried to emit a byte
20695 size attribute of -1 which ended up being encoded as an unsigned
20696 0xffffffff. Although 0xffffffff is technically a valid size value,
20697 an object of this size seems pretty unlikely so we can relatively
20698 safely treat these cases as if the size attribute was invalid and
20699 treat them as zero by default. */
20700 if (attr
->name
== DW_AT_byte_size
20701 && form
== DW_FORM_data4
20702 && attr
->as_unsigned () >= 0xffffffff)
20705 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20706 hex_string (attr
->as_unsigned ()));
20707 attr
->set_unsigned (0);
20713 /* Read an attribute described by an abbreviated attribute. */
20715 static const gdb_byte
*
20716 read_attribute (const struct die_reader_specs
*reader
,
20717 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20718 const gdb_byte
*info_ptr
)
20720 attr
->name
= abbrev
->name
;
20721 attr
->string_is_canonical
= 0;
20722 attr
->requires_reprocessing
= 0;
20723 return read_attribute_value (reader
, attr
, abbrev
->form
,
20724 abbrev
->implicit_const
, info_ptr
);
20727 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20729 static const char *
20730 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20731 LONGEST str_offset
)
20733 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20734 str_offset
, "DW_FORM_strp");
20737 /* Return pointer to string at .debug_str offset as read from BUF.
20738 BUF is assumed to be in a compilation unit described by CU_HEADER.
20739 Return *BYTES_READ_PTR count of bytes read from BUF. */
20741 static const char *
20742 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20743 const gdb_byte
*buf
,
20744 const struct comp_unit_head
*cu_header
,
20745 unsigned int *bytes_read_ptr
)
20747 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20749 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20755 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20756 const struct comp_unit_head
*cu_header
,
20757 unsigned int *bytes_read_ptr
)
20759 bfd
*abfd
= objfile
->obfd
;
20760 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20762 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20765 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20766 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20767 ADDR_SIZE is the size of addresses from the CU header. */
20770 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20771 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20773 struct objfile
*objfile
= per_objfile
->objfile
;
20774 bfd
*abfd
= objfile
->obfd
;
20775 const gdb_byte
*info_ptr
;
20776 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20778 per_objfile
->per_bfd
->addr
.read (objfile
);
20779 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20780 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20781 objfile_name (objfile
));
20782 if (addr_base_or_zero
+ addr_index
* addr_size
20783 >= per_objfile
->per_bfd
->addr
.size
)
20784 error (_("DW_FORM_addr_index pointing outside of "
20785 ".debug_addr section [in module %s]"),
20786 objfile_name (objfile
));
20787 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20788 + addr_index
* addr_size
);
20789 if (addr_size
== 4)
20790 return bfd_get_32 (abfd
, info_ptr
);
20792 return bfd_get_64 (abfd
, info_ptr
);
20795 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20798 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20800 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20801 cu
->addr_base
, cu
->header
.addr_size
);
20804 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20807 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20808 unsigned int *bytes_read
)
20810 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20811 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20813 return read_addr_index (cu
, addr_index
);
20819 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20820 dwarf2_per_objfile
*per_objfile
,
20821 unsigned int addr_index
)
20823 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20824 gdb::optional
<ULONGEST
> addr_base
;
20827 /* We need addr_base and addr_size.
20828 If we don't have PER_CU->cu, we have to get it.
20829 Nasty, but the alternative is storing the needed info in PER_CU,
20830 which at this point doesn't seem justified: it's not clear how frequently
20831 it would get used and it would increase the size of every PER_CU.
20832 Entry points like dwarf2_per_cu_addr_size do a similar thing
20833 so we're not in uncharted territory here.
20834 Alas we need to be a bit more complicated as addr_base is contained
20837 We don't need to read the entire CU(/TU).
20838 We just need the header and top level die.
20840 IWBN to use the aging mechanism to let us lazily later discard the CU.
20841 For now we skip this optimization. */
20845 addr_base
= cu
->addr_base
;
20846 addr_size
= cu
->header
.addr_size
;
20850 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20851 addr_base
= reader
.cu
->addr_base
;
20852 addr_size
= reader
.cu
->header
.addr_size
;
20855 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20858 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20859 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20862 static const char *
20863 read_str_index (struct dwarf2_cu
*cu
,
20864 struct dwarf2_section_info
*str_section
,
20865 struct dwarf2_section_info
*str_offsets_section
,
20866 ULONGEST str_offsets_base
, ULONGEST str_index
)
20868 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20869 struct objfile
*objfile
= per_objfile
->objfile
;
20870 const char *objf_name
= objfile_name (objfile
);
20871 bfd
*abfd
= objfile
->obfd
;
20872 const gdb_byte
*info_ptr
;
20873 ULONGEST str_offset
;
20874 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20876 str_section
->read (objfile
);
20877 str_offsets_section
->read (objfile
);
20878 if (str_section
->buffer
== NULL
)
20879 error (_("%s used without %s section"
20880 " in CU at offset %s [in module %s]"),
20881 form_name
, str_section
->get_name (),
20882 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20883 if (str_offsets_section
->buffer
== NULL
)
20884 error (_("%s used without %s section"
20885 " in CU at offset %s [in module %s]"),
20886 form_name
, str_section
->get_name (),
20887 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20888 info_ptr
= (str_offsets_section
->buffer
20890 + str_index
* cu
->header
.offset_size
);
20891 if (cu
->header
.offset_size
== 4)
20892 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20894 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20895 if (str_offset
>= str_section
->size
)
20896 error (_("Offset from %s pointing outside of"
20897 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20898 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20899 return (const char *) (str_section
->buffer
+ str_offset
);
20902 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20904 static const char *
20905 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20907 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20908 ? reader
->cu
->header
.addr_size
: 0;
20909 return read_str_index (reader
->cu
,
20910 &reader
->dwo_file
->sections
.str
,
20911 &reader
->dwo_file
->sections
.str_offsets
,
20912 str_offsets_base
, str_index
);
20915 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20917 static const char *
20918 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20920 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20921 const char *objf_name
= objfile_name (objfile
);
20922 static const char form_name
[] = "DW_FORM_GNU_str_index";
20923 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20925 if (!cu
->str_offsets_base
.has_value ())
20926 error (_("%s used in Fission stub without %s"
20927 " in CU at offset 0x%lx [in module %s]"),
20928 form_name
, str_offsets_attr_name
,
20929 (long) cu
->header
.offset_size
, objf_name
);
20931 return read_str_index (cu
,
20932 &cu
->per_objfile
->per_bfd
->str
,
20933 &cu
->per_objfile
->per_bfd
->str_offsets
,
20934 *cu
->str_offsets_base
, str_index
);
20937 /* Return the length of an LEB128 number in BUF. */
20940 leb128_size (const gdb_byte
*buf
)
20942 const gdb_byte
*begin
= buf
;
20948 if ((byte
& 128) == 0)
20949 return buf
- begin
;
20954 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20963 cu
->language
= language_c
;
20966 case DW_LANG_C_plus_plus
:
20967 case DW_LANG_C_plus_plus_11
:
20968 case DW_LANG_C_plus_plus_14
:
20969 cu
->language
= language_cplus
;
20972 cu
->language
= language_d
;
20974 case DW_LANG_Fortran77
:
20975 case DW_LANG_Fortran90
:
20976 case DW_LANG_Fortran95
:
20977 case DW_LANG_Fortran03
:
20978 case DW_LANG_Fortran08
:
20979 cu
->language
= language_fortran
;
20982 cu
->language
= language_go
;
20984 case DW_LANG_Mips_Assembler
:
20985 cu
->language
= language_asm
;
20987 case DW_LANG_Ada83
:
20988 case DW_LANG_Ada95
:
20989 cu
->language
= language_ada
;
20991 case DW_LANG_Modula2
:
20992 cu
->language
= language_m2
;
20994 case DW_LANG_Pascal83
:
20995 cu
->language
= language_pascal
;
20998 cu
->language
= language_objc
;
21001 case DW_LANG_Rust_old
:
21002 cu
->language
= language_rust
;
21004 case DW_LANG_Cobol74
:
21005 case DW_LANG_Cobol85
:
21007 cu
->language
= language_minimal
;
21010 cu
->language_defn
= language_def (cu
->language
);
21013 /* Return the named attribute or NULL if not there. */
21015 static struct attribute
*
21016 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
21021 struct attribute
*spec
= NULL
;
21023 for (i
= 0; i
< die
->num_attrs
; ++i
)
21025 if (die
->attrs
[i
].name
== name
)
21026 return &die
->attrs
[i
];
21027 if (die
->attrs
[i
].name
== DW_AT_specification
21028 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
21029 spec
= &die
->attrs
[i
];
21035 die
= follow_die_ref (die
, spec
, &cu
);
21041 /* Return the string associated with a string-typed attribute, or NULL if it
21042 is either not found or is of an incorrect type. */
21044 static const char *
21045 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
21047 struct attribute
*attr
;
21048 const char *str
= NULL
;
21050 attr
= dwarf2_attr (die
, name
, cu
);
21054 str
= attr
->as_string ();
21055 if (str
== nullptr)
21056 complaint (_("string type expected for attribute %s for "
21057 "DIE at %s in module %s"),
21058 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
21059 objfile_name (cu
->per_objfile
->objfile
));
21065 /* Return the dwo name or NULL if not present. If present, it is in either
21066 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
21067 static const char *
21068 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21070 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
21071 if (dwo_name
== nullptr)
21072 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
21076 /* Return non-zero iff the attribute NAME is defined for the given DIE,
21077 and holds a non-zero value. This function should only be used for
21078 DW_FORM_flag or DW_FORM_flag_present attributes. */
21081 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
21083 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
21085 return attr
!= nullptr && attr
->as_boolean ();
21089 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
21091 /* A DIE is a declaration if it has a DW_AT_declaration attribute
21092 which value is non-zero. However, we have to be careful with
21093 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
21094 (via dwarf2_flag_true_p) follows this attribute. So we may
21095 end up accidently finding a declaration attribute that belongs
21096 to a different DIE referenced by the specification attribute,
21097 even though the given DIE does not have a declaration attribute. */
21098 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
21099 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
21102 /* Return the die giving the specification for DIE, if there is
21103 one. *SPEC_CU is the CU containing DIE on input, and the CU
21104 containing the return value on output. If there is no
21105 specification, but there is an abstract origin, that is
21108 static struct die_info
*
21109 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
21111 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
21114 if (spec_attr
== NULL
)
21115 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
21117 if (spec_attr
== NULL
)
21120 return follow_die_ref (die
, spec_attr
, spec_cu
);
21123 /* Stub for free_line_header to match void * callback types. */
21126 free_line_header_voidp (void *arg
)
21128 struct line_header
*lh
= (struct line_header
*) arg
;
21133 /* A convenience function to find the proper .debug_line section for a CU. */
21135 static struct dwarf2_section_info
*
21136 get_debug_line_section (struct dwarf2_cu
*cu
)
21138 struct dwarf2_section_info
*section
;
21139 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21141 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
21143 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
21144 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
21145 else if (cu
->per_cu
->is_dwz
)
21147 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
21149 section
= &dwz
->line
;
21152 section
= &per_objfile
->per_bfd
->line
;
21157 /* Read the statement program header starting at OFFSET in
21158 .debug_line, or .debug_line.dwo. Return a pointer
21159 to a struct line_header, allocated using xmalloc.
21160 Returns NULL if there is a problem reading the header, e.g., if it
21161 has a version we don't understand.
21163 NOTE: the strings in the include directory and file name tables of
21164 the returned object point into the dwarf line section buffer,
21165 and must not be freed. */
21167 static line_header_up
21168 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
21170 struct dwarf2_section_info
*section
;
21171 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21173 section
= get_debug_line_section (cu
);
21174 section
->read (per_objfile
->objfile
);
21175 if (section
->buffer
== NULL
)
21177 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
21178 complaint (_("missing .debug_line.dwo section"));
21180 complaint (_("missing .debug_line section"));
21184 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
21185 per_objfile
, section
, &cu
->header
);
21188 /* Subroutine of dwarf_decode_lines to simplify it.
21189 Return the file name of the psymtab for the given file_entry.
21190 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21191 If space for the result is malloc'd, *NAME_HOLDER will be set.
21192 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
21194 static const char *
21195 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
21196 const dwarf2_psymtab
*pst
,
21197 const char *comp_dir
,
21198 gdb::unique_xmalloc_ptr
<char> *name_holder
)
21200 const char *include_name
= fe
.name
;
21201 const char *include_name_to_compare
= include_name
;
21202 const char *pst_filename
;
21205 const char *dir_name
= fe
.include_dir (lh
);
21207 gdb::unique_xmalloc_ptr
<char> hold_compare
;
21208 if (!IS_ABSOLUTE_PATH (include_name
)
21209 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
21211 /* Avoid creating a duplicate psymtab for PST.
21212 We do this by comparing INCLUDE_NAME and PST_FILENAME.
21213 Before we do the comparison, however, we need to account
21214 for DIR_NAME and COMP_DIR.
21215 First prepend dir_name (if non-NULL). If we still don't
21216 have an absolute path prepend comp_dir (if non-NULL).
21217 However, the directory we record in the include-file's
21218 psymtab does not contain COMP_DIR (to match the
21219 corresponding symtab(s)).
21224 bash$ gcc -g ./hello.c
21225 include_name = "hello.c"
21227 DW_AT_comp_dir = comp_dir = "/tmp"
21228 DW_AT_name = "./hello.c"
21232 if (dir_name
!= NULL
)
21234 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
21235 include_name
, (char *) NULL
));
21236 include_name
= name_holder
->get ();
21237 include_name_to_compare
= include_name
;
21239 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
21241 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
21242 include_name
, (char *) NULL
));
21243 include_name_to_compare
= hold_compare
.get ();
21247 pst_filename
= pst
->filename
;
21248 gdb::unique_xmalloc_ptr
<char> copied_name
;
21249 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
21251 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
21252 pst_filename
, (char *) NULL
));
21253 pst_filename
= copied_name
.get ();
21256 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
21260 return include_name
;
21263 /* State machine to track the state of the line number program. */
21265 class lnp_state_machine
21268 /* Initialize a machine state for the start of a line number
21270 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
21271 bool record_lines_p
);
21273 file_entry
*current_file ()
21275 /* lh->file_names is 0-based, but the file name numbers in the
21276 statement program are 1-based. */
21277 return m_line_header
->file_name_at (m_file
);
21280 /* Record the line in the state machine. END_SEQUENCE is true if
21281 we're processing the end of a sequence. */
21282 void record_line (bool end_sequence
);
21284 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
21285 nop-out rest of the lines in this sequence. */
21286 void check_line_address (struct dwarf2_cu
*cu
,
21287 const gdb_byte
*line_ptr
,
21288 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
21290 void handle_set_discriminator (unsigned int discriminator
)
21292 m_discriminator
= discriminator
;
21293 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21296 /* Handle DW_LNE_set_address. */
21297 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21300 address
+= baseaddr
;
21301 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21304 /* Handle DW_LNS_advance_pc. */
21305 void handle_advance_pc (CORE_ADDR adjust
);
21307 /* Handle a special opcode. */
21308 void handle_special_opcode (unsigned char op_code
);
21310 /* Handle DW_LNS_advance_line. */
21311 void handle_advance_line (int line_delta
)
21313 advance_line (line_delta
);
21316 /* Handle DW_LNS_set_file. */
21317 void handle_set_file (file_name_index file
);
21319 /* Handle DW_LNS_negate_stmt. */
21320 void handle_negate_stmt ()
21322 m_is_stmt
= !m_is_stmt
;
21325 /* Handle DW_LNS_const_add_pc. */
21326 void handle_const_add_pc ();
21328 /* Handle DW_LNS_fixed_advance_pc. */
21329 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21331 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21335 /* Handle DW_LNS_copy. */
21336 void handle_copy ()
21338 record_line (false);
21339 m_discriminator
= 0;
21342 /* Handle DW_LNE_end_sequence. */
21343 void handle_end_sequence ()
21345 m_currently_recording_lines
= true;
21349 /* Advance the line by LINE_DELTA. */
21350 void advance_line (int line_delta
)
21352 m_line
+= line_delta
;
21354 if (line_delta
!= 0)
21355 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21358 struct dwarf2_cu
*m_cu
;
21360 gdbarch
*m_gdbarch
;
21362 /* True if we're recording lines.
21363 Otherwise we're building partial symtabs and are just interested in
21364 finding include files mentioned by the line number program. */
21365 bool m_record_lines_p
;
21367 /* The line number header. */
21368 line_header
*m_line_header
;
21370 /* These are part of the standard DWARF line number state machine,
21371 and initialized according to the DWARF spec. */
21373 unsigned char m_op_index
= 0;
21374 /* The line table index of the current file. */
21375 file_name_index m_file
= 1;
21376 unsigned int m_line
= 1;
21378 /* These are initialized in the constructor. */
21380 CORE_ADDR m_address
;
21382 unsigned int m_discriminator
;
21384 /* Additional bits of state we need to track. */
21386 /* The last file that we called dwarf2_start_subfile for.
21387 This is only used for TLLs. */
21388 unsigned int m_last_file
= 0;
21389 /* The last file a line number was recorded for. */
21390 struct subfile
*m_last_subfile
= NULL
;
21392 /* The address of the last line entry. */
21393 CORE_ADDR m_last_address
;
21395 /* Set to true when a previous line at the same address (using
21396 m_last_address) had m_is_stmt true. This is reset to false when a
21397 line entry at a new address (m_address different to m_last_address) is
21399 bool m_stmt_at_address
= false;
21401 /* When true, record the lines we decode. */
21402 bool m_currently_recording_lines
= false;
21404 /* The last line number that was recorded, used to coalesce
21405 consecutive entries for the same line. This can happen, for
21406 example, when discriminators are present. PR 17276. */
21407 unsigned int m_last_line
= 0;
21408 bool m_line_has_non_zero_discriminator
= false;
21412 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21414 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21415 / m_line_header
->maximum_ops_per_instruction
)
21416 * m_line_header
->minimum_instruction_length
);
21417 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21418 m_op_index
= ((m_op_index
+ adjust
)
21419 % m_line_header
->maximum_ops_per_instruction
);
21423 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21425 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21426 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
21427 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
21428 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
21429 / m_line_header
->maximum_ops_per_instruction
)
21430 * m_line_header
->minimum_instruction_length
);
21431 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21432 m_op_index
= ((m_op_index
+ adj_opcode_d
)
21433 % m_line_header
->maximum_ops_per_instruction
);
21435 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
21436 advance_line (line_delta
);
21437 record_line (false);
21438 m_discriminator
= 0;
21442 lnp_state_machine::handle_set_file (file_name_index file
)
21446 const file_entry
*fe
= current_file ();
21448 dwarf2_debug_line_missing_file_complaint ();
21449 else if (m_record_lines_p
)
21451 const char *dir
= fe
->include_dir (m_line_header
);
21453 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21454 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21455 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21460 lnp_state_machine::handle_const_add_pc ()
21463 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21466 = (((m_op_index
+ adjust
)
21467 / m_line_header
->maximum_ops_per_instruction
)
21468 * m_line_header
->minimum_instruction_length
);
21470 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21471 m_op_index
= ((m_op_index
+ adjust
)
21472 % m_line_header
->maximum_ops_per_instruction
);
21475 /* Return non-zero if we should add LINE to the line number table.
21476 LINE is the line to add, LAST_LINE is the last line that was added,
21477 LAST_SUBFILE is the subfile for LAST_LINE.
21478 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21479 had a non-zero discriminator.
21481 We have to be careful in the presence of discriminators.
21482 E.g., for this line:
21484 for (i = 0; i < 100000; i++);
21486 clang can emit four line number entries for that one line,
21487 each with a different discriminator.
21488 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21490 However, we want gdb to coalesce all four entries into one.
21491 Otherwise the user could stepi into the middle of the line and
21492 gdb would get confused about whether the pc really was in the
21493 middle of the line.
21495 Things are further complicated by the fact that two consecutive
21496 line number entries for the same line is a heuristic used by gcc
21497 to denote the end of the prologue. So we can't just discard duplicate
21498 entries, we have to be selective about it. The heuristic we use is
21499 that we only collapse consecutive entries for the same line if at least
21500 one of those entries has a non-zero discriminator. PR 17276.
21502 Note: Addresses in the line number state machine can never go backwards
21503 within one sequence, thus this coalescing is ok. */
21506 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21507 unsigned int line
, unsigned int last_line
,
21508 int line_has_non_zero_discriminator
,
21509 struct subfile
*last_subfile
)
21511 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21513 if (line
!= last_line
)
21515 /* Same line for the same file that we've seen already.
21516 As a last check, for pr 17276, only record the line if the line
21517 has never had a non-zero discriminator. */
21518 if (!line_has_non_zero_discriminator
)
21523 /* Use the CU's builder to record line number LINE beginning at
21524 address ADDRESS in the line table of subfile SUBFILE. */
21527 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21528 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
21529 struct dwarf2_cu
*cu
)
21531 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21533 if (dwarf_line_debug
)
21535 fprintf_unfiltered (gdb_stdlog
,
21536 "Recording line %u, file %s, address %s\n",
21537 line
, lbasename (subfile
->name
),
21538 paddress (gdbarch
, address
));
21542 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21545 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21546 Mark the end of a set of line number records.
21547 The arguments are the same as for dwarf_record_line_1.
21548 If SUBFILE is NULL the request is ignored. */
21551 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21552 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21554 if (subfile
== NULL
)
21557 if (dwarf_line_debug
)
21559 fprintf_unfiltered (gdb_stdlog
,
21560 "Finishing current line, file %s, address %s\n",
21561 lbasename (subfile
->name
),
21562 paddress (gdbarch
, address
));
21565 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21569 lnp_state_machine::record_line (bool end_sequence
)
21571 if (dwarf_line_debug
)
21573 fprintf_unfiltered (gdb_stdlog
,
21574 "Processing actual line %u: file %u,"
21575 " address %s, is_stmt %u, discrim %u%s\n",
21577 paddress (m_gdbarch
, m_address
),
21578 m_is_stmt
, m_discriminator
,
21579 (end_sequence
? "\t(end sequence)" : ""));
21582 file_entry
*fe
= current_file ();
21585 dwarf2_debug_line_missing_file_complaint ();
21586 /* For now we ignore lines not starting on an instruction boundary.
21587 But not when processing end_sequence for compatibility with the
21588 previous version of the code. */
21589 else if (m_op_index
== 0 || end_sequence
)
21591 fe
->included_p
= 1;
21592 if (m_record_lines_p
)
21594 /* When we switch files we insert an end maker in the first file,
21595 switch to the second file and add a new line entry. The
21596 problem is that the end marker inserted in the first file will
21597 discard any previous line entries at the same address. If the
21598 line entries in the first file are marked as is-stmt, while
21599 the new line in the second file is non-stmt, then this means
21600 the end marker will discard is-stmt lines so we can have a
21601 non-stmt line. This means that there are less addresses at
21602 which the user can insert a breakpoint.
21604 To improve this we track the last address in m_last_address,
21605 and whether we have seen an is-stmt at this address. Then
21606 when switching files, if we have seen a stmt at the current
21607 address, and we are switching to create a non-stmt line, then
21608 discard the new line. */
21610 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21611 bool ignore_this_line
21612 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21613 && !m_is_stmt
&& m_stmt_at_address
)
21614 || (!end_sequence
&& m_line
== 0));
21616 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21618 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21619 m_currently_recording_lines
? m_cu
: nullptr);
21622 if (!end_sequence
&& !ignore_this_line
)
21624 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21626 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21627 m_line_has_non_zero_discriminator
,
21630 buildsym_compunit
*builder
= m_cu
->get_builder ();
21631 dwarf_record_line_1 (m_gdbarch
,
21632 builder
->get_current_subfile (),
21633 m_line
, m_address
, is_stmt
,
21634 m_currently_recording_lines
? m_cu
: nullptr);
21636 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21637 m_last_line
= m_line
;
21642 /* Track whether we have seen any m_is_stmt true at m_address in case we
21643 have multiple line table entries all at m_address. */
21644 if (m_last_address
!= m_address
)
21646 m_stmt_at_address
= false;
21647 m_last_address
= m_address
;
21649 m_stmt_at_address
|= m_is_stmt
;
21652 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21653 line_header
*lh
, bool record_lines_p
)
21657 m_record_lines_p
= record_lines_p
;
21658 m_line_header
= lh
;
21660 m_currently_recording_lines
= true;
21662 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21663 was a line entry for it so that the backend has a chance to adjust it
21664 and also record it in case it needs it. This is currently used by MIPS
21665 code, cf. `mips_adjust_dwarf2_line'. */
21666 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21667 m_is_stmt
= lh
->default_is_stmt
;
21668 m_discriminator
= 0;
21670 m_last_address
= m_address
;
21671 m_stmt_at_address
= false;
21675 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21676 const gdb_byte
*line_ptr
,
21677 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21679 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21680 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21681 located at 0x0. In this case, additionally check that if
21682 ADDRESS < UNRELOCATED_LOWPC. */
21684 if ((address
== 0 && address
< unrelocated_lowpc
)
21685 || address
== (CORE_ADDR
) -1)
21687 /* This line table is for a function which has been
21688 GCd by the linker. Ignore it. PR gdb/12528 */
21690 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21691 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21693 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21694 line_offset
, objfile_name (objfile
));
21695 m_currently_recording_lines
= false;
21696 /* Note: m_currently_recording_lines is left as false until we see
21697 DW_LNE_end_sequence. */
21701 /* Subroutine of dwarf_decode_lines to simplify it.
21702 Process the line number information in LH.
21703 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21704 program in order to set included_p for every referenced header. */
21707 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21708 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21710 const gdb_byte
*line_ptr
, *extended_end
;
21711 const gdb_byte
*line_end
;
21712 unsigned int bytes_read
, extended_len
;
21713 unsigned char op_code
, extended_op
;
21714 CORE_ADDR baseaddr
;
21715 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21716 bfd
*abfd
= objfile
->obfd
;
21717 struct gdbarch
*gdbarch
= objfile
->arch ();
21718 /* True if we're recording line info (as opposed to building partial
21719 symtabs and just interested in finding include files mentioned by
21720 the line number program). */
21721 bool record_lines_p
= !decode_for_pst_p
;
21723 baseaddr
= objfile
->text_section_offset ();
21725 line_ptr
= lh
->statement_program_start
;
21726 line_end
= lh
->statement_program_end
;
21728 /* Read the statement sequences until there's nothing left. */
21729 while (line_ptr
< line_end
)
21731 /* The DWARF line number program state machine. Reset the state
21732 machine at the start of each sequence. */
21733 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21734 bool end_sequence
= false;
21736 if (record_lines_p
)
21738 /* Start a subfile for the current file of the state
21740 const file_entry
*fe
= state_machine
.current_file ();
21743 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21746 /* Decode the table. */
21747 while (line_ptr
< line_end
&& !end_sequence
)
21749 op_code
= read_1_byte (abfd
, line_ptr
);
21752 if (op_code
>= lh
->opcode_base
)
21754 /* Special opcode. */
21755 state_machine
.handle_special_opcode (op_code
);
21757 else switch (op_code
)
21759 case DW_LNS_extended_op
:
21760 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21762 line_ptr
+= bytes_read
;
21763 extended_end
= line_ptr
+ extended_len
;
21764 extended_op
= read_1_byte (abfd
, line_ptr
);
21766 if (DW_LNE_lo_user
<= extended_op
21767 && extended_op
<= DW_LNE_hi_user
)
21769 /* Vendor extension, ignore. */
21770 line_ptr
= extended_end
;
21773 switch (extended_op
)
21775 case DW_LNE_end_sequence
:
21776 state_machine
.handle_end_sequence ();
21777 end_sequence
= true;
21779 case DW_LNE_set_address
:
21782 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21783 line_ptr
+= bytes_read
;
21785 state_machine
.check_line_address (cu
, line_ptr
,
21786 lowpc
- baseaddr
, address
);
21787 state_machine
.handle_set_address (baseaddr
, address
);
21790 case DW_LNE_define_file
:
21792 const char *cur_file
;
21793 unsigned int mod_time
, length
;
21796 cur_file
= read_direct_string (abfd
, line_ptr
,
21798 line_ptr
+= bytes_read
;
21799 dindex
= (dir_index
)
21800 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21801 line_ptr
+= bytes_read
;
21803 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21804 line_ptr
+= bytes_read
;
21806 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21807 line_ptr
+= bytes_read
;
21808 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21811 case DW_LNE_set_discriminator
:
21813 /* The discriminator is not interesting to the
21814 debugger; just ignore it. We still need to
21815 check its value though:
21816 if there are consecutive entries for the same
21817 (non-prologue) line we want to coalesce them.
21820 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21821 line_ptr
+= bytes_read
;
21823 state_machine
.handle_set_discriminator (discr
);
21827 complaint (_("mangled .debug_line section"));
21830 /* Make sure that we parsed the extended op correctly. If e.g.
21831 we expected a different address size than the producer used,
21832 we may have read the wrong number of bytes. */
21833 if (line_ptr
!= extended_end
)
21835 complaint (_("mangled .debug_line section"));
21840 state_machine
.handle_copy ();
21842 case DW_LNS_advance_pc
:
21845 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21846 line_ptr
+= bytes_read
;
21848 state_machine
.handle_advance_pc (adjust
);
21851 case DW_LNS_advance_line
:
21854 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21855 line_ptr
+= bytes_read
;
21857 state_machine
.handle_advance_line (line_delta
);
21860 case DW_LNS_set_file
:
21862 file_name_index file
21863 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21865 line_ptr
+= bytes_read
;
21867 state_machine
.handle_set_file (file
);
21870 case DW_LNS_set_column
:
21871 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21872 line_ptr
+= bytes_read
;
21874 case DW_LNS_negate_stmt
:
21875 state_machine
.handle_negate_stmt ();
21877 case DW_LNS_set_basic_block
:
21879 /* Add to the address register of the state machine the
21880 address increment value corresponding to special opcode
21881 255. I.e., this value is scaled by the minimum
21882 instruction length since special opcode 255 would have
21883 scaled the increment. */
21884 case DW_LNS_const_add_pc
:
21885 state_machine
.handle_const_add_pc ();
21887 case DW_LNS_fixed_advance_pc
:
21889 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21892 state_machine
.handle_fixed_advance_pc (addr_adj
);
21897 /* Unknown standard opcode, ignore it. */
21900 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21902 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21903 line_ptr
+= bytes_read
;
21910 dwarf2_debug_line_missing_end_sequence_complaint ();
21912 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21913 in which case we still finish recording the last line). */
21914 state_machine
.record_line (true);
21918 /* Decode the Line Number Program (LNP) for the given line_header
21919 structure and CU. The actual information extracted and the type
21920 of structures created from the LNP depends on the value of PST.
21922 1. If PST is NULL, then this procedure uses the data from the program
21923 to create all necessary symbol tables, and their linetables.
21925 2. If PST is not NULL, this procedure reads the program to determine
21926 the list of files included by the unit represented by PST, and
21927 builds all the associated partial symbol tables.
21929 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21930 It is used for relative paths in the line table.
21931 NOTE: When processing partial symtabs (pst != NULL),
21932 comp_dir == pst->dirname.
21934 NOTE: It is important that psymtabs have the same file name (via strcmp)
21935 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21936 symtab we don't use it in the name of the psymtabs we create.
21937 E.g. expand_line_sal requires this when finding psymtabs to expand.
21938 A good testcase for this is mb-inline.exp.
21940 LOWPC is the lowest address in CU (or 0 if not known).
21942 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21943 for its PC<->lines mapping information. Otherwise only the filename
21944 table is read in. */
21947 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21948 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21949 CORE_ADDR lowpc
, int decode_mapping
)
21951 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21952 const int decode_for_pst_p
= (pst
!= NULL
);
21954 if (decode_mapping
)
21955 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21957 if (decode_for_pst_p
)
21959 /* Now that we're done scanning the Line Header Program, we can
21960 create the psymtab of each included file. */
21961 for (auto &file_entry
: lh
->file_names ())
21962 if (file_entry
.included_p
== 1)
21964 gdb::unique_xmalloc_ptr
<char> name_holder
;
21965 const char *include_name
=
21966 psymtab_include_file_name (lh
, file_entry
, pst
,
21967 comp_dir
, &name_holder
);
21968 if (include_name
!= NULL
)
21969 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21974 /* Make sure a symtab is created for every file, even files
21975 which contain only variables (i.e. no code with associated
21977 buildsym_compunit
*builder
= cu
->get_builder ();
21978 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21980 for (auto &fe
: lh
->file_names ())
21982 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21983 if (builder
->get_current_subfile ()->symtab
== NULL
)
21985 builder
->get_current_subfile ()->symtab
21986 = allocate_symtab (cust
,
21987 builder
->get_current_subfile ()->name
);
21989 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21994 /* Start a subfile for DWARF. FILENAME is the name of the file and
21995 DIRNAME the name of the source directory which contains FILENAME
21996 or NULL if not known.
21997 This routine tries to keep line numbers from identical absolute and
21998 relative file names in a common subfile.
22000 Using the `list' example from the GDB testsuite, which resides in
22001 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
22002 of /srcdir/list0.c yields the following debugging information for list0.c:
22004 DW_AT_name: /srcdir/list0.c
22005 DW_AT_comp_dir: /compdir
22006 files.files[0].name: list0.h
22007 files.files[0].dir: /srcdir
22008 files.files[1].name: list0.c
22009 files.files[1].dir: /srcdir
22011 The line number information for list0.c has to end up in a single
22012 subfile, so that `break /srcdir/list0.c:1' works as expected.
22013 start_subfile will ensure that this happens provided that we pass the
22014 concatenation of files.files[1].dir and files.files[1].name as the
22018 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
22019 const char *dirname
)
22021 gdb::unique_xmalloc_ptr
<char> copy
;
22023 /* In order not to lose the line information directory,
22024 we concatenate it to the filename when it makes sense.
22025 Note that the Dwarf3 standard says (speaking of filenames in line
22026 information): ``The directory index is ignored for file names
22027 that represent full path names''. Thus ignoring dirname in the
22028 `else' branch below isn't an issue. */
22030 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
22032 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
22033 filename
= copy
.get ();
22036 cu
->get_builder ()->start_subfile (filename
);
22039 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
22040 buildsym_compunit constructor. */
22042 struct compunit_symtab
*
22043 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
22046 gdb_assert (m_builder
== nullptr);
22048 m_builder
.reset (new struct buildsym_compunit
22049 (this->per_objfile
->objfile
,
22050 name
, comp_dir
, language
, low_pc
));
22052 list_in_scope
= get_builder ()->get_file_symbols ();
22054 get_builder ()->record_debugformat ("DWARF 2");
22055 get_builder ()->record_producer (producer
);
22057 processing_has_namespace_info
= false;
22059 return get_builder ()->get_compunit_symtab ();
22063 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
22064 struct dwarf2_cu
*cu
)
22066 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22067 struct comp_unit_head
*cu_header
= &cu
->header
;
22069 /* NOTE drow/2003-01-30: There used to be a comment and some special
22070 code here to turn a symbol with DW_AT_external and a
22071 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
22072 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
22073 with some versions of binutils) where shared libraries could have
22074 relocations against symbols in their debug information - the
22075 minimal symbol would have the right address, but the debug info
22076 would not. It's no longer necessary, because we will explicitly
22077 apply relocations when we read in the debug information now. */
22079 /* A DW_AT_location attribute with no contents indicates that a
22080 variable has been optimized away. */
22081 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
22083 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22087 /* Handle one degenerate form of location expression specially, to
22088 preserve GDB's previous behavior when section offsets are
22089 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
22090 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
22092 if (attr
->form_is_block ())
22094 struct dwarf_block
*block
= attr
->as_block ();
22096 if ((block
->data
[0] == DW_OP_addr
22097 && block
->size
== 1 + cu_header
->addr_size
)
22098 || ((block
->data
[0] == DW_OP_GNU_addr_index
22099 || block
->data
[0] == DW_OP_addrx
)
22101 == 1 + leb128_size (&block
->data
[1]))))
22103 unsigned int dummy
;
22105 if (block
->data
[0] == DW_OP_addr
)
22106 SET_SYMBOL_VALUE_ADDRESS
22107 (sym
, cu
->header
.read_address (objfile
->obfd
,
22111 SET_SYMBOL_VALUE_ADDRESS
22112 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
22114 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
22115 fixup_symbol_section (sym
, objfile
);
22116 SET_SYMBOL_VALUE_ADDRESS
22118 SYMBOL_VALUE_ADDRESS (sym
)
22119 + objfile
->section_offsets
[sym
->section_index ()]);
22124 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
22125 expression evaluator, and use LOC_COMPUTED only when necessary
22126 (i.e. when the value of a register or memory location is
22127 referenced, or a thread-local block, etc.). Then again, it might
22128 not be worthwhile. I'm assuming that it isn't unless performance
22129 or memory numbers show me otherwise. */
22131 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
22133 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
22134 cu
->has_loclist
= true;
22137 /* Given a pointer to a DWARF information entry, figure out if we need
22138 to make a symbol table entry for it, and if so, create a new entry
22139 and return a pointer to it.
22140 If TYPE is NULL, determine symbol type from the die, otherwise
22141 used the passed type.
22142 If SPACE is not NULL, use it to hold the new symbol. If it is
22143 NULL, allocate a new symbol on the objfile's obstack. */
22145 static struct symbol
*
22146 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
22147 struct symbol
*space
)
22149 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22150 struct objfile
*objfile
= per_objfile
->objfile
;
22151 struct gdbarch
*gdbarch
= objfile
->arch ();
22152 struct symbol
*sym
= NULL
;
22154 struct attribute
*attr
= NULL
;
22155 struct attribute
*attr2
= NULL
;
22156 CORE_ADDR baseaddr
;
22157 struct pending
**list_to_add
= NULL
;
22159 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
22161 baseaddr
= objfile
->text_section_offset ();
22163 name
= dwarf2_name (die
, cu
);
22166 int suppress_add
= 0;
22171 sym
= new (&objfile
->objfile_obstack
) symbol
;
22172 OBJSTAT (objfile
, n_syms
++);
22174 /* Cache this symbol's name and the name's demangled form (if any). */
22175 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
22176 /* Fortran does not have mangling standard and the mangling does differ
22177 between gfortran, iFort etc. */
22178 const char *physname
22179 = (cu
->language
== language_fortran
22180 ? dwarf2_full_name (name
, die
, cu
)
22181 : dwarf2_physname (name
, die
, cu
));
22182 const char *linkagename
= dw2_linkage_name (die
, cu
);
22184 if (linkagename
== nullptr || cu
->language
== language_ada
)
22185 sym
->set_linkage_name (physname
);
22188 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
22189 sym
->set_linkage_name (linkagename
);
22192 /* Default assumptions.
22193 Use the passed type or decode it from the die. */
22194 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22195 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22197 SYMBOL_TYPE (sym
) = type
;
22199 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
22200 attr
= dwarf2_attr (die
,
22201 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
22203 if (attr
!= nullptr)
22204 SYMBOL_LINE (sym
) = attr
->constant_value (0);
22206 attr
= dwarf2_attr (die
,
22207 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
22209 if (attr
!= nullptr && attr
->is_nonnegative ())
22211 file_name_index file_index
22212 = (file_name_index
) attr
->as_nonnegative ();
22213 struct file_entry
*fe
;
22215 if (cu
->line_header
!= NULL
)
22216 fe
= cu
->line_header
->file_name_at (file_index
);
22221 complaint (_("file index out of range"));
22223 symbol_set_symtab (sym
, fe
->symtab
);
22229 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
22230 if (attr
!= nullptr)
22234 addr
= attr
->as_address ();
22235 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
22236 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
22237 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
22240 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22241 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
22242 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
22243 add_symbol_to_list (sym
, cu
->list_in_scope
);
22245 case DW_TAG_subprogram
:
22246 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22248 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22249 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22250 if ((attr2
!= nullptr && attr2
->as_boolean ())
22251 || cu
->language
== language_ada
22252 || cu
->language
== language_fortran
)
22254 /* Subprograms marked external are stored as a global symbol.
22255 Ada and Fortran subprograms, whether marked external or
22256 not, are always stored as a global symbol, because we want
22257 to be able to access them globally. For instance, we want
22258 to be able to break on a nested subprogram without having
22259 to specify the context. */
22260 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22264 list_to_add
= cu
->list_in_scope
;
22267 case DW_TAG_inlined_subroutine
:
22268 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22270 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22271 SYMBOL_INLINED (sym
) = 1;
22272 list_to_add
= cu
->list_in_scope
;
22274 case DW_TAG_template_value_param
:
22276 /* Fall through. */
22277 case DW_TAG_constant
:
22278 case DW_TAG_variable
:
22279 case DW_TAG_member
:
22280 /* Compilation with minimal debug info may result in
22281 variables with missing type entries. Change the
22282 misleading `void' type to something sensible. */
22283 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
22284 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
22286 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22287 /* In the case of DW_TAG_member, we should only be called for
22288 static const members. */
22289 if (die
->tag
== DW_TAG_member
)
22291 /* dwarf2_add_field uses die_is_declaration,
22292 so we do the same. */
22293 gdb_assert (die_is_declaration (die
, cu
));
22296 if (attr
!= nullptr)
22298 dwarf2_const_value (attr
, sym
, cu
);
22299 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22302 if (attr2
!= nullptr && attr2
->as_boolean ())
22303 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22305 list_to_add
= cu
->list_in_scope
;
22309 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22310 if (attr
!= nullptr)
22312 var_decode_location (attr
, sym
, cu
);
22313 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22315 /* Fortran explicitly imports any global symbols to the local
22316 scope by DW_TAG_common_block. */
22317 if (cu
->language
== language_fortran
&& die
->parent
22318 && die
->parent
->tag
== DW_TAG_common_block
)
22321 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22322 && SYMBOL_VALUE_ADDRESS (sym
) == 0
22323 && !per_objfile
->per_bfd
->has_section_at_zero
)
22325 /* When a static variable is eliminated by the linker,
22326 the corresponding debug information is not stripped
22327 out, but the variable address is set to null;
22328 do not add such variables into symbol table. */
22330 else if (attr2
!= nullptr && attr2
->as_boolean ())
22332 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22333 && (objfile
->flags
& OBJF_MAINLINE
) == 0
22334 && per_objfile
->per_bfd
->can_copy
)
22336 /* A global static variable might be subject to
22337 copy relocation. We first check for a local
22338 minsym, though, because maybe the symbol was
22339 marked hidden, in which case this would not
22341 bound_minimal_symbol found
22342 = (lookup_minimal_symbol_linkage
22343 (sym
->linkage_name (), objfile
));
22344 if (found
.minsym
!= nullptr)
22345 sym
->maybe_copied
= 1;
22348 /* A variable with DW_AT_external is never static,
22349 but it may be block-scoped. */
22351 = ((cu
->list_in_scope
22352 == cu
->get_builder ()->get_file_symbols ())
22353 ? cu
->get_builder ()->get_global_symbols ()
22354 : cu
->list_in_scope
);
22357 list_to_add
= cu
->list_in_scope
;
22361 /* We do not know the address of this symbol.
22362 If it is an external symbol and we have type information
22363 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22364 The address of the variable will then be determined from
22365 the minimal symbol table whenever the variable is
22367 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22369 /* Fortran explicitly imports any global symbols to the local
22370 scope by DW_TAG_common_block. */
22371 if (cu
->language
== language_fortran
&& die
->parent
22372 && die
->parent
->tag
== DW_TAG_common_block
)
22374 /* SYMBOL_CLASS doesn't matter here because
22375 read_common_block is going to reset it. */
22377 list_to_add
= cu
->list_in_scope
;
22379 else if (attr2
!= nullptr && attr2
->as_boolean ()
22380 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22382 /* A variable with DW_AT_external is never static, but it
22383 may be block-scoped. */
22385 = ((cu
->list_in_scope
22386 == cu
->get_builder ()->get_file_symbols ())
22387 ? cu
->get_builder ()->get_global_symbols ()
22388 : cu
->list_in_scope
);
22390 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22392 else if (!die_is_declaration (die
, cu
))
22394 /* Use the default LOC_OPTIMIZED_OUT class. */
22395 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22397 list_to_add
= cu
->list_in_scope
;
22401 case DW_TAG_formal_parameter
:
22403 /* If we are inside a function, mark this as an argument. If
22404 not, we might be looking at an argument to an inlined function
22405 when we do not have enough information to show inlined frames;
22406 pretend it's a local variable in that case so that the user can
22408 struct context_stack
*curr
22409 = cu
->get_builder ()->get_current_context_stack ();
22410 if (curr
!= nullptr && curr
->name
!= nullptr)
22411 SYMBOL_IS_ARGUMENT (sym
) = 1;
22412 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22413 if (attr
!= nullptr)
22415 var_decode_location (attr
, sym
, cu
);
22417 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22418 if (attr
!= nullptr)
22420 dwarf2_const_value (attr
, sym
, cu
);
22423 list_to_add
= cu
->list_in_scope
;
22426 case DW_TAG_unspecified_parameters
:
22427 /* From varargs functions; gdb doesn't seem to have any
22428 interest in this information, so just ignore it for now.
22431 case DW_TAG_template_type_param
:
22433 /* Fall through. */
22434 case DW_TAG_class_type
:
22435 case DW_TAG_interface_type
:
22436 case DW_TAG_structure_type
:
22437 case DW_TAG_union_type
:
22438 case DW_TAG_set_type
:
22439 case DW_TAG_enumeration_type
:
22440 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22441 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22444 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22445 really ever be static objects: otherwise, if you try
22446 to, say, break of a class's method and you're in a file
22447 which doesn't mention that class, it won't work unless
22448 the check for all static symbols in lookup_symbol_aux
22449 saves you. See the OtherFileClass tests in
22450 gdb.c++/namespace.exp. */
22454 buildsym_compunit
*builder
= cu
->get_builder ();
22456 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22457 && cu
->language
== language_cplus
22458 ? builder
->get_global_symbols ()
22459 : cu
->list_in_scope
);
22461 /* The semantics of C++ state that "struct foo {
22462 ... }" also defines a typedef for "foo". */
22463 if (cu
->language
== language_cplus
22464 || cu
->language
== language_ada
22465 || cu
->language
== language_d
22466 || cu
->language
== language_rust
)
22468 /* The symbol's name is already allocated along
22469 with this objfile, so we don't need to
22470 duplicate it for the type. */
22471 if (SYMBOL_TYPE (sym
)->name () == 0)
22472 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
22477 case DW_TAG_typedef
:
22478 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22479 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22480 list_to_add
= cu
->list_in_scope
;
22482 case DW_TAG_array_type
:
22483 case DW_TAG_base_type
:
22484 case DW_TAG_subrange_type
:
22485 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22486 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22487 list_to_add
= cu
->list_in_scope
;
22489 case DW_TAG_enumerator
:
22490 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22491 if (attr
!= nullptr)
22493 dwarf2_const_value (attr
, sym
, cu
);
22496 /* NOTE: carlton/2003-11-10: See comment above in the
22497 DW_TAG_class_type, etc. block. */
22500 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22501 && cu
->language
== language_cplus
22502 ? cu
->get_builder ()->get_global_symbols ()
22503 : cu
->list_in_scope
);
22506 case DW_TAG_imported_declaration
:
22507 case DW_TAG_namespace
:
22508 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22509 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22511 case DW_TAG_module
:
22512 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22513 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22514 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22516 case DW_TAG_common_block
:
22517 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22518 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22519 add_symbol_to_list (sym
, cu
->list_in_scope
);
22522 /* Not a tag we recognize. Hopefully we aren't processing
22523 trash data, but since we must specifically ignore things
22524 we don't recognize, there is nothing else we should do at
22526 complaint (_("unsupported tag: '%s'"),
22527 dwarf_tag_name (die
->tag
));
22533 sym
->hash_next
= objfile
->template_symbols
;
22534 objfile
->template_symbols
= sym
;
22535 list_to_add
= NULL
;
22538 if (list_to_add
!= NULL
)
22539 add_symbol_to_list (sym
, list_to_add
);
22541 /* For the benefit of old versions of GCC, check for anonymous
22542 namespaces based on the demangled name. */
22543 if (!cu
->processing_has_namespace_info
22544 && cu
->language
== language_cplus
)
22545 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22550 /* Given an attr with a DW_FORM_dataN value in host byte order,
22551 zero-extend it as appropriate for the symbol's type. The DWARF
22552 standard (v4) is not entirely clear about the meaning of using
22553 DW_FORM_dataN for a constant with a signed type, where the type is
22554 wider than the data. The conclusion of a discussion on the DWARF
22555 list was that this is unspecified. We choose to always zero-extend
22556 because that is the interpretation long in use by GCC. */
22559 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22560 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22562 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22563 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22564 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22565 LONGEST l
= attr
->constant_value (0);
22567 if (bits
< sizeof (*value
) * 8)
22569 l
&= ((LONGEST
) 1 << bits
) - 1;
22572 else if (bits
== sizeof (*value
) * 8)
22576 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22577 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22584 /* Read a constant value from an attribute. Either set *VALUE, or if
22585 the value does not fit in *VALUE, set *BYTES - either already
22586 allocated on the objfile obstack, or newly allocated on OBSTACK,
22587 or, set *BATON, if we translated the constant to a location
22591 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22592 const char *name
, struct obstack
*obstack
,
22593 struct dwarf2_cu
*cu
,
22594 LONGEST
*value
, const gdb_byte
**bytes
,
22595 struct dwarf2_locexpr_baton
**baton
)
22597 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22598 struct objfile
*objfile
= per_objfile
->objfile
;
22599 struct comp_unit_head
*cu_header
= &cu
->header
;
22600 struct dwarf_block
*blk
;
22601 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22602 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22608 switch (attr
->form
)
22611 case DW_FORM_addrx
:
22612 case DW_FORM_GNU_addr_index
:
22616 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22617 dwarf2_const_value_length_mismatch_complaint (name
,
22618 cu_header
->addr_size
,
22619 TYPE_LENGTH (type
));
22620 /* Symbols of this form are reasonably rare, so we just
22621 piggyback on the existing location code rather than writing
22622 a new implementation of symbol_computed_ops. */
22623 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22624 (*baton
)->per_objfile
= per_objfile
;
22625 (*baton
)->per_cu
= cu
->per_cu
;
22626 gdb_assert ((*baton
)->per_cu
);
22628 (*baton
)->size
= 2 + cu_header
->addr_size
;
22629 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22630 (*baton
)->data
= data
;
22632 data
[0] = DW_OP_addr
;
22633 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22634 byte_order
, attr
->as_address ());
22635 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22638 case DW_FORM_string
:
22641 case DW_FORM_GNU_str_index
:
22642 case DW_FORM_GNU_strp_alt
:
22643 /* The string is already allocated on the objfile obstack, point
22645 *bytes
= (const gdb_byte
*) attr
->as_string ();
22647 case DW_FORM_block1
:
22648 case DW_FORM_block2
:
22649 case DW_FORM_block4
:
22650 case DW_FORM_block
:
22651 case DW_FORM_exprloc
:
22652 case DW_FORM_data16
:
22653 blk
= attr
->as_block ();
22654 if (TYPE_LENGTH (type
) != blk
->size
)
22655 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22656 TYPE_LENGTH (type
));
22657 *bytes
= blk
->data
;
22660 /* The DW_AT_const_value attributes are supposed to carry the
22661 symbol's value "represented as it would be on the target
22662 architecture." By the time we get here, it's already been
22663 converted to host endianness, so we just need to sign- or
22664 zero-extend it as appropriate. */
22665 case DW_FORM_data1
:
22666 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22668 case DW_FORM_data2
:
22669 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22671 case DW_FORM_data4
:
22672 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22674 case DW_FORM_data8
:
22675 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22678 case DW_FORM_sdata
:
22679 case DW_FORM_implicit_const
:
22680 *value
= attr
->as_signed ();
22683 case DW_FORM_udata
:
22684 *value
= attr
->as_unsigned ();
22688 complaint (_("unsupported const value attribute form: '%s'"),
22689 dwarf_form_name (attr
->form
));
22696 /* Copy constant value from an attribute to a symbol. */
22699 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22700 struct dwarf2_cu
*cu
)
22702 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22704 const gdb_byte
*bytes
;
22705 struct dwarf2_locexpr_baton
*baton
;
22707 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22708 sym
->print_name (),
22709 &objfile
->objfile_obstack
, cu
,
22710 &value
, &bytes
, &baton
);
22714 SYMBOL_LOCATION_BATON (sym
) = baton
;
22715 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22717 else if (bytes
!= NULL
)
22719 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22720 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22724 SYMBOL_VALUE (sym
) = value
;
22725 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22729 /* Return the type of the die in question using its DW_AT_type attribute. */
22731 static struct type
*
22732 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22734 struct attribute
*type_attr
;
22736 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22739 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22740 /* A missing DW_AT_type represents a void type. */
22741 return objfile_type (objfile
)->builtin_void
;
22744 return lookup_die_type (die
, type_attr
, cu
);
22747 /* True iff CU's producer generates GNAT Ada auxiliary information
22748 that allows to find parallel types through that information instead
22749 of having to do expensive parallel lookups by type name. */
22752 need_gnat_info (struct dwarf2_cu
*cu
)
22754 /* Assume that the Ada compiler was GNAT, which always produces
22755 the auxiliary information. */
22756 return (cu
->language
== language_ada
);
22759 /* Return the auxiliary type of the die in question using its
22760 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22761 attribute is not present. */
22763 static struct type
*
22764 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22766 struct attribute
*type_attr
;
22768 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22772 return lookup_die_type (die
, type_attr
, cu
);
22775 /* If DIE has a descriptive_type attribute, then set the TYPE's
22776 descriptive type accordingly. */
22779 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22780 struct dwarf2_cu
*cu
)
22782 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22784 if (descriptive_type
)
22786 ALLOCATE_GNAT_AUX_TYPE (type
);
22787 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22791 /* Return the containing type of the die in question using its
22792 DW_AT_containing_type attribute. */
22794 static struct type
*
22795 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22797 struct attribute
*type_attr
;
22798 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22800 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22802 error (_("Dwarf Error: Problem turning containing type into gdb type "
22803 "[in module %s]"), objfile_name (objfile
));
22805 return lookup_die_type (die
, type_attr
, cu
);
22808 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22810 static struct type
*
22811 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22813 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22814 struct objfile
*objfile
= per_objfile
->objfile
;
22817 std::string message
22818 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22819 objfile_name (objfile
),
22820 sect_offset_str (cu
->header
.sect_off
),
22821 sect_offset_str (die
->sect_off
));
22822 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22824 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22827 /* Look up the type of DIE in CU using its type attribute ATTR.
22828 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22829 DW_AT_containing_type.
22830 If there is no type substitute an error marker. */
22832 static struct type
*
22833 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22834 struct dwarf2_cu
*cu
)
22836 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22837 struct objfile
*objfile
= per_objfile
->objfile
;
22838 struct type
*this_type
;
22840 gdb_assert (attr
->name
== DW_AT_type
22841 || attr
->name
== DW_AT_GNAT_descriptive_type
22842 || attr
->name
== DW_AT_containing_type
);
22844 /* First see if we have it cached. */
22846 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22848 struct dwarf2_per_cu_data
*per_cu
;
22849 sect_offset sect_off
= attr
->get_ref_die_offset ();
22851 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22852 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22854 else if (attr
->form_is_ref ())
22856 sect_offset sect_off
= attr
->get_ref_die_offset ();
22858 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22860 else if (attr
->form
== DW_FORM_ref_sig8
)
22862 ULONGEST signature
= attr
->as_signature ();
22864 return get_signatured_type (die
, signature
, cu
);
22868 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22869 " at %s [in module %s]"),
22870 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22871 objfile_name (objfile
));
22872 return build_error_marker_type (cu
, die
);
22875 /* If not cached we need to read it in. */
22877 if (this_type
== NULL
)
22879 struct die_info
*type_die
= NULL
;
22880 struct dwarf2_cu
*type_cu
= cu
;
22882 if (attr
->form_is_ref ())
22883 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22884 if (type_die
== NULL
)
22885 return build_error_marker_type (cu
, die
);
22886 /* If we find the type now, it's probably because the type came
22887 from an inter-CU reference and the type's CU got expanded before
22889 this_type
= read_type_die (type_die
, type_cu
);
22892 /* If we still don't have a type use an error marker. */
22894 if (this_type
== NULL
)
22895 return build_error_marker_type (cu
, die
);
22900 /* Return the type in DIE, CU.
22901 Returns NULL for invalid types.
22903 This first does a lookup in die_type_hash,
22904 and only reads the die in if necessary.
22906 NOTE: This can be called when reading in partial or full symbols. */
22908 static struct type
*
22909 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22911 struct type
*this_type
;
22913 this_type
= get_die_type (die
, cu
);
22917 return read_type_die_1 (die
, cu
);
22920 /* Read the type in DIE, CU.
22921 Returns NULL for invalid types. */
22923 static struct type
*
22924 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22926 struct type
*this_type
= NULL
;
22930 case DW_TAG_class_type
:
22931 case DW_TAG_interface_type
:
22932 case DW_TAG_structure_type
:
22933 case DW_TAG_union_type
:
22934 this_type
= read_structure_type (die
, cu
);
22936 case DW_TAG_enumeration_type
:
22937 this_type
= read_enumeration_type (die
, cu
);
22939 case DW_TAG_subprogram
:
22940 case DW_TAG_subroutine_type
:
22941 case DW_TAG_inlined_subroutine
:
22942 this_type
= read_subroutine_type (die
, cu
);
22944 case DW_TAG_array_type
:
22945 this_type
= read_array_type (die
, cu
);
22947 case DW_TAG_set_type
:
22948 this_type
= read_set_type (die
, cu
);
22950 case DW_TAG_pointer_type
:
22951 this_type
= read_tag_pointer_type (die
, cu
);
22953 case DW_TAG_ptr_to_member_type
:
22954 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22956 case DW_TAG_reference_type
:
22957 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22959 case DW_TAG_rvalue_reference_type
:
22960 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22962 case DW_TAG_const_type
:
22963 this_type
= read_tag_const_type (die
, cu
);
22965 case DW_TAG_volatile_type
:
22966 this_type
= read_tag_volatile_type (die
, cu
);
22968 case DW_TAG_restrict_type
:
22969 this_type
= read_tag_restrict_type (die
, cu
);
22971 case DW_TAG_string_type
:
22972 this_type
= read_tag_string_type (die
, cu
);
22974 case DW_TAG_typedef
:
22975 this_type
= read_typedef (die
, cu
);
22977 case DW_TAG_subrange_type
:
22978 this_type
= read_subrange_type (die
, cu
);
22980 case DW_TAG_base_type
:
22981 this_type
= read_base_type (die
, cu
);
22983 case DW_TAG_unspecified_type
:
22984 this_type
= read_unspecified_type (die
, cu
);
22986 case DW_TAG_namespace
:
22987 this_type
= read_namespace_type (die
, cu
);
22989 case DW_TAG_module
:
22990 this_type
= read_module_type (die
, cu
);
22992 case DW_TAG_atomic_type
:
22993 this_type
= read_tag_atomic_type (die
, cu
);
22996 complaint (_("unexpected tag in read_type_die: '%s'"),
22997 dwarf_tag_name (die
->tag
));
23004 /* See if we can figure out if the class lives in a namespace. We do
23005 this by looking for a member function; its demangled name will
23006 contain namespace info, if there is any.
23007 Return the computed name or NULL.
23008 Space for the result is allocated on the objfile's obstack.
23009 This is the full-die version of guess_partial_die_structure_name.
23010 In this case we know DIE has no useful parent. */
23012 static const char *
23013 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23015 struct die_info
*spec_die
;
23016 struct dwarf2_cu
*spec_cu
;
23017 struct die_info
*child
;
23018 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23021 spec_die
= die_specification (die
, &spec_cu
);
23022 if (spec_die
!= NULL
)
23028 for (child
= die
->child
;
23030 child
= child
->sibling
)
23032 if (child
->tag
== DW_TAG_subprogram
)
23034 const char *linkage_name
= dw2_linkage_name (child
, cu
);
23036 if (linkage_name
!= NULL
)
23038 gdb::unique_xmalloc_ptr
<char> actual_name
23039 (cu
->language_defn
->class_name_from_physname (linkage_name
));
23040 const char *name
= NULL
;
23042 if (actual_name
!= NULL
)
23044 const char *die_name
= dwarf2_name (die
, cu
);
23046 if (die_name
!= NULL
23047 && strcmp (die_name
, actual_name
.get ()) != 0)
23049 /* Strip off the class name from the full name.
23050 We want the prefix. */
23051 int die_name_len
= strlen (die_name
);
23052 int actual_name_len
= strlen (actual_name
.get ());
23053 const char *ptr
= actual_name
.get ();
23055 /* Test for '::' as a sanity check. */
23056 if (actual_name_len
> die_name_len
+ 2
23057 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
23058 name
= obstack_strndup (
23059 &objfile
->per_bfd
->storage_obstack
,
23060 ptr
, actual_name_len
- die_name_len
- 2);
23071 /* GCC might emit a nameless typedef that has a linkage name. Determine the
23072 prefix part in such case. See
23073 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23075 static const char *
23076 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
23078 struct attribute
*attr
;
23081 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
23082 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
23085 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
23088 attr
= dw2_linkage_name_attr (die
, cu
);
23089 const char *attr_name
= attr
->as_string ();
23090 if (attr
== NULL
|| attr_name
== NULL
)
23093 /* dwarf2_name had to be already called. */
23094 gdb_assert (attr
->canonical_string_p ());
23096 /* Strip the base name, keep any leading namespaces/classes. */
23097 base
= strrchr (attr_name
, ':');
23098 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
23101 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23102 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
23104 &base
[-1] - attr_name
);
23107 /* Return the name of the namespace/class that DIE is defined within,
23108 or "" if we can't tell. The caller should not xfree the result.
23110 For example, if we're within the method foo() in the following
23120 then determine_prefix on foo's die will return "N::C". */
23122 static const char *
23123 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
23125 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23126 struct die_info
*parent
, *spec_die
;
23127 struct dwarf2_cu
*spec_cu
;
23128 struct type
*parent_type
;
23129 const char *retval
;
23131 if (cu
->language
!= language_cplus
23132 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
23133 && cu
->language
!= language_rust
)
23136 retval
= anonymous_struct_prefix (die
, cu
);
23140 /* We have to be careful in the presence of DW_AT_specification.
23141 For example, with GCC 3.4, given the code
23145 // Definition of N::foo.
23149 then we'll have a tree of DIEs like this:
23151 1: DW_TAG_compile_unit
23152 2: DW_TAG_namespace // N
23153 3: DW_TAG_subprogram // declaration of N::foo
23154 4: DW_TAG_subprogram // definition of N::foo
23155 DW_AT_specification // refers to die #3
23157 Thus, when processing die #4, we have to pretend that we're in
23158 the context of its DW_AT_specification, namely the contex of die
23161 spec_die
= die_specification (die
, &spec_cu
);
23162 if (spec_die
== NULL
)
23163 parent
= die
->parent
;
23166 parent
= spec_die
->parent
;
23170 if (parent
== NULL
)
23172 else if (parent
->building_fullname
)
23175 const char *parent_name
;
23177 /* It has been seen on RealView 2.2 built binaries,
23178 DW_TAG_template_type_param types actually _defined_ as
23179 children of the parent class:
23182 template class <class Enum> Class{};
23183 Class<enum E> class_e;
23185 1: DW_TAG_class_type (Class)
23186 2: DW_TAG_enumeration_type (E)
23187 3: DW_TAG_enumerator (enum1:0)
23188 3: DW_TAG_enumerator (enum2:1)
23190 2: DW_TAG_template_type_param
23191 DW_AT_type DW_FORM_ref_udata (E)
23193 Besides being broken debug info, it can put GDB into an
23194 infinite loop. Consider:
23196 When we're building the full name for Class<E>, we'll start
23197 at Class, and go look over its template type parameters,
23198 finding E. We'll then try to build the full name of E, and
23199 reach here. We're now trying to build the full name of E,
23200 and look over the parent DIE for containing scope. In the
23201 broken case, if we followed the parent DIE of E, we'd again
23202 find Class, and once again go look at its template type
23203 arguments, etc., etc. Simply don't consider such parent die
23204 as source-level parent of this die (it can't be, the language
23205 doesn't allow it), and break the loop here. */
23206 name
= dwarf2_name (die
, cu
);
23207 parent_name
= dwarf2_name (parent
, cu
);
23208 complaint (_("template param type '%s' defined within parent '%s'"),
23209 name
? name
: "<unknown>",
23210 parent_name
? parent_name
: "<unknown>");
23214 switch (parent
->tag
)
23216 case DW_TAG_namespace
:
23217 parent_type
= read_type_die (parent
, cu
);
23218 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
23219 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
23220 Work around this problem here. */
23221 if (cu
->language
== language_cplus
23222 && strcmp (parent_type
->name (), "::") == 0)
23224 /* We give a name to even anonymous namespaces. */
23225 return parent_type
->name ();
23226 case DW_TAG_class_type
:
23227 case DW_TAG_interface_type
:
23228 case DW_TAG_structure_type
:
23229 case DW_TAG_union_type
:
23230 case DW_TAG_module
:
23231 parent_type
= read_type_die (parent
, cu
);
23232 if (parent_type
->name () != NULL
)
23233 return parent_type
->name ();
23235 /* An anonymous structure is only allowed non-static data
23236 members; no typedefs, no member functions, et cetera.
23237 So it does not need a prefix. */
23239 case DW_TAG_compile_unit
:
23240 case DW_TAG_partial_unit
:
23241 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
23242 if (cu
->language
== language_cplus
23243 && !per_objfile
->per_bfd
->types
.empty ()
23244 && die
->child
!= NULL
23245 && (die
->tag
== DW_TAG_class_type
23246 || die
->tag
== DW_TAG_structure_type
23247 || die
->tag
== DW_TAG_union_type
))
23249 const char *name
= guess_full_die_structure_name (die
, cu
);
23254 case DW_TAG_subprogram
:
23255 /* Nested subroutines in Fortran get a prefix with the name
23256 of the parent's subroutine. */
23257 if (cu
->language
== language_fortran
)
23259 if ((die
->tag
== DW_TAG_subprogram
)
23260 && (dwarf2_name (parent
, cu
) != NULL
))
23261 return dwarf2_name (parent
, cu
);
23263 return determine_prefix (parent
, cu
);
23264 case DW_TAG_enumeration_type
:
23265 parent_type
= read_type_die (parent
, cu
);
23266 if (TYPE_DECLARED_CLASS (parent_type
))
23268 if (parent_type
->name () != NULL
)
23269 return parent_type
->name ();
23272 /* Fall through. */
23274 return determine_prefix (parent
, cu
);
23278 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
23279 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
23280 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
23281 an obconcat, otherwise allocate storage for the result. The CU argument is
23282 used to determine the language and hence, the appropriate separator. */
23284 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
23287 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
23288 int physname
, struct dwarf2_cu
*cu
)
23290 const char *lead
= "";
23293 if (suffix
== NULL
|| suffix
[0] == '\0'
23294 || prefix
== NULL
|| prefix
[0] == '\0')
23296 else if (cu
->language
== language_d
)
23298 /* For D, the 'main' function could be defined in any module, but it
23299 should never be prefixed. */
23300 if (strcmp (suffix
, "D main") == 0)
23308 else if (cu
->language
== language_fortran
&& physname
)
23310 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
23311 DW_AT_MIPS_linkage_name is preferred and used instead. */
23319 if (prefix
== NULL
)
23321 if (suffix
== NULL
)
23328 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
23330 strcpy (retval
, lead
);
23331 strcat (retval
, prefix
);
23332 strcat (retval
, sep
);
23333 strcat (retval
, suffix
);
23338 /* We have an obstack. */
23339 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
23343 /* Get name of a die, return NULL if not found. */
23345 static const char *
23346 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
23347 struct objfile
*objfile
)
23349 if (name
&& cu
->language
== language_cplus
)
23351 gdb::unique_xmalloc_ptr
<char> canon_name
23352 = cp_canonicalize_string (name
);
23354 if (canon_name
!= nullptr)
23355 name
= objfile
->intern (canon_name
.get ());
23361 /* Get name of a die, return NULL if not found.
23362 Anonymous namespaces are converted to their magic string. */
23364 static const char *
23365 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23367 struct attribute
*attr
;
23368 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23370 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23371 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23372 if (attr_name
== nullptr
23373 && die
->tag
!= DW_TAG_namespace
23374 && die
->tag
!= DW_TAG_class_type
23375 && die
->tag
!= DW_TAG_interface_type
23376 && die
->tag
!= DW_TAG_structure_type
23377 && die
->tag
!= DW_TAG_union_type
)
23382 case DW_TAG_compile_unit
:
23383 case DW_TAG_partial_unit
:
23384 /* Compilation units have a DW_AT_name that is a filename, not
23385 a source language identifier. */
23386 case DW_TAG_enumeration_type
:
23387 case DW_TAG_enumerator
:
23388 /* These tags always have simple identifiers already; no need
23389 to canonicalize them. */
23392 case DW_TAG_namespace
:
23393 if (attr_name
!= nullptr)
23395 return CP_ANONYMOUS_NAMESPACE_STR
;
23397 case DW_TAG_class_type
:
23398 case DW_TAG_interface_type
:
23399 case DW_TAG_structure_type
:
23400 case DW_TAG_union_type
:
23401 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23402 structures or unions. These were of the form "._%d" in GCC 4.1,
23403 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23404 and GCC 4.4. We work around this problem by ignoring these. */
23405 if (attr_name
!= nullptr
23406 && (startswith (attr_name
, "._")
23407 || startswith (attr_name
, "<anonymous")))
23410 /* GCC might emit a nameless typedef that has a linkage name. See
23411 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23412 if (!attr
|| attr_name
== NULL
)
23414 attr
= dw2_linkage_name_attr (die
, cu
);
23415 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23416 if (attr
== NULL
|| attr_name
== NULL
)
23419 /* Avoid demangling attr_name the second time on a second
23420 call for the same DIE. */
23421 if (!attr
->canonical_string_p ())
23423 gdb::unique_xmalloc_ptr
<char> demangled
23424 (gdb_demangle (attr_name
, DMGL_TYPES
));
23425 if (demangled
== nullptr)
23428 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
23429 attr_name
= attr
->as_string ();
23432 /* Strip any leading namespaces/classes, keep only the
23433 base name. DW_AT_name for named DIEs does not
23434 contain the prefixes. */
23435 const char *base
= strrchr (attr_name
, ':');
23436 if (base
&& base
> attr_name
&& base
[-1] == ':')
23447 if (!attr
->canonical_string_p ())
23448 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
23450 return attr
->as_string ();
23453 /* Return the die that this die in an extension of, or NULL if there
23454 is none. *EXT_CU is the CU containing DIE on input, and the CU
23455 containing the return value on output. */
23457 static struct die_info
*
23458 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23460 struct attribute
*attr
;
23462 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23466 return follow_die_ref (die
, attr
, ext_cu
);
23470 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23474 print_spaces (indent
, f
);
23475 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23476 dwarf_tag_name (die
->tag
), die
->abbrev
,
23477 sect_offset_str (die
->sect_off
));
23479 if (die
->parent
!= NULL
)
23481 print_spaces (indent
, f
);
23482 fprintf_unfiltered (f
, " parent at offset: %s\n",
23483 sect_offset_str (die
->parent
->sect_off
));
23486 print_spaces (indent
, f
);
23487 fprintf_unfiltered (f
, " has children: %s\n",
23488 dwarf_bool_name (die
->child
!= NULL
));
23490 print_spaces (indent
, f
);
23491 fprintf_unfiltered (f
, " attributes:\n");
23493 for (i
= 0; i
< die
->num_attrs
; ++i
)
23495 print_spaces (indent
, f
);
23496 fprintf_unfiltered (f
, " %s (%s) ",
23497 dwarf_attr_name (die
->attrs
[i
].name
),
23498 dwarf_form_name (die
->attrs
[i
].form
));
23500 switch (die
->attrs
[i
].form
)
23503 case DW_FORM_addrx
:
23504 case DW_FORM_GNU_addr_index
:
23505 fprintf_unfiltered (f
, "address: ");
23506 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
23508 case DW_FORM_block2
:
23509 case DW_FORM_block4
:
23510 case DW_FORM_block
:
23511 case DW_FORM_block1
:
23512 fprintf_unfiltered (f
, "block: size %s",
23513 pulongest (die
->attrs
[i
].as_block ()->size
));
23515 case DW_FORM_exprloc
:
23516 fprintf_unfiltered (f
, "expression: size %s",
23517 pulongest (die
->attrs
[i
].as_block ()->size
));
23519 case DW_FORM_data16
:
23520 fprintf_unfiltered (f
, "constant of 16 bytes");
23522 case DW_FORM_ref_addr
:
23523 fprintf_unfiltered (f
, "ref address: ");
23524 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23526 case DW_FORM_GNU_ref_alt
:
23527 fprintf_unfiltered (f
, "alt ref address: ");
23528 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23534 case DW_FORM_ref_udata
:
23535 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23536 (long) (die
->attrs
[i
].as_unsigned ()));
23538 case DW_FORM_data1
:
23539 case DW_FORM_data2
:
23540 case DW_FORM_data4
:
23541 case DW_FORM_data8
:
23542 case DW_FORM_udata
:
23543 fprintf_unfiltered (f
, "constant: %s",
23544 pulongest (die
->attrs
[i
].as_unsigned ()));
23546 case DW_FORM_sec_offset
:
23547 fprintf_unfiltered (f
, "section offset: %s",
23548 pulongest (die
->attrs
[i
].as_unsigned ()));
23550 case DW_FORM_ref_sig8
:
23551 fprintf_unfiltered (f
, "signature: %s",
23552 hex_string (die
->attrs
[i
].as_signature ()));
23554 case DW_FORM_string
:
23556 case DW_FORM_line_strp
:
23558 case DW_FORM_GNU_str_index
:
23559 case DW_FORM_GNU_strp_alt
:
23560 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23561 die
->attrs
[i
].as_string ()
23562 ? die
->attrs
[i
].as_string () : "",
23563 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23566 if (die
->attrs
[i
].as_boolean ())
23567 fprintf_unfiltered (f
, "flag: TRUE");
23569 fprintf_unfiltered (f
, "flag: FALSE");
23571 case DW_FORM_flag_present
:
23572 fprintf_unfiltered (f
, "flag: TRUE");
23574 case DW_FORM_indirect
:
23575 /* The reader will have reduced the indirect form to
23576 the "base form" so this form should not occur. */
23577 fprintf_unfiltered (f
,
23578 "unexpected attribute form: DW_FORM_indirect");
23580 case DW_FORM_sdata
:
23581 case DW_FORM_implicit_const
:
23582 fprintf_unfiltered (f
, "constant: %s",
23583 plongest (die
->attrs
[i
].as_signed ()));
23586 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23587 die
->attrs
[i
].form
);
23590 fprintf_unfiltered (f
, "\n");
23595 dump_die_for_error (struct die_info
*die
)
23597 dump_die_shallow (gdb_stderr
, 0, die
);
23601 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23603 int indent
= level
* 4;
23605 gdb_assert (die
!= NULL
);
23607 if (level
>= max_level
)
23610 dump_die_shallow (f
, indent
, die
);
23612 if (die
->child
!= NULL
)
23614 print_spaces (indent
, f
);
23615 fprintf_unfiltered (f
, " Children:");
23616 if (level
+ 1 < max_level
)
23618 fprintf_unfiltered (f
, "\n");
23619 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23623 fprintf_unfiltered (f
,
23624 " [not printed, max nesting level reached]\n");
23628 if (die
->sibling
!= NULL
&& level
> 0)
23630 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23634 /* This is called from the pdie macro in gdbinit.in.
23635 It's not static so gcc will keep a copy callable from gdb. */
23638 dump_die (struct die_info
*die
, int max_level
)
23640 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23644 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23648 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23649 to_underlying (die
->sect_off
),
23655 /* Follow reference or signature attribute ATTR of SRC_DIE.
23656 On entry *REF_CU is the CU of SRC_DIE.
23657 On exit *REF_CU is the CU of the result. */
23659 static struct die_info
*
23660 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23661 struct dwarf2_cu
**ref_cu
)
23663 struct die_info
*die
;
23665 if (attr
->form_is_ref ())
23666 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23667 else if (attr
->form
== DW_FORM_ref_sig8
)
23668 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23671 dump_die_for_error (src_die
);
23672 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23673 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23679 /* Follow reference OFFSET.
23680 On entry *REF_CU is the CU of the source die referencing OFFSET.
23681 On exit *REF_CU is the CU of the result.
23682 Returns NULL if OFFSET is invalid. */
23684 static struct die_info
*
23685 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23686 struct dwarf2_cu
**ref_cu
)
23688 struct die_info temp_die
;
23689 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23690 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23692 gdb_assert (cu
->per_cu
!= NULL
);
23696 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23697 "source CU contains target offset: %d",
23698 sect_offset_str (cu
->per_cu
->sect_off
),
23699 sect_offset_str (sect_off
),
23700 cu
->header
.offset_in_cu_p (sect_off
));
23702 if (cu
->per_cu
->is_debug_types
)
23704 /* .debug_types CUs cannot reference anything outside their CU.
23705 If they need to, they have to reference a signatured type via
23706 DW_FORM_ref_sig8. */
23707 if (!cu
->header
.offset_in_cu_p (sect_off
))
23710 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23711 || !cu
->header
.offset_in_cu_p (sect_off
))
23713 struct dwarf2_per_cu_data
*per_cu
;
23715 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23718 dwarf_read_debug_printf_v ("target CU offset: %s, "
23719 "target CU DIEs loaded: %d",
23720 sect_offset_str (per_cu
->sect_off
),
23721 per_objfile
->get_cu (per_cu
) != nullptr);
23723 /* If necessary, add it to the queue and load its DIEs.
23725 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23726 it doesn't mean they are currently loaded. Since we require them
23727 to be loaded, we must check for ourselves. */
23728 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
)
23729 || per_objfile
->get_cu (per_cu
) == nullptr)
23730 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23731 false, cu
->language
);
23733 target_cu
= per_objfile
->get_cu (per_cu
);
23734 gdb_assert (target_cu
!= nullptr);
23736 else if (cu
->dies
== NULL
)
23738 /* We're loading full DIEs during partial symbol reading. */
23739 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23740 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23744 *ref_cu
= target_cu
;
23745 temp_die
.sect_off
= sect_off
;
23747 if (target_cu
!= cu
)
23748 target_cu
->ancestor
= cu
;
23750 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23752 to_underlying (sect_off
));
23755 /* Follow reference attribute ATTR of SRC_DIE.
23756 On entry *REF_CU is the CU of SRC_DIE.
23757 On exit *REF_CU is the CU of the result. */
23759 static struct die_info
*
23760 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23761 struct dwarf2_cu
**ref_cu
)
23763 sect_offset sect_off
= attr
->get_ref_die_offset ();
23764 struct dwarf2_cu
*cu
= *ref_cu
;
23765 struct die_info
*die
;
23767 die
= follow_die_offset (sect_off
,
23768 (attr
->form
== DW_FORM_GNU_ref_alt
23769 || cu
->per_cu
->is_dwz
),
23772 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23773 "at %s [in module %s]"),
23774 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23775 objfile_name (cu
->per_objfile
->objfile
));
23782 struct dwarf2_locexpr_baton
23783 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23784 dwarf2_per_cu_data
*per_cu
,
23785 dwarf2_per_objfile
*per_objfile
,
23786 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23787 bool resolve_abstract_p
)
23789 struct die_info
*die
;
23790 struct attribute
*attr
;
23791 struct dwarf2_locexpr_baton retval
;
23792 struct objfile
*objfile
= per_objfile
->objfile
;
23794 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23796 cu
= load_cu (per_cu
, per_objfile
, false);
23800 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23801 Instead just throw an error, not much else we can do. */
23802 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23803 sect_offset_str (sect_off
), objfile_name (objfile
));
23806 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23808 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23809 sect_offset_str (sect_off
), objfile_name (objfile
));
23811 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23812 if (!attr
&& resolve_abstract_p
23813 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23814 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23816 CORE_ADDR pc
= get_frame_pc ();
23817 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23818 struct gdbarch
*gdbarch
= objfile
->arch ();
23820 for (const auto &cand_off
23821 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23823 struct dwarf2_cu
*cand_cu
= cu
;
23824 struct die_info
*cand
23825 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23828 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23831 CORE_ADDR pc_low
, pc_high
;
23832 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23833 if (pc_low
== ((CORE_ADDR
) -1))
23835 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23836 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23837 if (!(pc_low
<= pc
&& pc
< pc_high
))
23841 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23848 /* DWARF: "If there is no such attribute, then there is no effect.".
23849 DATA is ignored if SIZE is 0. */
23851 retval
.data
= NULL
;
23854 else if (attr
->form_is_section_offset ())
23856 struct dwarf2_loclist_baton loclist_baton
;
23857 CORE_ADDR pc
= get_frame_pc ();
23860 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23862 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23864 retval
.size
= size
;
23868 if (!attr
->form_is_block ())
23869 error (_("Dwarf Error: DIE at %s referenced in module %s "
23870 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23871 sect_offset_str (sect_off
), objfile_name (objfile
));
23873 struct dwarf_block
*block
= attr
->as_block ();
23874 retval
.data
= block
->data
;
23875 retval
.size
= block
->size
;
23877 retval
.per_objfile
= per_objfile
;
23878 retval
.per_cu
= cu
->per_cu
;
23880 per_objfile
->age_comp_units ();
23887 struct dwarf2_locexpr_baton
23888 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23889 dwarf2_per_cu_data
*per_cu
,
23890 dwarf2_per_objfile
*per_objfile
,
23891 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
23893 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23895 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
23899 /* Write a constant of a given type as target-ordered bytes into
23902 static const gdb_byte
*
23903 write_constant_as_bytes (struct obstack
*obstack
,
23904 enum bfd_endian byte_order
,
23911 *len
= TYPE_LENGTH (type
);
23912 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23913 store_unsigned_integer (result
, *len
, byte_order
, value
);
23921 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23922 dwarf2_per_cu_data
*per_cu
,
23923 dwarf2_per_objfile
*per_objfile
,
23927 struct die_info
*die
;
23928 struct attribute
*attr
;
23929 const gdb_byte
*result
= NULL
;
23932 enum bfd_endian byte_order
;
23933 struct objfile
*objfile
= per_objfile
->objfile
;
23935 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23937 cu
= load_cu (per_cu
, per_objfile
, false);
23941 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23942 Instead just throw an error, not much else we can do. */
23943 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23944 sect_offset_str (sect_off
), objfile_name (objfile
));
23947 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23949 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23950 sect_offset_str (sect_off
), objfile_name (objfile
));
23952 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23956 byte_order
= (bfd_big_endian (objfile
->obfd
)
23957 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23959 switch (attr
->form
)
23962 case DW_FORM_addrx
:
23963 case DW_FORM_GNU_addr_index
:
23967 *len
= cu
->header
.addr_size
;
23968 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23969 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
23973 case DW_FORM_string
:
23976 case DW_FORM_GNU_str_index
:
23977 case DW_FORM_GNU_strp_alt
:
23978 /* The string is already allocated on the objfile obstack, point
23981 const char *attr_name
= attr
->as_string ();
23982 result
= (const gdb_byte
*) attr_name
;
23983 *len
= strlen (attr_name
);
23986 case DW_FORM_block1
:
23987 case DW_FORM_block2
:
23988 case DW_FORM_block4
:
23989 case DW_FORM_block
:
23990 case DW_FORM_exprloc
:
23991 case DW_FORM_data16
:
23993 struct dwarf_block
*block
= attr
->as_block ();
23994 result
= block
->data
;
23995 *len
= block
->size
;
23999 /* The DW_AT_const_value attributes are supposed to carry the
24000 symbol's value "represented as it would be on the target
24001 architecture." By the time we get here, it's already been
24002 converted to host endianness, so we just need to sign- or
24003 zero-extend it as appropriate. */
24004 case DW_FORM_data1
:
24005 type
= die_type (die
, cu
);
24006 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
24007 if (result
== NULL
)
24008 result
= write_constant_as_bytes (obstack
, byte_order
,
24011 case DW_FORM_data2
:
24012 type
= die_type (die
, cu
);
24013 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
24014 if (result
== NULL
)
24015 result
= write_constant_as_bytes (obstack
, byte_order
,
24018 case DW_FORM_data4
:
24019 type
= die_type (die
, cu
);
24020 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
24021 if (result
== NULL
)
24022 result
= write_constant_as_bytes (obstack
, byte_order
,
24025 case DW_FORM_data8
:
24026 type
= die_type (die
, cu
);
24027 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
24028 if (result
== NULL
)
24029 result
= write_constant_as_bytes (obstack
, byte_order
,
24033 case DW_FORM_sdata
:
24034 case DW_FORM_implicit_const
:
24035 type
= die_type (die
, cu
);
24036 result
= write_constant_as_bytes (obstack
, byte_order
,
24037 type
, attr
->as_signed (), len
);
24040 case DW_FORM_udata
:
24041 type
= die_type (die
, cu
);
24042 result
= write_constant_as_bytes (obstack
, byte_order
,
24043 type
, attr
->as_unsigned (), len
);
24047 complaint (_("unsupported const value attribute form: '%s'"),
24048 dwarf_form_name (attr
->form
));
24058 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
24059 dwarf2_per_cu_data
*per_cu
,
24060 dwarf2_per_objfile
*per_objfile
)
24062 struct die_info
*die
;
24064 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
24066 cu
= load_cu (per_cu
, per_objfile
, false);
24071 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
24075 return die_type (die
, cu
);
24081 dwarf2_get_die_type (cu_offset die_offset
,
24082 dwarf2_per_cu_data
*per_cu
,
24083 dwarf2_per_objfile
*per_objfile
)
24085 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
24086 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
24089 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
24090 On entry *REF_CU is the CU of SRC_DIE.
24091 On exit *REF_CU is the CU of the result.
24092 Returns NULL if the referenced DIE isn't found. */
24094 static struct die_info
*
24095 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
24096 struct dwarf2_cu
**ref_cu
)
24098 struct die_info temp_die
;
24099 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
24100 struct die_info
*die
;
24101 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
24104 /* While it might be nice to assert sig_type->type == NULL here,
24105 we can get here for DW_AT_imported_declaration where we need
24106 the DIE not the type. */
24108 /* If necessary, add it to the queue and load its DIEs.
24110 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
24111 it doesn't mean they are currently loaded. Since we require them
24112 to be loaded, we must check for ourselves. */
24113 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
24115 || per_objfile
->get_cu (&sig_type
->per_cu
) == nullptr)
24116 read_signatured_type (sig_type
, per_objfile
);
24118 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
24119 gdb_assert (sig_cu
!= NULL
);
24120 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
24121 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
24122 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
24123 to_underlying (temp_die
.sect_off
));
24126 /* For .gdb_index version 7 keep track of included TUs.
24127 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
24128 if (per_objfile
->per_bfd
->index_table
!= NULL
24129 && per_objfile
->per_bfd
->index_table
->version
<= 7)
24131 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
24136 sig_cu
->ancestor
= cu
;
24144 /* Follow signatured type referenced by ATTR in SRC_DIE.
24145 On entry *REF_CU is the CU of SRC_DIE.
24146 On exit *REF_CU is the CU of the result.
24147 The result is the DIE of the type.
24148 If the referenced type cannot be found an error is thrown. */
24150 static struct die_info
*
24151 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
24152 struct dwarf2_cu
**ref_cu
)
24154 ULONGEST signature
= attr
->as_signature ();
24155 struct signatured_type
*sig_type
;
24156 struct die_info
*die
;
24158 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
24160 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
24161 /* sig_type will be NULL if the signatured type is missing from
24163 if (sig_type
== NULL
)
24165 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24166 " from DIE at %s [in module %s]"),
24167 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
24168 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
24171 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
24174 dump_die_for_error (src_die
);
24175 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24176 " from DIE at %s [in module %s]"),
24177 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
24178 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
24184 /* Get the type specified by SIGNATURE referenced in DIE/CU,
24185 reading in and processing the type unit if necessary. */
24187 static struct type
*
24188 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
24189 struct dwarf2_cu
*cu
)
24191 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24192 struct signatured_type
*sig_type
;
24193 struct dwarf2_cu
*type_cu
;
24194 struct die_info
*type_die
;
24197 sig_type
= lookup_signatured_type (cu
, signature
);
24198 /* sig_type will be NULL if the signatured type is missing from
24200 if (sig_type
== NULL
)
24202 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24203 " from DIE at %s [in module %s]"),
24204 hex_string (signature
), sect_offset_str (die
->sect_off
),
24205 objfile_name (per_objfile
->objfile
));
24206 return build_error_marker_type (cu
, die
);
24209 /* If we already know the type we're done. */
24210 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
24211 if (type
!= nullptr)
24215 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
24216 if (type_die
!= NULL
)
24218 /* N.B. We need to call get_die_type to ensure only one type for this DIE
24219 is created. This is important, for example, because for c++ classes
24220 we need TYPE_NAME set which is only done by new_symbol. Blech. */
24221 type
= read_type_die (type_die
, type_cu
);
24224 complaint (_("Dwarf Error: Cannot build signatured type %s"
24225 " referenced from DIE at %s [in module %s]"),
24226 hex_string (signature
), sect_offset_str (die
->sect_off
),
24227 objfile_name (per_objfile
->objfile
));
24228 type
= build_error_marker_type (cu
, die
);
24233 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24234 " from DIE at %s [in module %s]"),
24235 hex_string (signature
), sect_offset_str (die
->sect_off
),
24236 objfile_name (per_objfile
->objfile
));
24237 type
= build_error_marker_type (cu
, die
);
24240 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
24245 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
24246 reading in and processing the type unit if necessary. */
24248 static struct type
*
24249 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
24250 struct dwarf2_cu
*cu
) /* ARI: editCase function */
24252 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
24253 if (attr
->form_is_ref ())
24255 struct dwarf2_cu
*type_cu
= cu
;
24256 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24258 return read_type_die (type_die
, type_cu
);
24260 else if (attr
->form
== DW_FORM_ref_sig8
)
24262 return get_signatured_type (die
, attr
->as_signature (), cu
);
24266 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24268 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24269 " at %s [in module %s]"),
24270 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24271 objfile_name (per_objfile
->objfile
));
24272 return build_error_marker_type (cu
, die
);
24276 /* Load the DIEs associated with type unit PER_CU into memory. */
24279 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
24280 dwarf2_per_objfile
*per_objfile
)
24282 struct signatured_type
*sig_type
;
24284 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24285 gdb_assert (! per_cu
->type_unit_group_p ());
24287 /* We have the per_cu, but we need the signatured_type.
24288 Fortunately this is an easy translation. */
24289 gdb_assert (per_cu
->is_debug_types
);
24290 sig_type
= (struct signatured_type
*) per_cu
;
24292 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
24294 read_signatured_type (sig_type
, per_objfile
);
24296 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
24299 /* Read in a signatured type and build its CU and DIEs.
24300 If the type is a stub for the real type in a DWO file,
24301 read in the real type from the DWO file as well. */
24304 read_signatured_type (signatured_type
*sig_type
,
24305 dwarf2_per_objfile
*per_objfile
)
24307 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24309 gdb_assert (per_cu
->is_debug_types
);
24310 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
24312 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
24314 if (!reader
.dummy_p
)
24316 struct dwarf2_cu
*cu
= reader
.cu
;
24317 const gdb_byte
*info_ptr
= reader
.info_ptr
;
24319 gdb_assert (cu
->die_hash
== NULL
);
24321 htab_create_alloc_ex (cu
->header
.length
/ 12,
24325 &cu
->comp_unit_obstack
,
24326 hashtab_obstack_allocate
,
24327 dummy_obstack_deallocate
);
24329 if (reader
.comp_unit_die
->has_children
)
24330 reader
.comp_unit_die
->child
24331 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
24332 reader
.comp_unit_die
);
24333 cu
->dies
= reader
.comp_unit_die
;
24334 /* comp_unit_die is not stored in die_hash, no need. */
24336 /* We try not to read any attributes in this function, because
24337 not all CUs needed for references have been loaded yet, and
24338 symbol table processing isn't initialized. But we have to
24339 set the CU language, or we won't be able to build types
24340 correctly. Similarly, if we do not read the producer, we can
24341 not apply producer-specific interpretation. */
24342 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24347 sig_type
->per_cu
.tu_read
= 1;
24350 /* Decode simple location descriptions.
24351 Given a pointer to a dwarf block that defines a location, compute
24352 the location and return the value. If COMPUTED is non-null, it is
24353 set to true to indicate that decoding was successful, and false
24354 otherwise. If COMPUTED is null, then this function may emit a
24358 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
24360 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
24362 size_t size
= blk
->size
;
24363 const gdb_byte
*data
= blk
->data
;
24364 CORE_ADDR stack
[64];
24366 unsigned int bytes_read
, unsnd
;
24369 if (computed
!= nullptr)
24375 stack
[++stacki
] = 0;
24414 stack
[++stacki
] = op
- DW_OP_lit0
;
24449 stack
[++stacki
] = op
- DW_OP_reg0
;
24452 if (computed
== nullptr)
24453 dwarf2_complex_location_expr_complaint ();
24460 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24462 stack
[++stacki
] = unsnd
;
24465 if (computed
== nullptr)
24466 dwarf2_complex_location_expr_complaint ();
24473 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
24478 case DW_OP_const1u
:
24479 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24483 case DW_OP_const1s
:
24484 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24488 case DW_OP_const2u
:
24489 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24493 case DW_OP_const2s
:
24494 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24498 case DW_OP_const4u
:
24499 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24503 case DW_OP_const4s
:
24504 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24508 case DW_OP_const8u
:
24509 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24514 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24520 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24525 stack
[stacki
+ 1] = stack
[stacki
];
24530 stack
[stacki
- 1] += stack
[stacki
];
24534 case DW_OP_plus_uconst
:
24535 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24541 stack
[stacki
- 1] -= stack
[stacki
];
24546 /* If we're not the last op, then we definitely can't encode
24547 this using GDB's address_class enum. This is valid for partial
24548 global symbols, although the variable's address will be bogus
24552 if (computed
== nullptr)
24553 dwarf2_complex_location_expr_complaint ();
24559 case DW_OP_GNU_push_tls_address
:
24560 case DW_OP_form_tls_address
:
24561 /* The top of the stack has the offset from the beginning
24562 of the thread control block at which the variable is located. */
24563 /* Nothing should follow this operator, so the top of stack would
24565 /* This is valid for partial global symbols, but the variable's
24566 address will be bogus in the psymtab. Make it always at least
24567 non-zero to not look as a variable garbage collected by linker
24568 which have DW_OP_addr 0. */
24571 if (computed
== nullptr)
24572 dwarf2_complex_location_expr_complaint ();
24579 case DW_OP_GNU_uninit
:
24580 if (computed
!= nullptr)
24585 case DW_OP_GNU_addr_index
:
24586 case DW_OP_GNU_const_index
:
24587 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24593 if (computed
== nullptr)
24595 const char *name
= get_DW_OP_name (op
);
24598 complaint (_("unsupported stack op: '%s'"),
24601 complaint (_("unsupported stack op: '%02x'"),
24605 return (stack
[stacki
]);
24608 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24609 outside of the allocated space. Also enforce minimum>0. */
24610 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24612 if (computed
== nullptr)
24613 complaint (_("location description stack overflow"));
24619 if (computed
== nullptr)
24620 complaint (_("location description stack underflow"));
24625 if (computed
!= nullptr)
24627 return (stack
[stacki
]);
24630 /* memory allocation interface */
24632 static struct dwarf_block
*
24633 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24635 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24638 static struct die_info
*
24639 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24641 struct die_info
*die
;
24642 size_t size
= sizeof (struct die_info
);
24645 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24647 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24648 memset (die
, 0, sizeof (struct die_info
));
24654 /* Macro support. */
24656 /* An overload of dwarf_decode_macros that finds the correct section
24657 and ensures it is read in before calling the other overload. */
24660 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24661 int section_is_gnu
)
24663 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24664 struct objfile
*objfile
= per_objfile
->objfile
;
24665 const struct line_header
*lh
= cu
->line_header
;
24666 unsigned int offset_size
= cu
->header
.offset_size
;
24667 struct dwarf2_section_info
*section
;
24668 const char *section_name
;
24670 if (cu
->dwo_unit
!= nullptr)
24672 if (section_is_gnu
)
24674 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24675 section_name
= ".debug_macro.dwo";
24679 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24680 section_name
= ".debug_macinfo.dwo";
24685 if (section_is_gnu
)
24687 section
= &per_objfile
->per_bfd
->macro
;
24688 section_name
= ".debug_macro";
24692 section
= &per_objfile
->per_bfd
->macinfo
;
24693 section_name
= ".debug_macinfo";
24697 section
->read (objfile
);
24698 if (section
->buffer
== nullptr)
24700 complaint (_("missing %s section"), section_name
);
24704 buildsym_compunit
*builder
= cu
->get_builder ();
24706 struct dwarf2_section_info
*str_offsets_section
;
24707 struct dwarf2_section_info
*str_section
;
24708 ULONGEST str_offsets_base
;
24710 if (cu
->dwo_unit
!= nullptr)
24712 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24713 ->sections
.str_offsets
;
24714 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24715 str_offsets_base
= cu
->header
.addr_size
;
24719 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24720 str_section
= &per_objfile
->per_bfd
->str
;
24721 str_offsets_base
= *cu
->str_offsets_base
;
24724 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24725 offset_size
, offset
, str_section
, str_offsets_section
,
24726 str_offsets_base
, section_is_gnu
);
24729 /* Return the .debug_loc section to use for CU.
24730 For DWO files use .debug_loc.dwo. */
24732 static struct dwarf2_section_info
*
24733 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24735 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24739 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24741 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24743 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24744 : &per_objfile
->per_bfd
->loc
);
24747 /* Return the .debug_rnglists section to use for CU. */
24748 static struct dwarf2_section_info
*
24749 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24751 if (cu
->header
.version
< 5)
24752 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24753 cu
->header
.version
);
24754 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24756 /* Make sure we read the .debug_rnglists section from the file that
24757 contains the DW_AT_ranges attribute we are reading. Normally that
24758 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24759 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24761 if (cu
->dwo_unit
!= nullptr
24762 && tag
!= DW_TAG_compile_unit
24763 && tag
!= DW_TAG_skeleton_unit
)
24765 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24767 if (sections
->rnglists
.size
> 0)
24768 return §ions
->rnglists
;
24770 error (_(".debug_rnglists section is missing from .dwo file."));
24772 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24775 /* A helper function that fills in a dwarf2_loclist_baton. */
24778 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24779 struct dwarf2_loclist_baton
*baton
,
24780 const struct attribute
*attr
)
24782 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24783 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24785 section
->read (per_objfile
->objfile
);
24787 baton
->per_objfile
= per_objfile
;
24788 baton
->per_cu
= cu
->per_cu
;
24789 gdb_assert (baton
->per_cu
);
24790 /* We don't know how long the location list is, but make sure we
24791 don't run off the edge of the section. */
24792 baton
->size
= section
->size
- attr
->as_unsigned ();
24793 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24794 if (cu
->base_address
.has_value ())
24795 baton
->base_address
= *cu
->base_address
;
24797 baton
->base_address
= 0;
24798 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24802 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24803 struct dwarf2_cu
*cu
, int is_block
)
24805 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24806 struct objfile
*objfile
= per_objfile
->objfile
;
24807 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24809 if (attr
->form_is_section_offset ()
24810 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24811 the section. If so, fall through to the complaint in the
24813 && attr
->as_unsigned () < section
->get_size (objfile
))
24815 struct dwarf2_loclist_baton
*baton
;
24817 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24819 fill_in_loclist_baton (cu
, baton
, attr
);
24821 if (!cu
->base_address
.has_value ())
24822 complaint (_("Location list used without "
24823 "specifying the CU base address."));
24825 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24826 ? dwarf2_loclist_block_index
24827 : dwarf2_loclist_index
);
24828 SYMBOL_LOCATION_BATON (sym
) = baton
;
24832 struct dwarf2_locexpr_baton
*baton
;
24834 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24835 baton
->per_objfile
= per_objfile
;
24836 baton
->per_cu
= cu
->per_cu
;
24837 gdb_assert (baton
->per_cu
);
24839 if (attr
->form_is_block ())
24841 /* Note that we're just copying the block's data pointer
24842 here, not the actual data. We're still pointing into the
24843 info_buffer for SYM's objfile; right now we never release
24844 that buffer, but when we do clean up properly this may
24846 struct dwarf_block
*block
= attr
->as_block ();
24847 baton
->size
= block
->size
;
24848 baton
->data
= block
->data
;
24852 dwarf2_invalid_attrib_class_complaint ("location description",
24853 sym
->natural_name ());
24857 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24858 ? dwarf2_locexpr_block_index
24859 : dwarf2_locexpr_index
);
24860 SYMBOL_LOCATION_BATON (sym
) = baton
;
24866 const comp_unit_head
*
24867 dwarf2_per_cu_data::get_header () const
24869 if (!m_header_read_in
)
24871 const gdb_byte
*info_ptr
24872 = this->section
->buffer
+ to_underlying (this->sect_off
);
24874 memset (&m_header
, 0, sizeof (m_header
));
24876 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24877 rcuh_kind::COMPILE
);
24879 m_header_read_in
= true;
24888 dwarf2_per_cu_data::addr_size () const
24890 return this->get_header ()->addr_size
;
24896 dwarf2_per_cu_data::offset_size () const
24898 return this->get_header ()->offset_size
;
24904 dwarf2_per_cu_data::ref_addr_size () const
24906 const comp_unit_head
*header
= this->get_header ();
24908 if (header
->version
== 2)
24909 return header
->addr_size
;
24911 return header
->offset_size
;
24917 dwarf2_cu::addr_type () const
24919 struct objfile
*objfile
= this->per_objfile
->objfile
;
24920 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
24921 struct type
*addr_type
= lookup_pointer_type (void_type
);
24922 int addr_size
= this->per_cu
->addr_size ();
24924 if (TYPE_LENGTH (addr_type
) == addr_size
)
24927 addr_type
= addr_sized_int_type (addr_type
->is_unsigned ());
24931 /* A helper function for dwarf2_find_containing_comp_unit that returns
24932 the index of the result, and that searches a vector. It will
24933 return a result even if the offset in question does not actually
24934 occur in any CU. This is separate so that it can be unit
24938 dwarf2_find_containing_comp_unit
24939 (sect_offset sect_off
,
24940 unsigned int offset_in_dwz
,
24941 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
24946 high
= all_comp_units
.size () - 1;
24949 struct dwarf2_per_cu_data
*mid_cu
;
24950 int mid
= low
+ (high
- low
) / 2;
24952 mid_cu
= all_comp_units
[mid
];
24953 if (mid_cu
->is_dwz
> offset_in_dwz
24954 || (mid_cu
->is_dwz
== offset_in_dwz
24955 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
24960 gdb_assert (low
== high
);
24964 /* Locate the .debug_info compilation unit from CU's objfile which contains
24965 the DIE at OFFSET. Raises an error on failure. */
24967 static struct dwarf2_per_cu_data
*
24968 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
24969 unsigned int offset_in_dwz
,
24970 dwarf2_per_objfile
*per_objfile
)
24972 int low
= dwarf2_find_containing_comp_unit
24973 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
24974 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
24976 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
24978 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
24979 error (_("Dwarf Error: could not find partial DIE containing "
24980 "offset %s [in module %s]"),
24981 sect_offset_str (sect_off
),
24982 bfd_get_filename (per_objfile
->objfile
->obfd
));
24984 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
24986 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
24990 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
24991 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
24992 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
24993 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25000 namespace selftests
{
25001 namespace find_containing_comp_unit
{
25006 struct dwarf2_per_cu_data one
{};
25007 struct dwarf2_per_cu_data two
{};
25008 struct dwarf2_per_cu_data three
{};
25009 struct dwarf2_per_cu_data four
{};
25012 two
.sect_off
= sect_offset (one
.length
);
25017 four
.sect_off
= sect_offset (three
.length
);
25021 std::vector
<dwarf2_per_cu_data
*> units
;
25022 units
.push_back (&one
);
25023 units
.push_back (&two
);
25024 units
.push_back (&three
);
25025 units
.push_back (&four
);
25029 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
25030 SELF_CHECK (units
[result
] == &one
);
25031 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
25032 SELF_CHECK (units
[result
] == &one
);
25033 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
25034 SELF_CHECK (units
[result
] == &two
);
25036 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
25037 SELF_CHECK (units
[result
] == &three
);
25038 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
25039 SELF_CHECK (units
[result
] == &three
);
25040 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
25041 SELF_CHECK (units
[result
] == &four
);
25047 #endif /* GDB_SELF_TEST */
25049 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
25051 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
25052 dwarf2_per_objfile
*per_objfile
)
25054 per_objfile (per_objfile
),
25056 has_loclist (false),
25057 checked_producer (false),
25058 producer_is_gxx_lt_4_6 (false),
25059 producer_is_gcc_lt_4_3 (false),
25060 producer_is_icc (false),
25061 producer_is_icc_lt_14 (false),
25062 producer_is_codewarrior (false),
25063 processing_has_namespace_info (false)
25067 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25070 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25071 enum language pretend_language
)
25073 struct attribute
*attr
;
25075 /* Set the language we're debugging. */
25076 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25077 if (attr
!= nullptr)
25078 set_cu_language (attr
->constant_value (0), cu
);
25081 cu
->language
= pretend_language
;
25082 cu
->language_defn
= language_def (cu
->language
);
25085 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25091 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
25093 auto it
= m_dwarf2_cus
.find (per_cu
);
25094 if (it
== m_dwarf2_cus
.end ())
25103 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
25105 gdb_assert (this->get_cu (per_cu
) == nullptr);
25107 m_dwarf2_cus
[per_cu
] = cu
;
25113 dwarf2_per_objfile::age_comp_units ()
25115 dwarf_read_debug_printf_v ("running");
25117 /* This is not expected to be called in the middle of CU expansion. There is
25118 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
25119 loaded in memory. Calling age_comp_units while the queue is in use could
25120 make us free the DIEs for a CU that is in the queue and therefore break
25122 gdb_assert (!this->per_bfd
->queue
.has_value ());
25124 /* Start by clearing all marks. */
25125 for (auto pair
: m_dwarf2_cus
)
25126 pair
.second
->mark
= false;
25128 /* Traverse all CUs, mark them and their dependencies if used recently
25130 for (auto pair
: m_dwarf2_cus
)
25132 dwarf2_cu
*cu
= pair
.second
;
25135 if (cu
->last_used
<= dwarf_max_cache_age
)
25139 /* Delete all CUs still not marked. */
25140 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
25142 dwarf2_cu
*cu
= it
->second
;
25146 dwarf_read_debug_printf_v ("deleting old CU %s",
25147 sect_offset_str (cu
->per_cu
->sect_off
));
25149 it
= m_dwarf2_cus
.erase (it
);
25159 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
25161 auto it
= m_dwarf2_cus
.find (per_cu
);
25162 if (it
== m_dwarf2_cus
.end ())
25167 m_dwarf2_cus
.erase (it
);
25170 dwarf2_per_objfile::~dwarf2_per_objfile ()
25175 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25176 We store these in a hash table separate from the DIEs, and preserve them
25177 when the DIEs are flushed out of cache.
25179 The CU "per_cu" pointer is needed because offset alone is not enough to
25180 uniquely identify the type. A file may have multiple .debug_types sections,
25181 or the type may come from a DWO file. Furthermore, while it's more logical
25182 to use per_cu->section+offset, with Fission the section with the data is in
25183 the DWO file but we don't know that section at the point we need it.
25184 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25185 because we can enter the lookup routine, get_die_type_at_offset, from
25186 outside this file, and thus won't necessarily have PER_CU->cu.
25187 Fortunately, PER_CU is stable for the life of the objfile. */
25189 struct dwarf2_per_cu_offset_and_type
25191 const struct dwarf2_per_cu_data
*per_cu
;
25192 sect_offset sect_off
;
25196 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25199 per_cu_offset_and_type_hash (const void *item
)
25201 const struct dwarf2_per_cu_offset_and_type
*ofs
25202 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25204 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25207 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25210 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25212 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25213 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25214 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25215 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25217 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25218 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25221 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25222 table if necessary. For convenience, return TYPE.
25224 The DIEs reading must have careful ordering to:
25225 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25226 reading current DIE.
25227 * Not trying to dereference contents of still incompletely read in types
25228 while reading in other DIEs.
25229 * Enable referencing still incompletely read in types just by a pointer to
25230 the type without accessing its fields.
25232 Therefore caller should follow these rules:
25233 * Try to fetch any prerequisite types we may need to build this DIE type
25234 before building the type and calling set_die_type.
25235 * After building type call set_die_type for current DIE as soon as
25236 possible before fetching more types to complete the current type.
25237 * Make the type as complete as possible before fetching more types. */
25239 static struct type
*
25240 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
25241 bool skip_data_location
)
25243 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
25244 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25245 struct objfile
*objfile
= per_objfile
->objfile
;
25246 struct attribute
*attr
;
25247 struct dynamic_prop prop
;
25249 /* For Ada types, make sure that the gnat-specific data is always
25250 initialized (if not already set). There are a few types where
25251 we should not be doing so, because the type-specific area is
25252 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25253 where the type-specific area is used to store the floatformat).
25254 But this is not a problem, because the gnat-specific information
25255 is actually not needed for these types. */
25256 if (need_gnat_info (cu
)
25257 && type
->code () != TYPE_CODE_FUNC
25258 && type
->code () != TYPE_CODE_FLT
25259 && type
->code () != TYPE_CODE_METHODPTR
25260 && type
->code () != TYPE_CODE_MEMBERPTR
25261 && type
->code () != TYPE_CODE_METHOD
25262 && type
->code () != TYPE_CODE_FIXED_POINT
25263 && !HAVE_GNAT_AUX_INFO (type
))
25264 INIT_GNAT_SPECIFIC (type
);
25266 /* Read DW_AT_allocated and set in type. */
25267 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25270 struct type
*prop_type
= cu
->addr_sized_int_type (false);
25271 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25272 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
25275 /* Read DW_AT_associated and set in type. */
25276 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25279 struct type
*prop_type
= cu
->addr_sized_int_type (false);
25280 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25281 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
25284 /* Read DW_AT_data_location and set in type. */
25285 if (!skip_data_location
)
25287 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25288 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
25289 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
25292 if (per_objfile
->die_type_hash
== NULL
)
25293 per_objfile
->die_type_hash
25294 = htab_up (htab_create_alloc (127,
25295 per_cu_offset_and_type_hash
,
25296 per_cu_offset_and_type_eq
,
25297 NULL
, xcalloc
, xfree
));
25299 ofs
.per_cu
= cu
->per_cu
;
25300 ofs
.sect_off
= die
->sect_off
;
25302 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25303 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
25305 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25306 sect_offset_str (die
->sect_off
));
25307 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25308 struct dwarf2_per_cu_offset_and_type
);
25313 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25314 or return NULL if the die does not have a saved type. */
25316 static struct type
*
25317 get_die_type_at_offset (sect_offset sect_off
,
25318 dwarf2_per_cu_data
*per_cu
,
25319 dwarf2_per_objfile
*per_objfile
)
25321 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25323 if (per_objfile
->die_type_hash
== NULL
)
25326 ofs
.per_cu
= per_cu
;
25327 ofs
.sect_off
= sect_off
;
25328 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25329 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
25336 /* Look up the type for DIE in CU in die_type_hash,
25337 or return NULL if DIE does not have a saved type. */
25339 static struct type
*
25340 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25342 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
25345 /* Add a dependence relationship from CU to REF_PER_CU. */
25348 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25349 struct dwarf2_per_cu_data
*ref_per_cu
)
25353 if (cu
->dependencies
== NULL
)
25355 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25356 NULL
, &cu
->comp_unit_obstack
,
25357 hashtab_obstack_allocate
,
25358 dummy_obstack_deallocate
);
25360 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25362 *slot
= ref_per_cu
;
25365 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25366 Set the mark field in every compilation unit in the
25367 cache that we must keep because we are keeping CU.
25369 DATA is the dwarf2_per_objfile object in which to look up CUs. */
25372 dwarf2_mark_helper (void **slot
, void *data
)
25374 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
25375 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
25376 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
25378 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25379 reading of the chain. As such dependencies remain valid it is not much
25380 useful to track and undo them during QUIT cleanups. */
25389 if (cu
->dependencies
!= nullptr)
25390 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
25395 /* Set the mark field in CU and in every other compilation unit in the
25396 cache that we must keep because we are keeping CU. */
25399 dwarf2_mark (struct dwarf2_cu
*cu
)
25406 if (cu
->dependencies
!= nullptr)
25407 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
25410 /* Trivial hash function for partial_die_info: the hash value of a DIE
25411 is its offset in .debug_info for this objfile. */
25414 partial_die_hash (const void *item
)
25416 const struct partial_die_info
*part_die
25417 = (const struct partial_die_info
*) item
;
25419 return to_underlying (part_die
->sect_off
);
25422 /* Trivial comparison function for partial_die_info structures: two DIEs
25423 are equal if they have the same offset. */
25426 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25428 const struct partial_die_info
*part_die_lhs
25429 = (const struct partial_die_info
*) item_lhs
;
25430 const struct partial_die_info
*part_die_rhs
25431 = (const struct partial_die_info
*) item_rhs
;
25433 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25436 struct cmd_list_element
*set_dwarf_cmdlist
;
25437 struct cmd_list_element
*show_dwarf_cmdlist
;
25440 show_check_physname (struct ui_file
*file
, int from_tty
,
25441 struct cmd_list_element
*c
, const char *value
)
25443 fprintf_filtered (file
,
25444 _("Whether to check \"physname\" is %s.\n"),
25448 void _initialize_dwarf2_read ();
25450 _initialize_dwarf2_read ()
25452 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
25453 Set DWARF specific variables.\n\
25454 Configure DWARF variables such as the cache size."),
25455 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25456 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25458 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
25459 Show DWARF specific variables.\n\
25460 Show DWARF variables such as the cache size."),
25461 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25462 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25464 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25465 &dwarf_max_cache_age
, _("\
25466 Set the upper bound on the age of cached DWARF compilation units."), _("\
25467 Show the upper bound on the age of cached DWARF compilation units."), _("\
25468 A higher limit means that cached compilation units will be stored\n\
25469 in memory longer, and more total memory will be used. Zero disables\n\
25470 caching, which can slow down startup."),
25472 show_dwarf_max_cache_age
,
25473 &set_dwarf_cmdlist
,
25474 &show_dwarf_cmdlist
);
25476 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25477 Set debugging of the DWARF reader."), _("\
25478 Show debugging of the DWARF reader."), _("\
25479 When enabled (non-zero), debugging messages are printed during DWARF\n\
25480 reading and symtab expansion. A value of 1 (one) provides basic\n\
25481 information. A value greater than 1 provides more verbose information."),
25484 &setdebuglist
, &showdebuglist
);
25486 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25487 Set debugging of the DWARF DIE reader."), _("\
25488 Show debugging of the DWARF DIE reader."), _("\
25489 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25490 The value is the maximum depth to print."),
25493 &setdebuglist
, &showdebuglist
);
25495 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25496 Set debugging of the dwarf line reader."), _("\
25497 Show debugging of the dwarf line reader."), _("\
25498 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25499 A value of 1 (one) provides basic information.\n\
25500 A value greater than 1 provides more verbose information."),
25503 &setdebuglist
, &showdebuglist
);
25505 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25506 Set cross-checking of \"physname\" code against demangler."), _("\
25507 Show cross-checking of \"physname\" code against demangler."), _("\
25508 When enabled, GDB's internal \"physname\" code is checked against\n\
25510 NULL
, show_check_physname
,
25511 &setdebuglist
, &showdebuglist
);
25513 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25514 no_class
, &use_deprecated_index_sections
, _("\
25515 Set whether to use deprecated gdb_index sections."), _("\
25516 Show whether to use deprecated gdb_index sections."), _("\
25517 When enabled, deprecated .gdb_index sections are used anyway.\n\
25518 Normally they are ignored either because of a missing feature or\n\
25519 performance issue.\n\
25520 Warning: This option must be enabled before gdb reads the file."),
25523 &setlist
, &showlist
);
25525 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25526 &dwarf2_locexpr_funcs
);
25527 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25528 &dwarf2_loclist_funcs
);
25530 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25531 &dwarf2_block_frame_base_locexpr_funcs
);
25532 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25533 &dwarf2_block_frame_base_loclist_funcs
);
25536 selftests::register_test ("dw2_expand_symtabs_matching",
25537 selftests::dw2_expand_symtabs_matching::run_test
);
25538 selftests::register_test ("dwarf2_find_containing_comp_unit",
25539 selftests::find_containing_comp_unit::run_test
);