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"
53 #include "gdb-demangle.h"
54 #include "filenames.h" /* for DOSish file names */
56 #include "complaints.h"
57 #include "dwarf2/expr.h"
58 #include "dwarf2/loc.h"
59 #include "cp-support.h"
65 #include "typeprint.h"
70 #include "gdbcore.h" /* for gnutarget */
71 #include "gdb/gdb-index.h"
76 #include "namespace.h"
77 #include "gdbsupport/function-view.h"
78 #include "gdbsupport/gdb_optional.h"
79 #include "gdbsupport/underlying.h"
80 #include "gdbsupport/hash_enum.h"
81 #include "filename-seen-cache.h"
85 #include <unordered_map>
86 #include "gdbsupport/selftest.h"
87 #include "rust-lang.h"
88 #include "gdbsupport/pathstuff.h"
89 #include "count-one-bits.h"
90 #include "debuginfod-support.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 static 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
, 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 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 (objfile
)
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
;
2152 /* A helper function to find the sections for a .dwz file. */
2155 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, dwz_file
*dwz_file
)
2157 /* Note that we only support the standard ELF names, because .dwz
2158 is ELF-only (at the time of writing). */
2159 if (dwarf2_elf_names
.abbrev
.matches (sectp
->name
))
2161 dwz_file
->abbrev
.s
.section
= sectp
;
2162 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2164 else if (dwarf2_elf_names
.info
.matches (sectp
->name
))
2166 dwz_file
->info
.s
.section
= sectp
;
2167 dwz_file
->info
.size
= bfd_section_size (sectp
);
2169 else if (dwarf2_elf_names
.str
.matches (sectp
->name
))
2171 dwz_file
->str
.s
.section
= sectp
;
2172 dwz_file
->str
.size
= bfd_section_size (sectp
);
2174 else if (dwarf2_elf_names
.line
.matches (sectp
->name
))
2176 dwz_file
->line
.s
.section
= sectp
;
2177 dwz_file
->line
.size
= bfd_section_size (sectp
);
2179 else if (dwarf2_elf_names
.macro
.matches (sectp
->name
))
2181 dwz_file
->macro
.s
.section
= sectp
;
2182 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2184 else if (dwarf2_elf_names
.gdb_index
.matches (sectp
->name
))
2186 dwz_file
->gdb_index
.s
.section
= sectp
;
2187 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2189 else if (dwarf2_elf_names
.debug_names
.matches (sectp
->name
))
2191 dwz_file
->debug_names
.s
.section
= sectp
;
2192 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2196 /* Attempt to find a .dwz file (whose full path is represented by
2197 FILENAME) in all of the specified debug file directories provided.
2199 Return the equivalent gdb_bfd_ref_ptr of the .dwz file found, or
2200 nullptr if it could not find anything. */
2202 static gdb_bfd_ref_ptr
2203 dwz_search_other_debugdirs (std::string
&filename
, bfd_byte
*buildid
,
2206 /* Let's assume that the path represented by FILENAME has the
2207 "/.dwz/" subpath in it. This is what (most) GNU/Linux
2208 distributions do, anyway. */
2209 size_t dwz_pos
= filename
.find ("/.dwz/");
2211 if (dwz_pos
== std::string::npos
)
2214 /* This is an obvious assertion, but it's here more to educate
2215 future readers of this code that FILENAME at DWZ_POS *must*
2216 contain a directory separator. */
2217 gdb_assert (IS_DIR_SEPARATOR (filename
[dwz_pos
]));
2219 gdb_bfd_ref_ptr dwz_bfd
;
2220 std::vector
<gdb::unique_xmalloc_ptr
<char>> debugdir_vec
2221 = dirnames_to_char_ptr_vec (debug_file_directory
);
2223 for (const gdb::unique_xmalloc_ptr
<char> &debugdir
: debugdir_vec
)
2225 /* The idea is to iterate over the
2226 debug file directories provided by the user and
2227 replace the hard-coded path in the "filename" by each
2228 debug-file-directory.
2230 For example, suppose that filename is:
2232 /usr/lib/debug/.dwz/foo.dwz
2234 And suppose that we have "$HOME/bar" as the
2235 debug-file-directory. We would then adjust filename
2238 $HOME/bar/.dwz/foo.dwz
2240 which would hopefully allow us to find the alt debug
2242 std::string ddir
= debugdir
.get ();
2247 /* Make sure the current debug-file-directory ends with a
2248 directory separator. This is needed because, if FILENAME
2249 contains something like "/usr/lib/abcde/.dwz/foo.dwz" and
2250 DDIR is "/usr/lib/abc", then could wrongfully skip it
2252 if (!IS_DIR_SEPARATOR (ddir
.back ()))
2253 ddir
+= SLASH_STRING
;
2255 /* Check whether the beginning of FILENAME is DDIR. If it is,
2256 then we are dealing with a file which we already attempted to
2257 open before, so we just skip it and continue processing the
2258 remaining debug file directories. */
2259 if (filename
.size () > ddir
.size ()
2260 && filename
.compare (0, ddir
.size (), ddir
) == 0)
2263 /* Replace FILENAME's default debug-file-directory with
2265 std::string new_filename
= ddir
+ &filename
[dwz_pos
+ 1];
2267 dwz_bfd
= gdb_bfd_open (new_filename
.c_str (), gnutarget
);
2269 if (dwz_bfd
== nullptr)
2272 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2274 dwz_bfd
.reset (nullptr);
2285 /* See dwarf2read.h. */
2288 dwarf2_get_dwz_file (dwarf2_per_bfd
*per_bfd
, bool require
)
2290 bfd_size_type buildid_len_arg
;
2294 if (per_bfd
->dwz_file
!= NULL
)
2295 return per_bfd
->dwz_file
.get ();
2297 bfd_set_error (bfd_error_no_error
);
2298 gdb::unique_xmalloc_ptr
<char> data
2299 (bfd_get_alt_debug_link_info (per_bfd
->obfd
,
2300 &buildid_len_arg
, &buildid
));
2303 if (bfd_get_error () == bfd_error_no_error
)
2307 error (_("could not read '.gnu_debugaltlink' section"));
2309 error (_("could not read '.gnu_debugaltlink' section: %s"),
2310 bfd_errmsg (bfd_get_error ()));
2313 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2315 buildid_len
= (size_t) buildid_len_arg
;
2317 std::string filename
= data
.get ();
2319 if (!IS_ABSOLUTE_PATH (filename
.c_str ()))
2321 gdb::unique_xmalloc_ptr
<char> abs
2322 = gdb_realpath (bfd_get_filename (per_bfd
->obfd
));
2324 filename
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2327 /* First try the file name given in the section. If that doesn't
2328 work, try to use the build-id instead. */
2329 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
.c_str (), gnutarget
));
2330 if (dwz_bfd
!= NULL
)
2332 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2333 dwz_bfd
.reset (nullptr);
2336 if (dwz_bfd
== NULL
)
2337 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2339 if (dwz_bfd
== nullptr)
2341 /* If the user has provided us with different
2342 debug file directories, we can try them in order. */
2343 dwz_bfd
= dwz_search_other_debugdirs (filename
, buildid
, buildid_len
);
2346 if (dwz_bfd
== nullptr)
2348 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2349 const char *origname
= bfd_get_filename (per_bfd
->obfd
);
2351 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2358 /* File successfully retrieved from server. */
2359 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
);
2361 if (dwz_bfd
== nullptr)
2362 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2363 alt_filename
.get ());
2364 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2365 dwz_bfd
.reset (nullptr);
2369 if (dwz_bfd
== NULL
)
2370 error (_("could not find '.gnu_debugaltlink' file for %s"),
2371 bfd_get_filename (per_bfd
->obfd
));
2373 std::unique_ptr
<struct dwz_file
> result
2374 (new struct dwz_file (std::move (dwz_bfd
)));
2376 for (asection
*sec
: gdb_bfd_sections (result
->dwz_bfd
))
2377 locate_dwz_sections (result
->dwz_bfd
.get (), sec
, result
.get ());
2379 gdb_bfd_record_inclusion (per_bfd
->obfd
, result
->dwz_bfd
.get ());
2380 per_bfd
->dwz_file
= std::move (result
);
2381 return per_bfd
->dwz_file
.get ();
2384 /* DWARF quick_symbols_functions support. */
2386 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2387 unique line tables, so we maintain a separate table of all .debug_line
2388 derived entries to support the sharing.
2389 All the quick functions need is the list of file names. We discard the
2390 line_header when we're done and don't need to record it here. */
2391 struct quick_file_names
2393 /* The data used to construct the hash key. */
2394 struct stmt_list_hash hash
;
2396 /* The number of entries in file_names, real_names. */
2397 unsigned int num_file_names
;
2399 /* The file names from the line table, after being run through
2401 const char **file_names
;
2403 /* The file names from the line table after being run through
2404 gdb_realpath. These are computed lazily. */
2405 const char **real_names
;
2408 /* When using the index (and thus not using psymtabs), each CU has an
2409 object of this type. This is used to hold information needed by
2410 the various "quick" methods. */
2411 struct dwarf2_per_cu_quick_data
2413 /* The file table. This can be NULL if there was no file table
2414 or it's currently not read in.
2415 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
2416 struct quick_file_names
*file_names
;
2418 /* A temporary mark bit used when iterating over all CUs in
2419 expand_symtabs_matching. */
2420 unsigned int mark
: 1;
2422 /* True if we've tried to read the file table and found there isn't one.
2423 There will be no point in trying to read it again next time. */
2424 unsigned int no_file_data
: 1;
2427 /* Utility hash function for a stmt_list_hash. */
2430 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2434 if (stmt_list_hash
->dwo_unit
!= NULL
)
2435 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2436 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2440 /* Utility equality function for a stmt_list_hash. */
2443 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2444 const struct stmt_list_hash
*rhs
)
2446 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2448 if (lhs
->dwo_unit
!= NULL
2449 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2452 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2455 /* Hash function for a quick_file_names. */
2458 hash_file_name_entry (const void *e
)
2460 const struct quick_file_names
*file_data
2461 = (const struct quick_file_names
*) e
;
2463 return hash_stmt_list_entry (&file_data
->hash
);
2466 /* Equality function for a quick_file_names. */
2469 eq_file_name_entry (const void *a
, const void *b
)
2471 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2472 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2474 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2477 /* Delete function for a quick_file_names. */
2480 delete_file_name_entry (void *e
)
2482 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2485 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2487 xfree ((void*) file_data
->file_names
[i
]);
2488 if (file_data
->real_names
)
2489 xfree ((void*) file_data
->real_names
[i
]);
2492 /* The space for the struct itself lives on the obstack, so we don't
2496 /* Create a quick_file_names hash table. */
2499 create_quick_file_names_table (unsigned int nr_initial_entries
)
2501 return htab_up (htab_create_alloc (nr_initial_entries
,
2502 hash_file_name_entry
, eq_file_name_entry
,
2503 delete_file_name_entry
, xcalloc
, xfree
));
2506 /* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE. This
2507 function is unrelated to symtabs, symtab would have to be created afterwards.
2508 You should call age_cached_comp_units after processing the CU. */
2511 load_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_per_objfile
*per_objfile
,
2514 if (per_cu
->is_debug_types
)
2515 load_full_type_unit (per_cu
, per_objfile
);
2517 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
2518 skip_partial
, language_minimal
);
2520 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
2522 return nullptr; /* Dummy CU. */
2524 dwarf2_find_base_address (cu
->dies
, cu
);
2529 /* Read in the symbols for PER_CU in the context of PER_OBJFILE. */
2532 dw2_do_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2533 dwarf2_per_objfile
*per_objfile
, bool skip_partial
)
2535 /* Skip type_unit_groups, reading the type units they contain
2536 is handled elsewhere. */
2537 if (per_cu
->type_unit_group_p ())
2541 /* The destructor of dwarf2_queue_guard frees any entries left on
2542 the queue. After this point we're guaranteed to leave this function
2543 with the dwarf queue empty. */
2544 dwarf2_queue_guard
q_guard (per_objfile
);
2546 if (!per_objfile
->symtab_set_p (per_cu
))
2548 queue_comp_unit (per_cu
, per_objfile
, language_minimal
);
2549 dwarf2_cu
*cu
= load_cu (per_cu
, per_objfile
, skip_partial
);
2551 /* If we just loaded a CU from a DWO, and we're working with an index
2552 that may badly handle TUs, load all the TUs in that DWO as well.
2553 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2554 if (!per_cu
->is_debug_types
2556 && cu
->dwo_unit
!= NULL
2557 && per_objfile
->per_bfd
->index_table
!= NULL
2558 && per_objfile
->per_bfd
->index_table
->version
<= 7
2559 /* DWP files aren't supported yet. */
2560 && get_dwp_file (per_objfile
) == NULL
)
2561 queue_and_load_all_dwo_tus (cu
);
2564 process_queue (per_objfile
);
2567 /* Age the cache, releasing compilation units that have not
2568 been used recently. */
2569 per_objfile
->age_comp_units ();
2572 /* Ensure that the symbols for PER_CU have been read in. DWARF2_PER_OBJFILE is
2573 the per-objfile for which this symtab is instantiated.
2575 Returns the resulting symbol table. */
2577 static struct compunit_symtab
*
2578 dw2_instantiate_symtab (dwarf2_per_cu_data
*per_cu
,
2579 dwarf2_per_objfile
*per_objfile
,
2582 gdb_assert (per_objfile
->per_bfd
->using_index
);
2584 if (!per_objfile
->symtab_set_p (per_cu
))
2586 free_cached_comp_units
freer (per_objfile
);
2587 scoped_restore decrementer
= increment_reading_symtab ();
2588 dw2_do_instantiate_symtab (per_cu
, per_objfile
, skip_partial
);
2589 process_cu_includes (per_objfile
);
2592 return per_objfile
->get_symtab (per_cu
);
2595 /* See declaration. */
2597 dwarf2_per_cu_data
*
2598 dwarf2_per_bfd::get_cutu (int index
)
2600 if (index
>= this->all_comp_units
.size ())
2602 index
-= this->all_comp_units
.size ();
2603 gdb_assert (index
< this->all_type_units
.size ());
2604 return &this->all_type_units
[index
]->per_cu
;
2607 return this->all_comp_units
[index
];
2610 /* See declaration. */
2612 dwarf2_per_cu_data
*
2613 dwarf2_per_bfd::get_cu (int index
)
2615 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2617 return this->all_comp_units
[index
];
2620 /* See declaration. */
2623 dwarf2_per_bfd::get_tu (int index
)
2625 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2627 return this->all_type_units
[index
];
2632 dwarf2_per_cu_data
*
2633 dwarf2_per_bfd::allocate_per_cu ()
2635 dwarf2_per_cu_data
*result
= OBSTACK_ZALLOC (&obstack
, dwarf2_per_cu_data
);
2636 result
->per_bfd
= this;
2637 result
->index
= m_num_psymtabs
++;
2644 dwarf2_per_bfd::allocate_signatured_type ()
2646 signatured_type
*result
= OBSTACK_ZALLOC (&obstack
, signatured_type
);
2647 result
->per_cu
.per_bfd
= this;
2648 result
->per_cu
.index
= m_num_psymtabs
++;
2652 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
2653 obstack, and constructed with the specified field values. */
2655 static dwarf2_per_cu_data
*
2656 create_cu_from_index_list (dwarf2_per_bfd
*per_bfd
,
2657 struct dwarf2_section_info
*section
,
2659 sect_offset sect_off
, ULONGEST length
)
2661 dwarf2_per_cu_data
*the_cu
= per_bfd
->allocate_per_cu ();
2662 the_cu
->sect_off
= sect_off
;
2663 the_cu
->length
= length
;
2664 the_cu
->section
= section
;
2665 the_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
2666 struct dwarf2_per_cu_quick_data
);
2667 the_cu
->is_dwz
= is_dwz
;
2671 /* A helper for create_cus_from_index that handles a given list of
2675 create_cus_from_index_list (dwarf2_per_bfd
*per_bfd
,
2676 const gdb_byte
*cu_list
, offset_type n_elements
,
2677 struct dwarf2_section_info
*section
,
2680 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2682 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2684 sect_offset sect_off
2685 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2686 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2689 dwarf2_per_cu_data
*per_cu
2690 = create_cu_from_index_list (per_bfd
, section
, is_dwz
, sect_off
,
2692 per_bfd
->all_comp_units
.push_back (per_cu
);
2696 /* Read the CU list from the mapped index, and use it to create all
2697 the CU objects for PER_BFD. */
2700 create_cus_from_index (dwarf2_per_bfd
*per_bfd
,
2701 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2702 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2704 gdb_assert (per_bfd
->all_comp_units
.empty ());
2705 per_bfd
->all_comp_units
.reserve ((cu_list_elements
+ dwz_elements
) / 2);
2707 create_cus_from_index_list (per_bfd
, cu_list
, cu_list_elements
,
2710 if (dwz_elements
== 0)
2713 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
2714 create_cus_from_index_list (per_bfd
, dwz_list
, dwz_elements
,
2718 /* Create the signatured type hash table from the index. */
2721 create_signatured_type_table_from_index
2722 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
2723 const gdb_byte
*bytes
, offset_type elements
)
2725 gdb_assert (per_bfd
->all_type_units
.empty ());
2726 per_bfd
->all_type_units
.reserve (elements
/ 3);
2728 htab_up sig_types_hash
= allocate_signatured_type_table ();
2730 for (offset_type i
= 0; i
< elements
; i
+= 3)
2732 struct signatured_type
*sig_type
;
2735 cu_offset type_offset_in_tu
;
2737 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2738 sect_offset sect_off
2739 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2741 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2743 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2746 sig_type
= per_bfd
->allocate_signatured_type ();
2747 sig_type
->signature
= signature
;
2748 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2749 sig_type
->per_cu
.is_debug_types
= 1;
2750 sig_type
->per_cu
.section
= section
;
2751 sig_type
->per_cu
.sect_off
= sect_off
;
2752 sig_type
->per_cu
.v
.quick
2753 = OBSTACK_ZALLOC (&per_bfd
->obstack
,
2754 struct dwarf2_per_cu_quick_data
);
2756 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2759 per_bfd
->all_type_units
.push_back (sig_type
);
2762 per_bfd
->signatured_types
= std::move (sig_types_hash
);
2765 /* Create the signatured type hash table from .debug_names. */
2768 create_signatured_type_table_from_debug_names
2769 (dwarf2_per_objfile
*per_objfile
,
2770 const mapped_debug_names
&map
,
2771 struct dwarf2_section_info
*section
,
2772 struct dwarf2_section_info
*abbrev_section
)
2774 struct objfile
*objfile
= per_objfile
->objfile
;
2776 section
->read (objfile
);
2777 abbrev_section
->read (objfile
);
2779 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
2780 per_objfile
->per_bfd
->all_type_units
.reserve (map
.tu_count
);
2782 htab_up sig_types_hash
= allocate_signatured_type_table ();
2784 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2786 struct signatured_type
*sig_type
;
2789 sect_offset sect_off
2790 = (sect_offset
) (extract_unsigned_integer
2791 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2793 map
.dwarf5_byte_order
));
2795 comp_unit_head cu_header
;
2796 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
2798 section
->buffer
+ to_underlying (sect_off
),
2801 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
2802 sig_type
->signature
= cu_header
.signature
;
2803 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2804 sig_type
->per_cu
.is_debug_types
= 1;
2805 sig_type
->per_cu
.section
= section
;
2806 sig_type
->per_cu
.sect_off
= sect_off
;
2807 sig_type
->per_cu
.v
.quick
2808 = OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
2809 struct dwarf2_per_cu_quick_data
);
2811 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2814 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
2817 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
2820 /* Read the address map data from the mapped index, and use it to
2821 populate the objfile's psymtabs_addrmap. */
2824 create_addrmap_from_index (dwarf2_per_objfile
*per_objfile
,
2825 struct mapped_index
*index
)
2827 struct objfile
*objfile
= per_objfile
->objfile
;
2828 struct gdbarch
*gdbarch
= objfile
->arch ();
2829 const gdb_byte
*iter
, *end
;
2830 struct addrmap
*mutable_map
;
2833 auto_obstack temp_obstack
;
2835 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2837 iter
= index
->address_table
.data ();
2838 end
= iter
+ index
->address_table
.size ();
2840 baseaddr
= objfile
->text_section_offset ();
2844 ULONGEST hi
, lo
, cu_index
;
2845 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2847 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2849 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2854 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2855 hex_string (lo
), hex_string (hi
));
2859 if (cu_index
>= per_objfile
->per_bfd
->all_comp_units
.size ())
2861 complaint (_(".gdb_index address table has invalid CU number %u"),
2862 (unsigned) cu_index
);
2866 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2867 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2868 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2869 per_objfile
->per_bfd
->get_cu (cu_index
));
2872 objfile
->partial_symtabs
->psymtabs_addrmap
2873 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2876 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2877 populate the objfile's psymtabs_addrmap. */
2880 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
2881 struct dwarf2_section_info
*section
)
2883 struct objfile
*objfile
= per_objfile
->objfile
;
2884 bfd
*abfd
= objfile
->obfd
;
2885 struct gdbarch
*gdbarch
= objfile
->arch ();
2886 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2888 auto_obstack temp_obstack
;
2889 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2891 std::unordered_map
<sect_offset
,
2892 dwarf2_per_cu_data
*,
2893 gdb::hash_enum
<sect_offset
>>
2894 debug_info_offset_to_per_cu
;
2895 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
2897 const auto insertpair
2898 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2899 if (!insertpair
.second
)
2901 warning (_("Section .debug_aranges in %s has duplicate "
2902 "debug_info_offset %s, ignoring .debug_aranges."),
2903 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2908 section
->read (objfile
);
2910 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2912 const gdb_byte
*addr
= section
->buffer
;
2914 while (addr
< section
->buffer
+ section
->size
)
2916 const gdb_byte
*const entry_addr
= addr
;
2917 unsigned int bytes_read
;
2919 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2923 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2924 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2925 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2926 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2928 warning (_("Section .debug_aranges in %s entry at offset %s "
2929 "length %s exceeds section length %s, "
2930 "ignoring .debug_aranges."),
2931 objfile_name (objfile
),
2932 plongest (entry_addr
- section
->buffer
),
2933 plongest (bytes_read
+ entry_length
),
2934 pulongest (section
->size
));
2938 /* The version number. */
2939 const uint16_t version
= read_2_bytes (abfd
, addr
);
2943 warning (_("Section .debug_aranges in %s entry at offset %s "
2944 "has unsupported version %d, ignoring .debug_aranges."),
2945 objfile_name (objfile
),
2946 plongest (entry_addr
- section
->buffer
), version
);
2950 const uint64_t debug_info_offset
2951 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2952 addr
+= offset_size
;
2953 const auto per_cu_it
2954 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2955 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2957 warning (_("Section .debug_aranges in %s entry at offset %s "
2958 "debug_info_offset %s does not exists, "
2959 "ignoring .debug_aranges."),
2960 objfile_name (objfile
),
2961 plongest (entry_addr
- section
->buffer
),
2962 pulongest (debug_info_offset
));
2965 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2967 const uint8_t address_size
= *addr
++;
2968 if (address_size
< 1 || address_size
> 8)
2970 warning (_("Section .debug_aranges in %s entry at offset %s "
2971 "address_size %u is invalid, ignoring .debug_aranges."),
2972 objfile_name (objfile
),
2973 plongest (entry_addr
- section
->buffer
), address_size
);
2977 const uint8_t segment_selector_size
= *addr
++;
2978 if (segment_selector_size
!= 0)
2980 warning (_("Section .debug_aranges in %s entry at offset %s "
2981 "segment_selector_size %u is not supported, "
2982 "ignoring .debug_aranges."),
2983 objfile_name (objfile
),
2984 plongest (entry_addr
- section
->buffer
),
2985 segment_selector_size
);
2989 /* Must pad to an alignment boundary that is twice the address
2990 size. It is undocumented by the DWARF standard but GCC does
2992 for (size_t padding
= ((-(addr
- section
->buffer
))
2993 & (2 * address_size
- 1));
2994 padding
> 0; padding
--)
2997 warning (_("Section .debug_aranges in %s entry at offset %s "
2998 "padding is not zero, ignoring .debug_aranges."),
2999 objfile_name (objfile
),
3000 plongest (entry_addr
- section
->buffer
));
3006 if (addr
+ 2 * address_size
> entry_end
)
3008 warning (_("Section .debug_aranges in %s entry at offset %s "
3009 "address list is not properly terminated, "
3010 "ignoring .debug_aranges."),
3011 objfile_name (objfile
),
3012 plongest (entry_addr
- section
->buffer
));
3015 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3017 addr
+= address_size
;
3018 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3020 addr
+= address_size
;
3021 if (start
== 0 && length
== 0)
3023 if (start
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
3025 /* Symbol was eliminated due to a COMDAT group. */
3028 ULONGEST end
= start
+ length
;
3029 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3031 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3033 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3037 objfile
->partial_symtabs
->psymtabs_addrmap
3038 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3041 /* Find a slot in the mapped index INDEX for the object named NAME.
3042 If NAME is found, set *VEC_OUT to point to the CU vector in the
3043 constant pool and return true. If NAME cannot be found, return
3047 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3048 offset_type
**vec_out
)
3051 offset_type slot
, step
;
3052 int (*cmp
) (const char *, const char *);
3054 gdb::unique_xmalloc_ptr
<char> without_params
;
3055 if (current_language
->la_language
== language_cplus
3056 || current_language
->la_language
== language_fortran
3057 || current_language
->la_language
== language_d
)
3059 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3062 if (strchr (name
, '(') != NULL
)
3064 without_params
= cp_remove_params (name
);
3066 if (without_params
!= NULL
)
3067 name
= without_params
.get ();
3071 /* Index version 4 did not support case insensitive searches. But the
3072 indices for case insensitive languages are built in lowercase, therefore
3073 simulate our NAME being searched is also lowercased. */
3074 hash
= mapped_index_string_hash ((index
->version
== 4
3075 && case_sensitivity
== case_sensitive_off
3076 ? 5 : index
->version
),
3079 slot
= hash
& (index
->symbol_table
.size () - 1);
3080 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3081 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3087 const auto &bucket
= index
->symbol_table
[slot
];
3088 if (bucket
.name
== 0 && bucket
.vec
== 0)
3091 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3092 if (!cmp (name
, str
))
3094 *vec_out
= (offset_type
*) (index
->constant_pool
3095 + MAYBE_SWAP (bucket
.vec
));
3099 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3103 /* A helper function that reads the .gdb_index from BUFFER and fills
3104 in MAP. FILENAME is the name of the file containing the data;
3105 it is used for error reporting. DEPRECATED_OK is true if it is
3106 ok to use deprecated sections.
3108 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3109 out parameters that are filled in with information about the CU and
3110 TU lists in the section.
3112 Returns true if all went well, false otherwise. */
3115 read_gdb_index_from_buffer (const char *filename
,
3117 gdb::array_view
<const gdb_byte
> buffer
,
3118 struct mapped_index
*map
,
3119 const gdb_byte
**cu_list
,
3120 offset_type
*cu_list_elements
,
3121 const gdb_byte
**types_list
,
3122 offset_type
*types_list_elements
)
3124 const gdb_byte
*addr
= &buffer
[0];
3126 /* Version check. */
3127 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3128 /* Versions earlier than 3 emitted every copy of a psymbol. This
3129 causes the index to behave very poorly for certain requests. Version 3
3130 contained incomplete addrmap. So, it seems better to just ignore such
3134 static int warning_printed
= 0;
3135 if (!warning_printed
)
3137 warning (_("Skipping obsolete .gdb_index section in %s."),
3139 warning_printed
= 1;
3143 /* Index version 4 uses a different hash function than index version
3146 Versions earlier than 6 did not emit psymbols for inlined
3147 functions. Using these files will cause GDB not to be able to
3148 set breakpoints on inlined functions by name, so we ignore these
3149 indices unless the user has done
3150 "set use-deprecated-index-sections on". */
3151 if (version
< 6 && !deprecated_ok
)
3153 static int warning_printed
= 0;
3154 if (!warning_printed
)
3157 Skipping deprecated .gdb_index section in %s.\n\
3158 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3159 to use the section anyway."),
3161 warning_printed
= 1;
3165 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3166 of the TU (for symbols coming from TUs),
3167 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3168 Plus gold-generated indices can have duplicate entries for global symbols,
3169 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3170 These are just performance bugs, and we can't distinguish gdb-generated
3171 indices from gold-generated ones, so issue no warning here. */
3173 /* Indexes with higher version than the one supported by GDB may be no
3174 longer backward compatible. */
3178 map
->version
= version
;
3180 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3183 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3184 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3188 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3189 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3190 - MAYBE_SWAP (metadata
[i
]))
3194 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3195 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3197 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3200 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3201 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3203 = gdb::array_view
<mapped_index::symbol_table_slot
>
3204 ((mapped_index::symbol_table_slot
*) symbol_table
,
3205 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3208 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3213 /* Callback types for dwarf2_read_gdb_index. */
3215 typedef gdb::function_view
3216 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_bfd
*)>
3217 get_gdb_index_contents_ftype
;
3218 typedef gdb::function_view
3219 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3220 get_gdb_index_contents_dwz_ftype
;
3222 /* Read .gdb_index. If everything went ok, initialize the "quick"
3223 elements of all the CUs and return 1. Otherwise, return 0. */
3226 dwarf2_read_gdb_index
3227 (dwarf2_per_objfile
*per_objfile
,
3228 get_gdb_index_contents_ftype get_gdb_index_contents
,
3229 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3231 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3232 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3233 struct dwz_file
*dwz
;
3234 struct objfile
*objfile
= per_objfile
->objfile
;
3235 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
3237 gdb::array_view
<const gdb_byte
> main_index_contents
3238 = get_gdb_index_contents (objfile
, per_bfd
);
3240 if (main_index_contents
.empty ())
3243 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3244 if (!read_gdb_index_from_buffer (objfile_name (objfile
),
3245 use_deprecated_index_sections
,
3246 main_index_contents
, map
.get (), &cu_list
,
3247 &cu_list_elements
, &types_list
,
3248 &types_list_elements
))
3251 /* Don't use the index if it's empty. */
3252 if (map
->symbol_table
.empty ())
3255 /* If there is a .dwz file, read it so we can get its CU list as
3257 dwz
= dwarf2_get_dwz_file (per_bfd
);
3260 struct mapped_index dwz_map
;
3261 const gdb_byte
*dwz_types_ignore
;
3262 offset_type dwz_types_elements_ignore
;
3264 gdb::array_view
<const gdb_byte
> dwz_index_content
3265 = get_gdb_index_contents_dwz (objfile
, dwz
);
3267 if (dwz_index_content
.empty ())
3270 if (!read_gdb_index_from_buffer (bfd_get_filename (dwz
->dwz_bfd
.get ()),
3271 1, dwz_index_content
, &dwz_map
,
3272 &dwz_list
, &dwz_list_elements
,
3274 &dwz_types_elements_ignore
))
3276 warning (_("could not read '.gdb_index' section from %s; skipping"),
3277 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3282 create_cus_from_index (per_bfd
, cu_list
, cu_list_elements
, dwz_list
,
3285 if (types_list_elements
)
3287 /* We can only handle a single .debug_types when we have an
3289 if (per_bfd
->types
.size () != 1)
3292 dwarf2_section_info
*section
= &per_bfd
->types
[0];
3294 create_signatured_type_table_from_index (per_bfd
, section
, types_list
,
3295 types_list_elements
);
3298 create_addrmap_from_index (per_objfile
, map
.get ());
3300 per_bfd
->index_table
= std::move (map
);
3301 per_bfd
->using_index
= 1;
3302 per_bfd
->quick_file_names_table
=
3303 create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
3305 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
3306 objfiles using the same BFD. */
3307 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
3308 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
3313 /* die_reader_func for dw2_get_file_names. */
3316 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3317 const gdb_byte
*info_ptr
,
3318 struct die_info
*comp_unit_die
)
3320 struct dwarf2_cu
*cu
= reader
->cu
;
3321 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3322 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
3323 struct dwarf2_per_cu_data
*lh_cu
;
3324 struct attribute
*attr
;
3326 struct quick_file_names
*qfn
;
3328 gdb_assert (! this_cu
->is_debug_types
);
3330 /* Our callers never want to match partial units -- instead they
3331 will match the enclosing full CU. */
3332 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3334 this_cu
->v
.quick
->no_file_data
= 1;
3342 sect_offset line_offset
{};
3344 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3345 if (attr
!= nullptr && attr
->form_is_unsigned ())
3347 struct quick_file_names find_entry
;
3349 line_offset
= (sect_offset
) attr
->as_unsigned ();
3351 /* We may have already read in this line header (TU line header sharing).
3352 If we have we're done. */
3353 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3354 find_entry
.hash
.line_sect_off
= line_offset
;
3355 slot
= htab_find_slot (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3356 &find_entry
, INSERT
);
3359 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3363 lh
= dwarf_decode_line_header (line_offset
, cu
);
3367 lh_cu
->v
.quick
->no_file_data
= 1;
3371 qfn
= XOBNEW (&per_objfile
->per_bfd
->obstack
, struct quick_file_names
);
3372 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3373 qfn
->hash
.line_sect_off
= line_offset
;
3374 gdb_assert (slot
!= NULL
);
3377 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3380 if (strcmp (fnd
.name
, "<unknown>") != 0)
3383 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3385 XOBNEWVEC (&per_objfile
->per_bfd
->obstack
, const char *,
3386 qfn
->num_file_names
);
3388 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3389 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3390 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3391 fnd
.comp_dir
).release ();
3392 qfn
->real_names
= NULL
;
3394 lh_cu
->v
.quick
->file_names
= qfn
;
3397 /* A helper for the "quick" functions which attempts to read the line
3398 table for THIS_CU. */
3400 static struct quick_file_names
*
3401 dw2_get_file_names (dwarf2_per_cu_data
*this_cu
,
3402 dwarf2_per_objfile
*per_objfile
)
3404 /* This should never be called for TUs. */
3405 gdb_assert (! this_cu
->is_debug_types
);
3406 /* Nor type unit groups. */
3407 gdb_assert (! this_cu
->type_unit_group_p ());
3409 if (this_cu
->v
.quick
->file_names
!= NULL
)
3410 return this_cu
->v
.quick
->file_names
;
3411 /* If we know there is no line data, no point in looking again. */
3412 if (this_cu
->v
.quick
->no_file_data
)
3415 cutu_reader
reader (this_cu
, per_objfile
);
3416 if (!reader
.dummy_p
)
3417 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3419 if (this_cu
->v
.quick
->no_file_data
)
3421 return this_cu
->v
.quick
->file_names
;
3424 /* A helper for the "quick" functions which computes and caches the
3425 real path for a given file name from the line table. */
3428 dw2_get_real_path (dwarf2_per_objfile
*per_objfile
,
3429 struct quick_file_names
*qfn
, int index
)
3431 if (qfn
->real_names
== NULL
)
3432 qfn
->real_names
= OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
3433 qfn
->num_file_names
, const char *);
3435 if (qfn
->real_names
[index
] == NULL
)
3436 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3438 return qfn
->real_names
[index
];
3441 static struct symtab
*
3442 dw2_find_last_source_symtab (struct objfile
*objfile
)
3444 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3445 dwarf2_per_cu_data
*dwarf_cu
= per_objfile
->per_bfd
->all_comp_units
.back ();
3446 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, per_objfile
, false);
3451 return compunit_primary_filetab (cust
);
3454 /* Traversal function for dw2_forget_cached_source_info. */
3457 dw2_free_cached_file_names (void **slot
, void *info
)
3459 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3461 if (file_data
->real_names
)
3465 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3467 xfree ((void*) file_data
->real_names
[i
]);
3468 file_data
->real_names
[i
] = NULL
;
3476 dw2_forget_cached_source_info (struct objfile
*objfile
)
3478 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3480 htab_traverse_noresize (per_objfile
->per_bfd
->quick_file_names_table
.get (),
3481 dw2_free_cached_file_names
, NULL
);
3484 /* Helper function for dw2_map_symtabs_matching_filename that expands
3485 the symtabs and calls the iterator. */
3488 dw2_map_expand_apply (struct objfile
*objfile
,
3489 struct dwarf2_per_cu_data
*per_cu
,
3490 const char *name
, const char *real_path
,
3491 gdb::function_view
<bool (symtab
*)> callback
)
3493 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3495 /* Don't visit already-expanded CUs. */
3496 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3497 if (per_objfile
->symtab_set_p (per_cu
))
3500 /* This may expand more than one symtab, and we want to iterate over
3502 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3504 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3505 last_made
, callback
);
3508 /* Implementation of the map_symtabs_matching_filename method. */
3511 dw2_map_symtabs_matching_filename
3512 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3513 gdb::function_view
<bool (symtab
*)> callback
)
3515 const char *name_basename
= lbasename (name
);
3516 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3518 /* The rule is CUs specify all the files, including those used by
3519 any TU, so there's no need to scan TUs here. */
3521 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3523 /* We only need to look at symtabs not already expanded. */
3524 if (per_objfile
->symtab_set_p (per_cu
))
3527 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3528 if (file_data
== NULL
)
3531 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3533 const char *this_name
= file_data
->file_names
[j
];
3534 const char *this_real_name
;
3536 if (compare_filenames_for_search (this_name
, name
))
3538 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3544 /* Before we invoke realpath, which can get expensive when many
3545 files are involved, do a quick comparison of the basenames. */
3546 if (! basenames_may_differ
3547 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3550 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
3551 if (compare_filenames_for_search (this_real_name
, name
))
3553 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3559 if (real_path
!= NULL
)
3561 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3562 gdb_assert (IS_ABSOLUTE_PATH (name
));
3563 if (this_real_name
!= NULL
3564 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3566 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3578 /* Struct used to manage iterating over all CUs looking for a symbol. */
3580 struct dw2_symtab_iterator
3582 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3583 dwarf2_per_objfile
*per_objfile
;
3584 /* If set, only look for symbols that match that block. Valid values are
3585 GLOBAL_BLOCK and STATIC_BLOCK. */
3586 gdb::optional
<block_enum
> block_index
;
3587 /* The kind of symbol we're looking for. */
3589 /* The list of CUs from the index entry of the symbol,
3590 or NULL if not found. */
3592 /* The next element in VEC to look at. */
3594 /* The number of elements in VEC, or zero if there is no match. */
3596 /* Have we seen a global version of the symbol?
3597 If so we can ignore all further global instances.
3598 This is to work around gold/15646, inefficient gold-generated
3603 /* Initialize the index symtab iterator ITER, common part. */
3606 dw2_symtab_iter_init_common (struct dw2_symtab_iterator
*iter
,
3607 dwarf2_per_objfile
*per_objfile
,
3608 gdb::optional
<block_enum
> block_index
,
3611 iter
->per_objfile
= per_objfile
;
3612 iter
->block_index
= block_index
;
3613 iter
->domain
= domain
;
3615 iter
->global_seen
= 0;
3620 /* Initialize the index symtab iterator ITER, const char *NAME variant. */
3623 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3624 dwarf2_per_objfile
*per_objfile
,
3625 gdb::optional
<block_enum
> block_index
,
3629 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3631 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3632 /* index is NULL if OBJF_READNOW. */
3636 if (find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3637 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3640 /* Initialize the index symtab iterator ITER, offset_type NAMEI variant. */
3643 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3644 dwarf2_per_objfile
*per_objfile
,
3645 gdb::optional
<block_enum
> block_index
,
3646 domain_enum domain
, offset_type namei
)
3648 dw2_symtab_iter_init_common (iter
, per_objfile
, block_index
, domain
);
3650 mapped_index
*index
= per_objfile
->per_bfd
->index_table
.get ();
3651 /* index is NULL if OBJF_READNOW. */
3655 gdb_assert (!index
->symbol_name_slot_invalid (namei
));
3656 const auto &bucket
= index
->symbol_table
[namei
];
3658 iter
->vec
= (offset_type
*) (index
->constant_pool
3659 + MAYBE_SWAP (bucket
.vec
));
3660 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3663 /* Return the next matching CU or NULL if there are no more. */
3665 static struct dwarf2_per_cu_data
*
3666 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3668 dwarf2_per_objfile
*per_objfile
= iter
->per_objfile
;
3670 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3672 offset_type cu_index_and_attrs
=
3673 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3674 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3675 gdb_index_symbol_kind symbol_kind
=
3676 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3677 /* Only check the symbol attributes if they're present.
3678 Indices prior to version 7 don't record them,
3679 and indices >= 7 may elide them for certain symbols
3680 (gold does this). */
3682 (per_objfile
->per_bfd
->index_table
->version
>= 7
3683 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3685 /* Don't crash on bad data. */
3686 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
3687 + per_objfile
->per_bfd
->all_type_units
.size ()))
3689 complaint (_(".gdb_index entry has bad CU index"
3690 " [in module %s]"), objfile_name (per_objfile
->objfile
));
3694 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
3696 /* Skip if already read in. */
3697 if (per_objfile
->symtab_set_p (per_cu
))
3700 /* Check static vs global. */
3703 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3705 if (iter
->block_index
.has_value ())
3707 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3709 if (is_static
!= want_static
)
3713 /* Work around gold/15646. */
3715 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
3717 if (iter
->global_seen
)
3720 iter
->global_seen
= 1;
3724 /* Only check the symbol's kind if it has one. */
3727 switch (iter
->domain
)
3730 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3731 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3732 /* Some types are also in VAR_DOMAIN. */
3733 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3737 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3741 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3745 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3760 static struct compunit_symtab
*
3761 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3762 const char *name
, domain_enum domain
)
3764 struct compunit_symtab
*stab_best
= NULL
;
3765 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3767 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3769 struct dw2_symtab_iterator iter
;
3770 struct dwarf2_per_cu_data
*per_cu
;
3772 dw2_symtab_iter_init (&iter
, per_objfile
, block_index
, domain
, name
);
3774 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3776 struct symbol
*sym
, *with_opaque
= NULL
;
3777 struct compunit_symtab
*stab
3778 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3779 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3780 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3782 sym
= block_find_symbol (block
, name
, domain
,
3783 block_find_non_opaque_type_preferred
,
3786 /* Some caution must be observed with overloaded functions
3787 and methods, since the index will not contain any overload
3788 information (but NAME might contain it). */
3791 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3793 if (with_opaque
!= NULL
3794 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3797 /* Keep looking through other CUs. */
3804 dw2_print_stats (struct objfile
*objfile
)
3806 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3807 int total
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3808 + per_objfile
->per_bfd
->all_type_units
.size ());
3811 for (int i
= 0; i
< total
; ++i
)
3813 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3815 if (!per_objfile
->symtab_set_p (per_cu
))
3818 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3819 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3822 /* This dumps minimal information about the index.
3823 It is called via "mt print objfiles".
3824 One use is to verify .gdb_index has been loaded by the
3825 gdb.dwarf2/gdb-index.exp testcase. */
3828 dw2_dump (struct objfile
*objfile
)
3830 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3832 gdb_assert (per_objfile
->per_bfd
->using_index
);
3833 printf_filtered (".gdb_index:");
3834 if (per_objfile
->per_bfd
->index_table
!= NULL
)
3836 printf_filtered (" version %d\n",
3837 per_objfile
->per_bfd
->index_table
->version
);
3840 printf_filtered (" faked for \"readnow\"\n");
3841 printf_filtered ("\n");
3845 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3846 const char *func_name
)
3848 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3850 struct dw2_symtab_iterator iter
;
3851 struct dwarf2_per_cu_data
*per_cu
;
3853 dw2_symtab_iter_init (&iter
, per_objfile
, {}, VAR_DOMAIN
, func_name
);
3855 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3856 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3861 dw2_expand_all_symtabs (struct objfile
*objfile
)
3863 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3864 int total_units
= (per_objfile
->per_bfd
->all_comp_units
.size ()
3865 + per_objfile
->per_bfd
->all_type_units
.size ());
3867 for (int i
= 0; i
< total_units
; ++i
)
3869 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (i
);
3871 /* We don't want to directly expand a partial CU, because if we
3872 read it with the wrong language, then assertion failures can
3873 be triggered later on. See PR symtab/23010. So, tell
3874 dw2_instantiate_symtab to skip partial CUs -- any important
3875 partial CU will be read via DW_TAG_imported_unit anyway. */
3876 dw2_instantiate_symtab (per_cu
, per_objfile
, true);
3881 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3882 const char *fullname
)
3884 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3886 /* We don't need to consider type units here.
3887 This is only called for examining code, e.g. expand_line_sal.
3888 There can be an order of magnitude (or more) more type units
3889 than comp units, and we avoid them if we can. */
3891 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
3893 /* We only need to look at symtabs not already expanded. */
3894 if (per_objfile
->symtab_set_p (per_cu
))
3897 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
3898 if (file_data
== NULL
)
3901 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3903 const char *this_fullname
= file_data
->file_names
[j
];
3905 if (filename_cmp (this_fullname
, fullname
) == 0)
3907 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
3915 dw2_expand_symtabs_matching_symbol
3916 (mapped_index_base
&index
,
3917 const lookup_name_info
&lookup_name_in
,
3918 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3919 enum search_domain kind
,
3920 gdb::function_view
<bool (offset_type
)> match_callback
,
3921 dwarf2_per_objfile
*per_objfile
);
3924 dw2_expand_symtabs_matching_one
3925 (dwarf2_per_cu_data
*per_cu
,
3926 dwarf2_per_objfile
*per_objfile
,
3927 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
3928 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
3931 dw2_map_matching_symbols
3932 (struct objfile
*objfile
,
3933 const lookup_name_info
&name
, domain_enum domain
,
3935 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3936 symbol_compare_ftype
*ordered_compare
)
3939 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
3941 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3943 if (per_objfile
->per_bfd
->index_table
!= nullptr)
3945 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
3947 const char *match_name
= name
.ada ().lookup_name ().c_str ();
3948 auto matcher
= [&] (const char *symname
)
3950 if (ordered_compare
== nullptr)
3952 return ordered_compare (symname
, match_name
) == 0;
3955 dw2_expand_symtabs_matching_symbol (index
, name
, matcher
, ALL_DOMAIN
,
3956 [&] (offset_type namei
)
3958 struct dw2_symtab_iterator iter
;
3959 struct dwarf2_per_cu_data
*per_cu
;
3961 dw2_symtab_iter_init (&iter
, per_objfile
, block_kind
, domain
,
3963 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3964 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
3971 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3972 proceed assuming all symtabs have been read in. */
3975 for (compunit_symtab
*cust
: objfile
->compunits ())
3977 const struct block
*block
;
3981 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3982 if (!iterate_over_symbols_terminated (block
, name
,
3988 /* Starting from a search name, return the string that finds the upper
3989 bound of all strings that start with SEARCH_NAME in a sorted name
3990 list. Returns the empty string to indicate that the upper bound is
3991 the end of the list. */
3994 make_sort_after_prefix_name (const char *search_name
)
3996 /* When looking to complete "func", we find the upper bound of all
3997 symbols that start with "func" by looking for where we'd insert
3998 the closest string that would follow "func" in lexicographical
3999 order. Usually, that's "func"-with-last-character-incremented,
4000 i.e. "fund". Mind non-ASCII characters, though. Usually those
4001 will be UTF-8 multi-byte sequences, but we can't be certain.
4002 Especially mind the 0xff character, which is a valid character in
4003 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4004 rule out compilers allowing it in identifiers. Note that
4005 conveniently, strcmp/strcasecmp are specified to compare
4006 characters interpreted as unsigned char. So what we do is treat
4007 the whole string as a base 256 number composed of a sequence of
4008 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4009 to 0, and carries 1 to the following more-significant position.
4010 If the very first character in SEARCH_NAME ends up incremented
4011 and carries/overflows, then the upper bound is the end of the
4012 list. The string after the empty string is also the empty
4015 Some examples of this operation:
4017 SEARCH_NAME => "+1" RESULT
4021 "\xff" "a" "\xff" => "\xff" "b"
4026 Then, with these symbols for example:
4032 completing "func" looks for symbols between "func" and
4033 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4034 which finds "func" and "func1", but not "fund".
4038 funcÿ (Latin1 'ÿ' [0xff])
4042 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4043 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4047 ÿÿ (Latin1 'ÿ' [0xff])
4050 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4051 the end of the list.
4053 std::string after
= search_name
;
4054 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4056 if (!after
.empty ())
4057 after
.back () = (unsigned char) after
.back () + 1;
4061 /* See declaration. */
4063 std::pair
<std::vector
<name_component
>::const_iterator
,
4064 std::vector
<name_component
>::const_iterator
>
4065 mapped_index_base::find_name_components_bounds
4066 (const lookup_name_info
&lookup_name_without_params
, language lang
,
4067 dwarf2_per_objfile
*per_objfile
) const
4070 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4072 const char *lang_name
4073 = lookup_name_without_params
.language_lookup_name (lang
);
4075 /* Comparison function object for lower_bound that matches against a
4076 given symbol name. */
4077 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4080 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
4081 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4082 return name_cmp (elem_name
, name
) < 0;
4085 /* Comparison function object for upper_bound that matches against a
4086 given symbol name. */
4087 auto lookup_compare_upper
= [&] (const char *name
,
4088 const name_component
&elem
)
4090 const char *elem_qualified
= this->symbol_name_at (elem
.idx
, per_objfile
);
4091 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4092 return name_cmp (name
, elem_name
) < 0;
4095 auto begin
= this->name_components
.begin ();
4096 auto end
= this->name_components
.end ();
4098 /* Find the lower bound. */
4101 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4104 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4107 /* Find the upper bound. */
4110 if (lookup_name_without_params
.completion_mode ())
4112 /* In completion mode, we want UPPER to point past all
4113 symbols names that have the same prefix. I.e., with
4114 these symbols, and completing "func":
4116 function << lower bound
4118 other_function << upper bound
4120 We find the upper bound by looking for the insertion
4121 point of "func"-with-last-character-incremented,
4123 std::string after
= make_sort_after_prefix_name (lang_name
);
4126 return std::lower_bound (lower
, end
, after
.c_str (),
4127 lookup_compare_lower
);
4130 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4133 return {lower
, upper
};
4136 /* See declaration. */
4139 mapped_index_base::build_name_components (dwarf2_per_objfile
*per_objfile
)
4141 if (!this->name_components
.empty ())
4144 this->name_components_casing
= case_sensitivity
;
4146 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4148 /* The code below only knows how to break apart components of C++
4149 symbol names (and other languages that use '::' as
4150 namespace/module separator) and Ada symbol names. */
4151 auto count
= this->symbol_name_count ();
4152 for (offset_type idx
= 0; idx
< count
; idx
++)
4154 if (this->symbol_name_slot_invalid (idx
))
4157 const char *name
= this->symbol_name_at (idx
, per_objfile
);
4159 /* Add each name component to the name component table. */
4160 unsigned int previous_len
= 0;
4162 if (strstr (name
, "::") != nullptr)
4164 for (unsigned int current_len
= cp_find_first_component (name
);
4165 name
[current_len
] != '\0';
4166 current_len
+= cp_find_first_component (name
+ current_len
))
4168 gdb_assert (name
[current_len
] == ':');
4169 this->name_components
.push_back ({previous_len
, idx
});
4170 /* Skip the '::'. */
4172 previous_len
= current_len
;
4177 /* Handle the Ada encoded (aka mangled) form here. */
4178 for (const char *iter
= strstr (name
, "__");
4180 iter
= strstr (iter
, "__"))
4182 this->name_components
.push_back ({previous_len
, idx
});
4184 previous_len
= iter
- name
;
4188 this->name_components
.push_back ({previous_len
, idx
});
4191 /* Sort name_components elements by name. */
4192 auto name_comp_compare
= [&] (const name_component
&left
,
4193 const name_component
&right
)
4195 const char *left_qualified
4196 = this->symbol_name_at (left
.idx
, per_objfile
);
4197 const char *right_qualified
4198 = this->symbol_name_at (right
.idx
, per_objfile
);
4200 const char *left_name
= left_qualified
+ left
.name_offset
;
4201 const char *right_name
= right_qualified
+ right
.name_offset
;
4203 return name_cmp (left_name
, right_name
) < 0;
4206 std::sort (this->name_components
.begin (),
4207 this->name_components
.end (),
4211 /* Helper for dw2_expand_symtabs_matching that works with a
4212 mapped_index_base instead of the containing objfile. This is split
4213 to a separate function in order to be able to unit test the
4214 name_components matching using a mock mapped_index_base. For each
4215 symbol name that matches, calls MATCH_CALLBACK, passing it the
4216 symbol's index in the mapped_index_base symbol table. */
4219 dw2_expand_symtabs_matching_symbol
4220 (mapped_index_base
&index
,
4221 const lookup_name_info
&lookup_name_in
,
4222 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4223 enum search_domain kind
,
4224 gdb::function_view
<bool (offset_type
)> match_callback
,
4225 dwarf2_per_objfile
*per_objfile
)
4227 lookup_name_info lookup_name_without_params
4228 = lookup_name_in
.make_ignore_params ();
4230 /* Build the symbol name component sorted vector, if we haven't
4232 index
.build_name_components (per_objfile
);
4234 /* The same symbol may appear more than once in the range though.
4235 E.g., if we're looking for symbols that complete "w", and we have
4236 a symbol named "w1::w2", we'll find the two name components for
4237 that same symbol in the range. To be sure we only call the
4238 callback once per symbol, we first collect the symbol name
4239 indexes that matched in a temporary vector and ignore
4241 std::vector
<offset_type
> matches
;
4243 struct name_and_matcher
4245 symbol_name_matcher_ftype
*matcher
;
4248 bool operator== (const name_and_matcher
&other
) const
4250 return matcher
== other
.matcher
&& strcmp (name
, other
.name
) == 0;
4254 /* A vector holding all the different symbol name matchers, for all
4256 std::vector
<name_and_matcher
> matchers
;
4258 for (int i
= 0; i
< nr_languages
; i
++)
4260 enum language lang_e
= (enum language
) i
;
4262 const language_defn
*lang
= language_def (lang_e
);
4263 symbol_name_matcher_ftype
*name_matcher
4264 = lang
->get_symbol_name_matcher (lookup_name_without_params
);
4266 name_and_matcher key
{
4268 lookup_name_without_params
.language_lookup_name (lang_e
)
4271 /* Don't insert the same comparison routine more than once.
4272 Note that we do this linear walk. This is not a problem in
4273 practice because the number of supported languages is
4275 if (std::find (matchers
.begin (), matchers
.end (), key
)
4278 matchers
.push_back (std::move (key
));
4281 = index
.find_name_components_bounds (lookup_name_without_params
,
4282 lang_e
, per_objfile
);
4284 /* Now for each symbol name in range, check to see if we have a name
4285 match, and if so, call the MATCH_CALLBACK callback. */
4287 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4289 const char *qualified
4290 = index
.symbol_name_at (bounds
.first
->idx
, per_objfile
);
4292 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4293 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4296 matches
.push_back (bounds
.first
->idx
);
4300 std::sort (matches
.begin (), matches
.end ());
4302 /* Finally call the callback, once per match. */
4304 for (offset_type idx
: matches
)
4308 if (!match_callback (idx
))
4314 /* Above we use a type wider than idx's for 'prev', since 0 and
4315 (offset_type)-1 are both possible values. */
4316 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4321 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4323 /* A mock .gdb_index/.debug_names-like name index table, enough to
4324 exercise dw2_expand_symtabs_matching_symbol, which works with the
4325 mapped_index_base interface. Builds an index from the symbol list
4326 passed as parameter to the constructor. */
4327 class mock_mapped_index
: public mapped_index_base
4330 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4331 : m_symbol_table (symbols
)
4334 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4336 /* Return the number of names in the symbol table. */
4337 size_t symbol_name_count () const override
4339 return m_symbol_table
.size ();
4342 /* Get the name of the symbol at IDX in the symbol table. */
4343 const char *symbol_name_at
4344 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
4346 return m_symbol_table
[idx
];
4350 gdb::array_view
<const char *> m_symbol_table
;
4353 /* Convenience function that converts a NULL pointer to a "<null>"
4354 string, to pass to print routines. */
4357 string_or_null (const char *str
)
4359 return str
!= NULL
? str
: "<null>";
4362 /* Check if a lookup_name_info built from
4363 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4364 index. EXPECTED_LIST is the list of expected matches, in expected
4365 matching order. If no match expected, then an empty list is
4366 specified. Returns true on success. On failure prints a warning
4367 indicating the file:line that failed, and returns false. */
4370 check_match (const char *file
, int line
,
4371 mock_mapped_index
&mock_index
,
4372 const char *name
, symbol_name_match_type match_type
,
4373 bool completion_mode
,
4374 std::initializer_list
<const char *> expected_list
,
4375 dwarf2_per_objfile
*per_objfile
)
4377 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4379 bool matched
= true;
4381 auto mismatch
= [&] (const char *expected_str
,
4384 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4385 "expected=\"%s\", got=\"%s\"\n"),
4387 (match_type
== symbol_name_match_type::FULL
4389 name
, string_or_null (expected_str
), string_or_null (got
));
4393 auto expected_it
= expected_list
.begin ();
4394 auto expected_end
= expected_list
.end ();
4396 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4398 [&] (offset_type idx
)
4400 const char *matched_name
= mock_index
.symbol_name_at (idx
, per_objfile
);
4401 const char *expected_str
4402 = expected_it
== expected_end
? NULL
: *expected_it
++;
4404 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4405 mismatch (expected_str
, matched_name
);
4409 const char *expected_str
4410 = expected_it
== expected_end
? NULL
: *expected_it
++;
4411 if (expected_str
!= NULL
)
4412 mismatch (expected_str
, NULL
);
4417 /* The symbols added to the mock mapped_index for testing (in
4419 static const char *test_symbols
[] = {
4428 "ns2::tmpl<int>::foo2",
4429 "(anonymous namespace)::A::B::C",
4431 /* These are used to check that the increment-last-char in the
4432 matching algorithm for completion doesn't match "t1_fund" when
4433 completing "t1_func". */
4439 /* A UTF-8 name with multi-byte sequences to make sure that
4440 cp-name-parser understands this as a single identifier ("função"
4441 is "function" in PT). */
4444 /* \377 (0xff) is Latin1 'ÿ'. */
4447 /* \377 (0xff) is Latin1 'ÿ'. */
4451 /* A name with all sorts of complications. Starts with "z" to make
4452 it easier for the completion tests below. */
4453 #define Z_SYM_NAME \
4454 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4455 "::tuple<(anonymous namespace)::ui*, " \
4456 "std::default_delete<(anonymous namespace)::ui>, void>"
4461 /* Returns true if the mapped_index_base::find_name_component_bounds
4462 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4463 in completion mode. */
4466 check_find_bounds_finds (mapped_index_base
&index
,
4467 const char *search_name
,
4468 gdb::array_view
<const char *> expected_syms
,
4469 dwarf2_per_objfile
*per_objfile
)
4471 lookup_name_info
lookup_name (search_name
,
4472 symbol_name_match_type::FULL
, true);
4474 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4478 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4479 if (distance
!= expected_syms
.size ())
4482 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4484 auto nc_elem
= bounds
.first
+ exp_elem
;
4485 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
, per_objfile
);
4486 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4493 /* Test the lower-level mapped_index::find_name_component_bounds
4497 test_mapped_index_find_name_component_bounds ()
4499 mock_mapped_index
mock_index (test_symbols
);
4501 mock_index
.build_name_components (NULL
/* per_objfile */);
4503 /* Test the lower-level mapped_index::find_name_component_bounds
4504 method in completion mode. */
4506 static const char *expected_syms
[] = {
4511 SELF_CHECK (check_find_bounds_finds
4512 (mock_index
, "t1_func", expected_syms
,
4513 NULL
/* per_objfile */));
4516 /* Check that the increment-last-char in the name matching algorithm
4517 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4519 static const char *expected_syms1
[] = {
4523 SELF_CHECK (check_find_bounds_finds
4524 (mock_index
, "\377", expected_syms1
, NULL
/* per_objfile */));
4526 static const char *expected_syms2
[] = {
4529 SELF_CHECK (check_find_bounds_finds
4530 (mock_index
, "\377\377", expected_syms2
,
4531 NULL
/* per_objfile */));
4535 /* Test dw2_expand_symtabs_matching_symbol. */
4538 test_dw2_expand_symtabs_matching_symbol ()
4540 mock_mapped_index
mock_index (test_symbols
);
4542 /* We let all tests run until the end even if some fails, for debug
4544 bool any_mismatch
= false;
4546 /* Create the expected symbols list (an initializer_list). Needed
4547 because lists have commas, and we need to pass them to CHECK,
4548 which is a macro. */
4549 #define EXPECT(...) { __VA_ARGS__ }
4551 /* Wrapper for check_match that passes down the current
4552 __FILE__/__LINE__. */
4553 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4554 any_mismatch |= !check_match (__FILE__, __LINE__, \
4556 NAME, MATCH_TYPE, COMPLETION_MODE, \
4557 EXPECTED_LIST, NULL)
4559 /* Identity checks. */
4560 for (const char *sym
: test_symbols
)
4562 /* Should be able to match all existing symbols. */
4563 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4566 /* Should be able to match all existing symbols with
4568 std::string with_params
= std::string (sym
) + "(int)";
4569 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4572 /* Should be able to match all existing symbols with
4573 parameters and qualifiers. */
4574 with_params
= std::string (sym
) + " ( int ) const";
4575 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4578 /* This should really find sym, but cp-name-parser.y doesn't
4579 know about lvalue/rvalue qualifiers yet. */
4580 with_params
= std::string (sym
) + " ( int ) &&";
4581 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4585 /* Check that the name matching algorithm for completion doesn't get
4586 confused with Latin1 'ÿ' / 0xff. */
4588 static const char str
[] = "\377";
4589 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4590 EXPECT ("\377", "\377\377123"));
4593 /* Check that the increment-last-char in the matching algorithm for
4594 completion doesn't match "t1_fund" when completing "t1_func". */
4596 static const char str
[] = "t1_func";
4597 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4598 EXPECT ("t1_func", "t1_func1"));
4601 /* Check that completion mode works at each prefix of the expected
4604 static const char str
[] = "function(int)";
4605 size_t len
= strlen (str
);
4608 for (size_t i
= 1; i
< len
; i
++)
4610 lookup
.assign (str
, i
);
4611 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4612 EXPECT ("function"));
4616 /* While "w" is a prefix of both components, the match function
4617 should still only be called once. */
4619 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4621 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4625 /* Same, with a "complicated" symbol. */
4627 static const char str
[] = Z_SYM_NAME
;
4628 size_t len
= strlen (str
);
4631 for (size_t i
= 1; i
< len
; i
++)
4633 lookup
.assign (str
, i
);
4634 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4635 EXPECT (Z_SYM_NAME
));
4639 /* In FULL mode, an incomplete symbol doesn't match. */
4641 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4645 /* A complete symbol with parameters matches any overload, since the
4646 index has no overload info. */
4648 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4649 EXPECT ("std::zfunction", "std::zfunction2"));
4650 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4651 EXPECT ("std::zfunction", "std::zfunction2"));
4652 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4653 EXPECT ("std::zfunction", "std::zfunction2"));
4656 /* Check that whitespace is ignored appropriately. A symbol with a
4657 template argument list. */
4659 static const char expected
[] = "ns::foo<int>";
4660 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4662 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4666 /* Check that whitespace is ignored appropriately. A symbol with a
4667 template argument list that includes a pointer. */
4669 static const char expected
[] = "ns::foo<char*>";
4670 /* Try both completion and non-completion modes. */
4671 static const bool completion_mode
[2] = {false, true};
4672 for (size_t i
= 0; i
< 2; i
++)
4674 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4675 completion_mode
[i
], EXPECT (expected
));
4676 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4677 completion_mode
[i
], EXPECT (expected
));
4679 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4680 completion_mode
[i
], EXPECT (expected
));
4681 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4682 completion_mode
[i
], EXPECT (expected
));
4687 /* Check method qualifiers are ignored. */
4688 static const char expected
[] = "ns::foo<char*>";
4689 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4690 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4691 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4692 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4693 CHECK_MATCH ("foo < char * > ( int ) const",
4694 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4695 CHECK_MATCH ("foo < char * > ( int ) &&",
4696 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4699 /* Test lookup names that don't match anything. */
4701 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4704 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4708 /* Some wild matching tests, exercising "(anonymous namespace)",
4709 which should not be confused with a parameter list. */
4711 static const char *syms
[] = {
4715 "A :: B :: C ( int )",
4720 for (const char *s
: syms
)
4722 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4723 EXPECT ("(anonymous namespace)::A::B::C"));
4728 static const char expected
[] = "ns2::tmpl<int>::foo2";
4729 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4731 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4735 SELF_CHECK (!any_mismatch
);
4744 test_mapped_index_find_name_component_bounds ();
4745 test_dw2_expand_symtabs_matching_symbol ();
4748 }} // namespace selftests::dw2_expand_symtabs_matching
4750 #endif /* GDB_SELF_TEST */
4752 /* If FILE_MATCHER is NULL or if PER_CU has
4753 dwarf2_per_cu_quick_data::MARK set (see
4754 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4755 EXPANSION_NOTIFY on it. */
4758 dw2_expand_symtabs_matching_one
4759 (dwarf2_per_cu_data
*per_cu
,
4760 dwarf2_per_objfile
*per_objfile
,
4761 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4762 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4764 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4766 bool symtab_was_null
= !per_objfile
->symtab_set_p (per_cu
);
4768 compunit_symtab
*symtab
4769 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
4770 gdb_assert (symtab
!= nullptr);
4772 if (expansion_notify
!= NULL
&& symtab_was_null
)
4773 expansion_notify (symtab
);
4777 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4778 matched, to expand corresponding CUs that were marked. IDX is the
4779 index of the symbol name that matched. */
4782 dw2_expand_marked_cus
4783 (dwarf2_per_objfile
*per_objfile
, offset_type idx
,
4784 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4785 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4788 offset_type
*vec
, vec_len
, vec_idx
;
4789 bool global_seen
= false;
4790 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4792 vec
= (offset_type
*) (index
.constant_pool
4793 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4794 vec_len
= MAYBE_SWAP (vec
[0]);
4795 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4797 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4798 /* This value is only valid for index versions >= 7. */
4799 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4800 gdb_index_symbol_kind symbol_kind
=
4801 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4802 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4803 /* Only check the symbol attributes if they're present.
4804 Indices prior to version 7 don't record them,
4805 and indices >= 7 may elide them for certain symbols
4806 (gold does this). */
4809 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4811 /* Work around gold/15646. */
4814 && symbol_kind
== GDB_INDEX_SYMBOL_KIND_TYPE
)
4822 /* Only check the symbol's kind if it has one. */
4827 case VARIABLES_DOMAIN
:
4828 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4831 case FUNCTIONS_DOMAIN
:
4832 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4836 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4839 case MODULES_DOMAIN
:
4840 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4848 /* Don't crash on bad data. */
4849 if (cu_index
>= (per_objfile
->per_bfd
->all_comp_units
.size ()
4850 + per_objfile
->per_bfd
->all_type_units
.size ()))
4852 complaint (_(".gdb_index entry has bad CU index"
4853 " [in module %s]"), objfile_name (per_objfile
->objfile
));
4857 dwarf2_per_cu_data
*per_cu
= per_objfile
->per_bfd
->get_cutu (cu_index
);
4858 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
4863 /* If FILE_MATCHER is non-NULL, set all the
4864 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4865 that match FILE_MATCHER. */
4868 dw_expand_symtabs_matching_file_matcher
4869 (dwarf2_per_objfile
*per_objfile
,
4870 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4872 if (file_matcher
== NULL
)
4875 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4877 NULL
, xcalloc
, xfree
));
4878 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4880 NULL
, xcalloc
, xfree
));
4882 /* The rule is CUs specify all the files, including those used by
4883 any TU, so there's no need to scan TUs here. */
4885 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4889 per_cu
->v
.quick
->mark
= 0;
4891 /* We only need to look at symtabs not already expanded. */
4892 if (per_objfile
->symtab_set_p (per_cu
))
4895 quick_file_names
*file_data
= dw2_get_file_names (per_cu
, per_objfile
);
4896 if (file_data
== NULL
)
4899 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4901 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4903 per_cu
->v
.quick
->mark
= 1;
4907 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4909 const char *this_real_name
;
4911 if (file_matcher (file_data
->file_names
[j
], false))
4913 per_cu
->v
.quick
->mark
= 1;
4917 /* Before we invoke realpath, which can get expensive when many
4918 files are involved, do a quick comparison of the basenames. */
4919 if (!basenames_may_differ
4920 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4924 this_real_name
= dw2_get_real_path (per_objfile
, file_data
, j
);
4925 if (file_matcher (this_real_name
, false))
4927 per_cu
->v
.quick
->mark
= 1;
4932 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4933 ? visited_found
.get ()
4934 : visited_not_found
.get (),
4941 dw2_expand_symtabs_matching
4942 (struct objfile
*objfile
,
4943 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4944 const lookup_name_info
*lookup_name
,
4945 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4946 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4947 enum search_domain kind
)
4949 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
4951 /* index_table is NULL if OBJF_READNOW. */
4952 if (!per_objfile
->per_bfd
->index_table
)
4955 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
4957 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
4959 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
4963 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
4964 file_matcher
, expansion_notify
);
4969 mapped_index
&index
= *per_objfile
->per_bfd
->index_table
;
4971 dw2_expand_symtabs_matching_symbol (index
, *lookup_name
,
4973 kind
, [&] (offset_type idx
)
4975 dw2_expand_marked_cus (per_objfile
, idx
, file_matcher
, expansion_notify
,
4981 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4984 static struct compunit_symtab
*
4985 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4990 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4991 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4994 if (cust
->includes
== NULL
)
4997 for (i
= 0; cust
->includes
[i
]; ++i
)
4999 struct compunit_symtab
*s
= cust
->includes
[i
];
5001 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5009 static struct compunit_symtab
*
5010 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5011 struct bound_minimal_symbol msymbol
,
5013 struct obj_section
*section
,
5016 struct dwarf2_per_cu_data
*data
;
5017 struct compunit_symtab
*result
;
5019 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5022 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
5023 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5024 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5028 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5029 if (warn_if_readin
&& per_objfile
->symtab_set_p (data
))
5030 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5031 paddress (objfile
->arch (), pc
));
5033 result
= recursively_find_pc_sect_compunit_symtab
5034 (dw2_instantiate_symtab (data
, per_objfile
, false), pc
);
5036 gdb_assert (result
!= NULL
);
5041 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5042 void *data
, int need_fullname
)
5044 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5046 if (!per_objfile
->per_bfd
->filenames_cache
)
5048 per_objfile
->per_bfd
->filenames_cache
.emplace ();
5050 htab_up
visited (htab_create_alloc (10,
5051 htab_hash_pointer
, htab_eq_pointer
,
5052 NULL
, xcalloc
, xfree
));
5054 /* The rule is CUs specify all the files, including those used
5055 by any TU, so there's no need to scan TUs here. We can
5056 ignore file names coming from already-expanded CUs. */
5058 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5060 if (per_objfile
->symtab_set_p (per_cu
))
5062 void **slot
= htab_find_slot (visited
.get (),
5063 per_cu
->v
.quick
->file_names
,
5066 *slot
= per_cu
->v
.quick
->file_names
;
5070 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5072 /* We only need to look at symtabs not already expanded. */
5073 if (per_objfile
->symtab_set_p (per_cu
))
5076 quick_file_names
*file_data
5077 = dw2_get_file_names (per_cu
, per_objfile
);
5078 if (file_data
== NULL
)
5081 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5084 /* Already visited. */
5089 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5091 const char *filename
= file_data
->file_names
[j
];
5092 per_objfile
->per_bfd
->filenames_cache
->seen (filename
);
5097 per_objfile
->per_bfd
->filenames_cache
->traverse ([&] (const char *filename
)
5099 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5102 this_real_name
= gdb_realpath (filename
);
5103 (*fun
) (filename
, this_real_name
.get (), data
);
5108 dw2_has_symbols (struct objfile
*objfile
)
5113 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5116 dw2_find_last_source_symtab
,
5117 dw2_forget_cached_source_info
,
5118 dw2_map_symtabs_matching_filename
,
5123 dw2_expand_symtabs_for_function
,
5124 dw2_expand_all_symtabs
,
5125 dw2_expand_symtabs_with_fullname
,
5126 dw2_map_matching_symbols
,
5127 dw2_expand_symtabs_matching
,
5128 dw2_find_pc_sect_compunit_symtab
,
5130 dw2_map_symbol_filenames
5133 /* DWARF-5 debug_names reader. */
5135 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5136 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5138 /* A helper function that reads the .debug_names section in SECTION
5139 and fills in MAP. FILENAME is the name of the file containing the
5140 section; it is used for error reporting.
5142 Returns true if all went well, false otherwise. */
5145 read_debug_names_from_section (struct objfile
*objfile
,
5146 const char *filename
,
5147 struct dwarf2_section_info
*section
,
5148 mapped_debug_names
&map
)
5150 if (section
->empty ())
5153 /* Older elfutils strip versions could keep the section in the main
5154 executable while splitting it for the separate debug info file. */
5155 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5158 section
->read (objfile
);
5160 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
5162 const gdb_byte
*addr
= section
->buffer
;
5164 bfd
*const abfd
= section
->get_bfd_owner ();
5166 unsigned int bytes_read
;
5167 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5170 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5171 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5172 if (bytes_read
+ length
!= section
->size
)
5174 /* There may be multiple per-CU indices. */
5175 warning (_("Section .debug_names in %s length %s does not match "
5176 "section length %s, ignoring .debug_names."),
5177 filename
, plongest (bytes_read
+ length
),
5178 pulongest (section
->size
));
5182 /* The version number. */
5183 uint16_t version
= read_2_bytes (abfd
, addr
);
5187 warning (_("Section .debug_names in %s has unsupported version %d, "
5188 "ignoring .debug_names."),
5194 uint16_t padding
= read_2_bytes (abfd
, addr
);
5198 warning (_("Section .debug_names in %s has unsupported padding %d, "
5199 "ignoring .debug_names."),
5204 /* comp_unit_count - The number of CUs in the CU list. */
5205 map
.cu_count
= read_4_bytes (abfd
, addr
);
5208 /* local_type_unit_count - The number of TUs in the local TU
5210 map
.tu_count
= read_4_bytes (abfd
, addr
);
5213 /* foreign_type_unit_count - The number of TUs in the foreign TU
5215 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5217 if (foreign_tu_count
!= 0)
5219 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5220 "ignoring .debug_names."),
5221 filename
, static_cast<unsigned long> (foreign_tu_count
));
5225 /* bucket_count - The number of hash buckets in the hash lookup
5227 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5230 /* name_count - The number of unique names in the index. */
5231 map
.name_count
= read_4_bytes (abfd
, addr
);
5234 /* abbrev_table_size - The size in bytes of the abbreviations
5236 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5239 /* augmentation_string_size - The size in bytes of the augmentation
5240 string. This value is rounded up to a multiple of 4. */
5241 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5243 map
.augmentation_is_gdb
= ((augmentation_string_size
5244 == sizeof (dwarf5_augmentation
))
5245 && memcmp (addr
, dwarf5_augmentation
,
5246 sizeof (dwarf5_augmentation
)) == 0);
5247 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5248 addr
+= augmentation_string_size
;
5251 map
.cu_table_reordered
= addr
;
5252 addr
+= map
.cu_count
* map
.offset_size
;
5254 /* List of Local TUs */
5255 map
.tu_table_reordered
= addr
;
5256 addr
+= map
.tu_count
* map
.offset_size
;
5258 /* Hash Lookup Table */
5259 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5260 addr
+= map
.bucket_count
* 4;
5261 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5262 addr
+= map
.name_count
* 4;
5265 map
.name_table_string_offs_reordered
= addr
;
5266 addr
+= map
.name_count
* map
.offset_size
;
5267 map
.name_table_entry_offs_reordered
= addr
;
5268 addr
+= map
.name_count
* map
.offset_size
;
5270 const gdb_byte
*abbrev_table_start
= addr
;
5273 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5278 const auto insertpair
5279 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5280 if (!insertpair
.second
)
5282 warning (_("Section .debug_names in %s has duplicate index %s, "
5283 "ignoring .debug_names."),
5284 filename
, pulongest (index_num
));
5287 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5288 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5293 mapped_debug_names::index_val::attr attr
;
5294 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5296 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5298 if (attr
.form
== DW_FORM_implicit_const
)
5300 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5304 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5306 indexval
.attr_vec
.push_back (std::move (attr
));
5309 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5311 warning (_("Section .debug_names in %s has abbreviation_table "
5312 "of size %s vs. written as %u, ignoring .debug_names."),
5313 filename
, plongest (addr
- abbrev_table_start
),
5317 map
.entry_pool
= addr
;
5322 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5326 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
5327 const mapped_debug_names
&map
,
5328 dwarf2_section_info
§ion
,
5331 if (!map
.augmentation_is_gdb
)
5333 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
5335 sect_offset sect_off
5336 = (sect_offset
) (extract_unsigned_integer
5337 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5339 map
.dwarf5_byte_order
));
5340 /* We don't know the length of the CU, because the CU list in a
5341 .debug_names index can be incomplete, so we can't use the start
5342 of the next CU as end of this CU. We create the CUs here with
5343 length 0, and in cutu_reader::cutu_reader we'll fill in the
5345 dwarf2_per_cu_data
*per_cu
5346 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5348 per_bfd
->all_comp_units
.push_back (per_cu
);
5353 sect_offset sect_off_prev
;
5354 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5356 sect_offset sect_off_next
;
5357 if (i
< map
.cu_count
)
5360 = (sect_offset
) (extract_unsigned_integer
5361 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5363 map
.dwarf5_byte_order
));
5366 sect_off_next
= (sect_offset
) section
.size
;
5369 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5370 dwarf2_per_cu_data
*per_cu
5371 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
5372 sect_off_prev
, length
);
5373 per_bfd
->all_comp_units
.push_back (per_cu
);
5375 sect_off_prev
= sect_off_next
;
5379 /* Read the CU list from the mapped index, and use it to create all
5380 the CU objects for this dwarf2_per_objfile. */
5383 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
5384 const mapped_debug_names
&map
,
5385 const mapped_debug_names
&dwz_map
)
5387 gdb_assert (per_bfd
->all_comp_units
.empty ());
5388 per_bfd
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5390 create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
5391 false /* is_dwz */);
5393 if (dwz_map
.cu_count
== 0)
5396 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5397 create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
5401 /* Read .debug_names. If everything went ok, initialize the "quick"
5402 elements of all the CUs and return true. Otherwise, return false. */
5405 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
5407 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
5408 mapped_debug_names dwz_map
;
5409 struct objfile
*objfile
= per_objfile
->objfile
;
5410 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
5412 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5413 &per_objfile
->per_bfd
->debug_names
, *map
))
5416 /* Don't use the index if it's empty. */
5417 if (map
->name_count
== 0)
5420 /* If there is a .dwz file, read it so we can get its CU list as
5422 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
5425 if (!read_debug_names_from_section (objfile
,
5426 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5427 &dwz
->debug_names
, dwz_map
))
5429 warning (_("could not read '.debug_names' section from %s; skipping"),
5430 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5435 create_cus_from_debug_names (per_bfd
, *map
, dwz_map
);
5437 if (map
->tu_count
!= 0)
5439 /* We can only handle a single .debug_types when we have an
5441 if (per_bfd
->types
.size () != 1)
5444 dwarf2_section_info
*section
= &per_bfd
->types
[0];
5446 create_signatured_type_table_from_debug_names
5447 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
5450 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
5452 per_bfd
->debug_names_table
= std::move (map
);
5453 per_bfd
->using_index
= 1;
5454 per_bfd
->quick_file_names_table
=
5455 create_quick_file_names_table (per_objfile
->per_bfd
->all_comp_units
.size ());
5457 /* Save partial symtabs in the per_bfd object, for the benefit of subsequent
5458 objfiles using the same BFD. */
5459 gdb_assert (per_bfd
->partial_symtabs
== nullptr);
5460 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
5465 /* Type used to manage iterating over all CUs looking for a symbol for
5468 class dw2_debug_names_iterator
5471 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5472 gdb::optional
<block_enum
> block_index
,
5474 const char *name
, dwarf2_per_objfile
*per_objfile
)
5475 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5476 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
5477 m_per_objfile (per_objfile
)
5480 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5481 search_domain search
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5484 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5485 m_per_objfile (per_objfile
)
5488 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5489 block_enum block_index
, domain_enum domain
,
5490 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5491 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5492 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
5493 m_per_objfile (per_objfile
)
5496 /* Return the next matching CU or NULL if there are no more. */
5497 dwarf2_per_cu_data
*next ();
5500 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5502 dwarf2_per_objfile
*per_objfile
);
5503 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5505 dwarf2_per_objfile
*per_objfile
);
5507 /* The internalized form of .debug_names. */
5508 const mapped_debug_names
&m_map
;
5510 /* If set, only look for symbols that match that block. Valid values are
5511 GLOBAL_BLOCK and STATIC_BLOCK. */
5512 const gdb::optional
<block_enum
> m_block_index
;
5514 /* The kind of symbol we're looking for. */
5515 const domain_enum m_domain
= UNDEF_DOMAIN
;
5516 const search_domain m_search
= ALL_DOMAIN
;
5518 /* The list of CUs from the index entry of the symbol, or NULL if
5520 const gdb_byte
*m_addr
;
5522 dwarf2_per_objfile
*m_per_objfile
;
5526 mapped_debug_names::namei_to_name
5527 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
5529 const ULONGEST namei_string_offs
5530 = extract_unsigned_integer ((name_table_string_offs_reordered
5531 + namei
* offset_size
),
5534 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
5537 /* Find a slot in .debug_names for the object named NAME. If NAME is
5538 found, return pointer to its pool data. If NAME cannot be found,
5542 dw2_debug_names_iterator::find_vec_in_debug_names
5543 (const mapped_debug_names
&map
, const char *name
,
5544 dwarf2_per_objfile
*per_objfile
)
5546 int (*cmp
) (const char *, const char *);
5548 gdb::unique_xmalloc_ptr
<char> without_params
;
5549 if (current_language
->la_language
== language_cplus
5550 || current_language
->la_language
== language_fortran
5551 || current_language
->la_language
== language_d
)
5553 /* NAME is already canonical. Drop any qualifiers as
5554 .debug_names does not contain any. */
5556 if (strchr (name
, '(') != NULL
)
5558 without_params
= cp_remove_params (name
);
5559 if (without_params
!= NULL
)
5560 name
= without_params
.get ();
5564 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5566 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5568 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5569 (map
.bucket_table_reordered
5570 + (full_hash
% map
.bucket_count
)), 4,
5571 map
.dwarf5_byte_order
);
5575 if (namei
>= map
.name_count
)
5577 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5579 namei
, map
.name_count
,
5580 objfile_name (per_objfile
->objfile
));
5586 const uint32_t namei_full_hash
5587 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5588 (map
.hash_table_reordered
+ namei
), 4,
5589 map
.dwarf5_byte_order
);
5590 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5593 if (full_hash
== namei_full_hash
)
5595 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
5597 #if 0 /* An expensive sanity check. */
5598 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5600 complaint (_("Wrong .debug_names hash for string at index %u "
5602 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5607 if (cmp (namei_string
, name
) == 0)
5609 const ULONGEST namei_entry_offs
5610 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5611 + namei
* map
.offset_size
),
5612 map
.offset_size
, map
.dwarf5_byte_order
);
5613 return map
.entry_pool
+ namei_entry_offs
;
5618 if (namei
>= map
.name_count
)
5624 dw2_debug_names_iterator::find_vec_in_debug_names
5625 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
5627 if (namei
>= map
.name_count
)
5629 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5631 namei
, map
.name_count
,
5632 objfile_name (per_objfile
->objfile
));
5636 const ULONGEST namei_entry_offs
5637 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5638 + namei
* map
.offset_size
),
5639 map
.offset_size
, map
.dwarf5_byte_order
);
5640 return map
.entry_pool
+ namei_entry_offs
;
5643 /* See dw2_debug_names_iterator. */
5645 dwarf2_per_cu_data
*
5646 dw2_debug_names_iterator::next ()
5651 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
5652 struct objfile
*objfile
= m_per_objfile
->objfile
;
5653 bfd
*const abfd
= objfile
->obfd
;
5657 unsigned int bytes_read
;
5658 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5659 m_addr
+= bytes_read
;
5663 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5664 if (indexval_it
== m_map
.abbrev_map
.cend ())
5666 complaint (_("Wrong .debug_names undefined abbrev code %s "
5668 pulongest (abbrev
), objfile_name (objfile
));
5671 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5672 enum class symbol_linkage
{
5676 } symbol_linkage_
= symbol_linkage::unknown
;
5677 dwarf2_per_cu_data
*per_cu
= NULL
;
5678 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5683 case DW_FORM_implicit_const
:
5684 ull
= attr
.implicit_const
;
5686 case DW_FORM_flag_present
:
5690 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5691 m_addr
+= bytes_read
;
5694 ull
= read_4_bytes (abfd
, m_addr
);
5698 ull
= read_8_bytes (abfd
, m_addr
);
5701 case DW_FORM_ref_sig8
:
5702 ull
= read_8_bytes (abfd
, m_addr
);
5706 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5707 dwarf_form_name (attr
.form
),
5708 objfile_name (objfile
));
5711 switch (attr
.dw_idx
)
5713 case DW_IDX_compile_unit
:
5714 /* Don't crash on bad data. */
5715 if (ull
>= m_per_objfile
->per_bfd
->all_comp_units
.size ())
5717 complaint (_(".debug_names entry has bad CU index %s"
5720 objfile_name (objfile
));
5723 per_cu
= per_bfd
->get_cutu (ull
);
5725 case DW_IDX_type_unit
:
5726 /* Don't crash on bad data. */
5727 if (ull
>= per_bfd
->all_type_units
.size ())
5729 complaint (_(".debug_names entry has bad TU index %s"
5732 objfile_name (objfile
));
5735 per_cu
= &per_bfd
->get_tu (ull
)->per_cu
;
5737 case DW_IDX_die_offset
:
5738 /* In a per-CU index (as opposed to a per-module index), index
5739 entries without CU attribute implicitly refer to the single CU. */
5741 per_cu
= per_bfd
->get_cu (0);
5743 case DW_IDX_GNU_internal
:
5744 if (!m_map
.augmentation_is_gdb
)
5746 symbol_linkage_
= symbol_linkage::static_
;
5748 case DW_IDX_GNU_external
:
5749 if (!m_map
.augmentation_is_gdb
)
5751 symbol_linkage_
= symbol_linkage::extern_
;
5756 /* Skip if already read in. */
5757 if (m_per_objfile
->symtab_set_p (per_cu
))
5760 /* Check static vs global. */
5761 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5763 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5764 const bool symbol_is_static
=
5765 symbol_linkage_
== symbol_linkage::static_
;
5766 if (want_static
!= symbol_is_static
)
5770 /* Match dw2_symtab_iter_next, symbol_kind
5771 and debug_names::psymbol_tag. */
5775 switch (indexval
.dwarf_tag
)
5777 case DW_TAG_variable
:
5778 case DW_TAG_subprogram
:
5779 /* Some types are also in VAR_DOMAIN. */
5780 case DW_TAG_typedef
:
5781 case DW_TAG_structure_type
:
5788 switch (indexval
.dwarf_tag
)
5790 case DW_TAG_typedef
:
5791 case DW_TAG_structure_type
:
5798 switch (indexval
.dwarf_tag
)
5801 case DW_TAG_variable
:
5808 switch (indexval
.dwarf_tag
)
5820 /* Match dw2_expand_symtabs_matching, symbol_kind and
5821 debug_names::psymbol_tag. */
5824 case VARIABLES_DOMAIN
:
5825 switch (indexval
.dwarf_tag
)
5827 case DW_TAG_variable
:
5833 case FUNCTIONS_DOMAIN
:
5834 switch (indexval
.dwarf_tag
)
5836 case DW_TAG_subprogram
:
5843 switch (indexval
.dwarf_tag
)
5845 case DW_TAG_typedef
:
5846 case DW_TAG_structure_type
:
5852 case MODULES_DOMAIN
:
5853 switch (indexval
.dwarf_tag
)
5867 static struct compunit_symtab
*
5868 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5869 const char *name
, domain_enum domain
)
5871 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5873 const auto &mapp
= per_objfile
->per_bfd
->debug_names_table
;
5876 /* index is NULL if OBJF_READNOW. */
5879 const auto &map
= *mapp
;
5881 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
, per_objfile
);
5883 struct compunit_symtab
*stab_best
= NULL
;
5884 struct dwarf2_per_cu_data
*per_cu
;
5885 while ((per_cu
= iter
.next ()) != NULL
)
5887 struct symbol
*sym
, *with_opaque
= NULL
;
5888 compunit_symtab
*stab
5889 = dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5890 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5891 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5893 sym
= block_find_symbol (block
, name
, domain
,
5894 block_find_non_opaque_type_preferred
,
5897 /* Some caution must be observed with overloaded functions and
5898 methods, since the index will not contain any overload
5899 information (but NAME might contain it). */
5902 && strcmp_iw (sym
->search_name (), name
) == 0)
5904 if (with_opaque
!= NULL
5905 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5908 /* Keep looking through other CUs. */
5914 /* This dumps minimal information about .debug_names. It is called
5915 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5916 uses this to verify that .debug_names has been loaded. */
5919 dw2_debug_names_dump (struct objfile
*objfile
)
5921 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5923 gdb_assert (per_objfile
->per_bfd
->using_index
);
5924 printf_filtered (".debug_names:");
5925 if (per_objfile
->per_bfd
->debug_names_table
)
5926 printf_filtered (" exists\n");
5928 printf_filtered (" faked for \"readnow\"\n");
5929 printf_filtered ("\n");
5933 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5934 const char *func_name
)
5936 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5938 /* per_objfile->per_bfd->debug_names_table is NULL if OBJF_READNOW. */
5939 if (per_objfile
->per_bfd
->debug_names_table
)
5941 const mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5943 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
,
5946 struct dwarf2_per_cu_data
*per_cu
;
5947 while ((per_cu
= iter
.next ()) != NULL
)
5948 dw2_instantiate_symtab (per_cu
, per_objfile
, false);
5953 dw2_debug_names_map_matching_symbols
5954 (struct objfile
*objfile
,
5955 const lookup_name_info
&name
, domain_enum domain
,
5957 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5958 symbol_compare_ftype
*ordered_compare
)
5960 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
5962 /* debug_names_table is NULL if OBJF_READNOW. */
5963 if (!per_objfile
->per_bfd
->debug_names_table
)
5966 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
5967 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5969 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5970 auto matcher
= [&] (const char *symname
)
5972 if (ordered_compare
== nullptr)
5974 return ordered_compare (symname
, match_name
) == 0;
5977 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5978 [&] (offset_type namei
)
5980 /* The name was matched, now expand corresponding CUs that were
5982 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
,
5985 struct dwarf2_per_cu_data
*per_cu
;
5986 while ((per_cu
= iter
.next ()) != NULL
)
5987 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
5992 /* It's a shame we couldn't do this inside the
5993 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5994 that have already been expanded. Instead, this loop matches what
5995 the psymtab code does. */
5996 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
5998 compunit_symtab
*symtab
= per_objfile
->get_symtab (per_cu
);
5999 if (symtab
!= nullptr)
6001 const struct block
*block
6002 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab
), block_kind
);
6003 if (!iterate_over_symbols_terminated (block
, name
,
6011 dw2_debug_names_expand_symtabs_matching
6012 (struct objfile
*objfile
,
6013 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6014 const lookup_name_info
*lookup_name
,
6015 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6016 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6017 enum search_domain kind
)
6019 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6021 /* debug_names_table is NULL if OBJF_READNOW. */
6022 if (!per_objfile
->per_bfd
->debug_names_table
)
6025 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
6027 if (symbol_matcher
== NULL
&& lookup_name
== NULL
)
6029 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
6033 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
6039 mapped_debug_names
&map
= *per_objfile
->per_bfd
->debug_names_table
;
6041 dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
6043 kind
, [&] (offset_type namei
)
6045 /* The name was matched, now expand corresponding CUs that were
6047 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
);
6049 struct dwarf2_per_cu_data
*per_cu
;
6050 while ((per_cu
= iter
.next ()) != NULL
)
6051 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, file_matcher
,
6057 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6060 dw2_find_last_source_symtab
,
6061 dw2_forget_cached_source_info
,
6062 dw2_map_symtabs_matching_filename
,
6063 dw2_debug_names_lookup_symbol
,
6066 dw2_debug_names_dump
,
6067 dw2_debug_names_expand_symtabs_for_function
,
6068 dw2_expand_all_symtabs
,
6069 dw2_expand_symtabs_with_fullname
,
6070 dw2_debug_names_map_matching_symbols
,
6071 dw2_debug_names_expand_symtabs_matching
,
6072 dw2_find_pc_sect_compunit_symtab
,
6074 dw2_map_symbol_filenames
6077 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6078 to either a dwarf2_per_bfd or dwz_file object. */
6080 template <typename T
>
6081 static gdb::array_view
<const gdb_byte
>
6082 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6084 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6086 if (section
->empty ())
6089 /* Older elfutils strip versions could keep the section in the main
6090 executable while splitting it for the separate debug info file. */
6091 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
6094 section
->read (obj
);
6096 /* dwarf2_section_info::size is a bfd_size_type, while
6097 gdb::array_view works with size_t. On 32-bit hosts, with
6098 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6099 is 32-bit. So we need an explicit narrowing conversion here.
6100 This is fine, because it's impossible to allocate or mmap an
6101 array/buffer larger than what size_t can represent. */
6102 return gdb::make_array_view (section
->buffer
, section
->size
);
6105 /* Lookup the index cache for the contents of the index associated to
6108 static gdb::array_view
<const gdb_byte
>
6109 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_bfd
*dwarf2_per_bfd
)
6111 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6112 if (build_id
== nullptr)
6115 return global_index_cache
.lookup_gdb_index (build_id
,
6116 &dwarf2_per_bfd
->index_cache_res
);
6119 /* Same as the above, but for DWZ. */
6121 static gdb::array_view
<const gdb_byte
>
6122 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6124 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6125 if (build_id
== nullptr)
6128 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6131 /* See symfile.h. */
6134 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6136 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6137 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6139 /* If we're about to read full symbols, don't bother with the
6140 indices. In this case we also don't care if some other debug
6141 format is making psymtabs, because they are all about to be
6143 if ((objfile
->flags
& OBJF_READNOW
))
6145 /* When using READNOW, the using_index flag (set below) indicates that
6146 PER_BFD was already initialized, when we loaded some other objfile. */
6147 if (per_bfd
->using_index
)
6149 *index_kind
= dw_index_kind::GDB_INDEX
;
6150 per_objfile
->resize_symtabs ();
6154 per_bfd
->using_index
= 1;
6155 create_all_comp_units (per_objfile
);
6156 create_all_type_units (per_objfile
);
6157 per_bfd
->quick_file_names_table
6158 = create_quick_file_names_table (per_bfd
->all_comp_units
.size ());
6159 per_objfile
->resize_symtabs ();
6161 for (int i
= 0; i
< (per_bfd
->all_comp_units
.size ()
6162 + per_bfd
->all_type_units
.size ()); ++i
)
6164 dwarf2_per_cu_data
*per_cu
= per_bfd
->get_cutu (i
);
6166 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
6167 struct dwarf2_per_cu_quick_data
);
6170 /* Return 1 so that gdb sees the "quick" functions. However,
6171 these functions will be no-ops because we will have expanded
6173 *index_kind
= dw_index_kind::GDB_INDEX
;
6177 /* Was a debug names index already read when we processed an objfile sharing
6179 if (per_bfd
->debug_names_table
!= nullptr)
6181 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6182 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6183 per_objfile
->resize_symtabs ();
6187 /* Was a GDB index already read when we processed an objfile sharing
6189 if (per_bfd
->index_table
!= nullptr)
6191 *index_kind
= dw_index_kind::GDB_INDEX
;
6192 per_objfile
->objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6193 per_objfile
->resize_symtabs ();
6197 /* There might already be partial symtabs built for this BFD. This happens
6198 when loading the same binary twice with the index-cache enabled. If so,
6199 don't try to read an index. The objfile / per_objfile initialization will
6200 be completed in dwarf2_build_psymtabs, in the standard partial symtabs
6202 if (per_bfd
->partial_symtabs
!= nullptr)
6205 if (dwarf2_read_debug_names (per_objfile
))
6207 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6208 per_objfile
->resize_symtabs ();
6212 if (dwarf2_read_gdb_index (per_objfile
,
6213 get_gdb_index_contents_from_section
<struct dwarf2_per_bfd
>,
6214 get_gdb_index_contents_from_section
<dwz_file
>))
6216 *index_kind
= dw_index_kind::GDB_INDEX
;
6217 per_objfile
->resize_symtabs ();
6221 /* ... otherwise, try to find the index in the index cache. */
6222 if (dwarf2_read_gdb_index (per_objfile
,
6223 get_gdb_index_contents_from_cache
,
6224 get_gdb_index_contents_from_cache_dwz
))
6226 global_index_cache
.hit ();
6227 *index_kind
= dw_index_kind::GDB_INDEX
;
6228 per_objfile
->resize_symtabs ();
6232 global_index_cache
.miss ();
6238 /* Build a partial symbol table. */
6241 dwarf2_build_psymtabs (struct objfile
*objfile
)
6243 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
6244 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6246 if (per_bfd
->partial_symtabs
!= nullptr)
6248 /* Partial symbols were already read, so now we can simply
6250 objfile
->partial_symtabs
= per_bfd
->partial_symtabs
;
6251 per_objfile
->resize_symtabs ();
6257 /* This isn't really ideal: all the data we allocate on the
6258 objfile's obstack is still uselessly kept around. However,
6259 freeing it seems unsafe. */
6260 psymtab_discarder
psymtabs (objfile
);
6261 dwarf2_build_psymtabs_hard (per_objfile
);
6264 per_objfile
->resize_symtabs ();
6266 /* (maybe) store an index in the cache. */
6267 global_index_cache
.store (per_objfile
);
6269 catch (const gdb_exception_error
&except
)
6271 exception_print (gdb_stderr
, except
);
6274 /* Finish by setting the local reference to partial symtabs, so that
6275 we don't try to read them again if reading another objfile with the same
6276 BFD. If we can't in fact share, this won't make a difference anyway as
6277 the dwarf2_per_bfd object won't be shared. */
6278 per_bfd
->partial_symtabs
= objfile
->partial_symtabs
;
6281 /* Find the base address of the compilation unit for range lists and
6282 location lists. It will normally be specified by DW_AT_low_pc.
6283 In DWARF-3 draft 4, the base address could be overridden by
6284 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6285 compilation units with discontinuous ranges. */
6288 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6290 struct attribute
*attr
;
6292 cu
->base_address
.reset ();
6294 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6295 if (attr
!= nullptr)
6296 cu
->base_address
= attr
->as_address ();
6299 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6300 if (attr
!= nullptr)
6301 cu
->base_address
= attr
->as_address ();
6305 /* Helper function that returns the proper abbrev section for
6308 static struct dwarf2_section_info
*
6309 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6311 struct dwarf2_section_info
*abbrev
;
6312 dwarf2_per_bfd
*per_bfd
= this_cu
->per_bfd
;
6314 if (this_cu
->is_dwz
)
6315 abbrev
= &dwarf2_get_dwz_file (per_bfd
, true)->abbrev
;
6317 abbrev
= &per_bfd
->abbrev
;
6322 /* Fetch the abbreviation table offset from a comp or type unit header. */
6325 read_abbrev_offset (dwarf2_per_objfile
*per_objfile
,
6326 struct dwarf2_section_info
*section
,
6327 sect_offset sect_off
)
6329 bfd
*abfd
= section
->get_bfd_owner ();
6330 const gdb_byte
*info_ptr
;
6331 unsigned int initial_length_size
, offset_size
;
6334 section
->read (per_objfile
->objfile
);
6335 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6336 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6337 offset_size
= initial_length_size
== 4 ? 4 : 8;
6338 info_ptr
+= initial_length_size
;
6340 version
= read_2_bytes (abfd
, info_ptr
);
6344 /* Skip unit type and address size. */
6348 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
6351 /* A partial symtab that is used only for include files. */
6352 struct dwarf2_include_psymtab
: public partial_symtab
6354 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
6355 : partial_symtab (filename
, objfile
)
6359 void read_symtab (struct objfile
*objfile
) override
6361 /* It's an include file, no symbols to read for it.
6362 Everything is in the includer symtab. */
6364 /* The expansion of a dwarf2_include_psymtab is just a trigger for
6365 expansion of the includer psymtab. We use the dependencies[0] field to
6366 model the includer. But if we go the regular route of calling
6367 expand_psymtab here, and having expand_psymtab call expand_dependencies
6368 to expand the includer, we'll only use expand_psymtab on the includer
6369 (making it a non-toplevel psymtab), while if we expand the includer via
6370 another path, we'll use read_symtab (making it a toplevel psymtab).
6371 So, don't pretend a dwarf2_include_psymtab is an actual toplevel
6372 psymtab, and trigger read_symtab on the includer here directly. */
6373 includer ()->read_symtab (objfile
);
6376 void expand_psymtab (struct objfile
*objfile
) override
6378 /* This is not called by read_symtab, and should not be called by any
6379 expand_dependencies. */
6383 bool readin_p (struct objfile
*objfile
) const override
6385 return includer ()->readin_p (objfile
);
6388 compunit_symtab
*get_compunit_symtab (struct objfile
*objfile
) const override
6394 partial_symtab
*includer () const
6396 /* An include psymtab has exactly one dependency: the psymtab that
6398 gdb_assert (this->number_of_dependencies
== 1);
6399 return this->dependencies
[0];
6403 /* Allocate a new partial symtab for file named NAME and mark this new
6404 partial symtab as being an include of PST. */
6407 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6408 struct objfile
*objfile
)
6410 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
6412 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6413 subpst
->dirname
= pst
->dirname
;
6415 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6416 subpst
->dependencies
[0] = pst
;
6417 subpst
->number_of_dependencies
= 1;
6420 /* Read the Line Number Program data and extract the list of files
6421 included by the source file represented by PST. Build an include
6422 partial symtab for each of these included files. */
6425 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6426 struct die_info
*die
,
6427 dwarf2_psymtab
*pst
)
6430 struct attribute
*attr
;
6432 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6433 if (attr
!= nullptr && attr
->form_is_unsigned ())
6434 lh
= dwarf_decode_line_header ((sect_offset
) attr
->as_unsigned (), cu
);
6436 return; /* No linetable, so no includes. */
6438 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6439 that we pass in the raw text_low here; that is ok because we're
6440 only decoding the line table to make include partial symtabs, and
6441 so the addresses aren't really used. */
6442 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6443 pst
->raw_text_low (), 1);
6447 hash_signatured_type (const void *item
)
6449 const struct signatured_type
*sig_type
6450 = (const struct signatured_type
*) item
;
6452 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6453 return sig_type
->signature
;
6457 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6459 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6460 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6462 return lhs
->signature
== rhs
->signature
;
6465 /* Allocate a hash table for signatured types. */
6468 allocate_signatured_type_table ()
6470 return htab_up (htab_create_alloc (41,
6471 hash_signatured_type
,
6473 NULL
, xcalloc
, xfree
));
6476 /* A helper function to add a signatured type CU to a table. */
6479 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6481 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6482 std::vector
<signatured_type
*> *all_type_units
6483 = (std::vector
<signatured_type
*> *) datum
;
6485 all_type_units
->push_back (sigt
);
6490 /* A helper for create_debug_types_hash_table. Read types from SECTION
6491 and fill them into TYPES_HTAB. It will process only type units,
6492 therefore DW_UT_type. */
6495 create_debug_type_hash_table (dwarf2_per_objfile
*per_objfile
,
6496 struct dwo_file
*dwo_file
,
6497 dwarf2_section_info
*section
, htab_up
&types_htab
,
6498 rcuh_kind section_kind
)
6500 struct objfile
*objfile
= per_objfile
->objfile
;
6501 struct dwarf2_section_info
*abbrev_section
;
6503 const gdb_byte
*info_ptr
, *end_ptr
;
6505 abbrev_section
= (dwo_file
!= NULL
6506 ? &dwo_file
->sections
.abbrev
6507 : &per_objfile
->per_bfd
->abbrev
);
6509 dwarf_read_debug_printf ("Reading %s for %s:",
6510 section
->get_name (),
6511 abbrev_section
->get_file_name ());
6513 section
->read (objfile
);
6514 info_ptr
= section
->buffer
;
6516 if (info_ptr
== NULL
)
6519 /* We can't set abfd until now because the section may be empty or
6520 not present, in which case the bfd is unknown. */
6521 abfd
= section
->get_bfd_owner ();
6523 /* We don't use cutu_reader here because we don't need to read
6524 any dies: the signature is in the header. */
6526 end_ptr
= info_ptr
+ section
->size
;
6527 while (info_ptr
< end_ptr
)
6529 struct signatured_type
*sig_type
;
6530 struct dwo_unit
*dwo_tu
;
6532 const gdb_byte
*ptr
= info_ptr
;
6533 struct comp_unit_head header
;
6534 unsigned int length
;
6536 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6538 /* Initialize it due to a false compiler warning. */
6539 header
.signature
= -1;
6540 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6542 /* We need to read the type's signature in order to build the hash
6543 table, but we don't need anything else just yet. */
6545 ptr
= read_and_check_comp_unit_head (per_objfile
, &header
, section
,
6546 abbrev_section
, ptr
, section_kind
);
6548 length
= header
.get_length ();
6550 /* Skip dummy type units. */
6551 if (ptr
>= info_ptr
+ length
6552 || peek_abbrev_code (abfd
, ptr
) == 0
6553 || (header
.unit_type
!= DW_UT_type
6554 && header
.unit_type
!= DW_UT_split_type
))
6560 if (types_htab
== NULL
)
6563 types_htab
= allocate_dwo_unit_table ();
6565 types_htab
= allocate_signatured_type_table ();
6571 dwo_tu
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, dwo_unit
);
6572 dwo_tu
->dwo_file
= dwo_file
;
6573 dwo_tu
->signature
= header
.signature
;
6574 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6575 dwo_tu
->section
= section
;
6576 dwo_tu
->sect_off
= sect_off
;
6577 dwo_tu
->length
= length
;
6581 /* N.B.: type_offset is not usable if this type uses a DWO file.
6582 The real type_offset is in the DWO file. */
6584 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6585 sig_type
->signature
= header
.signature
;
6586 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6587 sig_type
->per_cu
.is_debug_types
= 1;
6588 sig_type
->per_cu
.section
= section
;
6589 sig_type
->per_cu
.sect_off
= sect_off
;
6590 sig_type
->per_cu
.length
= length
;
6593 slot
= htab_find_slot (types_htab
.get (),
6594 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6596 gdb_assert (slot
!= NULL
);
6599 sect_offset dup_sect_off
;
6603 const struct dwo_unit
*dup_tu
6604 = (const struct dwo_unit
*) *slot
;
6606 dup_sect_off
= dup_tu
->sect_off
;
6610 const struct signatured_type
*dup_tu
6611 = (const struct signatured_type
*) *slot
;
6613 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6616 complaint (_("debug type entry at offset %s is duplicate to"
6617 " the entry at offset %s, signature %s"),
6618 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6619 hex_string (header
.signature
));
6621 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6623 dwarf_read_debug_printf_v (" offset %s, signature %s",
6624 sect_offset_str (sect_off
),
6625 hex_string (header
.signature
));
6631 /* Create the hash table of all entries in the .debug_types
6632 (or .debug_types.dwo) section(s).
6633 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6634 otherwise it is NULL.
6636 The result is a pointer to the hash table or NULL if there are no types.
6638 Note: This function processes DWO files only, not DWP files. */
6641 create_debug_types_hash_table (dwarf2_per_objfile
*per_objfile
,
6642 struct dwo_file
*dwo_file
,
6643 gdb::array_view
<dwarf2_section_info
> type_sections
,
6644 htab_up
&types_htab
)
6646 for (dwarf2_section_info
§ion
: type_sections
)
6647 create_debug_type_hash_table (per_objfile
, dwo_file
, §ion
, types_htab
,
6651 /* Create the hash table of all entries in the .debug_types section,
6652 and initialize all_type_units.
6653 The result is zero if there is an error (e.g. missing .debug_types section),
6654 otherwise non-zero. */
6657 create_all_type_units (dwarf2_per_objfile
*per_objfile
)
6661 create_debug_type_hash_table (per_objfile
, NULL
, &per_objfile
->per_bfd
->info
,
6662 types_htab
, rcuh_kind::COMPILE
);
6663 create_debug_types_hash_table (per_objfile
, NULL
, per_objfile
->per_bfd
->types
,
6665 if (types_htab
== NULL
)
6667 per_objfile
->per_bfd
->signatured_types
= NULL
;
6671 per_objfile
->per_bfd
->signatured_types
= std::move (types_htab
);
6673 gdb_assert (per_objfile
->per_bfd
->all_type_units
.empty ());
6674 per_objfile
->per_bfd
->all_type_units
.reserve
6675 (htab_elements (per_objfile
->per_bfd
->signatured_types
.get ()));
6677 htab_traverse_noresize (per_objfile
->per_bfd
->signatured_types
.get (),
6678 add_signatured_type_cu_to_table
,
6679 &per_objfile
->per_bfd
->all_type_units
);
6684 /* Add an entry for signature SIG to dwarf2_per_objfile->per_bfd->signatured_types.
6685 If SLOT is non-NULL, it is the entry to use in the hash table.
6686 Otherwise we find one. */
6688 static struct signatured_type
*
6689 add_type_unit (dwarf2_per_objfile
*per_objfile
, ULONGEST sig
, void **slot
)
6691 if (per_objfile
->per_bfd
->all_type_units
.size ()
6692 == per_objfile
->per_bfd
->all_type_units
.capacity ())
6693 ++per_objfile
->per_bfd
->tu_stats
.nr_all_type_units_reallocs
;
6695 signatured_type
*sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
6697 per_objfile
->resize_symtabs ();
6699 per_objfile
->per_bfd
->all_type_units
.push_back (sig_type
);
6700 sig_type
->signature
= sig
;
6701 sig_type
->per_cu
.is_debug_types
= 1;
6702 if (per_objfile
->per_bfd
->using_index
)
6704 sig_type
->per_cu
.v
.quick
=
6705 OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
,
6706 struct dwarf2_per_cu_quick_data
);
6711 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6714 gdb_assert (*slot
== NULL
);
6716 /* The rest of sig_type must be filled in by the caller. */
6720 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6721 Fill in SIG_ENTRY with DWO_ENTRY. */
6724 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
*per_objfile
,
6725 struct signatured_type
*sig_entry
,
6726 struct dwo_unit
*dwo_entry
)
6728 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
6730 /* Make sure we're not clobbering something we don't expect to. */
6731 gdb_assert (! sig_entry
->per_cu
.queued
);
6732 gdb_assert (per_objfile
->get_cu (&sig_entry
->per_cu
) == NULL
);
6733 if (per_bfd
->using_index
)
6735 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6736 gdb_assert (!per_objfile
->symtab_set_p (&sig_entry
->per_cu
));
6739 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6740 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6741 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6742 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6743 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6745 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6746 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6747 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6748 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6749 sig_entry
->per_cu
.per_bfd
= per_bfd
;
6750 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6751 sig_entry
->dwo_unit
= dwo_entry
;
6754 /* Subroutine of lookup_signatured_type.
6755 If we haven't read the TU yet, create the signatured_type data structure
6756 for a TU to be read in directly from a DWO file, bypassing the stub.
6757 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6758 using .gdb_index, then when reading a CU we want to stay in the DWO file
6759 containing that CU. Otherwise we could end up reading several other DWO
6760 files (due to comdat folding) to process the transitive closure of all the
6761 mentioned TUs, and that can be slow. The current DWO file will have every
6762 type signature that it needs.
6763 We only do this for .gdb_index because in the psymtab case we already have
6764 to read all the DWOs to build the type unit groups. */
6766 static struct signatured_type
*
6767 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6769 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6770 struct dwo_file
*dwo_file
;
6771 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6772 struct signatured_type find_sig_entry
, *sig_entry
;
6775 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6777 /* If TU skeletons have been removed then we may not have read in any
6779 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6780 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6782 /* We only ever need to read in one copy of a signatured type.
6783 Use the global signatured_types array to do our own comdat-folding
6784 of types. If this is the first time we're reading this TU, and
6785 the TU has an entry in .gdb_index, replace the recorded data from
6786 .gdb_index with this TU. */
6788 find_sig_entry
.signature
= sig
;
6789 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6790 &find_sig_entry
, INSERT
);
6791 sig_entry
= (struct signatured_type
*) *slot
;
6793 /* We can get here with the TU already read, *or* in the process of being
6794 read. Don't reassign the global entry to point to this DWO if that's
6795 the case. Also note that if the TU is already being read, it may not
6796 have come from a DWO, the program may be a mix of Fission-compiled
6797 code and non-Fission-compiled code. */
6799 /* Have we already tried to read this TU?
6800 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6801 needn't exist in the global table yet). */
6802 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6805 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6806 dwo_unit of the TU itself. */
6807 dwo_file
= cu
->dwo_unit
->dwo_file
;
6809 /* Ok, this is the first time we're reading this TU. */
6810 if (dwo_file
->tus
== NULL
)
6812 find_dwo_entry
.signature
= sig
;
6813 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6815 if (dwo_entry
== NULL
)
6818 /* If the global table doesn't have an entry for this TU, add one. */
6819 if (sig_entry
== NULL
)
6820 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6822 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6823 sig_entry
->per_cu
.tu_read
= 1;
6827 /* Subroutine of lookup_signatured_type.
6828 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6829 then try the DWP file. If the TU stub (skeleton) has been removed then
6830 it won't be in .gdb_index. */
6832 static struct signatured_type
*
6833 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6835 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6836 struct dwp_file
*dwp_file
= get_dwp_file (per_objfile
);
6837 struct dwo_unit
*dwo_entry
;
6838 struct signatured_type find_sig_entry
, *sig_entry
;
6841 gdb_assert (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
);
6842 gdb_assert (dwp_file
!= NULL
);
6844 /* If TU skeletons have been removed then we may not have read in any
6846 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6847 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
6849 find_sig_entry
.signature
= sig
;
6850 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
6851 &find_sig_entry
, INSERT
);
6852 sig_entry
= (struct signatured_type
*) *slot
;
6854 /* Have we already tried to read this TU?
6855 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6856 needn't exist in the global table yet). */
6857 if (sig_entry
!= NULL
)
6860 if (dwp_file
->tus
== NULL
)
6862 dwo_entry
= lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, NULL
, sig
,
6863 1 /* is_debug_types */);
6864 if (dwo_entry
== NULL
)
6867 sig_entry
= add_type_unit (per_objfile
, sig
, slot
);
6868 fill_in_sig_entry_from_dwo_entry (per_objfile
, sig_entry
, dwo_entry
);
6873 /* Lookup a signature based type for DW_FORM_ref_sig8.
6874 Returns NULL if signature SIG is not present in the table.
6875 It is up to the caller to complain about this. */
6877 static struct signatured_type
*
6878 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6880 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6882 if (cu
->dwo_unit
&& per_objfile
->per_bfd
->using_index
)
6884 /* We're in a DWO/DWP file, and we're using .gdb_index.
6885 These cases require special processing. */
6886 if (get_dwp_file (per_objfile
) == NULL
)
6887 return lookup_dwo_signatured_type (cu
, sig
);
6889 return lookup_dwp_signatured_type (cu
, sig
);
6893 struct signatured_type find_entry
, *entry
;
6895 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
6897 find_entry
.signature
= sig
;
6898 entry
= ((struct signatured_type
*)
6899 htab_find (per_objfile
->per_bfd
->signatured_types
.get (),
6905 /* Low level DIE reading support. */
6907 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6910 init_cu_die_reader (struct die_reader_specs
*reader
,
6911 struct dwarf2_cu
*cu
,
6912 struct dwarf2_section_info
*section
,
6913 struct dwo_file
*dwo_file
,
6914 struct abbrev_table
*abbrev_table
)
6916 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6917 reader
->abfd
= section
->get_bfd_owner ();
6919 reader
->dwo_file
= dwo_file
;
6920 reader
->die_section
= section
;
6921 reader
->buffer
= section
->buffer
;
6922 reader
->buffer_end
= section
->buffer
+ section
->size
;
6923 reader
->abbrev_table
= abbrev_table
;
6926 /* Subroutine of cutu_reader to simplify it.
6927 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6928 There's just a lot of work to do, and cutu_reader is big enough
6931 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6932 from it to the DIE in the DWO. If NULL we are skipping the stub.
6933 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6934 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6935 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6936 STUB_COMP_DIR may be non-NULL.
6937 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6938 are filled in with the info of the DIE from the DWO file.
6939 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6940 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6941 kept around for at least as long as *RESULT_READER.
6943 The result is non-zero if a valid (non-dummy) DIE was found. */
6946 read_cutu_die_from_dwo (dwarf2_cu
*cu
,
6947 struct dwo_unit
*dwo_unit
,
6948 struct die_info
*stub_comp_unit_die
,
6949 const char *stub_comp_dir
,
6950 struct die_reader_specs
*result_reader
,
6951 const gdb_byte
**result_info_ptr
,
6952 struct die_info
**result_comp_unit_die
,
6953 abbrev_table_up
*result_dwo_abbrev_table
)
6955 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
6956 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
6957 struct objfile
*objfile
= per_objfile
->objfile
;
6959 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6960 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6961 int i
,num_extra_attrs
;
6962 struct dwarf2_section_info
*dwo_abbrev_section
;
6963 struct die_info
*comp_unit_die
;
6965 /* At most one of these may be provided. */
6966 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6968 /* These attributes aren't processed until later:
6969 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6970 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6971 referenced later. However, these attributes are found in the stub
6972 which we won't have later. In order to not impose this complication
6973 on the rest of the code, we read them here and copy them to the
6982 if (stub_comp_unit_die
!= NULL
)
6984 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6986 if (!per_cu
->is_debug_types
)
6987 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6988 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6989 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6990 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6991 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6993 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6995 /* There should be a DW_AT_GNU_ranges_base attribute here (if needed).
6996 We need the value before we can process DW_AT_ranges values from the
6998 cu
->gnu_ranges_base
= stub_comp_unit_die
->gnu_ranges_base ();
7000 /* For DWARF5: record the DW_AT_rnglists_base value from the skeleton. If
7001 there are attributes of form DW_FORM_rnglistx in the skeleton, they'll
7002 need the rnglists base. Attributes of form DW_FORM_rnglistx in the
7003 split unit don't use it, as the DWO has its own .debug_rnglists.dwo
7005 cu
->rnglists_base
= stub_comp_unit_die
->rnglists_base ();
7007 else if (stub_comp_dir
!= NULL
)
7009 /* Reconstruct the comp_dir attribute to simplify the code below. */
7010 comp_dir
= OBSTACK_ZALLOC (&cu
->comp_unit_obstack
, struct attribute
);
7011 comp_dir
->name
= DW_AT_comp_dir
;
7012 comp_dir
->form
= DW_FORM_string
;
7013 comp_dir
->set_string_noncanonical (stub_comp_dir
);
7016 /* Set up for reading the DWO CU/TU. */
7017 cu
->dwo_unit
= dwo_unit
;
7018 dwarf2_section_info
*section
= dwo_unit
->section
;
7019 section
->read (objfile
);
7020 abfd
= section
->get_bfd_owner ();
7021 begin_info_ptr
= info_ptr
= (section
->buffer
7022 + to_underlying (dwo_unit
->sect_off
));
7023 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7025 if (per_cu
->is_debug_types
)
7027 signatured_type
*sig_type
= (struct signatured_type
*) per_cu
;
7029 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7030 section
, dwo_abbrev_section
,
7031 info_ptr
, rcuh_kind::TYPE
);
7032 /* This is not an assert because it can be caused by bad debug info. */
7033 if (sig_type
->signature
!= cu
->header
.signature
)
7035 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7036 " TU at offset %s [in module %s]"),
7037 hex_string (sig_type
->signature
),
7038 hex_string (cu
->header
.signature
),
7039 sect_offset_str (dwo_unit
->sect_off
),
7040 bfd_get_filename (abfd
));
7042 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7043 /* For DWOs coming from DWP files, we don't know the CU length
7044 nor the type's offset in the TU until now. */
7045 dwo_unit
->length
= cu
->header
.get_length ();
7046 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7048 /* Establish the type offset that can be used to lookup the type.
7049 For DWO files, we don't know it until now. */
7050 sig_type
->type_offset_in_section
7051 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7055 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7056 section
, dwo_abbrev_section
,
7057 info_ptr
, rcuh_kind::COMPILE
);
7058 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7059 /* For DWOs coming from DWP files, we don't know the CU length
7061 dwo_unit
->length
= cu
->header
.get_length ();
7064 dwo_abbrev_section
->read (objfile
);
7065 *result_dwo_abbrev_table
7066 = abbrev_table::read (dwo_abbrev_section
, cu
->header
.abbrev_sect_off
);
7067 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7068 result_dwo_abbrev_table
->get ());
7070 /* Read in the die, but leave space to copy over the attributes
7071 from the stub. This has the benefit of simplifying the rest of
7072 the code - all the work to maintain the illusion of a single
7073 DW_TAG_{compile,type}_unit DIE is done here. */
7074 num_extra_attrs
= ((stmt_list
!= NULL
)
7078 + (comp_dir
!= NULL
));
7079 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7082 /* Copy over the attributes from the stub to the DIE we just read in. */
7083 comp_unit_die
= *result_comp_unit_die
;
7084 i
= comp_unit_die
->num_attrs
;
7085 if (stmt_list
!= NULL
)
7086 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7088 comp_unit_die
->attrs
[i
++] = *low_pc
;
7089 if (high_pc
!= NULL
)
7090 comp_unit_die
->attrs
[i
++] = *high_pc
;
7092 comp_unit_die
->attrs
[i
++] = *ranges
;
7093 if (comp_dir
!= NULL
)
7094 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7095 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7097 if (dwarf_die_debug
)
7099 fprintf_unfiltered (gdb_stdlog
,
7100 "Read die from %s@0x%x of %s:\n",
7101 section
->get_name (),
7102 (unsigned) (begin_info_ptr
- section
->buffer
),
7103 bfd_get_filename (abfd
));
7104 dump_die (comp_unit_die
, dwarf_die_debug
);
7107 /* Skip dummy compilation units. */
7108 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7109 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7112 *result_info_ptr
= info_ptr
;
7116 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7117 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7118 signature is part of the header. */
7119 static gdb::optional
<ULONGEST
>
7120 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7122 if (cu
->header
.version
>= 5)
7123 return cu
->header
.signature
;
7124 struct attribute
*attr
;
7125 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7126 if (attr
== nullptr || !attr
->form_is_unsigned ())
7127 return gdb::optional
<ULONGEST
> ();
7128 return attr
->as_unsigned ();
7131 /* Subroutine of cutu_reader to simplify it.
7132 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7133 Returns NULL if the specified DWO unit cannot be found. */
7135 static struct dwo_unit
*
7136 lookup_dwo_unit (dwarf2_cu
*cu
, die_info
*comp_unit_die
, const char *dwo_name
)
7138 dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7139 struct dwo_unit
*dwo_unit
;
7140 const char *comp_dir
;
7142 gdb_assert (cu
!= NULL
);
7144 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7145 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7146 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7148 if (per_cu
->is_debug_types
)
7149 dwo_unit
= lookup_dwo_type_unit (cu
, dwo_name
, comp_dir
);
7152 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7154 if (!signature
.has_value ())
7155 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7157 dwo_name
, bfd_get_filename (per_cu
->per_bfd
->obfd
));
7159 dwo_unit
= lookup_dwo_comp_unit (cu
, dwo_name
, comp_dir
, *signature
);
7165 /* Subroutine of cutu_reader to simplify it.
7166 See it for a description of the parameters.
7167 Read a TU directly from a DWO file, bypassing the stub. */
7170 cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data
*this_cu
,
7171 dwarf2_per_objfile
*per_objfile
,
7172 dwarf2_cu
*existing_cu
)
7174 struct signatured_type
*sig_type
;
7176 /* Verify we can do the following downcast, and that we have the
7178 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7179 sig_type
= (struct signatured_type
*) this_cu
;
7180 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7184 if (existing_cu
!= nullptr)
7187 gdb_assert (cu
->dwo_unit
== sig_type
->dwo_unit
);
7188 /* There's no need to do the rereading_dwo_cu handling that
7189 cutu_reader does since we don't read the stub. */
7193 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7194 in per_objfile yet. */
7195 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7196 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7197 cu
= m_new_cu
.get ();
7200 /* A future optimization, if needed, would be to use an existing
7201 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7202 could share abbrev tables. */
7204 if (read_cutu_die_from_dwo (cu
, sig_type
->dwo_unit
,
7205 NULL
/* stub_comp_unit_die */,
7206 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7209 &m_dwo_abbrev_table
) == 0)
7216 /* Initialize a CU (or TU) and read its DIEs.
7217 If the CU defers to a DWO file, read the DWO file as well.
7219 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7220 Otherwise the table specified in the comp unit header is read in and used.
7221 This is an optimization for when we already have the abbrev table.
7223 If EXISTING_CU is non-NULL, then use it. Otherwise, a new CU is
7226 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7227 dwarf2_per_objfile
*per_objfile
,
7228 struct abbrev_table
*abbrev_table
,
7229 dwarf2_cu
*existing_cu
,
7231 : die_reader_specs
{},
7234 struct objfile
*objfile
= per_objfile
->objfile
;
7235 struct dwarf2_section_info
*section
= this_cu
->section
;
7236 bfd
*abfd
= section
->get_bfd_owner ();
7237 const gdb_byte
*begin_info_ptr
;
7238 struct signatured_type
*sig_type
= NULL
;
7239 struct dwarf2_section_info
*abbrev_section
;
7240 /* Non-zero if CU currently points to a DWO file and we need to
7241 reread it. When this happens we need to reread the skeleton die
7242 before we can reread the DWO file (this only applies to CUs, not TUs). */
7243 int rereading_dwo_cu
= 0;
7245 if (dwarf_die_debug
)
7246 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7247 this_cu
->is_debug_types
? "type" : "comp",
7248 sect_offset_str (this_cu
->sect_off
));
7250 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7251 file (instead of going through the stub), short-circuit all of this. */
7252 if (this_cu
->reading_dwo_directly
)
7254 /* Narrow down the scope of possibilities to have to understand. */
7255 gdb_assert (this_cu
->is_debug_types
);
7256 gdb_assert (abbrev_table
== NULL
);
7257 init_tu_and_read_dwo_dies (this_cu
, per_objfile
, existing_cu
);
7261 /* This is cheap if the section is already read in. */
7262 section
->read (objfile
);
7264 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7266 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7270 if (existing_cu
!= nullptr)
7273 /* If this CU is from a DWO file we need to start over, we need to
7274 refetch the attributes from the skeleton CU.
7275 This could be optimized by retrieving those attributes from when we
7276 were here the first time: the previous comp_unit_die was stored in
7277 comp_unit_obstack. But there's no data yet that we need this
7279 if (cu
->dwo_unit
!= NULL
)
7280 rereading_dwo_cu
= 1;
7284 /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu
7285 in per_objfile yet. */
7286 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7287 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7288 cu
= m_new_cu
.get ();
7291 /* Get the header. */
7292 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7294 /* We already have the header, there's no need to read it in again. */
7295 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7299 if (this_cu
->is_debug_types
)
7301 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7302 section
, abbrev_section
,
7303 info_ptr
, rcuh_kind::TYPE
);
7305 /* Since per_cu is the first member of struct signatured_type,
7306 we can go from a pointer to one to a pointer to the other. */
7307 sig_type
= (struct signatured_type
*) this_cu
;
7308 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7309 gdb_assert (sig_type
->type_offset_in_tu
7310 == cu
->header
.type_cu_offset_in_tu
);
7311 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7313 /* LENGTH has not been set yet for type units if we're
7314 using .gdb_index. */
7315 this_cu
->length
= cu
->header
.get_length ();
7317 /* Establish the type offset that can be used to lookup the type. */
7318 sig_type
->type_offset_in_section
=
7319 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7321 this_cu
->dwarf_version
= cu
->header
.version
;
7325 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &cu
->header
,
7326 section
, abbrev_section
,
7328 rcuh_kind::COMPILE
);
7330 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7331 if (this_cu
->length
== 0)
7332 this_cu
->length
= cu
->header
.get_length ();
7334 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
7335 this_cu
->dwarf_version
= cu
->header
.version
;
7339 /* Skip dummy compilation units. */
7340 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7341 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7347 /* If we don't have them yet, read the abbrevs for this compilation unit.
7348 And if we need to read them now, make sure they're freed when we're
7350 if (abbrev_table
!= NULL
)
7351 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7354 abbrev_section
->read (objfile
);
7355 m_abbrev_table_holder
7356 = abbrev_table::read (abbrev_section
, cu
->header
.abbrev_sect_off
);
7357 abbrev_table
= m_abbrev_table_holder
.get ();
7360 /* Read the top level CU/TU die. */
7361 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7362 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7364 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7370 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7371 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7372 table from the DWO file and pass the ownership over to us. It will be
7373 referenced from READER, so we must make sure to free it after we're done
7376 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7377 DWO CU, that this test will fail (the attribute will not be present). */
7378 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7379 if (dwo_name
!= nullptr)
7381 struct dwo_unit
*dwo_unit
;
7382 struct die_info
*dwo_comp_unit_die
;
7384 if (comp_unit_die
->has_children
)
7386 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7387 " has children (offset %s) [in module %s]"),
7388 sect_offset_str (this_cu
->sect_off
),
7389 bfd_get_filename (abfd
));
7391 dwo_unit
= lookup_dwo_unit (cu
, comp_unit_die
, dwo_name
);
7392 if (dwo_unit
!= NULL
)
7394 if (read_cutu_die_from_dwo (cu
, dwo_unit
,
7395 comp_unit_die
, NULL
,
7398 &m_dwo_abbrev_table
) == 0)
7404 comp_unit_die
= dwo_comp_unit_die
;
7408 /* Yikes, we couldn't find the rest of the DIE, we only have
7409 the stub. A complaint has already been logged. There's
7410 not much more we can do except pass on the stub DIE to
7411 die_reader_func. We don't want to throw an error on bad
7418 cutu_reader::keep ()
7420 /* Done, clean up. */
7421 gdb_assert (!dummy_p
);
7422 if (m_new_cu
!= NULL
)
7424 /* Save this dwarf2_cu in the per_objfile. The per_objfile owns it
7426 dwarf2_per_objfile
*per_objfile
= m_new_cu
->per_objfile
;
7427 per_objfile
->set_cu (m_this_cu
, m_new_cu
.release ());
7431 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7432 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7433 assumed to have already done the lookup to find the DWO file).
7435 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7436 THIS_CU->is_debug_types, but nothing else.
7438 We fill in THIS_CU->length.
7440 THIS_CU->cu is always freed when done.
7441 This is done in order to not leave THIS_CU->cu in a state where we have
7442 to care whether it refers to the "main" CU or the DWO CU.
7444 When parent_cu is passed, it is used to provide a default value for
7445 str_offsets_base and addr_base from the parent. */
7447 cutu_reader::cutu_reader (dwarf2_per_cu_data
*this_cu
,
7448 dwarf2_per_objfile
*per_objfile
,
7449 struct dwarf2_cu
*parent_cu
,
7450 struct dwo_file
*dwo_file
)
7451 : die_reader_specs
{},
7454 struct objfile
*objfile
= per_objfile
->objfile
;
7455 struct dwarf2_section_info
*section
= this_cu
->section
;
7456 bfd
*abfd
= section
->get_bfd_owner ();
7457 struct dwarf2_section_info
*abbrev_section
;
7458 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7460 if (dwarf_die_debug
)
7461 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7462 this_cu
->is_debug_types
? "type" : "comp",
7463 sect_offset_str (this_cu
->sect_off
));
7465 gdb_assert (per_objfile
->get_cu (this_cu
) == nullptr);
7467 abbrev_section
= (dwo_file
!= NULL
7468 ? &dwo_file
->sections
.abbrev
7469 : get_abbrev_section_for_cu (this_cu
));
7471 /* This is cheap if the section is already read in. */
7472 section
->read (objfile
);
7474 m_new_cu
.reset (new dwarf2_cu (this_cu
, per_objfile
));
7476 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7477 info_ptr
= read_and_check_comp_unit_head (per_objfile
, &m_new_cu
->header
,
7478 section
, abbrev_section
, info_ptr
,
7479 (this_cu
->is_debug_types
7481 : rcuh_kind::COMPILE
));
7483 if (parent_cu
!= nullptr)
7485 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7486 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7488 this_cu
->length
= m_new_cu
->header
.get_length ();
7490 /* Skip dummy compilation units. */
7491 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7492 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7498 abbrev_section
->read (objfile
);
7499 m_abbrev_table_holder
7500 = abbrev_table::read (abbrev_section
, m_new_cu
->header
.abbrev_sect_off
);
7502 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7503 m_abbrev_table_holder
.get ());
7504 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7508 /* Type Unit Groups.
7510 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7511 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7512 so that all types coming from the same compilation (.o file) are grouped
7513 together. A future step could be to put the types in the same symtab as
7514 the CU the types ultimately came from. */
7517 hash_type_unit_group (const void *item
)
7519 const struct type_unit_group
*tu_group
7520 = (const struct type_unit_group
*) item
;
7522 return hash_stmt_list_entry (&tu_group
->hash
);
7526 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7528 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7529 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7531 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7534 /* Allocate a hash table for type unit groups. */
7537 allocate_type_unit_groups_table ()
7539 return htab_up (htab_create_alloc (3,
7540 hash_type_unit_group
,
7542 NULL
, xcalloc
, xfree
));
7545 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7546 partial symtabs. We combine several TUs per psymtab to not let the size
7547 of any one psymtab grow too big. */
7548 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7549 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7551 /* Helper routine for get_type_unit_group.
7552 Create the type_unit_group object used to hold one or more TUs. */
7554 static struct type_unit_group
*
7555 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7557 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7558 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
7559 struct dwarf2_per_cu_data
*per_cu
;
7560 struct type_unit_group
*tu_group
;
7562 tu_group
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, type_unit_group
);
7563 per_cu
= &tu_group
->per_cu
;
7564 per_cu
->per_bfd
= per_bfd
;
7566 if (per_bfd
->using_index
)
7568 per_cu
->v
.quick
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
7569 struct dwarf2_per_cu_quick_data
);
7573 unsigned int line_offset
= to_underlying (line_offset_struct
);
7574 dwarf2_psymtab
*pst
;
7577 /* Give the symtab a useful name for debug purposes. */
7578 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7579 name
= string_printf ("<type_units_%d>",
7580 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7582 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7584 pst
= create_partial_symtab (per_cu
, per_objfile
, name
.c_str ());
7585 pst
->anonymous
= true;
7588 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7589 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7594 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7595 STMT_LIST is a DW_AT_stmt_list attribute. */
7597 static struct type_unit_group
*
7598 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7600 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7601 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7602 struct type_unit_group
*tu_group
;
7604 unsigned int line_offset
;
7605 struct type_unit_group type_unit_group_for_lookup
;
7607 if (per_objfile
->per_bfd
->type_unit_groups
== NULL
)
7608 per_objfile
->per_bfd
->type_unit_groups
= allocate_type_unit_groups_table ();
7610 /* Do we need to create a new group, or can we use an existing one? */
7612 if (stmt_list
!= nullptr && stmt_list
->form_is_unsigned ())
7614 line_offset
= stmt_list
->as_unsigned ();
7615 ++tu_stats
->nr_symtab_sharers
;
7619 /* Ugh, no stmt_list. Rare, but we have to handle it.
7620 We can do various things here like create one group per TU or
7621 spread them over multiple groups to split up the expansion work.
7622 To avoid worst case scenarios (too many groups or too large groups)
7623 we, umm, group them in bunches. */
7624 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7625 | (tu_stats
->nr_stmt_less_type_units
7626 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7627 ++tu_stats
->nr_stmt_less_type_units
;
7630 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7631 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7632 slot
= htab_find_slot (per_objfile
->per_bfd
->type_unit_groups
.get (),
7633 &type_unit_group_for_lookup
, INSERT
);
7636 tu_group
= (struct type_unit_group
*) *slot
;
7637 gdb_assert (tu_group
!= NULL
);
7641 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7642 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7644 ++tu_stats
->nr_symtabs
;
7650 /* Partial symbol tables. */
7652 /* Create a psymtab named NAME and assign it to PER_CU.
7654 The caller must fill in the following details:
7655 dirname, textlow, texthigh. */
7657 static dwarf2_psymtab
*
7658 create_partial_symtab (dwarf2_per_cu_data
*per_cu
,
7659 dwarf2_per_objfile
*per_objfile
,
7662 struct objfile
*objfile
= per_objfile
->objfile
;
7663 dwarf2_psymtab
*pst
;
7665 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7667 pst
->psymtabs_addrmap_supported
= true;
7669 /* This is the glue that links PST into GDB's symbol API. */
7670 per_cu
->v
.psymtab
= pst
;
7675 /* DIE reader function for process_psymtab_comp_unit. */
7678 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7679 const gdb_byte
*info_ptr
,
7680 struct die_info
*comp_unit_die
,
7681 enum language pretend_language
)
7683 struct dwarf2_cu
*cu
= reader
->cu
;
7684 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
7685 struct objfile
*objfile
= per_objfile
->objfile
;
7686 struct gdbarch
*gdbarch
= objfile
->arch ();
7687 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7689 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7690 dwarf2_psymtab
*pst
;
7691 enum pc_bounds_kind cu_bounds_kind
;
7692 const char *filename
;
7694 gdb_assert (! per_cu
->is_debug_types
);
7696 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7698 /* Allocate a new partial symbol table structure. */
7699 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7700 static const char artificial
[] = "<artificial>";
7701 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7702 if (filename
== NULL
)
7704 else if (strcmp (filename
, artificial
) == 0)
7706 debug_filename
.reset (concat (artificial
, "@",
7707 sect_offset_str (per_cu
->sect_off
),
7709 filename
= debug_filename
.get ();
7712 pst
= create_partial_symtab (per_cu
, per_objfile
, filename
);
7714 /* This must be done before calling dwarf2_build_include_psymtabs. */
7715 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7717 baseaddr
= objfile
->text_section_offset ();
7719 dwarf2_find_base_address (comp_unit_die
, cu
);
7721 /* Possibly set the default values of LOWPC and HIGHPC from
7723 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7724 &best_highpc
, cu
, pst
);
7725 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7728 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7731 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7733 /* Store the contiguous range if it is not empty; it can be
7734 empty for CUs with no code. */
7735 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7739 /* Check if comp unit has_children.
7740 If so, read the rest of the partial symbols from this comp unit.
7741 If not, there's no more debug_info for this comp unit. */
7742 if (comp_unit_die
->has_children
)
7744 struct partial_die_info
*first_die
;
7745 CORE_ADDR lowpc
, highpc
;
7747 lowpc
= ((CORE_ADDR
) -1);
7748 highpc
= ((CORE_ADDR
) 0);
7750 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7752 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7753 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7755 /* If we didn't find a lowpc, set it to highpc to avoid
7756 complaints from `maint check'. */
7757 if (lowpc
== ((CORE_ADDR
) -1))
7760 /* If the compilation unit didn't have an explicit address range,
7761 then use the information extracted from its child dies. */
7762 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7765 best_highpc
= highpc
;
7768 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7769 best_lowpc
+ baseaddr
)
7771 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7772 best_highpc
+ baseaddr
)
7777 if (!cu
->per_cu
->imported_symtabs_empty ())
7780 int len
= cu
->per_cu
->imported_symtabs_size ();
7782 /* Fill in 'dependencies' here; we fill in 'users' in a
7784 pst
->number_of_dependencies
= len
;
7786 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7787 for (i
= 0; i
< len
; ++i
)
7789 pst
->dependencies
[i
]
7790 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7793 cu
->per_cu
->imported_symtabs_free ();
7796 /* Get the list of files included in the current compilation unit,
7797 and build a psymtab for each of them. */
7798 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7800 dwarf_read_debug_printf ("Psymtab for %s unit @%s: %s - %s"
7801 ", %d global, %d static syms",
7802 per_cu
->is_debug_types
? "type" : "comp",
7803 sect_offset_str (per_cu
->sect_off
),
7804 paddress (gdbarch
, pst
->text_low (objfile
)),
7805 paddress (gdbarch
, pst
->text_high (objfile
)),
7806 (int) pst
->global_psymbols
.size (),
7807 (int) pst
->static_psymbols
.size ());
7810 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7811 Process compilation unit THIS_CU for a psymtab. */
7814 process_psymtab_comp_unit (dwarf2_per_cu_data
*this_cu
,
7815 dwarf2_per_objfile
*per_objfile
,
7816 bool want_partial_unit
,
7817 enum language pretend_language
)
7819 /* If this compilation unit was already read in, free the
7820 cached copy in order to read it in again. This is
7821 necessary because we skipped some symbols when we first
7822 read in the compilation unit (see load_partial_dies).
7823 This problem could be avoided, but the benefit is unclear. */
7824 per_objfile
->remove_cu (this_cu
);
7826 cutu_reader
reader (this_cu
, per_objfile
, nullptr, nullptr, false);
7828 switch (reader
.comp_unit_die
->tag
)
7830 case DW_TAG_compile_unit
:
7831 this_cu
->unit_type
= DW_UT_compile
;
7833 case DW_TAG_partial_unit
:
7834 this_cu
->unit_type
= DW_UT_partial
;
7836 case DW_TAG_type_unit
:
7837 this_cu
->unit_type
= DW_UT_type
;
7847 else if (this_cu
->is_debug_types
)
7848 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7849 reader
.comp_unit_die
);
7850 else if (want_partial_unit
7851 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7852 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7853 reader
.comp_unit_die
,
7856 this_cu
->lang
= reader
.cu
->language
;
7858 /* Age out any secondary CUs. */
7859 per_objfile
->age_comp_units ();
7862 /* Reader function for build_type_psymtabs. */
7865 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7866 const gdb_byte
*info_ptr
,
7867 struct die_info
*type_unit_die
)
7869 dwarf2_per_objfile
*per_objfile
= reader
->cu
->per_objfile
;
7870 struct dwarf2_cu
*cu
= reader
->cu
;
7871 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7872 struct signatured_type
*sig_type
;
7873 struct type_unit_group
*tu_group
;
7874 struct attribute
*attr
;
7875 struct partial_die_info
*first_die
;
7876 CORE_ADDR lowpc
, highpc
;
7877 dwarf2_psymtab
*pst
;
7879 gdb_assert (per_cu
->is_debug_types
);
7880 sig_type
= (struct signatured_type
*) per_cu
;
7882 if (! type_unit_die
->has_children
)
7885 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7886 tu_group
= get_type_unit_group (cu
, attr
);
7888 if (tu_group
->tus
== nullptr)
7889 tu_group
->tus
= new std::vector
<signatured_type
*>;
7890 tu_group
->tus
->push_back (sig_type
);
7892 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7893 pst
= create_partial_symtab (per_cu
, per_objfile
, "");
7894 pst
->anonymous
= true;
7896 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7898 lowpc
= (CORE_ADDR
) -1;
7899 highpc
= (CORE_ADDR
) 0;
7900 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7905 /* Struct used to sort TUs by their abbreviation table offset. */
7907 struct tu_abbrev_offset
7909 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7910 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7913 signatured_type
*sig_type
;
7914 sect_offset abbrev_offset
;
7917 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7920 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7921 const struct tu_abbrev_offset
&b
)
7923 return a
.abbrev_offset
< b
.abbrev_offset
;
7926 /* Efficiently read all the type units.
7927 This does the bulk of the work for build_type_psymtabs.
7929 The efficiency is because we sort TUs by the abbrev table they use and
7930 only read each abbrev table once. In one program there are 200K TUs
7931 sharing 8K abbrev tables.
7933 The main purpose of this function is to support building the
7934 dwarf2_per_objfile->per_bfd->type_unit_groups table.
7935 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7936 can collapse the search space by grouping them by stmt_list.
7937 The savings can be significant, in the same program from above the 200K TUs
7938 share 8K stmt_list tables.
7940 FUNC is expected to call get_type_unit_group, which will create the
7941 struct type_unit_group if necessary and add it to
7942 dwarf2_per_objfile->per_bfd->type_unit_groups. */
7945 build_type_psymtabs_1 (dwarf2_per_objfile
*per_objfile
)
7947 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
7948 abbrev_table_up abbrev_table
;
7949 sect_offset abbrev_offset
;
7951 /* It's up to the caller to not call us multiple times. */
7952 gdb_assert (per_objfile
->per_bfd
->type_unit_groups
== NULL
);
7954 if (per_objfile
->per_bfd
->all_type_units
.empty ())
7957 /* TUs typically share abbrev tables, and there can be way more TUs than
7958 abbrev tables. Sort by abbrev table to reduce the number of times we
7959 read each abbrev table in.
7960 Alternatives are to punt or to maintain a cache of abbrev tables.
7961 This is simpler and efficient enough for now.
7963 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7964 symtab to use). Typically TUs with the same abbrev offset have the same
7965 stmt_list value too so in practice this should work well.
7967 The basic algorithm here is:
7969 sort TUs by abbrev table
7970 for each TU with same abbrev table:
7971 read abbrev table if first user
7972 read TU top level DIE
7973 [IWBN if DWO skeletons had DW_AT_stmt_list]
7976 dwarf_read_debug_printf ("Building type unit groups ...");
7978 /* Sort in a separate table to maintain the order of all_type_units
7979 for .gdb_index: TU indices directly index all_type_units. */
7980 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7981 sorted_by_abbrev
.reserve (per_objfile
->per_bfd
->all_type_units
.size ());
7983 for (signatured_type
*sig_type
: per_objfile
->per_bfd
->all_type_units
)
7984 sorted_by_abbrev
.emplace_back
7985 (sig_type
, read_abbrev_offset (per_objfile
, sig_type
->per_cu
.section
,
7986 sig_type
->per_cu
.sect_off
));
7988 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7989 sort_tu_by_abbrev_offset
);
7991 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7993 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7995 /* Switch to the next abbrev table if necessary. */
7996 if (abbrev_table
== NULL
7997 || tu
.abbrev_offset
!= abbrev_offset
)
7999 abbrev_offset
= tu
.abbrev_offset
;
8000 per_objfile
->per_bfd
->abbrev
.read (per_objfile
->objfile
);
8002 abbrev_table::read (&per_objfile
->per_bfd
->abbrev
, abbrev_offset
);
8003 ++tu_stats
->nr_uniq_abbrev_tables
;
8006 cutu_reader
reader (&tu
.sig_type
->per_cu
, per_objfile
,
8007 abbrev_table
.get (), nullptr, false);
8008 if (!reader
.dummy_p
)
8009 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8010 reader
.comp_unit_die
);
8014 /* Print collected type unit statistics. */
8017 print_tu_stats (dwarf2_per_objfile
*per_objfile
)
8019 struct tu_stats
*tu_stats
= &per_objfile
->per_bfd
->tu_stats
;
8021 dwarf_read_debug_printf ("Type unit statistics:");
8022 dwarf_read_debug_printf (" %zu TUs",
8023 per_objfile
->per_bfd
->all_type_units
.size ());
8024 dwarf_read_debug_printf (" %d uniq abbrev tables",
8025 tu_stats
->nr_uniq_abbrev_tables
);
8026 dwarf_read_debug_printf (" %d symtabs from stmt_list entries",
8027 tu_stats
->nr_symtabs
);
8028 dwarf_read_debug_printf (" %d symtab sharers",
8029 tu_stats
->nr_symtab_sharers
);
8030 dwarf_read_debug_printf (" %d type units without a stmt_list",
8031 tu_stats
->nr_stmt_less_type_units
);
8032 dwarf_read_debug_printf (" %d all_type_units reallocs",
8033 tu_stats
->nr_all_type_units_reallocs
);
8036 /* Traversal function for build_type_psymtabs. */
8039 build_type_psymtab_dependencies (void **slot
, void *info
)
8041 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
8042 struct objfile
*objfile
= per_objfile
->objfile
;
8043 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8044 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8045 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8046 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8049 gdb_assert (len
> 0);
8050 gdb_assert (per_cu
->type_unit_group_p ());
8052 pst
->number_of_dependencies
= len
;
8053 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8054 for (i
= 0; i
< len
; ++i
)
8056 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8057 gdb_assert (iter
->per_cu
.is_debug_types
);
8058 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8059 iter
->type_unit_group
= tu_group
;
8062 delete tu_group
->tus
;
8063 tu_group
->tus
= nullptr;
8068 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8069 Build partial symbol tables for the .debug_types comp-units. */
8072 build_type_psymtabs (dwarf2_per_objfile
*per_objfile
)
8074 if (! create_all_type_units (per_objfile
))
8077 build_type_psymtabs_1 (per_objfile
);
8080 /* Traversal function for process_skeletonless_type_unit.
8081 Read a TU in a DWO file and build partial symbols for it. */
8084 process_skeletonless_type_unit (void **slot
, void *info
)
8086 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8087 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) info
;
8088 struct signatured_type find_entry
, *entry
;
8090 /* If this TU doesn't exist in the global table, add it and read it in. */
8092 if (per_objfile
->per_bfd
->signatured_types
== NULL
)
8093 per_objfile
->per_bfd
->signatured_types
= allocate_signatured_type_table ();
8095 find_entry
.signature
= dwo_unit
->signature
;
8096 slot
= htab_find_slot (per_objfile
->per_bfd
->signatured_types
.get (),
8097 &find_entry
, INSERT
);
8098 /* If we've already seen this type there's nothing to do. What's happening
8099 is we're doing our own version of comdat-folding here. */
8103 /* This does the job that create_all_type_units would have done for
8105 entry
= add_type_unit (per_objfile
, dwo_unit
->signature
, slot
);
8106 fill_in_sig_entry_from_dwo_entry (per_objfile
, entry
, dwo_unit
);
8109 /* This does the job that build_type_psymtabs_1 would have done. */
8110 cutu_reader
reader (&entry
->per_cu
, per_objfile
, nullptr, nullptr, false);
8111 if (!reader
.dummy_p
)
8112 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8113 reader
.comp_unit_die
);
8118 /* Traversal function for process_skeletonless_type_units. */
8121 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8123 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8125 if (dwo_file
->tus
!= NULL
)
8126 htab_traverse_noresize (dwo_file
->tus
.get (),
8127 process_skeletonless_type_unit
, info
);
8132 /* Scan all TUs of DWO files, verifying we've processed them.
8133 This is needed in case a TU was emitted without its skeleton.
8134 Note: This can't be done until we know what all the DWO files are. */
8137 process_skeletonless_type_units (dwarf2_per_objfile
*per_objfile
)
8139 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8140 if (get_dwp_file (per_objfile
) == NULL
8141 && per_objfile
->per_bfd
->dwo_files
!= NULL
)
8143 htab_traverse_noresize (per_objfile
->per_bfd
->dwo_files
.get (),
8144 process_dwo_file_for_skeletonless_type_units
,
8149 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8152 set_partial_user (dwarf2_per_objfile
*per_objfile
)
8154 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8156 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8161 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8163 /* Set the 'user' field only if it is not already set. */
8164 if (pst
->dependencies
[j
]->user
== NULL
)
8165 pst
->dependencies
[j
]->user
= pst
;
8170 /* Build the partial symbol table by doing a quick pass through the
8171 .debug_info and .debug_abbrev sections. */
8174 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
*per_objfile
)
8176 struct objfile
*objfile
= per_objfile
->objfile
;
8178 dwarf_read_debug_printf ("Building psymtabs of objfile %s ...",
8179 objfile_name (objfile
));
8181 scoped_restore restore_reading_psyms
8182 = make_scoped_restore (&per_objfile
->per_bfd
->reading_partial_symbols
,
8185 per_objfile
->per_bfd
->info
.read (objfile
);
8187 /* Any cached compilation units will be linked by the per-objfile
8188 read_in_chain. Make sure to free them when we're done. */
8189 free_cached_comp_units
freer (per_objfile
);
8191 build_type_psymtabs (per_objfile
);
8193 create_all_comp_units (per_objfile
);
8195 /* Create a temporary address map on a temporary obstack. We later
8196 copy this to the final obstack. */
8197 auto_obstack temp_obstack
;
8199 scoped_restore save_psymtabs_addrmap
8200 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8201 addrmap_create_mutable (&temp_obstack
));
8203 for (dwarf2_per_cu_data
*per_cu
: per_objfile
->per_bfd
->all_comp_units
)
8205 if (per_cu
->v
.psymtab
!= NULL
)
8206 /* In case a forward DW_TAG_imported_unit has read the CU already. */
8208 process_psymtab_comp_unit (per_cu
, per_objfile
, false,
8212 /* This has to wait until we read the CUs, we need the list of DWOs. */
8213 process_skeletonless_type_units (per_objfile
);
8215 /* Now that all TUs have been processed we can fill in the dependencies. */
8216 if (per_objfile
->per_bfd
->type_unit_groups
!= NULL
)
8218 htab_traverse_noresize (per_objfile
->per_bfd
->type_unit_groups
.get (),
8219 build_type_psymtab_dependencies
, per_objfile
);
8222 if (dwarf_read_debug
> 0)
8223 print_tu_stats (per_objfile
);
8225 set_partial_user (per_objfile
);
8227 objfile
->partial_symtabs
->psymtabs_addrmap
8228 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8229 objfile
->partial_symtabs
->obstack ());
8230 /* At this point we want to keep the address map. */
8231 save_psymtabs_addrmap
.release ();
8233 dwarf_read_debug_printf ("Done building psymtabs of %s",
8234 objfile_name (objfile
));
8237 /* Load the partial DIEs for a secondary CU into memory.
8238 This is also used when rereading a primary CU with load_all_dies. */
8241 load_partial_comp_unit (dwarf2_per_cu_data
*this_cu
,
8242 dwarf2_per_objfile
*per_objfile
,
8243 dwarf2_cu
*existing_cu
)
8245 cutu_reader
reader (this_cu
, per_objfile
, nullptr, existing_cu
, false);
8247 if (!reader
.dummy_p
)
8249 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8252 /* Check if comp unit has_children.
8253 If so, read the rest of the partial symbols from this comp unit.
8254 If not, there's no more debug_info for this comp unit. */
8255 if (reader
.comp_unit_die
->has_children
)
8256 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8263 read_comp_units_from_section (dwarf2_per_objfile
*per_objfile
,
8264 struct dwarf2_section_info
*section
,
8265 struct dwarf2_section_info
*abbrev_section
,
8266 unsigned int is_dwz
)
8268 const gdb_byte
*info_ptr
;
8269 struct objfile
*objfile
= per_objfile
->objfile
;
8271 dwarf_read_debug_printf ("Reading %s for %s",
8272 section
->get_name (),
8273 section
->get_file_name ());
8275 section
->read (objfile
);
8277 info_ptr
= section
->buffer
;
8279 while (info_ptr
< section
->buffer
+ section
->size
)
8281 struct dwarf2_per_cu_data
*this_cu
;
8283 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8285 comp_unit_head cu_header
;
8286 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
8287 abbrev_section
, info_ptr
,
8288 rcuh_kind::COMPILE
);
8290 /* Save the compilation unit for later lookup. */
8291 if (cu_header
.unit_type
!= DW_UT_type
)
8292 this_cu
= per_objfile
->per_bfd
->allocate_per_cu ();
8295 auto sig_type
= per_objfile
->per_bfd
->allocate_signatured_type ();
8296 sig_type
->signature
= cu_header
.signature
;
8297 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8298 this_cu
= &sig_type
->per_cu
;
8300 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8301 this_cu
->sect_off
= sect_off
;
8302 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8303 this_cu
->is_dwz
= is_dwz
;
8304 this_cu
->section
= section
;
8306 per_objfile
->per_bfd
->all_comp_units
.push_back (this_cu
);
8308 info_ptr
= info_ptr
+ this_cu
->length
;
8312 /* Create a list of all compilation units in OBJFILE.
8313 This is only done for -readnow and building partial symtabs. */
8316 create_all_comp_units (dwarf2_per_objfile
*per_objfile
)
8318 gdb_assert (per_objfile
->per_bfd
->all_comp_units
.empty ());
8319 read_comp_units_from_section (per_objfile
, &per_objfile
->per_bfd
->info
,
8320 &per_objfile
->per_bfd
->abbrev
, 0);
8322 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
);
8324 read_comp_units_from_section (per_objfile
, &dwz
->info
, &dwz
->abbrev
, 1);
8327 /* Process all loaded DIEs for compilation unit CU, starting at
8328 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8329 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8330 DW_AT_ranges). See the comments of add_partial_subprogram on how
8331 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8334 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8335 CORE_ADDR
*highpc
, int set_addrmap
,
8336 struct dwarf2_cu
*cu
)
8338 struct partial_die_info
*pdi
;
8340 /* Now, march along the PDI's, descending into ones which have
8341 interesting children but skipping the children of the other ones,
8342 until we reach the end of the compilation unit. */
8350 /* Anonymous namespaces or modules have no name but have interesting
8351 children, so we need to look at them. Ditto for anonymous
8354 if (pdi
->raw_name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8355 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8356 || pdi
->tag
== DW_TAG_imported_unit
8357 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8361 case DW_TAG_subprogram
:
8362 case DW_TAG_inlined_subroutine
:
8363 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8364 if (cu
->language
== language_cplus
)
8365 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8368 case DW_TAG_constant
:
8369 case DW_TAG_variable
:
8370 case DW_TAG_typedef
:
8371 case DW_TAG_union_type
:
8372 if (!pdi
->is_declaration
8373 || (pdi
->tag
== DW_TAG_variable
&& pdi
->is_external
))
8375 add_partial_symbol (pdi
, cu
);
8378 case DW_TAG_class_type
:
8379 case DW_TAG_interface_type
:
8380 case DW_TAG_structure_type
:
8381 if (!pdi
->is_declaration
)
8383 add_partial_symbol (pdi
, cu
);
8385 if ((cu
->language
== language_rust
8386 || cu
->language
== language_cplus
) && pdi
->has_children
)
8387 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8390 case DW_TAG_enumeration_type
:
8391 if (!pdi
->is_declaration
)
8392 add_partial_enumeration (pdi
, cu
);
8394 case DW_TAG_base_type
:
8395 case DW_TAG_subrange_type
:
8396 /* File scope base type definitions are added to the partial
8398 add_partial_symbol (pdi
, cu
);
8400 case DW_TAG_namespace
:
8401 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8404 if (!pdi
->is_declaration
)
8405 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8407 case DW_TAG_imported_unit
:
8409 struct dwarf2_per_cu_data
*per_cu
;
8411 /* For now we don't handle imported units in type units. */
8412 if (cu
->per_cu
->is_debug_types
)
8414 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8415 " supported in type units [in module %s]"),
8416 objfile_name (cu
->per_objfile
->objfile
));
8419 per_cu
= dwarf2_find_containing_comp_unit
8420 (pdi
->d
.sect_off
, pdi
->is_dwz
, cu
->per_objfile
);
8422 /* Go read the partial unit, if needed. */
8423 if (per_cu
->v
.psymtab
== NULL
)
8424 process_psymtab_comp_unit (per_cu
, cu
->per_objfile
, true,
8427 cu
->per_cu
->imported_symtabs_push (per_cu
);
8430 case DW_TAG_imported_declaration
:
8431 add_partial_symbol (pdi
, cu
);
8438 /* If the die has a sibling, skip to the sibling. */
8440 pdi
= pdi
->die_sibling
;
8444 /* Functions used to compute the fully scoped name of a partial DIE.
8446 Normally, this is simple. For C++, the parent DIE's fully scoped
8447 name is concatenated with "::" and the partial DIE's name.
8448 Enumerators are an exception; they use the scope of their parent
8449 enumeration type, i.e. the name of the enumeration type is not
8450 prepended to the enumerator.
8452 There are two complexities. One is DW_AT_specification; in this
8453 case "parent" means the parent of the target of the specification,
8454 instead of the direct parent of the DIE. The other is compilers
8455 which do not emit DW_TAG_namespace; in this case we try to guess
8456 the fully qualified name of structure types from their members'
8457 linkage names. This must be done using the DIE's children rather
8458 than the children of any DW_AT_specification target. We only need
8459 to do this for structures at the top level, i.e. if the target of
8460 any DW_AT_specification (if any; otherwise the DIE itself) does not
8463 /* Compute the scope prefix associated with PDI's parent, in
8464 compilation unit CU. The result will be allocated on CU's
8465 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8466 field. NULL is returned if no prefix is necessary. */
8468 partial_die_parent_scope (struct partial_die_info
*pdi
,
8469 struct dwarf2_cu
*cu
)
8471 const char *grandparent_scope
;
8472 struct partial_die_info
*parent
, *real_pdi
;
8474 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8475 then this means the parent of the specification DIE. */
8478 while (real_pdi
->has_specification
)
8480 auto res
= find_partial_die (real_pdi
->spec_offset
,
8481 real_pdi
->spec_is_dwz
, cu
);
8486 parent
= real_pdi
->die_parent
;
8490 if (parent
->scope_set
)
8491 return parent
->scope
;
8495 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8497 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8498 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8499 Work around this problem here. */
8500 if (cu
->language
== language_cplus
8501 && parent
->tag
== DW_TAG_namespace
8502 && strcmp (parent
->name (cu
), "::") == 0
8503 && grandparent_scope
== NULL
)
8505 parent
->scope
= NULL
;
8506 parent
->scope_set
= 1;
8510 /* Nested subroutines in Fortran get a prefix. */
8511 if (pdi
->tag
== DW_TAG_enumerator
)
8512 /* Enumerators should not get the name of the enumeration as a prefix. */
8513 parent
->scope
= grandparent_scope
;
8514 else if (parent
->tag
== DW_TAG_namespace
8515 || parent
->tag
== DW_TAG_module
8516 || parent
->tag
== DW_TAG_structure_type
8517 || parent
->tag
== DW_TAG_class_type
8518 || parent
->tag
== DW_TAG_interface_type
8519 || parent
->tag
== DW_TAG_union_type
8520 || parent
->tag
== DW_TAG_enumeration_type
8521 || (cu
->language
== language_fortran
8522 && parent
->tag
== DW_TAG_subprogram
8523 && pdi
->tag
== DW_TAG_subprogram
))
8525 if (grandparent_scope
== NULL
)
8526 parent
->scope
= parent
->name (cu
);
8528 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8530 parent
->name (cu
), 0, cu
);
8534 /* FIXME drow/2004-04-01: What should we be doing with
8535 function-local names? For partial symbols, we should probably be
8537 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8538 dwarf_tag_name (parent
->tag
),
8539 sect_offset_str (pdi
->sect_off
));
8540 parent
->scope
= grandparent_scope
;
8543 parent
->scope_set
= 1;
8544 return parent
->scope
;
8547 /* Return the fully scoped name associated with PDI, from compilation unit
8548 CU. The result will be allocated with malloc. */
8550 static gdb::unique_xmalloc_ptr
<char>
8551 partial_die_full_name (struct partial_die_info
*pdi
,
8552 struct dwarf2_cu
*cu
)
8554 const char *parent_scope
;
8556 /* If this is a template instantiation, we can not work out the
8557 template arguments from partial DIEs. So, unfortunately, we have
8558 to go through the full DIEs. At least any work we do building
8559 types here will be reused if full symbols are loaded later. */
8560 if (pdi
->has_template_arguments
)
8564 if (pdi
->name (cu
) != NULL
&& strchr (pdi
->name (cu
), '<') == NULL
)
8566 struct die_info
*die
;
8567 struct attribute attr
;
8568 struct dwarf2_cu
*ref_cu
= cu
;
8570 /* DW_FORM_ref_addr is using section offset. */
8571 attr
.name
= (enum dwarf_attribute
) 0;
8572 attr
.form
= DW_FORM_ref_addr
;
8573 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8574 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8576 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8580 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8581 if (parent_scope
== NULL
)
8584 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8590 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8592 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
8593 struct objfile
*objfile
= per_objfile
->objfile
;
8594 struct gdbarch
*gdbarch
= objfile
->arch ();
8596 const char *actual_name
= NULL
;
8599 baseaddr
= objfile
->text_section_offset ();
8601 gdb::unique_xmalloc_ptr
<char> built_actual_name
8602 = partial_die_full_name (pdi
, cu
);
8603 if (built_actual_name
!= NULL
)
8604 actual_name
= built_actual_name
.get ();
8606 if (actual_name
== NULL
)
8607 actual_name
= pdi
->name (cu
);
8609 partial_symbol psymbol
;
8610 memset (&psymbol
, 0, sizeof (psymbol
));
8611 psymbol
.ginfo
.set_language (cu
->language
, &objfile
->objfile_obstack
);
8612 psymbol
.ginfo
.set_section_index (-1);
8614 /* The code below indicates that the psymbol should be installed by
8616 gdb::optional
<psymbol_placement
> where
;
8620 case DW_TAG_inlined_subroutine
:
8621 case DW_TAG_subprogram
:
8622 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8624 if (pdi
->is_external
8625 || cu
->language
== language_ada
8626 || (cu
->language
== language_fortran
8627 && pdi
->die_parent
!= NULL
8628 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8630 /* Normally, only "external" DIEs are part of the global scope.
8631 But in Ada and Fortran, we want to be able to access nested
8632 procedures globally. So all Ada and Fortran subprograms are
8633 stored in the global scope. */
8634 where
= psymbol_placement::GLOBAL
;
8637 where
= psymbol_placement::STATIC
;
8639 psymbol
.domain
= VAR_DOMAIN
;
8640 psymbol
.aclass
= LOC_BLOCK
;
8641 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8642 psymbol
.ginfo
.value
.address
= addr
;
8644 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8645 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8647 case DW_TAG_constant
:
8648 psymbol
.domain
= VAR_DOMAIN
;
8649 psymbol
.aclass
= LOC_STATIC
;
8650 where
= (pdi
->is_external
8651 ? psymbol_placement::GLOBAL
8652 : psymbol_placement::STATIC
);
8654 case DW_TAG_variable
:
8656 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8660 && !per_objfile
->per_bfd
->has_section_at_zero
)
8662 /* A global or static variable may also have been stripped
8663 out by the linker if unused, in which case its address
8664 will be nullified; do not add such variables into partial
8665 symbol table then. */
8667 else if (pdi
->is_external
)
8670 Don't enter into the minimal symbol tables as there is
8671 a minimal symbol table entry from the ELF symbols already.
8672 Enter into partial symbol table if it has a location
8673 descriptor or a type.
8674 If the location descriptor is missing, new_symbol will create
8675 a LOC_UNRESOLVED symbol, the address of the variable will then
8676 be determined from the minimal symbol table whenever the variable
8678 The address for the partial symbol table entry is not
8679 used by GDB, but it comes in handy for debugging partial symbol
8682 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8684 psymbol
.domain
= VAR_DOMAIN
;
8685 psymbol
.aclass
= LOC_STATIC
;
8686 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8687 psymbol
.ginfo
.value
.address
= addr
;
8688 where
= psymbol_placement::GLOBAL
;
8693 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8695 /* Static Variable. Skip symbols whose value we cannot know (those
8696 without location descriptors or constant values). */
8697 if (!has_loc
&& !pdi
->has_const_value
)
8700 psymbol
.domain
= VAR_DOMAIN
;
8701 psymbol
.aclass
= LOC_STATIC
;
8702 psymbol
.ginfo
.set_section_index (SECT_OFF_TEXT (objfile
));
8704 psymbol
.ginfo
.value
.address
= addr
;
8705 where
= psymbol_placement::STATIC
;
8708 case DW_TAG_array_type
:
8709 case DW_TAG_typedef
:
8710 case DW_TAG_base_type
:
8711 case DW_TAG_subrange_type
:
8712 psymbol
.domain
= VAR_DOMAIN
;
8713 psymbol
.aclass
= LOC_TYPEDEF
;
8714 where
= psymbol_placement::STATIC
;
8716 case DW_TAG_imported_declaration
:
8717 case DW_TAG_namespace
:
8718 psymbol
.domain
= VAR_DOMAIN
;
8719 psymbol
.aclass
= LOC_TYPEDEF
;
8720 where
= psymbol_placement::GLOBAL
;
8723 /* With Fortran 77 there might be a "BLOCK DATA" module
8724 available without any name. If so, we skip the module as it
8725 doesn't bring any value. */
8726 if (actual_name
!= nullptr)
8728 psymbol
.domain
= MODULE_DOMAIN
;
8729 psymbol
.aclass
= LOC_TYPEDEF
;
8730 where
= psymbol_placement::GLOBAL
;
8733 case DW_TAG_class_type
:
8734 case DW_TAG_interface_type
:
8735 case DW_TAG_structure_type
:
8736 case DW_TAG_union_type
:
8737 case DW_TAG_enumeration_type
:
8738 /* Skip external references. The DWARF standard says in the section
8739 about "Structure, Union, and Class Type Entries": "An incomplete
8740 structure, union or class type is represented by a structure,
8741 union or class entry that does not have a byte size attribute
8742 and that has a DW_AT_declaration attribute." */
8743 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8746 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8747 static vs. global. */
8748 psymbol
.domain
= STRUCT_DOMAIN
;
8749 psymbol
.aclass
= LOC_TYPEDEF
;
8750 where
= (cu
->language
== language_cplus
8751 ? psymbol_placement::GLOBAL
8752 : psymbol_placement::STATIC
);
8754 case DW_TAG_enumerator
:
8755 psymbol
.domain
= VAR_DOMAIN
;
8756 psymbol
.aclass
= LOC_CONST
;
8757 where
= (cu
->language
== language_cplus
8758 ? psymbol_placement::GLOBAL
8759 : psymbol_placement::STATIC
);
8765 if (where
.has_value ())
8767 if (built_actual_name
!= nullptr)
8768 actual_name
= objfile
->intern (actual_name
);
8769 if (pdi
->linkage_name
== nullptr || cu
->language
== language_ada
)
8770 psymbol
.ginfo
.set_linkage_name (actual_name
);
8773 psymbol
.ginfo
.set_demangled_name (actual_name
,
8774 &objfile
->objfile_obstack
);
8775 psymbol
.ginfo
.set_linkage_name (pdi
->linkage_name
);
8777 cu
->per_cu
->v
.psymtab
->add_psymbol (psymbol
, *where
, objfile
);
8781 /* Read a partial die corresponding to a namespace; also, add a symbol
8782 corresponding to that namespace to the symbol table. NAMESPACE is
8783 the name of the enclosing namespace. */
8786 add_partial_namespace (struct partial_die_info
*pdi
,
8787 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8788 int set_addrmap
, struct dwarf2_cu
*cu
)
8790 /* Add a symbol for the namespace. */
8792 add_partial_symbol (pdi
, cu
);
8794 /* Now scan partial symbols in that namespace. */
8796 if (pdi
->has_children
)
8797 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8800 /* Read a partial die corresponding to a Fortran module. */
8803 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8804 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8806 /* Add a symbol for the namespace. */
8808 add_partial_symbol (pdi
, cu
);
8810 /* Now scan partial symbols in that module. */
8812 if (pdi
->has_children
)
8813 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8816 /* Read a partial die corresponding to a subprogram or an inlined
8817 subprogram and create a partial symbol for that subprogram.
8818 When the CU language allows it, this routine also defines a partial
8819 symbol for each nested subprogram that this subprogram contains.
8820 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8821 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8823 PDI may also be a lexical block, in which case we simply search
8824 recursively for subprograms defined inside that lexical block.
8825 Again, this is only performed when the CU language allows this
8826 type of definitions. */
8829 add_partial_subprogram (struct partial_die_info
*pdi
,
8830 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8831 int set_addrmap
, struct dwarf2_cu
*cu
)
8833 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8835 if (pdi
->has_pc_info
)
8837 if (pdi
->lowpc
< *lowpc
)
8838 *lowpc
= pdi
->lowpc
;
8839 if (pdi
->highpc
> *highpc
)
8840 *highpc
= pdi
->highpc
;
8843 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
8844 struct gdbarch
*gdbarch
= objfile
->arch ();
8846 CORE_ADDR this_highpc
;
8847 CORE_ADDR this_lowpc
;
8849 baseaddr
= objfile
->text_section_offset ();
8851 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8852 pdi
->lowpc
+ baseaddr
)
8855 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8856 pdi
->highpc
+ baseaddr
)
8858 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8859 this_lowpc
, this_highpc
- 1,
8860 cu
->per_cu
->v
.psymtab
);
8864 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8866 if (!pdi
->is_declaration
)
8867 /* Ignore subprogram DIEs that do not have a name, they are
8868 illegal. Do not emit a complaint at this point, we will
8869 do so when we convert this psymtab into a symtab. */
8871 add_partial_symbol (pdi
, cu
);
8875 if (! pdi
->has_children
)
8878 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8880 pdi
= pdi
->die_child
;
8884 if (pdi
->tag
== DW_TAG_subprogram
8885 || pdi
->tag
== DW_TAG_inlined_subroutine
8886 || pdi
->tag
== DW_TAG_lexical_block
)
8887 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8888 pdi
= pdi
->die_sibling
;
8893 /* Read a partial die corresponding to an enumeration type. */
8896 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8897 struct dwarf2_cu
*cu
)
8899 struct partial_die_info
*pdi
;
8901 if (enum_pdi
->name (cu
) != NULL
)
8902 add_partial_symbol (enum_pdi
, cu
);
8904 pdi
= enum_pdi
->die_child
;
8907 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->raw_name
== NULL
)
8908 complaint (_("malformed enumerator DIE ignored"));
8910 add_partial_symbol (pdi
, cu
);
8911 pdi
= pdi
->die_sibling
;
8915 /* Return the initial uleb128 in the die at INFO_PTR. */
8918 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8920 unsigned int bytes_read
;
8922 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8925 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8926 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8928 Return the corresponding abbrev, or NULL if the number is zero (indicating
8929 an empty DIE). In either case *BYTES_READ will be set to the length of
8930 the initial number. */
8932 static struct abbrev_info
*
8933 peek_die_abbrev (const die_reader_specs
&reader
,
8934 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8936 dwarf2_cu
*cu
= reader
.cu
;
8937 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
8938 unsigned int abbrev_number
8939 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8941 if (abbrev_number
== 0)
8944 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8947 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8948 " at offset %s [in module %s]"),
8949 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8950 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8956 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8957 Returns a pointer to the end of a series of DIEs, terminated by an empty
8958 DIE. Any children of the skipped DIEs will also be skipped. */
8960 static const gdb_byte
*
8961 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8965 unsigned int bytes_read
;
8966 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8969 return info_ptr
+ bytes_read
;
8971 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8975 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8976 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8977 abbrev corresponding to that skipped uleb128 should be passed in
8978 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8981 static const gdb_byte
*
8982 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8983 struct abbrev_info
*abbrev
)
8985 unsigned int bytes_read
;
8986 struct attribute attr
;
8987 bfd
*abfd
= reader
->abfd
;
8988 struct dwarf2_cu
*cu
= reader
->cu
;
8989 const gdb_byte
*buffer
= reader
->buffer
;
8990 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8991 unsigned int form
, i
;
8993 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8995 /* The only abbrev we care about is DW_AT_sibling. */
8996 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8998 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
8999 if (attr
.form
== DW_FORM_ref_addr
)
9000 complaint (_("ignoring absolute DW_AT_sibling"));
9003 sect_offset off
= attr
.get_ref_die_offset ();
9004 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9006 if (sibling_ptr
< info_ptr
)
9007 complaint (_("DW_AT_sibling points backwards"));
9008 else if (sibling_ptr
> reader
->buffer_end
)
9009 reader
->die_section
->overflow_complaint ();
9015 /* If it isn't DW_AT_sibling, skip this attribute. */
9016 form
= abbrev
->attrs
[i
].form
;
9020 case DW_FORM_ref_addr
:
9021 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9022 and later it is offset sized. */
9023 if (cu
->header
.version
== 2)
9024 info_ptr
+= cu
->header
.addr_size
;
9026 info_ptr
+= cu
->header
.offset_size
;
9028 case DW_FORM_GNU_ref_alt
:
9029 info_ptr
+= cu
->header
.offset_size
;
9032 info_ptr
+= cu
->header
.addr_size
;
9040 case DW_FORM_flag_present
:
9041 case DW_FORM_implicit_const
:
9058 case DW_FORM_ref_sig8
:
9061 case DW_FORM_data16
:
9064 case DW_FORM_string
:
9065 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9066 info_ptr
+= bytes_read
;
9068 case DW_FORM_sec_offset
:
9070 case DW_FORM_GNU_strp_alt
:
9071 info_ptr
+= cu
->header
.offset_size
;
9073 case DW_FORM_exprloc
:
9075 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9076 info_ptr
+= bytes_read
;
9078 case DW_FORM_block1
:
9079 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9081 case DW_FORM_block2
:
9082 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9084 case DW_FORM_block4
:
9085 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9091 case DW_FORM_ref_udata
:
9092 case DW_FORM_GNU_addr_index
:
9093 case DW_FORM_GNU_str_index
:
9094 case DW_FORM_rnglistx
:
9095 case DW_FORM_loclistx
:
9096 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9098 case DW_FORM_indirect
:
9099 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9100 info_ptr
+= bytes_read
;
9101 /* We need to continue parsing from here, so just go back to
9103 goto skip_attribute
;
9106 error (_("Dwarf Error: Cannot handle %s "
9107 "in DWARF reader [in module %s]"),
9108 dwarf_form_name (form
),
9109 bfd_get_filename (abfd
));
9113 if (abbrev
->has_children
)
9114 return skip_children (reader
, info_ptr
);
9119 /* Locate ORIG_PDI's sibling.
9120 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9122 static const gdb_byte
*
9123 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9124 struct partial_die_info
*orig_pdi
,
9125 const gdb_byte
*info_ptr
)
9127 /* Do we know the sibling already? */
9129 if (orig_pdi
->sibling
)
9130 return orig_pdi
->sibling
;
9132 /* Are there any children to deal with? */
9134 if (!orig_pdi
->has_children
)
9137 /* Skip the children the long way. */
9139 return skip_children (reader
, info_ptr
);
9142 /* Expand this partial symbol table into a full symbol table. SELF is
9146 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
9148 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9150 gdb_assert (!per_objfile
->symtab_set_p (per_cu_data
));
9152 /* If this psymtab is constructed from a debug-only objfile, the
9153 has_section_at_zero flag will not necessarily be correct. We
9154 can get the correct value for this flag by looking at the data
9155 associated with the (presumably stripped) associated objfile. */
9156 if (objfile
->separate_debug_objfile_backlink
)
9158 dwarf2_per_objfile
*per_objfile_backlink
9159 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9161 per_objfile
->per_bfd
->has_section_at_zero
9162 = per_objfile_backlink
->per_bfd
->has_section_at_zero
;
9165 expand_psymtab (objfile
);
9167 process_cu_includes (per_objfile
);
9170 /* Reading in full CUs. */
9172 /* Add PER_CU to the queue. */
9175 queue_comp_unit (dwarf2_per_cu_data
*per_cu
,
9176 dwarf2_per_objfile
*per_objfile
,
9177 enum language pretend_language
)
9181 gdb_assert (per_objfile
->per_bfd
->queue
.has_value ());
9182 per_cu
->per_bfd
->queue
->emplace (per_cu
, per_objfile
, pretend_language
);
9185 /* If PER_CU is not yet expanded of queued for expansion, add it to the queue.
9187 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9190 Return true if maybe_queue_comp_unit requires the caller to load the CU's
9191 DIEs, false otherwise.
9193 Explanation: there is an invariant that if a CU is queued for expansion
9194 (present in `dwarf2_per_bfd::queue`), then its DIEs are loaded
9195 (a dwarf2_cu object exists for this CU, and `dwarf2_per_objfile::get_cu`
9196 returns non-nullptr). If the CU gets enqueued by this function but its DIEs
9197 are not yet loaded, the the caller must load the CU's DIEs to ensure the
9198 invariant is respected.
9200 The caller is therefore not required to load the CU's DIEs (we return false)
9203 - the CU is already expanded, and therefore does not get enqueued
9204 - the CU gets enqueued for expansion, but its DIEs are already loaded
9206 Note that the caller should not use this function's return value as an
9207 indicator of whether the CU's DIEs are loaded right now, it should check
9208 that by calling `dwarf2_per_objfile::get_cu` instead. */
9211 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9212 dwarf2_per_cu_data
*per_cu
,
9213 dwarf2_per_objfile
*per_objfile
,
9214 enum language pretend_language
)
9216 /* We may arrive here during partial symbol reading, if we need full
9217 DIEs to process an unusual case (e.g. template arguments). Do
9218 not queue PER_CU, just tell our caller to load its DIEs. */
9219 if (per_cu
->per_bfd
->reading_partial_symbols
)
9221 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9223 if (cu
== NULL
|| cu
->dies
== NULL
)
9228 /* Mark the dependence relation so that we don't flush PER_CU
9230 if (dependent_cu
!= NULL
)
9231 dwarf2_add_dependence (dependent_cu
, per_cu
);
9233 /* If it's already on the queue, we have nothing to do. */
9236 /* Verify the invariant that if a CU is queued for expansion, its DIEs are
9238 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
9240 /* If the CU is queued for expansion, it should not already be
9242 gdb_assert (!per_objfile
->symtab_set_p (per_cu
));
9244 /* The DIEs are already loaded, the caller doesn't need to do it. */
9248 bool queued
= false;
9249 if (!per_objfile
->symtab_set_p (per_cu
))
9251 /* Add it to the queue. */
9252 queue_comp_unit (per_cu
, per_objfile
, pretend_language
);
9256 /* If the compilation unit is already loaded, just mark it as
9258 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9262 /* Ask the caller to load the CU's DIEs if the CU got enqueued for expansion
9263 and the DIEs are not already loaded. */
9264 return queued
&& cu
== nullptr;
9267 /* Process the queue. */
9270 process_queue (dwarf2_per_objfile
*per_objfile
)
9272 dwarf_read_debug_printf ("Expanding one or more symtabs of objfile %s ...",
9273 objfile_name (per_objfile
->objfile
));
9275 /* The queue starts out with one item, but following a DIE reference
9276 may load a new CU, adding it to the end of the queue. */
9277 while (!per_objfile
->per_bfd
->queue
->empty ())
9279 dwarf2_queue_item
&item
= per_objfile
->per_bfd
->queue
->front ();
9280 dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
9282 if (!per_objfile
->symtab_set_p (per_cu
))
9284 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
9286 /* Skip dummy CUs. */
9289 unsigned int debug_print_threshold
;
9292 if (per_cu
->is_debug_types
)
9294 struct signatured_type
*sig_type
=
9295 (struct signatured_type
*) per_cu
;
9297 sprintf (buf
, "TU %s at offset %s",
9298 hex_string (sig_type
->signature
),
9299 sect_offset_str (per_cu
->sect_off
));
9300 /* There can be 100s of TUs.
9301 Only print them in verbose mode. */
9302 debug_print_threshold
= 2;
9306 sprintf (buf
, "CU at offset %s",
9307 sect_offset_str (per_cu
->sect_off
));
9308 debug_print_threshold
= 1;
9311 if (dwarf_read_debug
>= debug_print_threshold
)
9312 dwarf_read_debug_printf ("Expanding symtab of %s", buf
);
9314 if (per_cu
->is_debug_types
)
9315 process_full_type_unit (cu
, item
.pretend_language
);
9317 process_full_comp_unit (cu
, item
.pretend_language
);
9319 if (dwarf_read_debug
>= debug_print_threshold
)
9320 dwarf_read_debug_printf ("Done expanding %s", buf
);
9325 per_objfile
->per_bfd
->queue
->pop ();
9328 dwarf_read_debug_printf ("Done expanding symtabs of %s.",
9329 objfile_name (per_objfile
->objfile
));
9332 /* Read in full symbols for PST, and anything it depends on. */
9335 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9337 gdb_assert (!readin_p (objfile
));
9339 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9340 free_cached_comp_units
freer (per_objfile
);
9341 expand_dependencies (objfile
);
9343 dw2_do_instantiate_symtab (per_cu_data
, per_objfile
, false);
9344 gdb_assert (get_compunit_symtab (objfile
) != nullptr);
9347 /* See psympriv.h. */
9350 dwarf2_psymtab::readin_p (struct objfile
*objfile
) const
9352 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9353 return per_objfile
->symtab_set_p (per_cu_data
);
9356 /* See psympriv.h. */
9359 dwarf2_psymtab::get_compunit_symtab (struct objfile
*objfile
) const
9361 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
9362 return per_objfile
->get_symtab (per_cu_data
);
9365 /* Trivial hash function for die_info: the hash value of a DIE
9366 is its offset in .debug_info for this objfile. */
9369 die_hash (const void *item
)
9371 const struct die_info
*die
= (const struct die_info
*) item
;
9373 return to_underlying (die
->sect_off
);
9376 /* Trivial comparison function for die_info structures: two DIEs
9377 are equal if they have the same offset. */
9380 die_eq (const void *item_lhs
, const void *item_rhs
)
9382 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9383 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9385 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9388 /* Load the DIEs associated with PER_CU into memory.
9390 In some cases, the caller, while reading partial symbols, will need to load
9391 the full symbols for the CU for some reason. It will already have a
9392 dwarf2_cu object for THIS_CU and pass it as EXISTING_CU, so it can be re-used
9393 rather than creating a new one. */
9396 load_full_comp_unit (dwarf2_per_cu_data
*this_cu
,
9397 dwarf2_per_objfile
*per_objfile
,
9398 dwarf2_cu
*existing_cu
,
9400 enum language pretend_language
)
9402 gdb_assert (! this_cu
->is_debug_types
);
9404 cutu_reader
reader (this_cu
, per_objfile
, NULL
, existing_cu
, skip_partial
);
9408 struct dwarf2_cu
*cu
= reader
.cu
;
9409 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9411 gdb_assert (cu
->die_hash
== NULL
);
9413 htab_create_alloc_ex (cu
->header
.length
/ 12,
9417 &cu
->comp_unit_obstack
,
9418 hashtab_obstack_allocate
,
9419 dummy_obstack_deallocate
);
9421 if (reader
.comp_unit_die
->has_children
)
9422 reader
.comp_unit_die
->child
9423 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9424 &info_ptr
, reader
.comp_unit_die
);
9425 cu
->dies
= reader
.comp_unit_die
;
9426 /* comp_unit_die is not stored in die_hash, no need. */
9428 /* We try not to read any attributes in this function, because not
9429 all CUs needed for references have been loaded yet, and symbol
9430 table processing isn't initialized. But we have to set the CU language,
9431 or we won't be able to build types correctly.
9432 Similarly, if we do not read the producer, we can not apply
9433 producer-specific interpretation. */
9434 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9439 /* Add a DIE to the delayed physname list. */
9442 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9443 const char *name
, struct die_info
*die
,
9444 struct dwarf2_cu
*cu
)
9446 struct delayed_method_info mi
;
9448 mi
.fnfield_index
= fnfield_index
;
9452 cu
->method_list
.push_back (mi
);
9455 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9456 "const" / "volatile". If so, decrements LEN by the length of the
9457 modifier and return true. Otherwise return false. */
9461 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9463 size_t mod_len
= sizeof (mod
) - 1;
9464 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9472 /* Compute the physnames of any methods on the CU's method list.
9474 The computation of method physnames is delayed in order to avoid the
9475 (bad) condition that one of the method's formal parameters is of an as yet
9479 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9481 /* Only C++ delays computing physnames. */
9482 if (cu
->method_list
.empty ())
9484 gdb_assert (cu
->language
== language_cplus
);
9486 for (const delayed_method_info
&mi
: cu
->method_list
)
9488 const char *physname
;
9489 struct fn_fieldlist
*fn_flp
9490 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9491 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9492 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9493 = physname
? physname
: "";
9495 /* Since there's no tag to indicate whether a method is a
9496 const/volatile overload, extract that information out of the
9498 if (physname
!= NULL
)
9500 size_t len
= strlen (physname
);
9504 if (physname
[len
] == ')') /* shortcut */
9506 else if (check_modifier (physname
, len
, " const"))
9507 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9508 else if (check_modifier (physname
, len
, " volatile"))
9509 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9516 /* The list is no longer needed. */
9517 cu
->method_list
.clear ();
9520 /* Go objects should be embedded in a DW_TAG_module DIE,
9521 and it's not clear if/how imported objects will appear.
9522 To keep Go support simple until that's worked out,
9523 go back through what we've read and create something usable.
9524 We could do this while processing each DIE, and feels kinda cleaner,
9525 but that way is more invasive.
9526 This is to, for example, allow the user to type "p var" or "b main"
9527 without having to specify the package name, and allow lookups
9528 of module.object to work in contexts that use the expression
9532 fixup_go_packaging (struct dwarf2_cu
*cu
)
9534 gdb::unique_xmalloc_ptr
<char> package_name
;
9535 struct pending
*list
;
9538 for (list
= *cu
->get_builder ()->get_global_symbols ();
9542 for (i
= 0; i
< list
->nsyms
; ++i
)
9544 struct symbol
*sym
= list
->symbol
[i
];
9546 if (sym
->language () == language_go
9547 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9549 gdb::unique_xmalloc_ptr
<char> this_package_name
9550 (go_symbol_package_name (sym
));
9552 if (this_package_name
== NULL
)
9554 if (package_name
== NULL
)
9555 package_name
= std::move (this_package_name
);
9558 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9559 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9560 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9561 (symbol_symtab (sym
) != NULL
9562 ? symtab_to_filename_for_display
9563 (symbol_symtab (sym
))
9564 : objfile_name (objfile
)),
9565 this_package_name
.get (), package_name
.get ());
9571 if (package_name
!= NULL
)
9573 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
9574 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9575 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9576 saved_package_name
);
9579 sym
= new (&objfile
->objfile_obstack
) symbol
;
9580 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9581 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9582 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9583 e.g., "main" finds the "main" module and not C's main(). */
9584 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9585 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9586 SYMBOL_TYPE (sym
) = type
;
9588 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9592 /* Allocate a fully-qualified name consisting of the two parts on the
9596 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9598 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9601 /* A helper that allocates a variant part to attach to a Rust enum
9602 type. OBSTACK is where the results should be allocated. TYPE is
9603 the type we're processing. DISCRIMINANT_INDEX is the index of the
9604 discriminant. It must be the index of one of the fields of TYPE,
9605 or -1 to mean there is no discriminant (univariant enum).
9606 DEFAULT_INDEX is the index of the default field; or -1 if there is
9607 no default. RANGES is indexed by "effective" field number (the
9608 field index, but omitting the discriminant and default fields) and
9609 must hold the discriminant values used by the variants. Note that
9610 RANGES must have a lifetime at least as long as OBSTACK -- either
9611 already allocated on it, or static. */
9614 alloc_rust_variant (struct obstack
*obstack
, struct type
*type
,
9615 int discriminant_index
, int default_index
,
9616 gdb::array_view
<discriminant_range
> ranges
)
9618 /* When DISCRIMINANT_INDEX == -1, we have a univariant enum. */
9619 gdb_assert (discriminant_index
== -1
9620 || (discriminant_index
>= 0
9621 && discriminant_index
< type
->num_fields ()));
9622 gdb_assert (default_index
== -1
9623 || (default_index
>= 0 && default_index
< type
->num_fields ()));
9625 /* We have one variant for each non-discriminant field. */
9626 int n_variants
= type
->num_fields ();
9627 if (discriminant_index
!= -1)
9630 variant
*variants
= new (obstack
) variant
[n_variants
];
9633 for (int i
= 0; i
< type
->num_fields (); ++i
)
9635 if (i
== discriminant_index
)
9638 variants
[var_idx
].first_field
= i
;
9639 variants
[var_idx
].last_field
= i
+ 1;
9641 /* The default field does not need a range, but other fields do.
9642 We skipped the discriminant above. */
9643 if (i
!= default_index
)
9645 variants
[var_idx
].discriminants
= ranges
.slice (range_idx
, 1);
9652 gdb_assert (range_idx
== ranges
.size ());
9653 gdb_assert (var_idx
== n_variants
);
9655 variant_part
*part
= new (obstack
) variant_part
;
9656 part
->discriminant_index
= discriminant_index
;
9657 /* If there is no discriminant, then whether it is signed is of no
9660 = (discriminant_index
== -1
9662 : type
->field (discriminant_index
).type ()->is_unsigned ());
9663 part
->variants
= gdb::array_view
<variant
> (variants
, n_variants
);
9665 void *storage
= obstack_alloc (obstack
, sizeof (gdb::array_view
<variant_part
>));
9666 gdb::array_view
<variant_part
> *prop_value
9667 = new (storage
) gdb::array_view
<variant_part
> (part
, 1);
9669 struct dynamic_prop prop
;
9670 prop
.set_variant_parts (prop_value
);
9672 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
9675 /* Some versions of rustc emitted enums in an unusual way.
9677 Ordinary enums were emitted as unions. The first element of each
9678 structure in the union was named "RUST$ENUM$DISR". This element
9679 held the discriminant.
9681 These versions of Rust also implemented the "non-zero"
9682 optimization. When the enum had two values, and one is empty and
9683 the other holds a pointer that cannot be zero, the pointer is used
9684 as the discriminant, with a zero value meaning the empty variant.
9685 Here, the union's first member is of the form
9686 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9687 where the fieldnos are the indices of the fields that should be
9688 traversed in order to find the field (which may be several fields deep)
9689 and the variantname is the name of the variant of the case when the
9692 This function recognizes whether TYPE is of one of these forms,
9693 and, if so, smashes it to be a variant type. */
9696 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9698 gdb_assert (type
->code () == TYPE_CODE_UNION
);
9700 /* We don't need to deal with empty enums. */
9701 if (type
->num_fields () == 0)
9704 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9705 if (type
->num_fields () == 1
9706 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9708 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9710 /* Decode the field name to find the offset of the
9712 ULONGEST bit_offset
= 0;
9713 struct type
*field_type
= type
->field (0).type ();
9714 while (name
[0] >= '0' && name
[0] <= '9')
9717 unsigned long index
= strtoul (name
, &tail
, 10);
9720 || index
>= field_type
->num_fields ()
9721 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9722 != FIELD_LOC_KIND_BITPOS
))
9724 complaint (_("Could not parse Rust enum encoding string \"%s\""
9726 TYPE_FIELD_NAME (type
, 0),
9727 objfile_name (objfile
));
9732 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9733 field_type
= field_type
->field (index
).type ();
9736 /* Smash this type to be a structure type. We have to do this
9737 because the type has already been recorded. */
9738 type
->set_code (TYPE_CODE_STRUCT
);
9739 type
->set_num_fields (3);
9740 /* Save the field we care about. */
9741 struct field saved_field
= type
->field (0);
9743 ((struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
)));
9745 /* Put the discriminant at index 0. */
9746 type
->field (0).set_type (field_type
);
9747 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9748 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9749 SET_FIELD_BITPOS (type
->field (0), bit_offset
);
9751 /* The order of fields doesn't really matter, so put the real
9752 field at index 1 and the data-less field at index 2. */
9753 type
->field (1) = saved_field
;
9754 TYPE_FIELD_NAME (type
, 1)
9755 = rust_last_path_segment (type
->field (1).type ()->name ());
9756 type
->field (1).type ()->set_name
9757 (rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9758 TYPE_FIELD_NAME (type
, 1)));
9760 const char *dataless_name
9761 = rust_fully_qualify (&objfile
->objfile_obstack
, type
->name (),
9763 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9765 type
->field (2).set_type (dataless_type
);
9766 /* NAME points into the original discriminant name, which
9767 already has the correct lifetime. */
9768 TYPE_FIELD_NAME (type
, 2) = name
;
9769 SET_FIELD_BITPOS (type
->field (2), 0);
9771 /* Indicate that this is a variant type. */
9772 static discriminant_range ranges
[1] = { { 0, 0 } };
9773 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, 1, ranges
);
9775 /* A union with a single anonymous field is probably an old-style
9777 else if (type
->num_fields () == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9779 /* Smash this type to be a structure type. We have to do this
9780 because the type has already been recorded. */
9781 type
->set_code (TYPE_CODE_STRUCT
);
9783 struct type
*field_type
= type
->field (0).type ();
9784 const char *variant_name
9785 = rust_last_path_segment (field_type
->name ());
9786 TYPE_FIELD_NAME (type
, 0) = variant_name
;
9787 field_type
->set_name
9788 (rust_fully_qualify (&objfile
->objfile_obstack
,
9789 type
->name (), variant_name
));
9791 alloc_rust_variant (&objfile
->objfile_obstack
, type
, -1, 0, {});
9795 struct type
*disr_type
= nullptr;
9796 for (int i
= 0; i
< type
->num_fields (); ++i
)
9798 disr_type
= type
->field (i
).type ();
9800 if (disr_type
->code () != TYPE_CODE_STRUCT
)
9802 /* All fields of a true enum will be structs. */
9805 else if (disr_type
->num_fields () == 0)
9807 /* Could be data-less variant, so keep going. */
9808 disr_type
= nullptr;
9810 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9811 "RUST$ENUM$DISR") != 0)
9813 /* Not a Rust enum. */
9823 /* If we got here without a discriminant, then it's probably
9825 if (disr_type
== nullptr)
9828 /* Smash this type to be a structure type. We have to do this
9829 because the type has already been recorded. */
9830 type
->set_code (TYPE_CODE_STRUCT
);
9832 /* Make space for the discriminant field. */
9833 struct field
*disr_field
= &disr_type
->field (0);
9835 = (struct field
*) TYPE_ZALLOC (type
, ((type
->num_fields () + 1)
9836 * sizeof (struct field
)));
9837 memcpy (new_fields
+ 1, type
->fields (),
9838 type
->num_fields () * sizeof (struct field
));
9839 type
->set_fields (new_fields
);
9840 type
->set_num_fields (type
->num_fields () + 1);
9842 /* Install the discriminant at index 0 in the union. */
9843 type
->field (0) = *disr_field
;
9844 TYPE_FIELD_ARTIFICIAL (type
, 0) = 1;
9845 TYPE_FIELD_NAME (type
, 0) = "<<discriminant>>";
9847 /* We need a way to find the correct discriminant given a
9848 variant name. For convenience we build a map here. */
9849 struct type
*enum_type
= disr_field
->type ();
9850 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9851 for (int i
= 0; i
< enum_type
->num_fields (); ++i
)
9853 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9856 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9857 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9861 int n_fields
= type
->num_fields ();
9862 /* We don't need a range entry for the discriminant, but we do
9863 need one for every other field, as there is no default
9865 discriminant_range
*ranges
= XOBNEWVEC (&objfile
->objfile_obstack
,
9868 /* Skip the discriminant here. */
9869 for (int i
= 1; i
< n_fields
; ++i
)
9871 /* Find the final word in the name of this variant's type.
9872 That name can be used to look up the correct
9874 const char *variant_name
9875 = rust_last_path_segment (type
->field (i
).type ()->name ());
9877 auto iter
= discriminant_map
.find (variant_name
);
9878 if (iter
!= discriminant_map
.end ())
9880 ranges
[i
- 1].low
= iter
->second
;
9881 ranges
[i
- 1].high
= iter
->second
;
9884 /* In Rust, each element should have the size of the
9886 TYPE_LENGTH (type
->field (i
).type ()) = TYPE_LENGTH (type
);
9888 /* Remove the discriminant field, if it exists. */
9889 struct type
*sub_type
= type
->field (i
).type ();
9890 if (sub_type
->num_fields () > 0)
9892 sub_type
->set_num_fields (sub_type
->num_fields () - 1);
9893 sub_type
->set_fields (sub_type
->fields () + 1);
9895 TYPE_FIELD_NAME (type
, i
) = variant_name
;
9897 (rust_fully_qualify (&objfile
->objfile_obstack
,
9898 type
->name (), variant_name
));
9901 /* Indicate that this is a variant type. */
9902 alloc_rust_variant (&objfile
->objfile_obstack
, type
, 0, -1,
9903 gdb::array_view
<discriminant_range
> (ranges
,
9908 /* Rewrite some Rust unions to be structures with variants parts. */
9911 rust_union_quirks (struct dwarf2_cu
*cu
)
9913 gdb_assert (cu
->language
== language_rust
);
9914 for (type
*type_
: cu
->rust_unions
)
9915 quirk_rust_enum (type_
, cu
->per_objfile
->objfile
);
9916 /* We don't need this any more. */
9917 cu
->rust_unions
.clear ();
9922 type_unit_group_unshareable
*
9923 dwarf2_per_objfile::get_type_unit_group_unshareable (type_unit_group
*tu_group
)
9925 auto iter
= this->m_type_units
.find (tu_group
);
9926 if (iter
!= this->m_type_units
.end ())
9927 return iter
->second
.get ();
9929 type_unit_group_unshareable_up
uniq (new type_unit_group_unshareable
);
9930 type_unit_group_unshareable
*result
= uniq
.get ();
9931 this->m_type_units
[tu_group
] = std::move (uniq
);
9936 dwarf2_per_objfile::get_type_for_signatured_type
9937 (signatured_type
*sig_type
) const
9939 auto iter
= this->m_type_map
.find (sig_type
);
9940 if (iter
== this->m_type_map
.end ())
9943 return iter
->second
;
9946 void dwarf2_per_objfile::set_type_for_signatured_type
9947 (signatured_type
*sig_type
, struct type
*type
)
9949 gdb_assert (this->m_type_map
.find (sig_type
) == this->m_type_map
.end ());
9951 this->m_type_map
[sig_type
] = type
;
9954 /* A helper function for computing the list of all symbol tables
9955 included by PER_CU. */
9958 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9959 htab_t all_children
, htab_t all_type_symtabs
,
9960 dwarf2_per_cu_data
*per_cu
,
9961 dwarf2_per_objfile
*per_objfile
,
9962 struct compunit_symtab
*immediate_parent
)
9964 void **slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9967 /* This inclusion and its children have been processed. */
9973 /* Only add a CU if it has a symbol table. */
9974 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
9977 /* If this is a type unit only add its symbol table if we haven't
9978 seen it yet (type unit per_cu's can share symtabs). */
9979 if (per_cu
->is_debug_types
)
9981 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9985 result
->push_back (cust
);
9986 if (cust
->user
== NULL
)
9987 cust
->user
= immediate_parent
;
9992 result
->push_back (cust
);
9993 if (cust
->user
== NULL
)
9994 cust
->user
= immediate_parent
;
9998 if (!per_cu
->imported_symtabs_empty ())
9999 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10001 recursively_compute_inclusions (result
, all_children
,
10002 all_type_symtabs
, ptr
, per_objfile
,
10007 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10011 compute_compunit_symtab_includes (dwarf2_per_cu_data
*per_cu
,
10012 dwarf2_per_objfile
*per_objfile
)
10014 gdb_assert (! per_cu
->is_debug_types
);
10016 if (!per_cu
->imported_symtabs_empty ())
10019 std::vector
<compunit_symtab
*> result_symtabs
;
10020 compunit_symtab
*cust
= per_objfile
->get_symtab (per_cu
);
10022 /* If we don't have a symtab, we can just skip this case. */
10026 htab_up
all_children (htab_create_alloc (1, htab_hash_pointer
,
10028 NULL
, xcalloc
, xfree
));
10029 htab_up
all_type_symtabs (htab_create_alloc (1, htab_hash_pointer
,
10031 NULL
, xcalloc
, xfree
));
10033 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10035 recursively_compute_inclusions (&result_symtabs
, all_children
.get (),
10036 all_type_symtabs
.get (), ptr
,
10037 per_objfile
, cust
);
10040 /* Now we have a transitive closure of all the included symtabs. */
10041 len
= result_symtabs
.size ();
10043 = XOBNEWVEC (&per_objfile
->objfile
->objfile_obstack
,
10044 struct compunit_symtab
*, len
+ 1);
10045 memcpy (cust
->includes
, result_symtabs
.data (),
10046 len
* sizeof (compunit_symtab
*));
10047 cust
->includes
[len
] = NULL
;
10051 /* Compute the 'includes' field for the symtabs of all the CUs we just
10055 process_cu_includes (dwarf2_per_objfile
*per_objfile
)
10057 for (dwarf2_per_cu_data
*iter
: per_objfile
->per_bfd
->just_read_cus
)
10059 if (! iter
->is_debug_types
)
10060 compute_compunit_symtab_includes (iter
, per_objfile
);
10063 per_objfile
->per_bfd
->just_read_cus
.clear ();
10066 /* Generate full symbol information for CU, whose DIEs have
10067 already been loaded into memory. */
10070 process_full_comp_unit (dwarf2_cu
*cu
, enum language pretend_language
)
10072 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10073 struct objfile
*objfile
= per_objfile
->objfile
;
10074 struct gdbarch
*gdbarch
= objfile
->arch ();
10075 CORE_ADDR lowpc
, highpc
;
10076 struct compunit_symtab
*cust
;
10077 CORE_ADDR baseaddr
;
10078 struct block
*static_block
;
10081 baseaddr
= objfile
->text_section_offset ();
10083 /* Clear the list here in case something was left over. */
10084 cu
->method_list
.clear ();
10086 cu
->language
= pretend_language
;
10087 cu
->language_defn
= language_def (cu
->language
);
10089 dwarf2_find_base_address (cu
->dies
, cu
);
10091 /* Do line number decoding in read_file_scope () */
10092 process_die (cu
->dies
, cu
);
10094 /* For now fudge the Go package. */
10095 if (cu
->language
== language_go
)
10096 fixup_go_packaging (cu
);
10098 /* Now that we have processed all the DIEs in the CU, all the types
10099 should be complete, and it should now be safe to compute all of the
10101 compute_delayed_physnames (cu
);
10103 if (cu
->language
== language_rust
)
10104 rust_union_quirks (cu
);
10106 /* Some compilers don't define a DW_AT_high_pc attribute for the
10107 compilation unit. If the DW_AT_high_pc is missing, synthesize
10108 it, by scanning the DIE's below the compilation unit. */
10109 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10111 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10112 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10114 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10115 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10116 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10117 addrmap to help ensure it has an accurate map of pc values belonging to
10119 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10121 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10122 SECT_OFF_TEXT (objfile
),
10127 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10129 /* Set symtab language to language from DW_AT_language. If the
10130 compilation is from a C file generated by language preprocessors, do
10131 not set the language if it was already deduced by start_subfile. */
10132 if (!(cu
->language
== language_c
10133 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10134 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10136 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10137 produce DW_AT_location with location lists but it can be possibly
10138 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10139 there were bugs in prologue debug info, fixed later in GCC-4.5
10140 by "unwind info for epilogues" patch (which is not directly related).
10142 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10143 needed, it would be wrong due to missing DW_AT_producer there.
10145 Still one can confuse GDB by using non-standard GCC compilation
10146 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10148 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10149 cust
->locations_valid
= 1;
10151 if (gcc_4_minor
>= 5)
10152 cust
->epilogue_unwind_valid
= 1;
10154 cust
->call_site_htab
= cu
->call_site_htab
;
10157 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10159 /* Push it for inclusion processing later. */
10160 per_objfile
->per_bfd
->just_read_cus
.push_back (cu
->per_cu
);
10162 /* Not needed any more. */
10163 cu
->reset_builder ();
10166 /* Generate full symbol information for type unit CU, whose DIEs have
10167 already been loaded into memory. */
10170 process_full_type_unit (dwarf2_cu
*cu
,
10171 enum language pretend_language
)
10173 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10174 struct objfile
*objfile
= per_objfile
->objfile
;
10175 struct compunit_symtab
*cust
;
10176 struct signatured_type
*sig_type
;
10178 gdb_assert (cu
->per_cu
->is_debug_types
);
10179 sig_type
= (struct signatured_type
*) cu
->per_cu
;
10181 /* Clear the list here in case something was left over. */
10182 cu
->method_list
.clear ();
10184 cu
->language
= pretend_language
;
10185 cu
->language_defn
= language_def (cu
->language
);
10187 /* The symbol tables are set up in read_type_unit_scope. */
10188 process_die (cu
->dies
, cu
);
10190 /* For now fudge the Go package. */
10191 if (cu
->language
== language_go
)
10192 fixup_go_packaging (cu
);
10194 /* Now that we have processed all the DIEs in the CU, all the types
10195 should be complete, and it should now be safe to compute all of the
10197 compute_delayed_physnames (cu
);
10199 if (cu
->language
== language_rust
)
10200 rust_union_quirks (cu
);
10202 /* TUs share symbol tables.
10203 If this is the first TU to use this symtab, complete the construction
10204 of it with end_expandable_symtab. Otherwise, complete the addition of
10205 this TU's symbols to the existing symtab. */
10206 type_unit_group_unshareable
*tug_unshare
=
10207 per_objfile
->get_type_unit_group_unshareable (sig_type
->type_unit_group
);
10208 if (tug_unshare
->compunit_symtab
== NULL
)
10210 buildsym_compunit
*builder
= cu
->get_builder ();
10211 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10212 tug_unshare
->compunit_symtab
= cust
;
10216 /* Set symtab language to language from DW_AT_language. If the
10217 compilation is from a C file generated by language preprocessors,
10218 do not set the language if it was already deduced by
10220 if (!(cu
->language
== language_c
10221 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10222 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10227 cu
->get_builder ()->augment_type_symtab ();
10228 cust
= tug_unshare
->compunit_symtab
;
10231 per_objfile
->set_symtab (cu
->per_cu
, cust
);
10233 /* Not needed any more. */
10234 cu
->reset_builder ();
10237 /* Process an imported unit DIE. */
10240 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10242 struct attribute
*attr
;
10244 /* For now we don't handle imported units in type units. */
10245 if (cu
->per_cu
->is_debug_types
)
10247 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10248 " supported in type units [in module %s]"),
10249 objfile_name (cu
->per_objfile
->objfile
));
10252 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10255 sect_offset sect_off
= attr
->get_ref_die_offset ();
10256 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10257 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
10258 dwarf2_per_cu_data
*per_cu
10259 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
, per_objfile
);
10261 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
10262 into another compilation unit, at root level. Regard this as a hint,
10264 if (die
->parent
&& die
->parent
->parent
== NULL
10265 && per_cu
->unit_type
== DW_UT_compile
10266 && per_cu
->lang
== language_cplus
)
10269 /* If necessary, add it to the queue and load its DIEs. */
10270 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
))
10271 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
10272 false, cu
->language
);
10274 cu
->per_cu
->imported_symtabs_push (per_cu
);
10278 /* RAII object that represents a process_die scope: i.e.,
10279 starts/finishes processing a DIE. */
10280 class process_die_scope
10283 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10284 : m_die (die
), m_cu (cu
)
10286 /* We should only be processing DIEs not already in process. */
10287 gdb_assert (!m_die
->in_process
);
10288 m_die
->in_process
= true;
10291 ~process_die_scope ()
10293 m_die
->in_process
= false;
10295 /* If we're done processing the DIE for the CU that owns the line
10296 header, we don't need the line header anymore. */
10297 if (m_cu
->line_header_die_owner
== m_die
)
10299 delete m_cu
->line_header
;
10300 m_cu
->line_header
= NULL
;
10301 m_cu
->line_header_die_owner
= NULL
;
10310 /* Process a die and its children. */
10313 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10315 process_die_scope
scope (die
, cu
);
10319 case DW_TAG_padding
:
10321 case DW_TAG_compile_unit
:
10322 case DW_TAG_partial_unit
:
10323 read_file_scope (die
, cu
);
10325 case DW_TAG_type_unit
:
10326 read_type_unit_scope (die
, cu
);
10328 case DW_TAG_subprogram
:
10329 /* Nested subprograms in Fortran get a prefix. */
10330 if (cu
->language
== language_fortran
10331 && die
->parent
!= NULL
10332 && die
->parent
->tag
== DW_TAG_subprogram
)
10333 cu
->processing_has_namespace_info
= true;
10334 /* Fall through. */
10335 case DW_TAG_inlined_subroutine
:
10336 read_func_scope (die
, cu
);
10338 case DW_TAG_lexical_block
:
10339 case DW_TAG_try_block
:
10340 case DW_TAG_catch_block
:
10341 read_lexical_block_scope (die
, cu
);
10343 case DW_TAG_call_site
:
10344 case DW_TAG_GNU_call_site
:
10345 read_call_site_scope (die
, cu
);
10347 case DW_TAG_class_type
:
10348 case DW_TAG_interface_type
:
10349 case DW_TAG_structure_type
:
10350 case DW_TAG_union_type
:
10351 process_structure_scope (die
, cu
);
10353 case DW_TAG_enumeration_type
:
10354 process_enumeration_scope (die
, cu
);
10357 /* These dies have a type, but processing them does not create
10358 a symbol or recurse to process the children. Therefore we can
10359 read them on-demand through read_type_die. */
10360 case DW_TAG_subroutine_type
:
10361 case DW_TAG_set_type
:
10362 case DW_TAG_pointer_type
:
10363 case DW_TAG_ptr_to_member_type
:
10364 case DW_TAG_reference_type
:
10365 case DW_TAG_rvalue_reference_type
:
10366 case DW_TAG_string_type
:
10369 case DW_TAG_array_type
:
10370 /* We only need to handle this case for Ada -- in other
10371 languages, it's normal for the compiler to emit a typedef
10373 if (cu
->language
!= language_ada
)
10376 case DW_TAG_base_type
:
10377 case DW_TAG_subrange_type
:
10378 case DW_TAG_typedef
:
10379 /* Add a typedef symbol for the type definition, if it has a
10381 new_symbol (die
, read_type_die (die
, cu
), cu
);
10383 case DW_TAG_common_block
:
10384 read_common_block (die
, cu
);
10386 case DW_TAG_common_inclusion
:
10388 case DW_TAG_namespace
:
10389 cu
->processing_has_namespace_info
= true;
10390 read_namespace (die
, cu
);
10392 case DW_TAG_module
:
10393 cu
->processing_has_namespace_info
= true;
10394 read_module (die
, cu
);
10396 case DW_TAG_imported_declaration
:
10397 cu
->processing_has_namespace_info
= true;
10398 if (read_namespace_alias (die
, cu
))
10400 /* The declaration is not a global namespace alias. */
10401 /* Fall through. */
10402 case DW_TAG_imported_module
:
10403 cu
->processing_has_namespace_info
= true;
10404 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10405 || cu
->language
!= language_fortran
))
10406 complaint (_("Tag '%s' has unexpected children"),
10407 dwarf_tag_name (die
->tag
));
10408 read_import_statement (die
, cu
);
10411 case DW_TAG_imported_unit
:
10412 process_imported_unit_die (die
, cu
);
10415 case DW_TAG_variable
:
10416 read_variable (die
, cu
);
10420 new_symbol (die
, NULL
, cu
);
10425 /* DWARF name computation. */
10427 /* A helper function for dwarf2_compute_name which determines whether DIE
10428 needs to have the name of the scope prepended to the name listed in the
10432 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10434 struct attribute
*attr
;
10438 case DW_TAG_namespace
:
10439 case DW_TAG_typedef
:
10440 case DW_TAG_class_type
:
10441 case DW_TAG_interface_type
:
10442 case DW_TAG_structure_type
:
10443 case DW_TAG_union_type
:
10444 case DW_TAG_enumeration_type
:
10445 case DW_TAG_enumerator
:
10446 case DW_TAG_subprogram
:
10447 case DW_TAG_inlined_subroutine
:
10448 case DW_TAG_member
:
10449 case DW_TAG_imported_declaration
:
10452 case DW_TAG_variable
:
10453 case DW_TAG_constant
:
10454 /* We only need to prefix "globally" visible variables. These include
10455 any variable marked with DW_AT_external or any variable that
10456 lives in a namespace. [Variables in anonymous namespaces
10457 require prefixing, but they are not DW_AT_external.] */
10459 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10461 struct dwarf2_cu
*spec_cu
= cu
;
10463 return die_needs_namespace (die_specification (die
, &spec_cu
),
10467 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10468 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10469 && die
->parent
->tag
!= DW_TAG_module
)
10471 /* A variable in a lexical block of some kind does not need a
10472 namespace, even though in C++ such variables may be external
10473 and have a mangled name. */
10474 if (die
->parent
->tag
== DW_TAG_lexical_block
10475 || die
->parent
->tag
== DW_TAG_try_block
10476 || die
->parent
->tag
== DW_TAG_catch_block
10477 || die
->parent
->tag
== DW_TAG_subprogram
)
10486 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10487 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10488 defined for the given DIE. */
10490 static struct attribute
*
10491 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10493 struct attribute
*attr
;
10495 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10497 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10502 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10503 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10504 defined for the given DIE. */
10506 static const char *
10507 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10509 const char *linkage_name
;
10511 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10512 if (linkage_name
== NULL
)
10513 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10515 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10516 See https://github.com/rust-lang/rust/issues/32925. */
10517 if (cu
->language
== language_rust
&& linkage_name
!= NULL
10518 && strchr (linkage_name
, '{') != NULL
)
10519 linkage_name
= NULL
;
10521 return linkage_name
;
10524 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10525 compute the physname for the object, which include a method's:
10526 - formal parameters (C++),
10527 - receiver type (Go),
10529 The term "physname" is a bit confusing.
10530 For C++, for example, it is the demangled name.
10531 For Go, for example, it's the mangled name.
10533 For Ada, return the DIE's linkage name rather than the fully qualified
10534 name. PHYSNAME is ignored..
10536 The result is allocated on the objfile->per_bfd's obstack and
10539 static const char *
10540 dwarf2_compute_name (const char *name
,
10541 struct die_info
*die
, struct dwarf2_cu
*cu
,
10544 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10547 name
= dwarf2_name (die
, cu
);
10549 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10550 but otherwise compute it by typename_concat inside GDB.
10551 FIXME: Actually this is not really true, or at least not always true.
10552 It's all very confusing. compute_and_set_names doesn't try to demangle
10553 Fortran names because there is no mangling standard. So new_symbol
10554 will set the demangled name to the result of dwarf2_full_name, and it is
10555 the demangled name that GDB uses if it exists. */
10556 if (cu
->language
== language_ada
10557 || (cu
->language
== language_fortran
&& physname
))
10559 /* For Ada unit, we prefer the linkage name over the name, as
10560 the former contains the exported name, which the user expects
10561 to be able to reference. Ideally, we want the user to be able
10562 to reference this entity using either natural or linkage name,
10563 but we haven't started looking at this enhancement yet. */
10564 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10566 if (linkage_name
!= NULL
)
10567 return linkage_name
;
10570 /* These are the only languages we know how to qualify names in. */
10572 && (cu
->language
== language_cplus
10573 || cu
->language
== language_fortran
|| cu
->language
== language_d
10574 || cu
->language
== language_rust
))
10576 if (die_needs_namespace (die
, cu
))
10578 const char *prefix
;
10579 const char *canonical_name
= NULL
;
10583 prefix
= determine_prefix (die
, cu
);
10584 if (*prefix
!= '\0')
10586 gdb::unique_xmalloc_ptr
<char> prefixed_name
10587 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10589 buf
.puts (prefixed_name
.get ());
10594 /* Template parameters may be specified in the DIE's DW_AT_name, or
10595 as children with DW_TAG_template_type_param or
10596 DW_TAG_value_type_param. If the latter, add them to the name
10597 here. If the name already has template parameters, then
10598 skip this step; some versions of GCC emit both, and
10599 it is more efficient to use the pre-computed name.
10601 Something to keep in mind about this process: it is very
10602 unlikely, or in some cases downright impossible, to produce
10603 something that will match the mangled name of a function.
10604 If the definition of the function has the same debug info,
10605 we should be able to match up with it anyway. But fallbacks
10606 using the minimal symbol, for instance to find a method
10607 implemented in a stripped copy of libstdc++, will not work.
10608 If we do not have debug info for the definition, we will have to
10609 match them up some other way.
10611 When we do name matching there is a related problem with function
10612 templates; two instantiated function templates are allowed to
10613 differ only by their return types, which we do not add here. */
10615 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10617 struct attribute
*attr
;
10618 struct die_info
*child
;
10620 const language_defn
*cplus_lang
= language_def (cu
->language
);
10622 die
->building_fullname
= 1;
10624 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10628 const gdb_byte
*bytes
;
10629 struct dwarf2_locexpr_baton
*baton
;
10632 if (child
->tag
!= DW_TAG_template_type_param
10633 && child
->tag
!= DW_TAG_template_value_param
)
10644 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10647 complaint (_("template parameter missing DW_AT_type"));
10648 buf
.puts ("UNKNOWN_TYPE");
10651 type
= die_type (child
, cu
);
10653 if (child
->tag
== DW_TAG_template_type_param
)
10655 cplus_lang
->print_type (type
, "", &buf
, -1, 0,
10656 &type_print_raw_options
);
10660 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10663 complaint (_("template parameter missing "
10664 "DW_AT_const_value"));
10665 buf
.puts ("UNKNOWN_VALUE");
10669 dwarf2_const_value_attr (attr
, type
, name
,
10670 &cu
->comp_unit_obstack
, cu
,
10671 &value
, &bytes
, &baton
);
10673 if (type
->has_no_signedness ())
10674 /* GDB prints characters as NUMBER 'CHAR'. If that's
10675 changed, this can use value_print instead. */
10676 cplus_lang
->printchar (value
, type
, &buf
);
10679 struct value_print_options opts
;
10682 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10686 baton
->per_objfile
);
10687 else if (bytes
!= NULL
)
10689 v
= allocate_value (type
);
10690 memcpy (value_contents_writeable (v
), bytes
,
10691 TYPE_LENGTH (type
));
10694 v
= value_from_longest (type
, value
);
10696 /* Specify decimal so that we do not depend on
10698 get_formatted_print_options (&opts
, 'd');
10700 value_print (v
, &buf
, &opts
);
10705 die
->building_fullname
= 0;
10709 /* Close the argument list, with a space if necessary
10710 (nested templates). */
10711 if (!buf
.empty () && buf
.string ().back () == '>')
10718 /* For C++ methods, append formal parameter type
10719 information, if PHYSNAME. */
10721 if (physname
&& die
->tag
== DW_TAG_subprogram
10722 && cu
->language
== language_cplus
)
10724 struct type
*type
= read_type_die (die
, cu
);
10726 c_type_print_args (type
, &buf
, 1, cu
->language
,
10727 &type_print_raw_options
);
10729 if (cu
->language
== language_cplus
)
10731 /* Assume that an artificial first parameter is
10732 "this", but do not crash if it is not. RealView
10733 marks unnamed (and thus unused) parameters as
10734 artificial; there is no way to differentiate
10736 if (type
->num_fields () > 0
10737 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10738 && type
->field (0).type ()->code () == TYPE_CODE_PTR
10739 && TYPE_CONST (TYPE_TARGET_TYPE (type
->field (0).type ())))
10740 buf
.puts (" const");
10744 const std::string
&intermediate_name
= buf
.string ();
10746 if (cu
->language
== language_cplus
)
10748 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10751 /* If we only computed INTERMEDIATE_NAME, or if
10752 INTERMEDIATE_NAME is already canonical, then we need to
10754 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10755 name
= objfile
->intern (intermediate_name
);
10757 name
= canonical_name
;
10764 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10765 If scope qualifiers are appropriate they will be added. The result
10766 will be allocated on the storage_obstack, or NULL if the DIE does
10767 not have a name. NAME may either be from a previous call to
10768 dwarf2_name or NULL.
10770 The output string will be canonicalized (if C++). */
10772 static const char *
10773 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10775 return dwarf2_compute_name (name
, die
, cu
, 0);
10778 /* Construct a physname for the given DIE in CU. NAME may either be
10779 from a previous call to dwarf2_name or NULL. The result will be
10780 allocated on the objfile_objstack or NULL if the DIE does not have a
10783 The output string will be canonicalized (if C++). */
10785 static const char *
10786 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10788 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10789 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10792 /* In this case dwarf2_compute_name is just a shortcut not building anything
10794 if (!die_needs_namespace (die
, cu
))
10795 return dwarf2_compute_name (name
, die
, cu
, 1);
10797 if (cu
->language
!= language_rust
)
10798 mangled
= dw2_linkage_name (die
, cu
);
10800 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10802 gdb::unique_xmalloc_ptr
<char> demangled
;
10803 if (mangled
!= NULL
)
10806 if (language_def (cu
->language
)->store_sym_names_in_linkage_form_p ())
10808 /* Do nothing (do not demangle the symbol name). */
10812 /* Use DMGL_RET_DROP for C++ template functions to suppress
10813 their return type. It is easier for GDB users to search
10814 for such functions as `name(params)' than `long name(params)'.
10815 In such case the minimal symbol names do not match the full
10816 symbol names but for template functions there is never a need
10817 to look up their definition from their declaration so
10818 the only disadvantage remains the minimal symbol variant
10819 `long name(params)' does not have the proper inferior type. */
10820 demangled
.reset (gdb_demangle (mangled
,
10821 (DMGL_PARAMS
| DMGL_ANSI
10822 | DMGL_RET_DROP
)));
10825 canon
= demangled
.get ();
10833 if (canon
== NULL
|| check_physname
)
10835 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10837 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10839 /* It may not mean a bug in GDB. The compiler could also
10840 compute DW_AT_linkage_name incorrectly. But in such case
10841 GDB would need to be bug-to-bug compatible. */
10843 complaint (_("Computed physname <%s> does not match demangled <%s> "
10844 "(from linkage <%s>) - DIE at %s [in module %s]"),
10845 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10846 objfile_name (objfile
));
10848 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10849 is available here - over computed PHYSNAME. It is safer
10850 against both buggy GDB and buggy compilers. */
10864 retval
= objfile
->intern (retval
);
10869 /* Inspect DIE in CU for a namespace alias. If one exists, record
10870 a new symbol for it.
10872 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10875 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10877 struct attribute
*attr
;
10879 /* If the die does not have a name, this is not a namespace
10881 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10885 struct die_info
*d
= die
;
10886 struct dwarf2_cu
*imported_cu
= cu
;
10888 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10889 keep inspecting DIEs until we hit the underlying import. */
10890 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10891 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10893 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10897 d
= follow_die_ref (d
, attr
, &imported_cu
);
10898 if (d
->tag
!= DW_TAG_imported_declaration
)
10902 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10904 complaint (_("DIE at %s has too many recursively imported "
10905 "declarations"), sect_offset_str (d
->sect_off
));
10912 sect_offset sect_off
= attr
->get_ref_die_offset ();
10914 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, cu
->per_objfile
);
10915 if (type
!= NULL
&& type
->code () == TYPE_CODE_NAMESPACE
)
10917 /* This declaration is a global namespace alias. Add
10918 a symbol for it whose type is the aliased namespace. */
10919 new_symbol (die
, type
, cu
);
10928 /* Return the using directives repository (global or local?) to use in the
10929 current context for CU.
10931 For Ada, imported declarations can materialize renamings, which *may* be
10932 global. However it is impossible (for now?) in DWARF to distinguish
10933 "external" imported declarations and "static" ones. As all imported
10934 declarations seem to be static in all other languages, make them all CU-wide
10935 global only in Ada. */
10937 static struct using_direct
**
10938 using_directives (struct dwarf2_cu
*cu
)
10940 if (cu
->language
== language_ada
10941 && cu
->get_builder ()->outermost_context_p ())
10942 return cu
->get_builder ()->get_global_using_directives ();
10944 return cu
->get_builder ()->get_local_using_directives ();
10947 /* Read the import statement specified by the given die and record it. */
10950 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10952 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
10953 struct attribute
*import_attr
;
10954 struct die_info
*imported_die
, *child_die
;
10955 struct dwarf2_cu
*imported_cu
;
10956 const char *imported_name
;
10957 const char *imported_name_prefix
;
10958 const char *canonical_name
;
10959 const char *import_alias
;
10960 const char *imported_declaration
= NULL
;
10961 const char *import_prefix
;
10962 std::vector
<const char *> excludes
;
10964 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10965 if (import_attr
== NULL
)
10967 complaint (_("Tag '%s' has no DW_AT_import"),
10968 dwarf_tag_name (die
->tag
));
10973 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10974 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10975 if (imported_name
== NULL
)
10977 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10979 The import in the following code:
10993 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10994 <52> DW_AT_decl_file : 1
10995 <53> DW_AT_decl_line : 6
10996 <54> DW_AT_import : <0x75>
10997 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10998 <59> DW_AT_name : B
10999 <5b> DW_AT_decl_file : 1
11000 <5c> DW_AT_decl_line : 2
11001 <5d> DW_AT_type : <0x6e>
11003 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11004 <76> DW_AT_byte_size : 4
11005 <77> DW_AT_encoding : 5 (signed)
11007 imports the wrong die ( 0x75 instead of 0x58 ).
11008 This case will be ignored until the gcc bug is fixed. */
11012 /* Figure out the local name after import. */
11013 import_alias
= dwarf2_name (die
, cu
);
11015 /* Figure out where the statement is being imported to. */
11016 import_prefix
= determine_prefix (die
, cu
);
11018 /* Figure out what the scope of the imported die is and prepend it
11019 to the name of the imported die. */
11020 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11022 if (imported_die
->tag
!= DW_TAG_namespace
11023 && imported_die
->tag
!= DW_TAG_module
)
11025 imported_declaration
= imported_name
;
11026 canonical_name
= imported_name_prefix
;
11028 else if (strlen (imported_name_prefix
) > 0)
11029 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11030 imported_name_prefix
,
11031 (cu
->language
== language_d
? "." : "::"),
11032 imported_name
, (char *) NULL
);
11034 canonical_name
= imported_name
;
11036 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11037 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11038 child_die
= child_die
->sibling
)
11040 /* DWARF-4: A Fortran use statement with a “rename list” may be
11041 represented by an imported module entry with an import attribute
11042 referring to the module and owned entries corresponding to those
11043 entities that are renamed as part of being imported. */
11045 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11047 complaint (_("child DW_TAG_imported_declaration expected "
11048 "- DIE at %s [in module %s]"),
11049 sect_offset_str (child_die
->sect_off
),
11050 objfile_name (objfile
));
11054 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11055 if (import_attr
== NULL
)
11057 complaint (_("Tag '%s' has no DW_AT_import"),
11058 dwarf_tag_name (child_die
->tag
));
11063 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11065 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11066 if (imported_name
== NULL
)
11068 complaint (_("child DW_TAG_imported_declaration has unknown "
11069 "imported name - DIE at %s [in module %s]"),
11070 sect_offset_str (child_die
->sect_off
),
11071 objfile_name (objfile
));
11075 excludes
.push_back (imported_name
);
11077 process_die (child_die
, cu
);
11080 add_using_directive (using_directives (cu
),
11084 imported_declaration
,
11087 &objfile
->objfile_obstack
);
11090 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11091 types, but gives them a size of zero. Starting with version 14,
11092 ICC is compatible with GCC. */
11095 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11097 if (!cu
->checked_producer
)
11098 check_producer (cu
);
11100 return cu
->producer_is_icc_lt_14
;
11103 /* ICC generates a DW_AT_type for C void functions. This was observed on
11104 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11105 which says that void functions should not have a DW_AT_type. */
11108 producer_is_icc (struct dwarf2_cu
*cu
)
11110 if (!cu
->checked_producer
)
11111 check_producer (cu
);
11113 return cu
->producer_is_icc
;
11116 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11117 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11118 this, it was first present in GCC release 4.3.0. */
11121 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11123 if (!cu
->checked_producer
)
11124 check_producer (cu
);
11126 return cu
->producer_is_gcc_lt_4_3
;
11129 static file_and_directory
11130 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11132 file_and_directory res
;
11134 /* Find the filename. Do not use dwarf2_name here, since the filename
11135 is not a source language identifier. */
11136 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11137 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11139 if (res
.comp_dir
== NULL
11140 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11141 && IS_ABSOLUTE_PATH (res
.name
))
11143 res
.comp_dir_storage
= ldirname (res
.name
);
11144 if (!res
.comp_dir_storage
.empty ())
11145 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11147 if (res
.comp_dir
!= NULL
)
11149 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11150 directory, get rid of it. */
11151 const char *cp
= strchr (res
.comp_dir
, ':');
11153 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11154 res
.comp_dir
= cp
+ 1;
11157 if (res
.name
== NULL
)
11158 res
.name
= "<unknown>";
11163 /* Handle DW_AT_stmt_list for a compilation unit.
11164 DIE is the DW_TAG_compile_unit die for CU.
11165 COMP_DIR is the compilation directory. LOWPC is passed to
11166 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11169 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11170 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11172 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11173 struct attribute
*attr
;
11174 struct line_header line_header_local
;
11175 hashval_t line_header_local_hash
;
11177 int decode_mapping
;
11179 gdb_assert (! cu
->per_cu
->is_debug_types
);
11181 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11182 if (attr
== NULL
|| !attr
->form_is_unsigned ())
11185 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11187 /* The line header hash table is only created if needed (it exists to
11188 prevent redundant reading of the line table for partial_units).
11189 If we're given a partial_unit, we'll need it. If we're given a
11190 compile_unit, then use the line header hash table if it's already
11191 created, but don't create one just yet. */
11193 if (per_objfile
->line_header_hash
== NULL
11194 && die
->tag
== DW_TAG_partial_unit
)
11196 per_objfile
->line_header_hash
11197 .reset (htab_create_alloc (127, line_header_hash_voidp
,
11198 line_header_eq_voidp
,
11199 free_line_header_voidp
,
11203 line_header_local
.sect_off
= line_offset
;
11204 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11205 line_header_local_hash
= line_header_hash (&line_header_local
);
11206 if (per_objfile
->line_header_hash
!= NULL
)
11208 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11209 &line_header_local
,
11210 line_header_local_hash
, NO_INSERT
);
11212 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11213 is not present in *SLOT (since if there is something in *SLOT then
11214 it will be for a partial_unit). */
11215 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11217 gdb_assert (*slot
!= NULL
);
11218 cu
->line_header
= (struct line_header
*) *slot
;
11223 /* dwarf_decode_line_header does not yet provide sufficient information.
11224 We always have to call also dwarf_decode_lines for it. */
11225 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11229 cu
->line_header
= lh
.release ();
11230 cu
->line_header_die_owner
= die
;
11232 if (per_objfile
->line_header_hash
== NULL
)
11236 slot
= htab_find_slot_with_hash (per_objfile
->line_header_hash
.get (),
11237 &line_header_local
,
11238 line_header_local_hash
, INSERT
);
11239 gdb_assert (slot
!= NULL
);
11241 if (slot
!= NULL
&& *slot
== NULL
)
11243 /* This newly decoded line number information unit will be owned
11244 by line_header_hash hash table. */
11245 *slot
= cu
->line_header
;
11246 cu
->line_header_die_owner
= NULL
;
11250 /* We cannot free any current entry in (*slot) as that struct line_header
11251 may be already used by multiple CUs. Create only temporary decoded
11252 line_header for this CU - it may happen at most once for each line
11253 number information unit. And if we're not using line_header_hash
11254 then this is what we want as well. */
11255 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11257 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11258 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11263 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11266 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11268 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
11269 struct objfile
*objfile
= per_objfile
->objfile
;
11270 struct gdbarch
*gdbarch
= objfile
->arch ();
11271 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11272 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11273 struct attribute
*attr
;
11274 struct die_info
*child_die
;
11275 CORE_ADDR baseaddr
;
11277 prepare_one_comp_unit (cu
, die
, cu
->language
);
11278 baseaddr
= objfile
->text_section_offset ();
11280 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11282 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11283 from finish_block. */
11284 if (lowpc
== ((CORE_ADDR
) -1))
11286 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11288 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11290 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11291 standardised yet. As a workaround for the language detection we fall
11292 back to the DW_AT_producer string. */
11293 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11294 cu
->language
= language_opencl
;
11296 /* Similar hack for Go. */
11297 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11298 set_cu_language (DW_LANG_Go
, cu
);
11300 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11302 /* Decode line number information if present. We do this before
11303 processing child DIEs, so that the line header table is available
11304 for DW_AT_decl_file. */
11305 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11307 /* Process all dies in compilation unit. */
11308 if (die
->child
!= NULL
)
11310 child_die
= die
->child
;
11311 while (child_die
&& child_die
->tag
)
11313 process_die (child_die
, cu
);
11314 child_die
= child_die
->sibling
;
11318 /* Decode macro information, if present. Dwarf 2 macro information
11319 refers to information in the line number info statement program
11320 header, so we can only read it if we've read the header
11322 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11324 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11325 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11327 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11328 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11330 dwarf_decode_macros (cu
, attr
->as_unsigned (), 1);
11334 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11335 if (attr
!= nullptr && attr
->form_is_unsigned () && cu
->line_header
)
11337 unsigned int macro_offset
= attr
->as_unsigned ();
11339 dwarf_decode_macros (cu
, macro_offset
, 0);
11345 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11347 struct type_unit_group
*tu_group
;
11349 struct attribute
*attr
;
11351 struct signatured_type
*sig_type
;
11353 gdb_assert (per_cu
->is_debug_types
);
11354 sig_type
= (struct signatured_type
*) per_cu
;
11356 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11358 /* If we're using .gdb_index (includes -readnow) then
11359 per_cu->type_unit_group may not have been set up yet. */
11360 if (sig_type
->type_unit_group
== NULL
)
11361 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11362 tu_group
= sig_type
->type_unit_group
;
11364 /* If we've already processed this stmt_list there's no real need to
11365 do it again, we could fake it and just recreate the part we need
11366 (file name,index -> symtab mapping). If data shows this optimization
11367 is useful we can do it then. */
11368 type_unit_group_unshareable
*tug_unshare
11369 = per_objfile
->get_type_unit_group_unshareable (tu_group
);
11370 first_time
= tug_unshare
->compunit_symtab
== NULL
;
11372 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11375 if (attr
!= NULL
&& attr
->form_is_unsigned ())
11377 sect_offset line_offset
= (sect_offset
) attr
->as_unsigned ();
11378 lh
= dwarf_decode_line_header (line_offset
, this);
11383 start_symtab ("", NULL
, 0);
11386 gdb_assert (tug_unshare
->symtabs
== NULL
);
11387 gdb_assert (m_builder
== nullptr);
11388 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11389 m_builder
.reset (new struct buildsym_compunit
11390 (COMPUNIT_OBJFILE (cust
), "",
11391 COMPUNIT_DIRNAME (cust
),
11392 compunit_language (cust
),
11394 list_in_scope
= get_builder ()->get_file_symbols ();
11399 line_header
= lh
.release ();
11400 line_header_die_owner
= die
;
11404 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11406 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11407 still initializing it, and our caller (a few levels up)
11408 process_full_type_unit still needs to know if this is the first
11411 tug_unshare
->symtabs
11412 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
11413 struct symtab
*, line_header
->file_names_size ());
11415 auto &file_names
= line_header
->file_names ();
11416 for (i
= 0; i
< file_names
.size (); ++i
)
11418 file_entry
&fe
= file_names
[i
];
11419 dwarf2_start_subfile (this, fe
.name
,
11420 fe
.include_dir (line_header
));
11421 buildsym_compunit
*b
= get_builder ();
11422 if (b
->get_current_subfile ()->symtab
== NULL
)
11424 /* NOTE: start_subfile will recognize when it's been
11425 passed a file it has already seen. So we can't
11426 assume there's a simple mapping from
11427 cu->line_header->file_names to subfiles, plus
11428 cu->line_header->file_names may contain dups. */
11429 b
->get_current_subfile ()->symtab
11430 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11433 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11434 tug_unshare
->symtabs
[i
] = fe
.symtab
;
11439 gdb_assert (m_builder
== nullptr);
11440 struct compunit_symtab
*cust
= tug_unshare
->compunit_symtab
;
11441 m_builder
.reset (new struct buildsym_compunit
11442 (COMPUNIT_OBJFILE (cust
), "",
11443 COMPUNIT_DIRNAME (cust
),
11444 compunit_language (cust
),
11446 list_in_scope
= get_builder ()->get_file_symbols ();
11448 auto &file_names
= line_header
->file_names ();
11449 for (i
= 0; i
< file_names
.size (); ++i
)
11451 file_entry
&fe
= file_names
[i
];
11452 fe
.symtab
= tug_unshare
->symtabs
[i
];
11456 /* The main symtab is allocated last. Type units don't have DW_AT_name
11457 so they don't have a "real" (so to speak) symtab anyway.
11458 There is later code that will assign the main symtab to all symbols
11459 that don't have one. We need to handle the case of a symbol with a
11460 missing symtab (DW_AT_decl_file) anyway. */
11463 /* Process DW_TAG_type_unit.
11464 For TUs we want to skip the first top level sibling if it's not the
11465 actual type being defined by this TU. In this case the first top
11466 level sibling is there to provide context only. */
11469 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11471 struct die_info
*child_die
;
11473 prepare_one_comp_unit (cu
, die
, language_minimal
);
11475 /* Initialize (or reinitialize) the machinery for building symtabs.
11476 We do this before processing child DIEs, so that the line header table
11477 is available for DW_AT_decl_file. */
11478 cu
->setup_type_unit_groups (die
);
11480 if (die
->child
!= NULL
)
11482 child_die
= die
->child
;
11483 while (child_die
&& child_die
->tag
)
11485 process_die (child_die
, cu
);
11486 child_die
= child_die
->sibling
;
11493 http://gcc.gnu.org/wiki/DebugFission
11494 http://gcc.gnu.org/wiki/DebugFissionDWP
11496 To simplify handling of both DWO files ("object" files with the DWARF info)
11497 and DWP files (a file with the DWOs packaged up into one file), we treat
11498 DWP files as having a collection of virtual DWO files. */
11501 hash_dwo_file (const void *item
)
11503 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11506 hash
= htab_hash_string (dwo_file
->dwo_name
);
11507 if (dwo_file
->comp_dir
!= NULL
)
11508 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11513 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11515 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11516 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11518 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11520 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11521 return lhs
->comp_dir
== rhs
->comp_dir
;
11522 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11525 /* Allocate a hash table for DWO files. */
11528 allocate_dwo_file_hash_table ()
11530 auto delete_dwo_file
= [] (void *item
)
11532 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11537 return htab_up (htab_create_alloc (41,
11544 /* Lookup DWO file DWO_NAME. */
11547 lookup_dwo_file_slot (dwarf2_per_objfile
*per_objfile
,
11548 const char *dwo_name
,
11549 const char *comp_dir
)
11551 struct dwo_file find_entry
;
11554 if (per_objfile
->per_bfd
->dwo_files
== NULL
)
11555 per_objfile
->per_bfd
->dwo_files
= allocate_dwo_file_hash_table ();
11557 find_entry
.dwo_name
= dwo_name
;
11558 find_entry
.comp_dir
= comp_dir
;
11559 slot
= htab_find_slot (per_objfile
->per_bfd
->dwo_files
.get (), &find_entry
,
11566 hash_dwo_unit (const void *item
)
11568 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11570 /* This drops the top 32 bits of the id, but is ok for a hash. */
11571 return dwo_unit
->signature
;
11575 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11577 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11578 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11580 /* The signature is assumed to be unique within the DWO file.
11581 So while object file CU dwo_id's always have the value zero,
11582 that's OK, assuming each object file DWO file has only one CU,
11583 and that's the rule for now. */
11584 return lhs
->signature
== rhs
->signature
;
11587 /* Allocate a hash table for DWO CUs,TUs.
11588 There is one of these tables for each of CUs,TUs for each DWO file. */
11591 allocate_dwo_unit_table ()
11593 /* Start out with a pretty small number.
11594 Generally DWO files contain only one CU and maybe some TUs. */
11595 return htab_up (htab_create_alloc (3,
11598 NULL
, xcalloc
, xfree
));
11601 /* die_reader_func for create_dwo_cu. */
11604 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11605 const gdb_byte
*info_ptr
,
11606 struct die_info
*comp_unit_die
,
11607 struct dwo_file
*dwo_file
,
11608 struct dwo_unit
*dwo_unit
)
11610 struct dwarf2_cu
*cu
= reader
->cu
;
11611 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11612 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11614 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11615 if (!signature
.has_value ())
11617 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11618 " its dwo_id [in module %s]"),
11619 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11623 dwo_unit
->dwo_file
= dwo_file
;
11624 dwo_unit
->signature
= *signature
;
11625 dwo_unit
->section
= section
;
11626 dwo_unit
->sect_off
= sect_off
;
11627 dwo_unit
->length
= cu
->per_cu
->length
;
11629 dwarf_read_debug_printf (" offset %s, dwo_id %s",
11630 sect_offset_str (sect_off
),
11631 hex_string (dwo_unit
->signature
));
11634 /* Create the dwo_units for the CUs in a DWO_FILE.
11635 Note: This function processes DWO files only, not DWP files. */
11638 create_cus_hash_table (dwarf2_per_objfile
*per_objfile
,
11639 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11640 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11642 struct objfile
*objfile
= per_objfile
->objfile
;
11643 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
11644 const gdb_byte
*info_ptr
, *end_ptr
;
11646 section
.read (objfile
);
11647 info_ptr
= section
.buffer
;
11649 if (info_ptr
== NULL
)
11652 dwarf_read_debug_printf ("Reading %s for %s:",
11653 section
.get_name (),
11654 section
.get_file_name ());
11656 end_ptr
= info_ptr
+ section
.size
;
11657 while (info_ptr
< end_ptr
)
11659 struct dwarf2_per_cu_data per_cu
;
11660 struct dwo_unit read_unit
{};
11661 struct dwo_unit
*dwo_unit
;
11663 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11665 memset (&per_cu
, 0, sizeof (per_cu
));
11666 per_cu
.per_bfd
= per_bfd
;
11667 per_cu
.is_debug_types
= 0;
11668 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11669 per_cu
.section
= §ion
;
11671 cutu_reader
reader (&per_cu
, per_objfile
, cu
, &dwo_file
);
11672 if (!reader
.dummy_p
)
11673 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11674 &dwo_file
, &read_unit
);
11675 info_ptr
+= per_cu
.length
;
11677 // If the unit could not be parsed, skip it.
11678 if (read_unit
.dwo_file
== NULL
)
11681 if (cus_htab
== NULL
)
11682 cus_htab
= allocate_dwo_unit_table ();
11684 dwo_unit
= OBSTACK_ZALLOC (&per_bfd
->obstack
,
11686 *dwo_unit
= read_unit
;
11687 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11688 gdb_assert (slot
!= NULL
);
11691 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11692 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11694 complaint (_("debug cu entry at offset %s is duplicate to"
11695 " the entry at offset %s, signature %s"),
11696 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11697 hex_string (dwo_unit
->signature
));
11699 *slot
= (void *)dwo_unit
;
11703 /* DWP file .debug_{cu,tu}_index section format:
11704 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11705 [ref: http://dwarfstd.org/doc/DWARF5.pdf, sect 7.3.5 "DWARF Package Files"]
11707 DWP Versions 1 & 2 are older, pre-standard format versions. The first
11708 officially standard DWP format was published with DWARF v5 and is called
11709 Version 5. There are no versions 3 or 4.
11713 Both index sections have the same format, and serve to map a 64-bit
11714 signature to a set of section numbers. Each section begins with a header,
11715 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11716 indexes, and a pool of 32-bit section numbers. The index sections will be
11717 aligned at 8-byte boundaries in the file.
11719 The index section header consists of:
11721 V, 32 bit version number
11723 N, 32 bit number of compilation units or type units in the index
11724 M, 32 bit number of slots in the hash table
11726 Numbers are recorded using the byte order of the application binary.
11728 The hash table begins at offset 16 in the section, and consists of an array
11729 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11730 order of the application binary). Unused slots in the hash table are 0.
11731 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11733 The parallel table begins immediately after the hash table
11734 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11735 array of 32-bit indexes (using the byte order of the application binary),
11736 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11737 table contains a 32-bit index into the pool of section numbers. For unused
11738 hash table slots, the corresponding entry in the parallel table will be 0.
11740 The pool of section numbers begins immediately following the hash table
11741 (at offset 16 + 12 * M from the beginning of the section). The pool of
11742 section numbers consists of an array of 32-bit words (using the byte order
11743 of the application binary). Each item in the array is indexed starting
11744 from 0. The hash table entry provides the index of the first section
11745 number in the set. Additional section numbers in the set follow, and the
11746 set is terminated by a 0 entry (section number 0 is not used in ELF).
11748 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11749 section must be the first entry in the set, and the .debug_abbrev.dwo must
11750 be the second entry. Other members of the set may follow in any order.
11754 DWP Versions 2 and 5:
11756 DWP Versions 2 and 5 combine all the .debug_info, etc. sections into one,
11757 and the entries in the index tables are now offsets into these sections.
11758 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11761 Index Section Contents:
11763 Hash Table of Signatures dwp_hash_table.hash_table
11764 Parallel Table of Indices dwp_hash_table.unit_table
11765 Table of Section Offsets dwp_hash_table.{v2|v5}.{section_ids,offsets}
11766 Table of Section Sizes dwp_hash_table.{v2|v5}.sizes
11768 The index section header consists of:
11770 V, 32 bit version number
11771 L, 32 bit number of columns in the table of section offsets
11772 N, 32 bit number of compilation units or type units in the index
11773 M, 32 bit number of slots in the hash table
11775 Numbers are recorded using the byte order of the application binary.
11777 The hash table has the same format as version 1.
11778 The parallel table of indices has the same format as version 1,
11779 except that the entries are origin-1 indices into the table of sections
11780 offsets and the table of section sizes.
11782 The table of offsets begins immediately following the parallel table
11783 (at offset 16 + 12 * M from the beginning of the section). The table is
11784 a two-dimensional array of 32-bit words (using the byte order of the
11785 application binary), with L columns and N+1 rows, in row-major order.
11786 Each row in the array is indexed starting from 0. The first row provides
11787 a key to the remaining rows: each column in this row provides an identifier
11788 for a debug section, and the offsets in the same column of subsequent rows
11789 refer to that section. The section identifiers for Version 2 are:
11791 DW_SECT_INFO 1 .debug_info.dwo
11792 DW_SECT_TYPES 2 .debug_types.dwo
11793 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11794 DW_SECT_LINE 4 .debug_line.dwo
11795 DW_SECT_LOC 5 .debug_loc.dwo
11796 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11797 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11798 DW_SECT_MACRO 8 .debug_macro.dwo
11800 The section identifiers for Version 5 are:
11802 DW_SECT_INFO_V5 1 .debug_info.dwo
11803 DW_SECT_RESERVED_V5 2 --
11804 DW_SECT_ABBREV_V5 3 .debug_abbrev.dwo
11805 DW_SECT_LINE_V5 4 .debug_line.dwo
11806 DW_SECT_LOCLISTS_V5 5 .debug_loclists.dwo
11807 DW_SECT_STR_OFFSETS_V5 6 .debug_str_offsets.dwo
11808 DW_SECT_MACRO_V5 7 .debug_macro.dwo
11809 DW_SECT_RNGLISTS_V5 8 .debug_rnglists.dwo
11811 The offsets provided by the CU and TU index sections are the base offsets
11812 for the contributions made by each CU or TU to the corresponding section
11813 in the package file. Each CU and TU header contains an abbrev_offset
11814 field, used to find the abbreviations table for that CU or TU within the
11815 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11816 be interpreted as relative to the base offset given in the index section.
11817 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11818 should be interpreted as relative to the base offset for .debug_line.dwo,
11819 and offsets into other debug sections obtained from DWARF attributes should
11820 also be interpreted as relative to the corresponding base offset.
11822 The table of sizes begins immediately following the table of offsets.
11823 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11824 with L columns and N rows, in row-major order. Each row in the array is
11825 indexed starting from 1 (row 0 is shared by the two tables).
11829 Hash table lookup is handled the same in version 1 and 2:
11831 We assume that N and M will not exceed 2^32 - 1.
11832 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11834 Given a 64-bit compilation unit signature or a type signature S, an entry
11835 in the hash table is located as follows:
11837 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11838 the low-order k bits all set to 1.
11840 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11842 3) If the hash table entry at index H matches the signature, use that
11843 entry. If the hash table entry at index H is unused (all zeroes),
11844 terminate the search: the signature is not present in the table.
11846 4) Let H = (H + H') modulo M. Repeat at Step 3.
11848 Because M > N and H' and M are relatively prime, the search is guaranteed
11849 to stop at an unused slot or find the match. */
11851 /* Create a hash table to map DWO IDs to their CU/TU entry in
11852 .debug_{info,types}.dwo in DWP_FILE.
11853 Returns NULL if there isn't one.
11854 Note: This function processes DWP files only, not DWO files. */
11856 static struct dwp_hash_table
*
11857 create_dwp_hash_table (dwarf2_per_objfile
*per_objfile
,
11858 struct dwp_file
*dwp_file
, int is_debug_types
)
11860 struct objfile
*objfile
= per_objfile
->objfile
;
11861 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11862 const gdb_byte
*index_ptr
, *index_end
;
11863 struct dwarf2_section_info
*index
;
11864 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11865 struct dwp_hash_table
*htab
;
11867 if (is_debug_types
)
11868 index
= &dwp_file
->sections
.tu_index
;
11870 index
= &dwp_file
->sections
.cu_index
;
11872 if (index
->empty ())
11874 index
->read (objfile
);
11876 index_ptr
= index
->buffer
;
11877 index_end
= index_ptr
+ index
->size
;
11879 /* For Version 5, the version is really 2 bytes of data & 2 bytes of padding.
11880 For now it's safe to just read 4 bytes (particularly as it's difficult to
11881 tell if you're dealing with Version 5 before you've read the version). */
11882 version
= read_4_bytes (dbfd
, index_ptr
);
11884 if (version
== 2 || version
== 5)
11885 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11889 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11891 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11894 if (version
!= 1 && version
!= 2 && version
!= 5)
11896 error (_("Dwarf Error: unsupported DWP file version (%s)"
11897 " [in module %s]"),
11898 pulongest (version
), dwp_file
->name
);
11900 if (nr_slots
!= (nr_slots
& -nr_slots
))
11902 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11903 " is not power of 2 [in module %s]"),
11904 pulongest (nr_slots
), dwp_file
->name
);
11907 htab
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwp_hash_table
);
11908 htab
->version
= version
;
11909 htab
->nr_columns
= nr_columns
;
11910 htab
->nr_units
= nr_units
;
11911 htab
->nr_slots
= nr_slots
;
11912 htab
->hash_table
= index_ptr
;
11913 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11915 /* Exit early if the table is empty. */
11916 if (nr_slots
== 0 || nr_units
== 0
11917 || (version
== 2 && nr_columns
== 0)
11918 || (version
== 5 && nr_columns
== 0))
11920 /* All must be zero. */
11921 if (nr_slots
!= 0 || nr_units
!= 0
11922 || (version
== 2 && nr_columns
!= 0)
11923 || (version
== 5 && nr_columns
!= 0))
11925 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11926 " all zero [in modules %s]"),
11934 htab
->section_pool
.v1
.indices
=
11935 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11936 /* It's harder to decide whether the section is too small in v1.
11937 V1 is deprecated anyway so we punt. */
11939 else if (version
== 2)
11941 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11942 int *ids
= htab
->section_pool
.v2
.section_ids
;
11943 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11944 /* Reverse map for error checking. */
11945 int ids_seen
[DW_SECT_MAX
+ 1];
11948 if (nr_columns
< 2)
11950 error (_("Dwarf Error: bad DWP hash table, too few columns"
11951 " in section table [in module %s]"),
11954 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11956 error (_("Dwarf Error: bad DWP hash table, too many columns"
11957 " in section table [in module %s]"),
11960 memset (ids
, 255, sizeof_ids
);
11961 memset (ids_seen
, 255, sizeof (ids_seen
));
11962 for (i
= 0; i
< nr_columns
; ++i
)
11964 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11966 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11968 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11969 " in section table [in module %s]"),
11970 id
, dwp_file
->name
);
11972 if (ids_seen
[id
] != -1)
11974 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11975 " id %d in section table [in module %s]"),
11976 id
, dwp_file
->name
);
11981 /* Must have exactly one info or types section. */
11982 if (((ids_seen
[DW_SECT_INFO
] != -1)
11983 + (ids_seen
[DW_SECT_TYPES
] != -1))
11986 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11987 " DWO info/types section [in module %s]"),
11990 /* Must have an abbrev section. */
11991 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11993 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11994 " section [in module %s]"),
11997 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11998 htab
->section_pool
.v2
.sizes
=
11999 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12000 * nr_units
* nr_columns
);
12001 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12002 * nr_units
* nr_columns
))
12005 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12006 " [in module %s]"),
12010 else /* version == 5 */
12012 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12013 int *ids
= htab
->section_pool
.v5
.section_ids
;
12014 size_t sizeof_ids
= sizeof (htab
->section_pool
.v5
.section_ids
);
12015 /* Reverse map for error checking. */
12016 int ids_seen
[DW_SECT_MAX_V5
+ 1];
12018 if (nr_columns
< 2)
12020 error (_("Dwarf Error: bad DWP hash table, too few columns"
12021 " in section table [in module %s]"),
12024 if (nr_columns
> MAX_NR_V5_DWO_SECTIONS
)
12026 error (_("Dwarf Error: bad DWP hash table, too many columns"
12027 " in section table [in module %s]"),
12030 memset (ids
, 255, sizeof_ids
);
12031 memset (ids_seen
, 255, sizeof (ids_seen
));
12032 for (int i
= 0; i
< nr_columns
; ++i
)
12034 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12036 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX_V5
)
12038 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12039 " in section table [in module %s]"),
12040 id
, dwp_file
->name
);
12042 if (ids_seen
[id
] != -1)
12044 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12045 " id %d in section table [in module %s]"),
12046 id
, dwp_file
->name
);
12051 /* Must have seen an info section. */
12052 if (ids_seen
[DW_SECT_INFO_V5
] == -1)
12054 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12055 " DWO info/types section [in module %s]"),
12058 /* Must have an abbrev section. */
12059 if (ids_seen
[DW_SECT_ABBREV_V5
] == -1)
12061 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12062 " section [in module %s]"),
12065 htab
->section_pool
.v5
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12066 htab
->section_pool
.v5
.sizes
12067 = htab
->section_pool
.v5
.offsets
+ (sizeof (uint32_t)
12068 * nr_units
* nr_columns
);
12069 if ((htab
->section_pool
.v5
.sizes
+ (sizeof (uint32_t)
12070 * nr_units
* nr_columns
))
12073 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12074 " [in module %s]"),
12082 /* Update SECTIONS with the data from SECTP.
12084 This function is like the other "locate" section routines, but in
12085 this context the sections to read comes from the DWP V1 hash table,
12086 not the full ELF section table.
12088 The result is non-zero for success, or zero if an error was found. */
12091 locate_v1_virtual_dwo_sections (asection
*sectp
,
12092 struct virtual_v1_dwo_sections
*sections
)
12094 const struct dwop_section_names
*names
= &dwop_section_names
;
12096 if (names
->abbrev_dwo
.matches (sectp
->name
))
12098 /* There can be only one. */
12099 if (sections
->abbrev
.s
.section
!= NULL
)
12101 sections
->abbrev
.s
.section
= sectp
;
12102 sections
->abbrev
.size
= bfd_section_size (sectp
);
12104 else if (names
->info_dwo
.matches (sectp
->name
)
12105 || names
->types_dwo
.matches (sectp
->name
))
12107 /* There can be only one. */
12108 if (sections
->info_or_types
.s
.section
!= NULL
)
12110 sections
->info_or_types
.s
.section
= sectp
;
12111 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12113 else if (names
->line_dwo
.matches (sectp
->name
))
12115 /* There can be only one. */
12116 if (sections
->line
.s
.section
!= NULL
)
12118 sections
->line
.s
.section
= sectp
;
12119 sections
->line
.size
= bfd_section_size (sectp
);
12121 else if (names
->loc_dwo
.matches (sectp
->name
))
12123 /* There can be only one. */
12124 if (sections
->loc
.s
.section
!= NULL
)
12126 sections
->loc
.s
.section
= sectp
;
12127 sections
->loc
.size
= bfd_section_size (sectp
);
12129 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12131 /* There can be only one. */
12132 if (sections
->macinfo
.s
.section
!= NULL
)
12134 sections
->macinfo
.s
.section
= sectp
;
12135 sections
->macinfo
.size
= bfd_section_size (sectp
);
12137 else if (names
->macro_dwo
.matches (sectp
->name
))
12139 /* There can be only one. */
12140 if (sections
->macro
.s
.section
!= NULL
)
12142 sections
->macro
.s
.section
= sectp
;
12143 sections
->macro
.size
= bfd_section_size (sectp
);
12145 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12147 /* There can be only one. */
12148 if (sections
->str_offsets
.s
.section
!= NULL
)
12150 sections
->str_offsets
.s
.section
= sectp
;
12151 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12155 /* No other kind of section is valid. */
12162 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12163 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12164 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12165 This is for DWP version 1 files. */
12167 static struct dwo_unit
*
12168 create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
*per_objfile
,
12169 struct dwp_file
*dwp_file
,
12170 uint32_t unit_index
,
12171 const char *comp_dir
,
12172 ULONGEST signature
, int is_debug_types
)
12174 const struct dwp_hash_table
*dwp_htab
=
12175 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12176 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12177 const char *kind
= is_debug_types
? "TU" : "CU";
12178 struct dwo_file
*dwo_file
;
12179 struct dwo_unit
*dwo_unit
;
12180 struct virtual_v1_dwo_sections sections
;
12181 void **dwo_file_slot
;
12184 gdb_assert (dwp_file
->version
== 1);
12186 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V1 file: %s",
12187 kind
, pulongest (unit_index
), hex_string (signature
),
12190 /* Fetch the sections of this DWO unit.
12191 Put a limit on the number of sections we look for so that bad data
12192 doesn't cause us to loop forever. */
12194 #define MAX_NR_V1_DWO_SECTIONS \
12195 (1 /* .debug_info or .debug_types */ \
12196 + 1 /* .debug_abbrev */ \
12197 + 1 /* .debug_line */ \
12198 + 1 /* .debug_loc */ \
12199 + 1 /* .debug_str_offsets */ \
12200 + 1 /* .debug_macro or .debug_macinfo */ \
12201 + 1 /* trailing zero */)
12203 memset (§ions
, 0, sizeof (sections
));
12205 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12208 uint32_t section_nr
=
12209 read_4_bytes (dbfd
,
12210 dwp_htab
->section_pool
.v1
.indices
12211 + (unit_index
+ i
) * sizeof (uint32_t));
12213 if (section_nr
== 0)
12215 if (section_nr
>= dwp_file
->num_sections
)
12217 error (_("Dwarf Error: bad DWP hash table, section number too large"
12218 " [in module %s]"),
12222 sectp
= dwp_file
->elf_sections
[section_nr
];
12223 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12225 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12226 " [in module %s]"),
12232 || sections
.info_or_types
.empty ()
12233 || sections
.abbrev
.empty ())
12235 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12236 " [in module %s]"),
12239 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12241 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12242 " [in module %s]"),
12246 /* It's easier for the rest of the code if we fake a struct dwo_file and
12247 have dwo_unit "live" in that. At least for now.
12249 The DWP file can be made up of a random collection of CUs and TUs.
12250 However, for each CU + set of TUs that came from the same original DWO
12251 file, we can combine them back into a virtual DWO file to save space
12252 (fewer struct dwo_file objects to allocate). Remember that for really
12253 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12255 std::string virtual_dwo_name
=
12256 string_printf ("virtual-dwo/%d-%d-%d-%d",
12257 sections
.abbrev
.get_id (),
12258 sections
.line
.get_id (),
12259 sections
.loc
.get_id (),
12260 sections
.str_offsets
.get_id ());
12261 /* Can we use an existing virtual DWO file? */
12262 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12264 /* Create one if necessary. */
12265 if (*dwo_file_slot
== NULL
)
12267 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12268 virtual_dwo_name
.c_str ());
12270 dwo_file
= new struct dwo_file
;
12271 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12272 dwo_file
->comp_dir
= comp_dir
;
12273 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12274 dwo_file
->sections
.line
= sections
.line
;
12275 dwo_file
->sections
.loc
= sections
.loc
;
12276 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12277 dwo_file
->sections
.macro
= sections
.macro
;
12278 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12279 /* The "str" section is global to the entire DWP file. */
12280 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12281 /* The info or types section is assigned below to dwo_unit,
12282 there's no need to record it in dwo_file.
12283 Also, we can't simply record type sections in dwo_file because
12284 we record a pointer into the vector in dwo_unit. As we collect more
12285 types we'll grow the vector and eventually have to reallocate space
12286 for it, invalidating all copies of pointers into the previous
12288 *dwo_file_slot
= dwo_file
;
12292 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12293 virtual_dwo_name
.c_str ());
12295 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12298 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12299 dwo_unit
->dwo_file
= dwo_file
;
12300 dwo_unit
->signature
= signature
;
12301 dwo_unit
->section
=
12302 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12303 *dwo_unit
->section
= sections
.info_or_types
;
12304 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12309 /* Subroutine of create_dwo_unit_in_dwp_v2 and create_dwo_unit_in_dwp_v5 to
12310 simplify them. Given a pointer to the containing section SECTION, and
12311 OFFSET,SIZE of the piece within that section used by a TU/CU, return a
12312 virtual section of just that piece. */
12314 static struct dwarf2_section_info
12315 create_dwp_v2_or_v5_section (dwarf2_per_objfile
*per_objfile
,
12316 struct dwarf2_section_info
*section
,
12317 bfd_size_type offset
, bfd_size_type size
)
12319 struct dwarf2_section_info result
;
12322 gdb_assert (section
!= NULL
);
12323 gdb_assert (!section
->is_virtual
);
12325 memset (&result
, 0, sizeof (result
));
12326 result
.s
.containing_section
= section
;
12327 result
.is_virtual
= true;
12332 sectp
= section
->get_bfd_section ();
12334 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12335 bounds of the real section. This is a pretty-rare event, so just
12336 flag an error (easier) instead of a warning and trying to cope. */
12338 || offset
+ size
> bfd_section_size (sectp
))
12340 error (_("Dwarf Error: Bad DWP V2 or V5 section info, doesn't fit"
12341 " in section %s [in module %s]"),
12342 sectp
? bfd_section_name (sectp
) : "<unknown>",
12343 objfile_name (per_objfile
->objfile
));
12346 result
.virtual_offset
= offset
;
12347 result
.size
= size
;
12351 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12352 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12353 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12354 This is for DWP version 2 files. */
12356 static struct dwo_unit
*
12357 create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
*per_objfile
,
12358 struct dwp_file
*dwp_file
,
12359 uint32_t unit_index
,
12360 const char *comp_dir
,
12361 ULONGEST signature
, int is_debug_types
)
12363 const struct dwp_hash_table
*dwp_htab
=
12364 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12365 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12366 const char *kind
= is_debug_types
? "TU" : "CU";
12367 struct dwo_file
*dwo_file
;
12368 struct dwo_unit
*dwo_unit
;
12369 struct virtual_v2_or_v5_dwo_sections sections
;
12370 void **dwo_file_slot
;
12373 gdb_assert (dwp_file
->version
== 2);
12375 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V2 file: %s",
12376 kind
, pulongest (unit_index
), hex_string (signature
),
12379 /* Fetch the section offsets of this DWO unit. */
12381 memset (§ions
, 0, sizeof (sections
));
12383 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12385 uint32_t offset
= read_4_bytes (dbfd
,
12386 dwp_htab
->section_pool
.v2
.offsets
12387 + (((unit_index
- 1) * dwp_htab
->nr_columns
12389 * sizeof (uint32_t)));
12390 uint32_t size
= read_4_bytes (dbfd
,
12391 dwp_htab
->section_pool
.v2
.sizes
12392 + (((unit_index
- 1) * dwp_htab
->nr_columns
12394 * sizeof (uint32_t)));
12396 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12399 case DW_SECT_TYPES
:
12400 sections
.info_or_types_offset
= offset
;
12401 sections
.info_or_types_size
= size
;
12403 case DW_SECT_ABBREV
:
12404 sections
.abbrev_offset
= offset
;
12405 sections
.abbrev_size
= size
;
12408 sections
.line_offset
= offset
;
12409 sections
.line_size
= size
;
12412 sections
.loc_offset
= offset
;
12413 sections
.loc_size
= size
;
12415 case DW_SECT_STR_OFFSETS
:
12416 sections
.str_offsets_offset
= offset
;
12417 sections
.str_offsets_size
= size
;
12419 case DW_SECT_MACINFO
:
12420 sections
.macinfo_offset
= offset
;
12421 sections
.macinfo_size
= size
;
12423 case DW_SECT_MACRO
:
12424 sections
.macro_offset
= offset
;
12425 sections
.macro_size
= size
;
12430 /* It's easier for the rest of the code if we fake a struct dwo_file and
12431 have dwo_unit "live" in that. At least for now.
12433 The DWP file can be made up of a random collection of CUs and TUs.
12434 However, for each CU + set of TUs that came from the same original DWO
12435 file, we can combine them back into a virtual DWO file to save space
12436 (fewer struct dwo_file objects to allocate). Remember that for really
12437 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12439 std::string virtual_dwo_name
=
12440 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12441 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12442 (long) (sections
.line_size
? sections
.line_offset
: 0),
12443 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12444 (long) (sections
.str_offsets_size
12445 ? sections
.str_offsets_offset
: 0));
12446 /* Can we use an existing virtual DWO file? */
12447 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, virtual_dwo_name
.c_str (),
12449 /* Create one if necessary. */
12450 if (*dwo_file_slot
== NULL
)
12452 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12453 virtual_dwo_name
.c_str ());
12455 dwo_file
= new struct dwo_file
;
12456 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12457 dwo_file
->comp_dir
= comp_dir
;
12458 dwo_file
->sections
.abbrev
=
12459 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.abbrev
,
12460 sections
.abbrev_offset
,
12461 sections
.abbrev_size
);
12462 dwo_file
->sections
.line
=
12463 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.line
,
12464 sections
.line_offset
,
12465 sections
.line_size
);
12466 dwo_file
->sections
.loc
=
12467 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.loc
,
12468 sections
.loc_offset
, sections
.loc_size
);
12469 dwo_file
->sections
.macinfo
=
12470 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macinfo
,
12471 sections
.macinfo_offset
,
12472 sections
.macinfo_size
);
12473 dwo_file
->sections
.macro
=
12474 create_dwp_v2_or_v5_section (per_objfile
, &dwp_file
->sections
.macro
,
12475 sections
.macro_offset
,
12476 sections
.macro_size
);
12477 dwo_file
->sections
.str_offsets
=
12478 create_dwp_v2_or_v5_section (per_objfile
,
12479 &dwp_file
->sections
.str_offsets
,
12480 sections
.str_offsets_offset
,
12481 sections
.str_offsets_size
);
12482 /* The "str" section is global to the entire DWP file. */
12483 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12484 /* The info or types section is assigned below to dwo_unit,
12485 there's no need to record it in dwo_file.
12486 Also, we can't simply record type sections in dwo_file because
12487 we record a pointer into the vector in dwo_unit. As we collect more
12488 types we'll grow the vector and eventually have to reallocate space
12489 for it, invalidating all copies of pointers into the previous
12491 *dwo_file_slot
= dwo_file
;
12495 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12496 virtual_dwo_name
.c_str ());
12498 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12501 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12502 dwo_unit
->dwo_file
= dwo_file
;
12503 dwo_unit
->signature
= signature
;
12504 dwo_unit
->section
=
12505 XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12506 *dwo_unit
->section
= create_dwp_v2_or_v5_section
12509 ? &dwp_file
->sections
.types
12510 : &dwp_file
->sections
.info
,
12511 sections
.info_or_types_offset
,
12512 sections
.info_or_types_size
);
12513 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12518 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12519 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12520 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12521 This is for DWP version 5 files. */
12523 static struct dwo_unit
*
12524 create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile
*per_objfile
,
12525 struct dwp_file
*dwp_file
,
12526 uint32_t unit_index
,
12527 const char *comp_dir
,
12528 ULONGEST signature
, int is_debug_types
)
12530 const struct dwp_hash_table
*dwp_htab
12531 = is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12532 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12533 const char *kind
= is_debug_types
? "TU" : "CU";
12534 struct dwo_file
*dwo_file
;
12535 struct dwo_unit
*dwo_unit
;
12536 struct virtual_v2_or_v5_dwo_sections sections
{};
12537 void **dwo_file_slot
;
12539 gdb_assert (dwp_file
->version
== 5);
12541 dwarf_read_debug_printf ("Reading %s %s/%s in DWP V5 file: %s",
12542 kind
, pulongest (unit_index
), hex_string (signature
),
12545 /* Fetch the section offsets of this DWO unit. */
12547 /* memset (§ions, 0, sizeof (sections)); */
12549 for (int i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12551 uint32_t offset
= read_4_bytes (dbfd
,
12552 dwp_htab
->section_pool
.v5
.offsets
12553 + (((unit_index
- 1)
12554 * dwp_htab
->nr_columns
12556 * sizeof (uint32_t)));
12557 uint32_t size
= read_4_bytes (dbfd
,
12558 dwp_htab
->section_pool
.v5
.sizes
12559 + (((unit_index
- 1) * dwp_htab
->nr_columns
12561 * sizeof (uint32_t)));
12563 switch (dwp_htab
->section_pool
.v5
.section_ids
[i
])
12565 case DW_SECT_ABBREV_V5
:
12566 sections
.abbrev_offset
= offset
;
12567 sections
.abbrev_size
= size
;
12569 case DW_SECT_INFO_V5
:
12570 sections
.info_or_types_offset
= offset
;
12571 sections
.info_or_types_size
= size
;
12573 case DW_SECT_LINE_V5
:
12574 sections
.line_offset
= offset
;
12575 sections
.line_size
= size
;
12577 case DW_SECT_LOCLISTS_V5
:
12578 sections
.loclists_offset
= offset
;
12579 sections
.loclists_size
= size
;
12581 case DW_SECT_MACRO_V5
:
12582 sections
.macro_offset
= offset
;
12583 sections
.macro_size
= size
;
12585 case DW_SECT_RNGLISTS_V5
:
12586 sections
.rnglists_offset
= offset
;
12587 sections
.rnglists_size
= size
;
12589 case DW_SECT_STR_OFFSETS_V5
:
12590 sections
.str_offsets_offset
= offset
;
12591 sections
.str_offsets_size
= size
;
12593 case DW_SECT_RESERVED_V5
:
12599 /* It's easier for the rest of the code if we fake a struct dwo_file and
12600 have dwo_unit "live" in that. At least for now.
12602 The DWP file can be made up of a random collection of CUs and TUs.
12603 However, for each CU + set of TUs that came from the same original DWO
12604 file, we can combine them back into a virtual DWO file to save space
12605 (fewer struct dwo_file objects to allocate). Remember that for really
12606 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12608 std::string virtual_dwo_name
=
12609 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld-%ld-%ld",
12610 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12611 (long) (sections
.line_size
? sections
.line_offset
: 0),
12612 (long) (sections
.loclists_size
? sections
.loclists_offset
: 0),
12613 (long) (sections
.str_offsets_size
12614 ? sections
.str_offsets_offset
: 0),
12615 (long) (sections
.macro_size
? sections
.macro_offset
: 0),
12616 (long) (sections
.rnglists_size
? sections
.rnglists_offset
: 0));
12617 /* Can we use an existing virtual DWO file? */
12618 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
,
12619 virtual_dwo_name
.c_str (),
12621 /* Create one if necessary. */
12622 if (*dwo_file_slot
== NULL
)
12624 dwarf_read_debug_printf ("Creating virtual DWO: %s",
12625 virtual_dwo_name
.c_str ());
12627 dwo_file
= new struct dwo_file
;
12628 dwo_file
->dwo_name
= per_objfile
->objfile
->intern (virtual_dwo_name
);
12629 dwo_file
->comp_dir
= comp_dir
;
12630 dwo_file
->sections
.abbrev
=
12631 create_dwp_v2_or_v5_section (per_objfile
,
12632 &dwp_file
->sections
.abbrev
,
12633 sections
.abbrev_offset
,
12634 sections
.abbrev_size
);
12635 dwo_file
->sections
.line
=
12636 create_dwp_v2_or_v5_section (per_objfile
,
12637 &dwp_file
->sections
.line
,
12638 sections
.line_offset
, sections
.line_size
);
12639 dwo_file
->sections
.macro
=
12640 create_dwp_v2_or_v5_section (per_objfile
,
12641 &dwp_file
->sections
.macro
,
12642 sections
.macro_offset
,
12643 sections
.macro_size
);
12644 dwo_file
->sections
.loclists
=
12645 create_dwp_v2_or_v5_section (per_objfile
,
12646 &dwp_file
->sections
.loclists
,
12647 sections
.loclists_offset
,
12648 sections
.loclists_size
);
12649 dwo_file
->sections
.rnglists
=
12650 create_dwp_v2_or_v5_section (per_objfile
,
12651 &dwp_file
->sections
.rnglists
,
12652 sections
.rnglists_offset
,
12653 sections
.rnglists_size
);
12654 dwo_file
->sections
.str_offsets
=
12655 create_dwp_v2_or_v5_section (per_objfile
,
12656 &dwp_file
->sections
.str_offsets
,
12657 sections
.str_offsets_offset
,
12658 sections
.str_offsets_size
);
12659 /* The "str" section is global to the entire DWP file. */
12660 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12661 /* The info or types section is assigned below to dwo_unit,
12662 there's no need to record it in dwo_file.
12663 Also, we can't simply record type sections in dwo_file because
12664 we record a pointer into the vector in dwo_unit. As we collect more
12665 types we'll grow the vector and eventually have to reallocate space
12666 for it, invalidating all copies of pointers into the previous
12668 *dwo_file_slot
= dwo_file
;
12672 dwarf_read_debug_printf ("Using existing virtual DWO: %s",
12673 virtual_dwo_name
.c_str ());
12675 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12678 dwo_unit
= OBSTACK_ZALLOC (&per_objfile
->per_bfd
->obstack
, struct dwo_unit
);
12679 dwo_unit
->dwo_file
= dwo_file
;
12680 dwo_unit
->signature
= signature
;
12682 = XOBNEW (&per_objfile
->per_bfd
->obstack
, struct dwarf2_section_info
);
12683 *dwo_unit
->section
= create_dwp_v2_or_v5_section (per_objfile
,
12684 &dwp_file
->sections
.info
,
12685 sections
.info_or_types_offset
,
12686 sections
.info_or_types_size
);
12687 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12692 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12693 Returns NULL if the signature isn't found. */
12695 static struct dwo_unit
*
12696 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
*per_objfile
,
12697 struct dwp_file
*dwp_file
, const char *comp_dir
,
12698 ULONGEST signature
, int is_debug_types
)
12700 const struct dwp_hash_table
*dwp_htab
=
12701 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12702 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12703 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12704 uint32_t hash
= signature
& mask
;
12705 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12708 struct dwo_unit find_dwo_cu
;
12710 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12711 find_dwo_cu
.signature
= signature
;
12712 slot
= htab_find_slot (is_debug_types
12713 ? dwp_file
->loaded_tus
.get ()
12714 : dwp_file
->loaded_cus
.get (),
12715 &find_dwo_cu
, INSERT
);
12718 return (struct dwo_unit
*) *slot
;
12720 /* Use a for loop so that we don't loop forever on bad debug info. */
12721 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12723 ULONGEST signature_in_table
;
12725 signature_in_table
=
12726 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12727 if (signature_in_table
== signature
)
12729 uint32_t unit_index
=
12730 read_4_bytes (dbfd
,
12731 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12733 if (dwp_file
->version
== 1)
12735 *slot
= create_dwo_unit_in_dwp_v1 (per_objfile
, dwp_file
,
12736 unit_index
, comp_dir
,
12737 signature
, is_debug_types
);
12739 else if (dwp_file
->version
== 2)
12741 *slot
= create_dwo_unit_in_dwp_v2 (per_objfile
, dwp_file
,
12742 unit_index
, comp_dir
,
12743 signature
, is_debug_types
);
12745 else /* version == 5 */
12747 *slot
= create_dwo_unit_in_dwp_v5 (per_objfile
, dwp_file
,
12748 unit_index
, comp_dir
,
12749 signature
, is_debug_types
);
12751 return (struct dwo_unit
*) *slot
;
12753 if (signature_in_table
== 0)
12755 hash
= (hash
+ hash2
) & mask
;
12758 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12759 " [in module %s]"),
12763 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12764 Open the file specified by FILE_NAME and hand it off to BFD for
12765 preliminary analysis. Return a newly initialized bfd *, which
12766 includes a canonicalized copy of FILE_NAME.
12767 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12768 SEARCH_CWD is true if the current directory is to be searched.
12769 It will be searched before debug-file-directory.
12770 If successful, the file is added to the bfd include table of the
12771 objfile's bfd (see gdb_bfd_record_inclusion).
12772 If unable to find/open the file, return NULL.
12773 NOTE: This function is derived from symfile_bfd_open. */
12775 static gdb_bfd_ref_ptr
12776 try_open_dwop_file (dwarf2_per_objfile
*per_objfile
,
12777 const char *file_name
, int is_dwp
, int search_cwd
)
12780 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12781 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12782 to debug_file_directory. */
12783 const char *search_path
;
12784 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12786 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12789 if (*debug_file_directory
!= '\0')
12791 search_path_holder
.reset (concat (".", dirname_separator_string
,
12792 debug_file_directory
,
12794 search_path
= search_path_holder
.get ();
12800 search_path
= debug_file_directory
;
12802 openp_flags flags
= OPF_RETURN_REALPATH
;
12804 flags
|= OPF_SEARCH_IN_PATH
;
12806 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12807 desc
= openp (search_path
, flags
, file_name
,
12808 O_RDONLY
| O_BINARY
, &absolute_name
);
12812 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12814 if (sym_bfd
== NULL
)
12816 bfd_set_cacheable (sym_bfd
.get (), 1);
12818 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12821 /* Success. Record the bfd as having been included by the objfile's bfd.
12822 This is important because things like demangled_names_hash lives in the
12823 objfile's per_bfd space and may have references to things like symbol
12824 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12825 gdb_bfd_record_inclusion (per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12830 /* Try to open DWO file FILE_NAME.
12831 COMP_DIR is the DW_AT_comp_dir attribute.
12832 The result is the bfd handle of the file.
12833 If there is a problem finding or opening the file, return NULL.
12834 Upon success, the canonicalized path of the file is stored in the bfd,
12835 same as symfile_bfd_open. */
12837 static gdb_bfd_ref_ptr
12838 open_dwo_file (dwarf2_per_objfile
*per_objfile
,
12839 const char *file_name
, const char *comp_dir
)
12841 if (IS_ABSOLUTE_PATH (file_name
))
12842 return try_open_dwop_file (per_objfile
, file_name
,
12843 0 /*is_dwp*/, 0 /*search_cwd*/);
12845 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12847 if (comp_dir
!= NULL
)
12849 gdb::unique_xmalloc_ptr
<char> path_to_try
12850 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12852 /* NOTE: If comp_dir is a relative path, this will also try the
12853 search path, which seems useful. */
12854 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, path_to_try
.get (),
12856 1 /*search_cwd*/));
12861 /* That didn't work, try debug-file-directory, which, despite its name,
12862 is a list of paths. */
12864 if (*debug_file_directory
== '\0')
12867 return try_open_dwop_file (per_objfile
, file_name
,
12868 0 /*is_dwp*/, 1 /*search_cwd*/);
12871 /* This function is mapped across the sections and remembers the offset and
12872 size of each of the DWO debugging sections we are interested in. */
12875 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
,
12876 dwo_sections
*dwo_sections
)
12878 const struct dwop_section_names
*names
= &dwop_section_names
;
12880 if (names
->abbrev_dwo
.matches (sectp
->name
))
12882 dwo_sections
->abbrev
.s
.section
= sectp
;
12883 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12885 else if (names
->info_dwo
.matches (sectp
->name
))
12887 dwo_sections
->info
.s
.section
= sectp
;
12888 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12890 else if (names
->line_dwo
.matches (sectp
->name
))
12892 dwo_sections
->line
.s
.section
= sectp
;
12893 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12895 else if (names
->loc_dwo
.matches (sectp
->name
))
12897 dwo_sections
->loc
.s
.section
= sectp
;
12898 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12900 else if (names
->loclists_dwo
.matches (sectp
->name
))
12902 dwo_sections
->loclists
.s
.section
= sectp
;
12903 dwo_sections
->loclists
.size
= bfd_section_size (sectp
);
12905 else if (names
->macinfo_dwo
.matches (sectp
->name
))
12907 dwo_sections
->macinfo
.s
.section
= sectp
;
12908 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12910 else if (names
->macro_dwo
.matches (sectp
->name
))
12912 dwo_sections
->macro
.s
.section
= sectp
;
12913 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12915 else if (names
->rnglists_dwo
.matches (sectp
->name
))
12917 dwo_sections
->rnglists
.s
.section
= sectp
;
12918 dwo_sections
->rnglists
.size
= bfd_section_size (sectp
);
12920 else if (names
->str_dwo
.matches (sectp
->name
))
12922 dwo_sections
->str
.s
.section
= sectp
;
12923 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12925 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
12927 dwo_sections
->str_offsets
.s
.section
= sectp
;
12928 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12930 else if (names
->types_dwo
.matches (sectp
->name
))
12932 struct dwarf2_section_info type_section
;
12934 memset (&type_section
, 0, sizeof (type_section
));
12935 type_section
.s
.section
= sectp
;
12936 type_section
.size
= bfd_section_size (sectp
);
12937 dwo_sections
->types
.push_back (type_section
);
12941 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12942 by PER_CU. This is for the non-DWP case.
12943 The result is NULL if DWO_NAME can't be found. */
12945 static struct dwo_file
*
12946 open_and_init_dwo_file (dwarf2_cu
*cu
, const char *dwo_name
,
12947 const char *comp_dir
)
12949 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
12951 gdb_bfd_ref_ptr dbfd
= open_dwo_file (per_objfile
, dwo_name
, comp_dir
);
12954 dwarf_read_debug_printf ("DWO file not found: %s", dwo_name
);
12959 dwo_file_up
dwo_file (new struct dwo_file
);
12960 dwo_file
->dwo_name
= dwo_name
;
12961 dwo_file
->comp_dir
= comp_dir
;
12962 dwo_file
->dbfd
= std::move (dbfd
);
12964 for (asection
*sec
: gdb_bfd_sections (dwo_file
->dbfd
))
12965 dwarf2_locate_dwo_sections (dwo_file
->dbfd
.get (), sec
,
12966 &dwo_file
->sections
);
12968 create_cus_hash_table (per_objfile
, cu
, *dwo_file
, dwo_file
->sections
.info
,
12971 if (cu
->per_cu
->dwarf_version
< 5)
12973 create_debug_types_hash_table (per_objfile
, dwo_file
.get (),
12974 dwo_file
->sections
.types
, dwo_file
->tus
);
12978 create_debug_type_hash_table (per_objfile
, dwo_file
.get (),
12979 &dwo_file
->sections
.info
, dwo_file
->tus
,
12980 rcuh_kind::COMPILE
);
12983 dwarf_read_debug_printf ("DWO file found: %s", dwo_name
);
12985 return dwo_file
.release ();
12988 /* This function is mapped across the sections and remembers the offset and
12989 size of each of the DWP debugging sections common to version 1 and 2 that
12990 we are interested in. */
12993 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12994 dwp_file
*dwp_file
)
12996 const struct dwop_section_names
*names
= &dwop_section_names
;
12997 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12999 /* Record the ELF section number for later lookup: this is what the
13000 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13001 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13002 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13004 /* Look for specific sections that we need. */
13005 if (names
->str_dwo
.matches (sectp
->name
))
13007 dwp_file
->sections
.str
.s
.section
= sectp
;
13008 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
13010 else if (names
->cu_index
.matches (sectp
->name
))
13012 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13013 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
13015 else if (names
->tu_index
.matches (sectp
->name
))
13017 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13018 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
13022 /* This function is mapped across the sections and remembers the offset and
13023 size of each of the DWP version 2 debugging sections that we are interested
13024 in. This is split into a separate function because we don't know if we
13025 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
13028 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13030 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13031 const struct dwop_section_names
*names
= &dwop_section_names
;
13032 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13034 /* Record the ELF section number for later lookup: this is what the
13035 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13036 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13037 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13039 /* Look for specific sections that we need. */
13040 if (names
->abbrev_dwo
.matches (sectp
->name
))
13042 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13043 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13045 else if (names
->info_dwo
.matches (sectp
->name
))
13047 dwp_file
->sections
.info
.s
.section
= sectp
;
13048 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13050 else if (names
->line_dwo
.matches (sectp
->name
))
13052 dwp_file
->sections
.line
.s
.section
= sectp
;
13053 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13055 else if (names
->loc_dwo
.matches (sectp
->name
))
13057 dwp_file
->sections
.loc
.s
.section
= sectp
;
13058 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
13060 else if (names
->macinfo_dwo
.matches (sectp
->name
))
13062 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13063 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
13065 else if (names
->macro_dwo
.matches (sectp
->name
))
13067 dwp_file
->sections
.macro
.s
.section
= sectp
;
13068 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13070 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
13072 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13073 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13075 else if (names
->types_dwo
.matches (sectp
->name
))
13077 dwp_file
->sections
.types
.s
.section
= sectp
;
13078 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13082 /* This function is mapped across the sections and remembers the offset and
13083 size of each of the DWP version 5 debugging sections that we are interested
13084 in. This is split into a separate function because we don't know if we
13085 have version 1 or 2 or 5 until we parse the cu_index/tu_index sections. */
13088 dwarf2_locate_v5_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13090 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13091 const struct dwop_section_names
*names
= &dwop_section_names
;
13092 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13094 /* Record the ELF section number for later lookup: this is what the
13095 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13096 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13097 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13099 /* Look for specific sections that we need. */
13100 if (names
->abbrev_dwo
.matches (sectp
->name
))
13102 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13103 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13105 else if (names
->info_dwo
.matches (sectp
->name
))
13107 dwp_file
->sections
.info
.s
.section
= sectp
;
13108 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13110 else if (names
->line_dwo
.matches (sectp
->name
))
13112 dwp_file
->sections
.line
.s
.section
= sectp
;
13113 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13115 else if (names
->loclists_dwo
.matches (sectp
->name
))
13117 dwp_file
->sections
.loclists
.s
.section
= sectp
;
13118 dwp_file
->sections
.loclists
.size
= bfd_section_size (sectp
);
13120 else if (names
->macro_dwo
.matches (sectp
->name
))
13122 dwp_file
->sections
.macro
.s
.section
= sectp
;
13123 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13125 else if (names
->rnglists_dwo
.matches (sectp
->name
))
13127 dwp_file
->sections
.rnglists
.s
.section
= sectp
;
13128 dwp_file
->sections
.rnglists
.size
= bfd_section_size (sectp
);
13130 else if (names
->str_offsets_dwo
.matches (sectp
->name
))
13132 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13133 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13137 /* Hash function for dwp_file loaded CUs/TUs. */
13140 hash_dwp_loaded_cutus (const void *item
)
13142 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13144 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13145 return dwo_unit
->signature
;
13148 /* Equality function for dwp_file loaded CUs/TUs. */
13151 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13153 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13154 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13156 return dua
->signature
== dub
->signature
;
13159 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13162 allocate_dwp_loaded_cutus_table ()
13164 return htab_up (htab_create_alloc (3,
13165 hash_dwp_loaded_cutus
,
13166 eq_dwp_loaded_cutus
,
13167 NULL
, xcalloc
, xfree
));
13170 /* Try to open DWP file FILE_NAME.
13171 The result is the bfd handle of the file.
13172 If there is a problem finding or opening the file, return NULL.
13173 Upon success, the canonicalized path of the file is stored in the bfd,
13174 same as symfile_bfd_open. */
13176 static gdb_bfd_ref_ptr
13177 open_dwp_file (dwarf2_per_objfile
*per_objfile
, const char *file_name
)
13179 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (per_objfile
, file_name
,
13181 1 /*search_cwd*/));
13185 /* Work around upstream bug 15652.
13186 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13187 [Whether that's a "bug" is debatable, but it is getting in our way.]
13188 We have no real idea where the dwp file is, because gdb's realpath-ing
13189 of the executable's path may have discarded the needed info.
13190 [IWBN if the dwp file name was recorded in the executable, akin to
13191 .gnu_debuglink, but that doesn't exist yet.]
13192 Strip the directory from FILE_NAME and search again. */
13193 if (*debug_file_directory
!= '\0')
13195 /* Don't implicitly search the current directory here.
13196 If the user wants to search "." to handle this case,
13197 it must be added to debug-file-directory. */
13198 return try_open_dwop_file (per_objfile
, lbasename (file_name
),
13206 /* Initialize the use of the DWP file for the current objfile.
13207 By convention the name of the DWP file is ${objfile}.dwp.
13208 The result is NULL if it can't be found. */
13210 static std::unique_ptr
<struct dwp_file
>
13211 open_and_init_dwp_file (dwarf2_per_objfile
*per_objfile
)
13213 struct objfile
*objfile
= per_objfile
->objfile
;
13215 /* Try to find first .dwp for the binary file before any symbolic links
13218 /* If the objfile is a debug file, find the name of the real binary
13219 file and get the name of dwp file from there. */
13220 std::string dwp_name
;
13221 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13223 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13224 const char *backlink_basename
= lbasename (backlink
->original_name
);
13226 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13229 dwp_name
= objfile
->original_name
;
13231 dwp_name
+= ".dwp";
13233 gdb_bfd_ref_ptr
dbfd (open_dwp_file (per_objfile
, dwp_name
.c_str ()));
13235 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13237 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13238 dwp_name
= objfile_name (objfile
);
13239 dwp_name
+= ".dwp";
13240 dbfd
= open_dwp_file (per_objfile
, dwp_name
.c_str ());
13245 dwarf_read_debug_printf ("DWP file not found: %s", dwp_name
.c_str ());
13247 return std::unique_ptr
<dwp_file
> ();
13250 const char *name
= bfd_get_filename (dbfd
.get ());
13251 std::unique_ptr
<struct dwp_file
> dwp_file
13252 (new struct dwp_file (name
, std::move (dbfd
)));
13254 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13255 dwp_file
->elf_sections
=
13256 OBSTACK_CALLOC (&per_objfile
->per_bfd
->obstack
,
13257 dwp_file
->num_sections
, asection
*);
13259 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13260 dwarf2_locate_common_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13263 dwp_file
->cus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 0);
13265 dwp_file
->tus
= create_dwp_hash_table (per_objfile
, dwp_file
.get (), 1);
13267 /* The DWP file version is stored in the hash table. Oh well. */
13268 if (dwp_file
->cus
&& dwp_file
->tus
13269 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13271 /* Technically speaking, we should try to limp along, but this is
13272 pretty bizarre. We use pulongest here because that's the established
13273 portability solution (e.g, we cannot use %u for uint32_t). */
13274 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13275 " TU version %s [in DWP file %s]"),
13276 pulongest (dwp_file
->cus
->version
),
13277 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13281 dwp_file
->version
= dwp_file
->cus
->version
;
13282 else if (dwp_file
->tus
)
13283 dwp_file
->version
= dwp_file
->tus
->version
;
13285 dwp_file
->version
= 2;
13287 for (asection
*sec
: gdb_bfd_sections (dwp_file
->dbfd
))
13289 if (dwp_file
->version
== 2)
13290 dwarf2_locate_v2_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13293 dwarf2_locate_v5_dwp_sections (dwp_file
->dbfd
.get (), sec
,
13297 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
13298 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
13300 dwarf_read_debug_printf ("DWP file found: %s", dwp_file
->name
);
13301 dwarf_read_debug_printf (" %s CUs, %s TUs",
13302 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13303 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13308 /* Wrapper around open_and_init_dwp_file, only open it once. */
13310 static struct dwp_file
*
13311 get_dwp_file (dwarf2_per_objfile
*per_objfile
)
13313 if (!per_objfile
->per_bfd
->dwp_checked
)
13315 per_objfile
->per_bfd
->dwp_file
= open_and_init_dwp_file (per_objfile
);
13316 per_objfile
->per_bfd
->dwp_checked
= 1;
13318 return per_objfile
->per_bfd
->dwp_file
.get ();
13321 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13322 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13323 or in the DWP file for the objfile, referenced by THIS_UNIT.
13324 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13325 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13327 This is called, for example, when wanting to read a variable with a
13328 complex location. Therefore we don't want to do file i/o for every call.
13329 Therefore we don't want to look for a DWO file on every call.
13330 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13331 then we check if we've already seen DWO_NAME, and only THEN do we check
13334 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13335 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13337 static struct dwo_unit
*
13338 lookup_dwo_cutu (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13339 ULONGEST signature
, int is_debug_types
)
13341 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13342 struct objfile
*objfile
= per_objfile
->objfile
;
13343 const char *kind
= is_debug_types
? "TU" : "CU";
13344 void **dwo_file_slot
;
13345 struct dwo_file
*dwo_file
;
13346 struct dwp_file
*dwp_file
;
13348 /* First see if there's a DWP file.
13349 If we have a DWP file but didn't find the DWO inside it, don't
13350 look for the original DWO file. It makes gdb behave differently
13351 depending on whether one is debugging in the build tree. */
13353 dwp_file
= get_dwp_file (per_objfile
);
13354 if (dwp_file
!= NULL
)
13356 const struct dwp_hash_table
*dwp_htab
=
13357 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13359 if (dwp_htab
!= NULL
)
13361 struct dwo_unit
*dwo_cutu
=
13362 lookup_dwo_unit_in_dwp (per_objfile
, dwp_file
, comp_dir
, signature
,
13365 if (dwo_cutu
!= NULL
)
13367 dwarf_read_debug_printf ("Virtual DWO %s %s found: @%s",
13368 kind
, hex_string (signature
),
13369 host_address_to_string (dwo_cutu
));
13377 /* No DWP file, look for the DWO file. */
13379 dwo_file_slot
= lookup_dwo_file_slot (per_objfile
, dwo_name
, comp_dir
);
13380 if (*dwo_file_slot
== NULL
)
13382 /* Read in the file and build a table of the CUs/TUs it contains. */
13383 *dwo_file_slot
= open_and_init_dwo_file (cu
, dwo_name
, comp_dir
);
13385 /* NOTE: This will be NULL if unable to open the file. */
13386 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13388 if (dwo_file
!= NULL
)
13390 struct dwo_unit
*dwo_cutu
= NULL
;
13392 if (is_debug_types
&& dwo_file
->tus
)
13394 struct dwo_unit find_dwo_cutu
;
13396 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13397 find_dwo_cutu
.signature
= signature
;
13399 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
13402 else if (!is_debug_types
&& dwo_file
->cus
)
13404 struct dwo_unit find_dwo_cutu
;
13406 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13407 find_dwo_cutu
.signature
= signature
;
13408 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
13412 if (dwo_cutu
!= NULL
)
13414 dwarf_read_debug_printf ("DWO %s %s(%s) found: @%s",
13415 kind
, dwo_name
, hex_string (signature
),
13416 host_address_to_string (dwo_cutu
));
13423 /* We didn't find it. This could mean a dwo_id mismatch, or
13424 someone deleted the DWO/DWP file, or the search path isn't set up
13425 correctly to find the file. */
13427 dwarf_read_debug_printf ("DWO %s %s(%s) not found",
13428 kind
, dwo_name
, hex_string (signature
));
13430 /* This is a warning and not a complaint because it can be caused by
13431 pilot error (e.g., user accidentally deleting the DWO). */
13433 /* Print the name of the DWP file if we looked there, helps the user
13434 better diagnose the problem. */
13435 std::string dwp_text
;
13437 if (dwp_file
!= NULL
)
13438 dwp_text
= string_printf (" [in DWP file %s]",
13439 lbasename (dwp_file
->name
));
13441 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13442 " [in module %s]"),
13443 kind
, dwo_name
, hex_string (signature
), dwp_text
.c_str (), kind
,
13444 sect_offset_str (cu
->per_cu
->sect_off
), objfile_name (objfile
));
13449 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13450 See lookup_dwo_cutu_unit for details. */
13452 static struct dwo_unit
*
13453 lookup_dwo_comp_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
,
13454 ULONGEST signature
)
13456 gdb_assert (!cu
->per_cu
->is_debug_types
);
13458 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, signature
, 0);
13461 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13462 See lookup_dwo_cutu_unit for details. */
13464 static struct dwo_unit
*
13465 lookup_dwo_type_unit (dwarf2_cu
*cu
, const char *dwo_name
, const char *comp_dir
)
13467 gdb_assert (cu
->per_cu
->is_debug_types
);
13469 signatured_type
*sig_type
= (signatured_type
*) cu
->per_cu
;
13471 return lookup_dwo_cutu (cu
, dwo_name
, comp_dir
, sig_type
->signature
, 1);
13474 /* Traversal function for queue_and_load_all_dwo_tus. */
13477 queue_and_load_dwo_tu (void **slot
, void *info
)
13479 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13480 dwarf2_cu
*cu
= (dwarf2_cu
*) info
;
13481 ULONGEST signature
= dwo_unit
->signature
;
13482 signatured_type
*sig_type
= lookup_dwo_signatured_type (cu
, signature
);
13484 if (sig_type
!= NULL
)
13486 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13488 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13489 a real dependency of PER_CU on SIG_TYPE. That is detected later
13490 while processing PER_CU. */
13491 if (maybe_queue_comp_unit (NULL
, sig_cu
, cu
->per_objfile
, cu
->language
))
13492 load_full_type_unit (sig_cu
, cu
->per_objfile
);
13493 cu
->per_cu
->imported_symtabs_push (sig_cu
);
13499 /* Queue all TUs contained in the DWO of CU to be read in.
13500 The DWO may have the only definition of the type, though it may not be
13501 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13502 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13505 queue_and_load_all_dwo_tus (dwarf2_cu
*cu
)
13507 struct dwo_unit
*dwo_unit
;
13508 struct dwo_file
*dwo_file
;
13510 gdb_assert (cu
!= nullptr);
13511 gdb_assert (!cu
->per_cu
->is_debug_types
);
13512 gdb_assert (get_dwp_file (cu
->per_objfile
) == nullptr);
13514 dwo_unit
= cu
->dwo_unit
;
13515 gdb_assert (dwo_unit
!= NULL
);
13517 dwo_file
= dwo_unit
->dwo_file
;
13518 if (dwo_file
->tus
!= NULL
)
13519 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
, cu
);
13522 /* Read in various DIEs. */
13524 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13525 Inherit only the children of the DW_AT_abstract_origin DIE not being
13526 already referenced by DW_AT_abstract_origin from the children of the
13530 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13532 struct die_info
*child_die
;
13533 sect_offset
*offsetp
;
13534 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13535 struct die_info
*origin_die
;
13536 /* Iterator of the ORIGIN_DIE children. */
13537 struct die_info
*origin_child_die
;
13538 struct attribute
*attr
;
13539 struct dwarf2_cu
*origin_cu
;
13540 struct pending
**origin_previous_list_in_scope
;
13542 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13546 /* Note that following die references may follow to a die in a
13550 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13552 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13554 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13555 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13557 if (die
->tag
!= origin_die
->tag
13558 && !(die
->tag
== DW_TAG_inlined_subroutine
13559 && origin_die
->tag
== DW_TAG_subprogram
))
13560 complaint (_("DIE %s and its abstract origin %s have different tags"),
13561 sect_offset_str (die
->sect_off
),
13562 sect_offset_str (origin_die
->sect_off
));
13564 std::vector
<sect_offset
> offsets
;
13566 for (child_die
= die
->child
;
13567 child_die
&& child_die
->tag
;
13568 child_die
= child_die
->sibling
)
13570 struct die_info
*child_origin_die
;
13571 struct dwarf2_cu
*child_origin_cu
;
13573 /* We are trying to process concrete instance entries:
13574 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13575 it's not relevant to our analysis here. i.e. detecting DIEs that are
13576 present in the abstract instance but not referenced in the concrete
13578 if (child_die
->tag
== DW_TAG_call_site
13579 || child_die
->tag
== DW_TAG_GNU_call_site
)
13582 /* For each CHILD_DIE, find the corresponding child of
13583 ORIGIN_DIE. If there is more than one layer of
13584 DW_AT_abstract_origin, follow them all; there shouldn't be,
13585 but GCC versions at least through 4.4 generate this (GCC PR
13587 child_origin_die
= child_die
;
13588 child_origin_cu
= cu
;
13591 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13595 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13599 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13600 counterpart may exist. */
13601 if (child_origin_die
!= child_die
)
13603 if (child_die
->tag
!= child_origin_die
->tag
13604 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13605 && child_origin_die
->tag
== DW_TAG_subprogram
))
13606 complaint (_("Child DIE %s and its abstract origin %s have "
13608 sect_offset_str (child_die
->sect_off
),
13609 sect_offset_str (child_origin_die
->sect_off
));
13610 if (child_origin_die
->parent
!= origin_die
)
13611 complaint (_("Child DIE %s and its abstract origin %s have "
13612 "different parents"),
13613 sect_offset_str (child_die
->sect_off
),
13614 sect_offset_str (child_origin_die
->sect_off
));
13616 offsets
.push_back (child_origin_die
->sect_off
);
13619 std::sort (offsets
.begin (), offsets
.end ());
13620 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13621 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13622 if (offsetp
[-1] == *offsetp
)
13623 complaint (_("Multiple children of DIE %s refer "
13624 "to DIE %s as their abstract origin"),
13625 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13627 offsetp
= offsets
.data ();
13628 origin_child_die
= origin_die
->child
;
13629 while (origin_child_die
&& origin_child_die
->tag
)
13631 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13632 while (offsetp
< offsets_end
13633 && *offsetp
< origin_child_die
->sect_off
)
13635 if (offsetp
>= offsets_end
13636 || *offsetp
> origin_child_die
->sect_off
)
13638 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13639 Check whether we're already processing ORIGIN_CHILD_DIE.
13640 This can happen with mutually referenced abstract_origins.
13642 if (!origin_child_die
->in_process
)
13643 process_die (origin_child_die
, origin_cu
);
13645 origin_child_die
= origin_child_die
->sibling
;
13647 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13649 if (cu
!= origin_cu
)
13650 compute_delayed_physnames (origin_cu
);
13654 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13656 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13657 struct gdbarch
*gdbarch
= objfile
->arch ();
13658 struct context_stack
*newobj
;
13661 struct die_info
*child_die
;
13662 struct attribute
*attr
, *call_line
, *call_file
;
13664 CORE_ADDR baseaddr
;
13665 struct block
*block
;
13666 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13667 std::vector
<struct symbol
*> template_args
;
13668 struct template_symbol
*templ_func
= NULL
;
13672 /* If we do not have call site information, we can't show the
13673 caller of this inlined function. That's too confusing, so
13674 only use the scope for local variables. */
13675 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13676 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13677 if (call_line
== NULL
|| call_file
== NULL
)
13679 read_lexical_block_scope (die
, cu
);
13684 baseaddr
= objfile
->text_section_offset ();
13686 name
= dwarf2_name (die
, cu
);
13688 /* Ignore functions with missing or empty names. These are actually
13689 illegal according to the DWARF standard. */
13692 complaint (_("missing name for subprogram DIE at %s"),
13693 sect_offset_str (die
->sect_off
));
13697 /* Ignore functions with missing or invalid low and high pc attributes. */
13698 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13699 <= PC_BOUNDS_INVALID
)
13701 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13702 if (attr
== nullptr || !attr
->as_boolean ())
13703 complaint (_("cannot get low and high bounds "
13704 "for subprogram DIE at %s"),
13705 sect_offset_str (die
->sect_off
));
13709 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13710 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13712 /* If we have any template arguments, then we must allocate a
13713 different sort of symbol. */
13714 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
13716 if (child_die
->tag
== DW_TAG_template_type_param
13717 || child_die
->tag
== DW_TAG_template_value_param
)
13719 templ_func
= new (&objfile
->objfile_obstack
) template_symbol
;
13720 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13725 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13726 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13727 (struct symbol
*) templ_func
);
13729 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13730 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13733 /* If there is a location expression for DW_AT_frame_base, record
13735 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13736 if (attr
!= nullptr)
13737 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13739 /* If there is a location for the static link, record it. */
13740 newobj
->static_link
= NULL
;
13741 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13742 if (attr
!= nullptr)
13744 newobj
->static_link
13745 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13746 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13750 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13752 if (die
->child
!= NULL
)
13754 child_die
= die
->child
;
13755 while (child_die
&& child_die
->tag
)
13757 if (child_die
->tag
== DW_TAG_template_type_param
13758 || child_die
->tag
== DW_TAG_template_value_param
)
13760 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13763 template_args
.push_back (arg
);
13766 process_die (child_die
, cu
);
13767 child_die
= child_die
->sibling
;
13771 inherit_abstract_dies (die
, cu
);
13773 /* If we have a DW_AT_specification, we might need to import using
13774 directives from the context of the specification DIE. See the
13775 comment in determine_prefix. */
13776 if (cu
->language
== language_cplus
13777 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13779 struct dwarf2_cu
*spec_cu
= cu
;
13780 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13784 child_die
= spec_die
->child
;
13785 while (child_die
&& child_die
->tag
)
13787 if (child_die
->tag
== DW_TAG_imported_module
)
13788 process_die (child_die
, spec_cu
);
13789 child_die
= child_die
->sibling
;
13792 /* In some cases, GCC generates specification DIEs that
13793 themselves contain DW_AT_specification attributes. */
13794 spec_die
= die_specification (spec_die
, &spec_cu
);
13798 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13799 /* Make a block for the local symbols within. */
13800 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13801 cstk
.static_link
, lowpc
, highpc
);
13803 /* For C++, set the block's scope. */
13804 if ((cu
->language
== language_cplus
13805 || cu
->language
== language_fortran
13806 || cu
->language
== language_d
13807 || cu
->language
== language_rust
)
13808 && cu
->processing_has_namespace_info
)
13809 block_set_scope (block
, determine_prefix (die
, cu
),
13810 &objfile
->objfile_obstack
);
13812 /* If we have address ranges, record them. */
13813 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13815 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13817 /* Attach template arguments to function. */
13818 if (!template_args
.empty ())
13820 gdb_assert (templ_func
!= NULL
);
13822 templ_func
->n_template_arguments
= template_args
.size ();
13823 templ_func
->template_arguments
13824 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13825 templ_func
->n_template_arguments
);
13826 memcpy (templ_func
->template_arguments
,
13827 template_args
.data (),
13828 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13830 /* Make sure that the symtab is set on the new symbols. Even
13831 though they don't appear in this symtab directly, other parts
13832 of gdb assume that symbols do, and this is reasonably
13834 for (symbol
*sym
: template_args
)
13835 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13838 /* In C++, we can have functions nested inside functions (e.g., when
13839 a function declares a class that has methods). This means that
13840 when we finish processing a function scope, we may need to go
13841 back to building a containing block's symbol lists. */
13842 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13843 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13845 /* If we've finished processing a top-level function, subsequent
13846 symbols go in the file symbol list. */
13847 if (cu
->get_builder ()->outermost_context_p ())
13848 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13851 /* Process all the DIES contained within a lexical block scope. Start
13852 a new scope, process the dies, and then close the scope. */
13855 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13857 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
13858 struct gdbarch
*gdbarch
= objfile
->arch ();
13859 CORE_ADDR lowpc
, highpc
;
13860 struct die_info
*child_die
;
13861 CORE_ADDR baseaddr
;
13863 baseaddr
= objfile
->text_section_offset ();
13865 /* Ignore blocks with missing or invalid low and high pc attributes. */
13866 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13867 as multiple lexical blocks? Handling children in a sane way would
13868 be nasty. Might be easier to properly extend generic blocks to
13869 describe ranges. */
13870 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13872 case PC_BOUNDS_NOT_PRESENT
:
13873 /* DW_TAG_lexical_block has no attributes, process its children as if
13874 there was no wrapping by that DW_TAG_lexical_block.
13875 GCC does no longer produces such DWARF since GCC r224161. */
13876 for (child_die
= die
->child
;
13877 child_die
!= NULL
&& child_die
->tag
;
13878 child_die
= child_die
->sibling
)
13880 /* We might already be processing this DIE. This can happen
13881 in an unusual circumstance -- where a subroutine A
13882 appears lexically in another subroutine B, but A actually
13883 inlines B. The recursion is broken here, rather than in
13884 inherit_abstract_dies, because it seems better to simply
13885 drop concrete children here. */
13886 if (!child_die
->in_process
)
13887 process_die (child_die
, cu
);
13890 case PC_BOUNDS_INVALID
:
13893 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13894 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13896 cu
->get_builder ()->push_context (0, lowpc
);
13897 if (die
->child
!= NULL
)
13899 child_die
= die
->child
;
13900 while (child_die
&& child_die
->tag
)
13902 process_die (child_die
, cu
);
13903 child_die
= child_die
->sibling
;
13906 inherit_abstract_dies (die
, cu
);
13907 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13909 if (*cu
->get_builder ()->get_local_symbols () != NULL
13910 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13912 struct block
*block
13913 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13914 cstk
.start_addr
, highpc
);
13916 /* Note that recording ranges after traversing children, as we
13917 do here, means that recording a parent's ranges entails
13918 walking across all its children's ranges as they appear in
13919 the address map, which is quadratic behavior.
13921 It would be nicer to record the parent's ranges before
13922 traversing its children, simply overriding whatever you find
13923 there. But since we don't even decide whether to create a
13924 block until after we've traversed its children, that's hard
13926 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13928 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13929 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13932 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13935 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13937 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
13938 struct objfile
*objfile
= per_objfile
->objfile
;
13939 struct gdbarch
*gdbarch
= objfile
->arch ();
13940 CORE_ADDR pc
, baseaddr
;
13941 struct attribute
*attr
;
13942 struct call_site
*call_site
, call_site_local
;
13945 struct die_info
*child_die
;
13947 baseaddr
= objfile
->text_section_offset ();
13949 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13952 /* This was a pre-DWARF-5 GNU extension alias
13953 for DW_AT_call_return_pc. */
13954 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13958 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13959 "DIE %s [in module %s]"),
13960 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13963 pc
= attr
->as_address () + baseaddr
;
13964 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13966 if (cu
->call_site_htab
== NULL
)
13967 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13968 NULL
, &objfile
->objfile_obstack
,
13969 hashtab_obstack_allocate
, NULL
);
13970 call_site_local
.pc
= pc
;
13971 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13974 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13975 "DIE %s [in module %s]"),
13976 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13977 objfile_name (objfile
));
13981 /* Count parameters at the caller. */
13984 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13985 child_die
= child_die
->sibling
)
13987 if (child_die
->tag
!= DW_TAG_call_site_parameter
13988 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13990 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13991 "DW_TAG_call_site child DIE %s [in module %s]"),
13992 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13993 objfile_name (objfile
));
14001 = ((struct call_site
*)
14002 obstack_alloc (&objfile
->objfile_obstack
,
14003 sizeof (*call_site
)
14004 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14006 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14007 call_site
->pc
= pc
;
14009 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14010 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14012 struct die_info
*func_die
;
14014 /* Skip also over DW_TAG_inlined_subroutine. */
14015 for (func_die
= die
->parent
;
14016 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14017 && func_die
->tag
!= DW_TAG_subroutine_type
;
14018 func_die
= func_die
->parent
);
14020 /* DW_AT_call_all_calls is a superset
14021 of DW_AT_call_all_tail_calls. */
14023 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14024 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14025 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14026 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14028 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14029 not complete. But keep CALL_SITE for look ups via call_site_htab,
14030 both the initial caller containing the real return address PC and
14031 the final callee containing the current PC of a chain of tail
14032 calls do not need to have the tail call list complete. But any
14033 function candidate for a virtual tail call frame searched via
14034 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14035 determined unambiguously. */
14039 struct type
*func_type
= NULL
;
14042 func_type
= get_die_type (func_die
, cu
);
14043 if (func_type
!= NULL
)
14045 gdb_assert (func_type
->code () == TYPE_CODE_FUNC
);
14047 /* Enlist this call site to the function. */
14048 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14049 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14052 complaint (_("Cannot find function owning DW_TAG_call_site "
14053 "DIE %s [in module %s]"),
14054 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14058 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14060 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14062 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14065 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14066 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14068 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14069 if (!attr
|| (attr
->form_is_block () && attr
->as_block ()->size
== 0))
14070 /* Keep NULL DWARF_BLOCK. */;
14071 else if (attr
->form_is_block ())
14073 struct dwarf2_locexpr_baton
*dlbaton
;
14074 struct dwarf_block
*block
= attr
->as_block ();
14076 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14077 dlbaton
->data
= block
->data
;
14078 dlbaton
->size
= block
->size
;
14079 dlbaton
->per_objfile
= per_objfile
;
14080 dlbaton
->per_cu
= cu
->per_cu
;
14082 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14084 else if (attr
->form_is_ref ())
14086 struct dwarf2_cu
*target_cu
= cu
;
14087 struct die_info
*target_die
;
14089 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14090 gdb_assert (target_cu
->per_objfile
->objfile
== objfile
);
14091 if (die_is_declaration (target_die
, target_cu
))
14093 const char *target_physname
;
14095 /* Prefer the mangled name; otherwise compute the demangled one. */
14096 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14097 if (target_physname
== NULL
)
14098 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14099 if (target_physname
== NULL
)
14100 complaint (_("DW_AT_call_target target DIE has invalid "
14101 "physname, for referencing DIE %s [in module %s]"),
14102 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14104 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14110 /* DW_AT_entry_pc should be preferred. */
14111 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14112 <= PC_BOUNDS_INVALID
)
14113 complaint (_("DW_AT_call_target target DIE has invalid "
14114 "low pc, for referencing DIE %s [in module %s]"),
14115 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14118 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14119 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14124 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14125 "block nor reference, for DIE %s [in module %s]"),
14126 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14128 call_site
->per_cu
= cu
->per_cu
;
14129 call_site
->per_objfile
= per_objfile
;
14131 for (child_die
= die
->child
;
14132 child_die
&& child_die
->tag
;
14133 child_die
= child_die
->sibling
)
14135 struct call_site_parameter
*parameter
;
14136 struct attribute
*loc
, *origin
;
14138 if (child_die
->tag
!= DW_TAG_call_site_parameter
14139 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14141 /* Already printed the complaint above. */
14145 gdb_assert (call_site
->parameter_count
< nparams
);
14146 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14148 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14149 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14150 register is contained in DW_AT_call_value. */
14152 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14153 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14154 if (origin
== NULL
)
14156 /* This was a pre-DWARF-5 GNU extension alias
14157 for DW_AT_call_parameter. */
14158 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14160 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
14162 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14164 sect_offset sect_off
= origin
->get_ref_die_offset ();
14165 if (!cu
->header
.offset_in_cu_p (sect_off
))
14167 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14168 binding can be done only inside one CU. Such referenced DIE
14169 therefore cannot be even moved to DW_TAG_partial_unit. */
14170 complaint (_("DW_AT_call_parameter offset is not in CU for "
14171 "DW_TAG_call_site child DIE %s [in module %s]"),
14172 sect_offset_str (child_die
->sect_off
),
14173 objfile_name (objfile
));
14176 parameter
->u
.param_cu_off
14177 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14179 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
14181 complaint (_("No DW_FORM_block* DW_AT_location for "
14182 "DW_TAG_call_site child DIE %s [in module %s]"),
14183 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14188 struct dwarf_block
*block
= loc
->as_block ();
14190 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14191 (block
->data
, &block
->data
[block
->size
]);
14192 if (parameter
->u
.dwarf_reg
!= -1)
14193 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14194 else if (dwarf_block_to_sp_offset (gdbarch
, block
->data
,
14195 &block
->data
[block
->size
],
14196 ¶meter
->u
.fb_offset
))
14197 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14200 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14201 "for DW_FORM_block* DW_AT_location is supported for "
14202 "DW_TAG_call_site child DIE %s "
14204 sect_offset_str (child_die
->sect_off
),
14205 objfile_name (objfile
));
14210 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14212 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14213 if (attr
== NULL
|| !attr
->form_is_block ())
14215 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14216 "DW_TAG_call_site child DIE %s [in module %s]"),
14217 sect_offset_str (child_die
->sect_off
),
14218 objfile_name (objfile
));
14222 struct dwarf_block
*block
= attr
->as_block ();
14223 parameter
->value
= block
->data
;
14224 parameter
->value_size
= block
->size
;
14226 /* Parameters are not pre-cleared by memset above. */
14227 parameter
->data_value
= NULL
;
14228 parameter
->data_value_size
= 0;
14229 call_site
->parameter_count
++;
14231 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14233 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14234 if (attr
!= nullptr)
14236 if (!attr
->form_is_block ())
14237 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14238 "DW_TAG_call_site child DIE %s [in module %s]"),
14239 sect_offset_str (child_die
->sect_off
),
14240 objfile_name (objfile
));
14243 block
= attr
->as_block ();
14244 parameter
->data_value
= block
->data
;
14245 parameter
->data_value_size
= block
->size
;
14251 /* Helper function for read_variable. If DIE represents a virtual
14252 table, then return the type of the concrete object that is
14253 associated with the virtual table. Otherwise, return NULL. */
14255 static struct type
*
14256 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14258 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14262 /* Find the type DIE. */
14263 struct die_info
*type_die
= NULL
;
14264 struct dwarf2_cu
*type_cu
= cu
;
14266 if (attr
->form_is_ref ())
14267 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14268 if (type_die
== NULL
)
14271 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14273 return die_containing_type (type_die
, type_cu
);
14276 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14279 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14281 struct rust_vtable_symbol
*storage
= NULL
;
14283 if (cu
->language
== language_rust
)
14285 struct type
*containing_type
= rust_containing_type (die
, cu
);
14287 if (containing_type
!= NULL
)
14289 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14291 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol
;
14292 storage
->concrete_type
= containing_type
;
14293 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14297 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14298 struct attribute
*abstract_origin
14299 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14300 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14301 if (res
== NULL
&& loc
&& abstract_origin
)
14303 /* We have a variable without a name, but with a location and an abstract
14304 origin. This may be a concrete instance of an abstract variable
14305 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14307 struct dwarf2_cu
*origin_cu
= cu
;
14308 struct die_info
*origin_die
14309 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14310 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14311 per_objfile
->per_bfd
->abstract_to_concrete
14312 [origin_die
->sect_off
].push_back (die
->sect_off
);
14316 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14317 reading .debug_rnglists.
14318 Callback's type should be:
14319 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14320 Return true if the attributes are present and valid, otherwise,
14323 template <typename Callback
>
14325 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14326 dwarf_tag tag
, Callback
&&callback
)
14328 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14329 struct objfile
*objfile
= per_objfile
->objfile
;
14330 bfd
*obfd
= objfile
->obfd
;
14331 /* Base address selection entry. */
14332 gdb::optional
<CORE_ADDR
> base
;
14333 const gdb_byte
*buffer
;
14334 CORE_ADDR baseaddr
;
14335 bool overflow
= false;
14336 ULONGEST addr_index
;
14337 struct dwarf2_section_info
*rnglists_section
;
14339 base
= cu
->base_address
;
14340 rnglists_section
= cu_debug_rnglists_section (cu
, tag
);
14341 rnglists_section
->read (objfile
);
14343 if (offset
>= rnglists_section
->size
)
14345 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14349 buffer
= rnglists_section
->buffer
+ offset
;
14351 baseaddr
= objfile
->text_section_offset ();
14355 /* Initialize it due to a false compiler warning. */
14356 CORE_ADDR range_beginning
= 0, range_end
= 0;
14357 const gdb_byte
*buf_end
= (rnglists_section
->buffer
14358 + rnglists_section
->size
);
14359 unsigned int bytes_read
;
14361 if (buffer
== buf_end
)
14366 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14369 case DW_RLE_end_of_list
:
14371 case DW_RLE_base_address
:
14372 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14377 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14378 buffer
+= bytes_read
;
14380 case DW_RLE_base_addressx
:
14381 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14382 buffer
+= bytes_read
;
14383 base
= read_addr_index (cu
, addr_index
);
14385 case DW_RLE_start_length
:
14386 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14391 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14393 buffer
+= bytes_read
;
14394 range_end
= (range_beginning
14395 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14396 buffer
+= bytes_read
;
14397 if (buffer
> buf_end
)
14403 case DW_RLE_startx_length
:
14404 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14405 buffer
+= bytes_read
;
14406 range_beginning
= read_addr_index (cu
, addr_index
);
14407 if (buffer
> buf_end
)
14412 range_end
= (range_beginning
14413 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14414 buffer
+= bytes_read
;
14416 case DW_RLE_offset_pair
:
14417 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14418 buffer
+= bytes_read
;
14419 if (buffer
> buf_end
)
14424 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14425 buffer
+= bytes_read
;
14426 if (buffer
> buf_end
)
14432 case DW_RLE_start_end
:
14433 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14438 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
14440 buffer
+= bytes_read
;
14441 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
14442 buffer
+= bytes_read
;
14444 case DW_RLE_startx_endx
:
14445 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14446 buffer
+= bytes_read
;
14447 range_beginning
= read_addr_index (cu
, addr_index
);
14448 if (buffer
> buf_end
)
14453 addr_index
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14454 buffer
+= bytes_read
;
14455 range_end
= read_addr_index (cu
, addr_index
);
14458 complaint (_("Invalid .debug_rnglists data (no base address)"));
14461 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14463 if (rlet
== DW_RLE_base_address
)
14466 if (range_beginning
> range_end
)
14468 /* Inverted range entries are invalid. */
14469 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14473 /* Empty range entries have no effect. */
14474 if (range_beginning
== range_end
)
14477 /* Only DW_RLE_offset_pair needs the base address added. */
14478 if (rlet
== DW_RLE_offset_pair
)
14480 if (!base
.has_value ())
14482 /* We have no valid base address for the DW_RLE_offset_pair. */
14483 complaint (_("Invalid .debug_rnglists data (no base address for "
14484 "DW_RLE_offset_pair)"));
14488 range_beginning
+= *base
;
14489 range_end
+= *base
;
14492 /* A not-uncommon case of bad debug info.
14493 Don't pollute the addrmap with bad data. */
14494 if (range_beginning
+ baseaddr
== 0
14495 && !per_objfile
->per_bfd
->has_section_at_zero
)
14497 complaint (_(".debug_rnglists entry has start address of zero"
14498 " [in module %s]"), objfile_name (objfile
));
14502 callback (range_beginning
, range_end
);
14507 complaint (_("Offset %d is not terminated "
14508 "for DW_AT_ranges attribute"),
14516 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14517 Callback's type should be:
14518 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14519 Return 1 if the attributes are present and valid, otherwise, return 0. */
14521 template <typename Callback
>
14523 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
, dwarf_tag tag
,
14524 Callback
&&callback
)
14526 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14527 struct objfile
*objfile
= per_objfile
->objfile
;
14528 struct comp_unit_head
*cu_header
= &cu
->header
;
14529 bfd
*obfd
= objfile
->obfd
;
14530 unsigned int addr_size
= cu_header
->addr_size
;
14531 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14532 /* Base address selection entry. */
14533 gdb::optional
<CORE_ADDR
> base
;
14534 unsigned int dummy
;
14535 const gdb_byte
*buffer
;
14536 CORE_ADDR baseaddr
;
14538 if (cu_header
->version
>= 5)
14539 return dwarf2_rnglists_process (offset
, cu
, tag
, callback
);
14541 base
= cu
->base_address
;
14543 per_objfile
->per_bfd
->ranges
.read (objfile
);
14544 if (offset
>= per_objfile
->per_bfd
->ranges
.size
)
14546 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14550 buffer
= per_objfile
->per_bfd
->ranges
.buffer
+ offset
;
14552 baseaddr
= objfile
->text_section_offset ();
14556 CORE_ADDR range_beginning
, range_end
;
14558 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14559 buffer
+= addr_size
;
14560 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
14561 buffer
+= addr_size
;
14562 offset
+= 2 * addr_size
;
14564 /* An end of list marker is a pair of zero addresses. */
14565 if (range_beginning
== 0 && range_end
== 0)
14566 /* Found the end of list entry. */
14569 /* Each base address selection entry is a pair of 2 values.
14570 The first is the largest possible address, the second is
14571 the base address. Check for a base address here. */
14572 if ((range_beginning
& mask
) == mask
)
14574 /* If we found the largest possible address, then we already
14575 have the base address in range_end. */
14580 if (!base
.has_value ())
14582 /* We have no valid base address for the ranges
14584 complaint (_("Invalid .debug_ranges data (no base address)"));
14588 if (range_beginning
> range_end
)
14590 /* Inverted range entries are invalid. */
14591 complaint (_("Invalid .debug_ranges data (inverted range)"));
14595 /* Empty range entries have no effect. */
14596 if (range_beginning
== range_end
)
14599 range_beginning
+= *base
;
14600 range_end
+= *base
;
14602 /* A not-uncommon case of bad debug info.
14603 Don't pollute the addrmap with bad data. */
14604 if (range_beginning
+ baseaddr
== 0
14605 && !per_objfile
->per_bfd
->has_section_at_zero
)
14607 complaint (_(".debug_ranges entry has start address of zero"
14608 " [in module %s]"), objfile_name (objfile
));
14612 callback (range_beginning
, range_end
);
14618 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14619 Return 1 if the attributes are present and valid, otherwise, return 0.
14620 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14623 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14624 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14625 dwarf2_psymtab
*ranges_pst
, dwarf_tag tag
)
14627 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14628 struct gdbarch
*gdbarch
= objfile
->arch ();
14629 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14632 CORE_ADDR high
= 0;
14635 retval
= dwarf2_ranges_process (offset
, cu
, tag
,
14636 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14638 if (ranges_pst
!= NULL
)
14643 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14644 range_beginning
+ baseaddr
)
14646 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14647 range_end
+ baseaddr
)
14649 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14650 lowpc
, highpc
- 1, ranges_pst
);
14653 /* FIXME: This is recording everything as a low-high
14654 segment of consecutive addresses. We should have a
14655 data structure for discontiguous block ranges
14659 low
= range_beginning
;
14665 if (range_beginning
< low
)
14666 low
= range_beginning
;
14667 if (range_end
> high
)
14675 /* If the first entry is an end-of-list marker, the range
14676 describes an empty scope, i.e. no instructions. */
14682 *high_return
= high
;
14686 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14687 definition for the return value. *LOWPC and *HIGHPC are set iff
14688 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14690 static enum pc_bounds_kind
14691 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14692 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14693 dwarf2_psymtab
*pst
)
14695 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
14696 struct attribute
*attr
;
14697 struct attribute
*attr_high
;
14699 CORE_ADDR high
= 0;
14700 enum pc_bounds_kind ret
;
14702 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14705 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14706 if (attr
!= nullptr)
14708 low
= attr
->as_address ();
14709 high
= attr_high
->as_address ();
14710 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14714 /* Found high w/o low attribute. */
14715 return PC_BOUNDS_INVALID
;
14717 /* Found consecutive range of addresses. */
14718 ret
= PC_BOUNDS_HIGH_LOW
;
14722 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14723 if (attr
!= nullptr && attr
->form_is_unsigned ())
14725 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14726 on DWARF version). */
14727 ULONGEST ranges_offset
= attr
->as_unsigned ();
14729 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14731 if (die
->tag
!= DW_TAG_compile_unit
)
14732 ranges_offset
+= cu
->gnu_ranges_base
;
14734 /* Value of the DW_AT_ranges attribute is the offset in the
14735 .debug_ranges section. */
14736 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
,
14738 return PC_BOUNDS_INVALID
;
14739 /* Found discontinuous range of addresses. */
14740 ret
= PC_BOUNDS_RANGES
;
14743 return PC_BOUNDS_NOT_PRESENT
;
14746 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14748 return PC_BOUNDS_INVALID
;
14750 /* When using the GNU linker, .gnu.linkonce. sections are used to
14751 eliminate duplicate copies of functions and vtables and such.
14752 The linker will arbitrarily choose one and discard the others.
14753 The AT_*_pc values for such functions refer to local labels in
14754 these sections. If the section from that file was discarded, the
14755 labels are not in the output, so the relocs get a value of 0.
14756 If this is a discarded function, mark the pc bounds as invalid,
14757 so that GDB will ignore it. */
14758 if (low
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
14759 return PC_BOUNDS_INVALID
;
14767 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14768 its low and high PC addresses. Do nothing if these addresses could not
14769 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14770 and HIGHPC to the high address if greater than HIGHPC. */
14773 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14774 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14775 struct dwarf2_cu
*cu
)
14777 CORE_ADDR low
, high
;
14778 struct die_info
*child
= die
->child
;
14780 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14782 *lowpc
= std::min (*lowpc
, low
);
14783 *highpc
= std::max (*highpc
, high
);
14786 /* If the language does not allow nested subprograms (either inside
14787 subprograms or lexical blocks), we're done. */
14788 if (cu
->language
!= language_ada
)
14791 /* Check all the children of the given DIE. If it contains nested
14792 subprograms, then check their pc bounds. Likewise, we need to
14793 check lexical blocks as well, as they may also contain subprogram
14795 while (child
&& child
->tag
)
14797 if (child
->tag
== DW_TAG_subprogram
14798 || child
->tag
== DW_TAG_lexical_block
)
14799 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14800 child
= child
->sibling
;
14804 /* Get the low and high pc's represented by the scope DIE, and store
14805 them in *LOWPC and *HIGHPC. If the correct values can't be
14806 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14809 get_scope_pc_bounds (struct die_info
*die
,
14810 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14811 struct dwarf2_cu
*cu
)
14813 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14814 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14815 CORE_ADDR current_low
, current_high
;
14817 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14818 >= PC_BOUNDS_RANGES
)
14820 best_low
= current_low
;
14821 best_high
= current_high
;
14825 struct die_info
*child
= die
->child
;
14827 while (child
&& child
->tag
)
14829 switch (child
->tag
) {
14830 case DW_TAG_subprogram
:
14831 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14833 case DW_TAG_namespace
:
14834 case DW_TAG_module
:
14835 /* FIXME: carlton/2004-01-16: Should we do this for
14836 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14837 that current GCC's always emit the DIEs corresponding
14838 to definitions of methods of classes as children of a
14839 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14840 the DIEs giving the declarations, which could be
14841 anywhere). But I don't see any reason why the
14842 standards says that they have to be there. */
14843 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14845 if (current_low
!= ((CORE_ADDR
) -1))
14847 best_low
= std::min (best_low
, current_low
);
14848 best_high
= std::max (best_high
, current_high
);
14856 child
= child
->sibling
;
14861 *highpc
= best_high
;
14864 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14868 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14869 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14871 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
14872 struct gdbarch
*gdbarch
= objfile
->arch ();
14873 struct attribute
*attr
;
14874 struct attribute
*attr_high
;
14876 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14879 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14880 if (attr
!= nullptr)
14882 CORE_ADDR low
= attr
->as_address ();
14883 CORE_ADDR high
= attr_high
->as_address ();
14885 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
14888 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14889 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14890 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14894 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14895 if (attr
!= nullptr && attr
->form_is_unsigned ())
14897 /* Offset in the .debug_ranges or .debug_rnglist section (depending
14898 on DWARF version). */
14899 ULONGEST ranges_offset
= attr
->as_unsigned ();
14901 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
14903 if (die
->tag
!= DW_TAG_compile_unit
)
14904 ranges_offset
+= cu
->gnu_ranges_base
;
14906 std::vector
<blockrange
> blockvec
;
14907 dwarf2_ranges_process (ranges_offset
, cu
, die
->tag
,
14908 [&] (CORE_ADDR start
, CORE_ADDR end
)
14912 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14913 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14914 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14915 blockvec
.emplace_back (start
, end
);
14918 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14922 /* Check whether the producer field indicates either of GCC < 4.6, or the
14923 Intel C/C++ compiler, and cache the result in CU. */
14926 check_producer (struct dwarf2_cu
*cu
)
14930 if (cu
->producer
== NULL
)
14932 /* For unknown compilers expect their behavior is DWARF version
14935 GCC started to support .debug_types sections by -gdwarf-4 since
14936 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14937 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14938 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14939 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14941 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14943 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14944 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14946 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14948 cu
->producer_is_icc
= true;
14949 cu
->producer_is_icc_lt_14
= major
< 14;
14951 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14952 cu
->producer_is_codewarrior
= true;
14955 /* For other non-GCC compilers, expect their behavior is DWARF version
14959 cu
->checked_producer
= true;
14962 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14963 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14964 during 4.6.0 experimental. */
14967 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14969 if (!cu
->checked_producer
)
14970 check_producer (cu
);
14972 return cu
->producer_is_gxx_lt_4_6
;
14976 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14977 with incorrect is_stmt attributes. */
14980 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14982 if (!cu
->checked_producer
)
14983 check_producer (cu
);
14985 return cu
->producer_is_codewarrior
;
14988 /* Return the accessibility of DIE, as given by DW_AT_accessibility.
14989 If that attribute is not available, return the appropriate
14992 static enum dwarf_access_attribute
14993 dwarf2_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14995 attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14996 if (attr
!= nullptr)
14998 LONGEST value
= attr
->constant_value (-1);
14999 if (value
== DW_ACCESS_public
15000 || value
== DW_ACCESS_protected
15001 || value
== DW_ACCESS_private
)
15002 return (dwarf_access_attribute
) value
;
15003 complaint (_("Unhandled DW_AT_accessibility value (%s)"),
15007 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
15009 /* The default DWARF 2 accessibility for members is public, the default
15010 accessibility for inheritance is private. */
15012 if (die
->tag
!= DW_TAG_inheritance
)
15013 return DW_ACCESS_public
;
15015 return DW_ACCESS_private
;
15019 /* DWARF 3+ defines the default accessibility a different way. The same
15020 rules apply now for DW_TAG_inheritance as for the members and it only
15021 depends on the container kind. */
15023 if (die
->parent
->tag
== DW_TAG_class_type
)
15024 return DW_ACCESS_private
;
15026 return DW_ACCESS_public
;
15030 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
15031 offset. If the attribute was not found return 0, otherwise return
15032 1. If it was found but could not properly be handled, set *OFFSET
15036 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15039 struct attribute
*attr
;
15041 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15046 /* Note that we do not check for a section offset first here.
15047 This is because DW_AT_data_member_location is new in DWARF 4,
15048 so if we see it, we can assume that a constant form is really
15049 a constant and not a section offset. */
15050 if (attr
->form_is_constant ())
15051 *offset
= attr
->constant_value (0);
15052 else if (attr
->form_is_section_offset ())
15053 dwarf2_complex_location_expr_complaint ();
15054 else if (attr
->form_is_block ())
15055 *offset
= decode_locdesc (attr
->as_block (), cu
);
15057 dwarf2_complex_location_expr_complaint ();
15065 /* Look for DW_AT_data_member_location and store the results in FIELD. */
15068 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15069 struct field
*field
)
15071 struct attribute
*attr
;
15073 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15076 if (attr
->form_is_constant ())
15078 LONGEST offset
= attr
->constant_value (0);
15079 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
15081 else if (attr
->form_is_section_offset ())
15082 dwarf2_complex_location_expr_complaint ();
15083 else if (attr
->form_is_block ())
15086 CORE_ADDR offset
= decode_locdesc (attr
->as_block (), cu
, &handled
);
15088 SET_FIELD_BITPOS (*field
, offset
* bits_per_byte
);
15091 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
15092 struct objfile
*objfile
= per_objfile
->objfile
;
15093 struct dwarf2_locexpr_baton
*dlbaton
15094 = XOBNEW (&objfile
->objfile_obstack
,
15095 struct dwarf2_locexpr_baton
);
15096 dlbaton
->data
= attr
->as_block ()->data
;
15097 dlbaton
->size
= attr
->as_block ()->size
;
15098 /* When using this baton, we want to compute the address
15099 of the field, not the value. This is why
15100 is_reference is set to false here. */
15101 dlbaton
->is_reference
= false;
15102 dlbaton
->per_objfile
= per_objfile
;
15103 dlbaton
->per_cu
= cu
->per_cu
;
15105 SET_FIELD_DWARF_BLOCK (*field
, dlbaton
);
15109 dwarf2_complex_location_expr_complaint ();
15113 /* Add an aggregate field to the field list. */
15116 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15117 struct dwarf2_cu
*cu
)
15119 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15120 struct gdbarch
*gdbarch
= objfile
->arch ();
15121 struct nextfield
*new_field
;
15122 struct attribute
*attr
;
15124 const char *fieldname
= "";
15126 if (die
->tag
== DW_TAG_inheritance
)
15128 fip
->baseclasses
.emplace_back ();
15129 new_field
= &fip
->baseclasses
.back ();
15133 fip
->fields
.emplace_back ();
15134 new_field
= &fip
->fields
.back ();
15137 new_field
->offset
= die
->sect_off
;
15139 new_field
->accessibility
= dwarf2_access_attribute (die
, cu
);
15140 if (new_field
->accessibility
!= DW_ACCESS_public
)
15141 fip
->non_public_fields
= true;
15143 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15144 if (attr
!= nullptr)
15145 new_field
->virtuality
= attr
->as_virtuality ();
15147 new_field
->virtuality
= DW_VIRTUALITY_none
;
15149 fp
= &new_field
->field
;
15151 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15153 /* Data member other than a C++ static data member. */
15155 /* Get type of field. */
15156 fp
->set_type (die_type (die
, cu
));
15158 SET_FIELD_BITPOS (*fp
, 0);
15160 /* Get bit size of field (zero if none). */
15161 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15162 if (attr
!= nullptr)
15164 FIELD_BITSIZE (*fp
) = attr
->constant_value (0);
15168 FIELD_BITSIZE (*fp
) = 0;
15171 /* Get bit offset of field. */
15172 handle_data_member_location (die
, cu
, fp
);
15173 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15174 if (attr
!= nullptr && attr
->form_is_constant ())
15176 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15178 /* For big endian bits, the DW_AT_bit_offset gives the
15179 additional bit offset from the MSB of the containing
15180 anonymous object to the MSB of the field. We don't
15181 have to do anything special since we don't need to
15182 know the size of the anonymous object. */
15183 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15184 + attr
->constant_value (0)));
15188 /* For little endian bits, compute the bit offset to the
15189 MSB of the anonymous object, subtract off the number of
15190 bits from the MSB of the field to the MSB of the
15191 object, and then subtract off the number of bits of
15192 the field itself. The result is the bit offset of
15193 the LSB of the field. */
15194 int anonymous_size
;
15195 int bit_offset
= attr
->constant_value (0);
15197 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15198 if (attr
!= nullptr && attr
->form_is_constant ())
15200 /* The size of the anonymous object containing
15201 the bit field is explicit, so use the
15202 indicated size (in bytes). */
15203 anonymous_size
= attr
->constant_value (0);
15207 /* The size of the anonymous object containing
15208 the bit field must be inferred from the type
15209 attribute of the data member containing the
15211 anonymous_size
= TYPE_LENGTH (fp
->type ());
15213 SET_FIELD_BITPOS (*fp
,
15214 (FIELD_BITPOS (*fp
)
15215 + anonymous_size
* bits_per_byte
15216 - bit_offset
- FIELD_BITSIZE (*fp
)));
15219 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15221 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15222 + attr
->constant_value (0)));
15224 /* Get name of field. */
15225 fieldname
= dwarf2_name (die
, cu
);
15226 if (fieldname
== NULL
)
15229 /* The name is already allocated along with this objfile, so we don't
15230 need to duplicate it for the type. */
15231 fp
->name
= fieldname
;
15233 /* Change accessibility for artificial fields (e.g. virtual table
15234 pointer or virtual base class pointer) to private. */
15235 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15237 FIELD_ARTIFICIAL (*fp
) = 1;
15238 new_field
->accessibility
= DW_ACCESS_private
;
15239 fip
->non_public_fields
= true;
15242 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15244 /* C++ static member. */
15246 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15247 is a declaration, but all versions of G++ as of this writing
15248 (so through at least 3.2.1) incorrectly generate
15249 DW_TAG_variable tags. */
15251 const char *physname
;
15253 /* Get name of field. */
15254 fieldname
= dwarf2_name (die
, cu
);
15255 if (fieldname
== NULL
)
15258 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15260 /* Only create a symbol if this is an external value.
15261 new_symbol checks this and puts the value in the global symbol
15262 table, which we want. If it is not external, new_symbol
15263 will try to put the value in cu->list_in_scope which is wrong. */
15264 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15266 /* A static const member, not much different than an enum as far as
15267 we're concerned, except that we can support more types. */
15268 new_symbol (die
, NULL
, cu
);
15271 /* Get physical name. */
15272 physname
= dwarf2_physname (fieldname
, die
, cu
);
15274 /* The name is already allocated along with this objfile, so we don't
15275 need to duplicate it for the type. */
15276 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15277 fp
->set_type (die_type (die
, cu
));
15278 FIELD_NAME (*fp
) = fieldname
;
15280 else if (die
->tag
== DW_TAG_inheritance
)
15282 /* C++ base class field. */
15283 handle_data_member_location (die
, cu
, fp
);
15284 FIELD_BITSIZE (*fp
) = 0;
15285 fp
->set_type (die_type (die
, cu
));
15286 FIELD_NAME (*fp
) = fp
->type ()->name ();
15289 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15292 /* Can the type given by DIE define another type? */
15295 type_can_define_types (const struct die_info
*die
)
15299 case DW_TAG_typedef
:
15300 case DW_TAG_class_type
:
15301 case DW_TAG_structure_type
:
15302 case DW_TAG_union_type
:
15303 case DW_TAG_enumeration_type
:
15311 /* Add a type definition defined in the scope of the FIP's class. */
15314 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15315 struct dwarf2_cu
*cu
)
15317 struct decl_field fp
;
15318 memset (&fp
, 0, sizeof (fp
));
15320 gdb_assert (type_can_define_types (die
));
15322 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15323 fp
.name
= dwarf2_name (die
, cu
);
15324 fp
.type
= read_type_die (die
, cu
);
15326 /* Save accessibility. */
15327 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15328 switch (accessibility
)
15330 case DW_ACCESS_public
:
15331 /* The assumed value if neither private nor protected. */
15333 case DW_ACCESS_private
:
15336 case DW_ACCESS_protected
:
15337 fp
.is_protected
= 1;
15341 if (die
->tag
== DW_TAG_typedef
)
15342 fip
->typedef_field_list
.push_back (fp
);
15344 fip
->nested_types_list
.push_back (fp
);
15347 /* A convenience typedef that's used when finding the discriminant
15348 field for a variant part. */
15349 typedef std::unordered_map
<sect_offset
, int, gdb::hash_enum
<sect_offset
>>
15352 /* Compute the discriminant range for a given variant. OBSTACK is
15353 where the results will be stored. VARIANT is the variant to
15354 process. IS_UNSIGNED indicates whether the discriminant is signed
15357 static const gdb::array_view
<discriminant_range
>
15358 convert_variant_range (struct obstack
*obstack
, const variant_field
&variant
,
15361 std::vector
<discriminant_range
> ranges
;
15363 if (variant
.default_branch
)
15366 if (variant
.discr_list_data
== nullptr)
15368 discriminant_range r
15369 = {variant
.discriminant_value
, variant
.discriminant_value
};
15370 ranges
.push_back (r
);
15374 gdb::array_view
<const gdb_byte
> data (variant
.discr_list_data
->data
,
15375 variant
.discr_list_data
->size
);
15376 while (!data
.empty ())
15378 if (data
[0] != DW_DSC_range
&& data
[0] != DW_DSC_label
)
15380 complaint (_("invalid discriminant marker: %d"), data
[0]);
15383 bool is_range
= data
[0] == DW_DSC_range
;
15384 data
= data
.slice (1);
15386 ULONGEST low
, high
;
15387 unsigned int bytes_read
;
15391 complaint (_("DW_AT_discr_list missing low value"));
15395 low
= read_unsigned_leb128 (nullptr, data
.data (), &bytes_read
);
15397 low
= (ULONGEST
) read_signed_leb128 (nullptr, data
.data (),
15399 data
= data
.slice (bytes_read
);
15405 complaint (_("DW_AT_discr_list missing high value"));
15409 high
= read_unsigned_leb128 (nullptr, data
.data (),
15412 high
= (LONGEST
) read_signed_leb128 (nullptr, data
.data (),
15414 data
= data
.slice (bytes_read
);
15419 ranges
.push_back ({ low
, high
});
15423 discriminant_range
*result
= XOBNEWVEC (obstack
, discriminant_range
,
15425 std::copy (ranges
.begin (), ranges
.end (), result
);
15426 return gdb::array_view
<discriminant_range
> (result
, ranges
.size ());
15429 static const gdb::array_view
<variant_part
> create_variant_parts
15430 (struct obstack
*obstack
,
15431 const offset_map_type
&offset_map
,
15432 struct field_info
*fi
,
15433 const std::vector
<variant_part_builder
> &variant_parts
);
15435 /* Fill in a "struct variant" for a given variant field. RESULT is
15436 the variant to fill in. OBSTACK is where any needed allocations
15437 will be done. OFFSET_MAP holds the mapping from section offsets to
15438 fields for the type. FI describes the fields of the type we're
15439 processing. FIELD is the variant field we're converting. */
15442 create_one_variant (variant
&result
, struct obstack
*obstack
,
15443 const offset_map_type
&offset_map
,
15444 struct field_info
*fi
, const variant_field
&field
)
15446 result
.discriminants
= convert_variant_range (obstack
, field
, false);
15447 result
.first_field
= field
.first_field
+ fi
->baseclasses
.size ();
15448 result
.last_field
= field
.last_field
+ fi
->baseclasses
.size ();
15449 result
.parts
= create_variant_parts (obstack
, offset_map
, fi
,
15450 field
.variant_parts
);
15453 /* Fill in a "struct variant_part" for a given variant part. RESULT
15454 is the variant part to fill in. OBSTACK is where any needed
15455 allocations will be done. OFFSET_MAP holds the mapping from
15456 section offsets to fields for the type. FI describes the fields of
15457 the type we're processing. BUILDER is the variant part to be
15461 create_one_variant_part (variant_part
&result
,
15462 struct obstack
*obstack
,
15463 const offset_map_type
&offset_map
,
15464 struct field_info
*fi
,
15465 const variant_part_builder
&builder
)
15467 auto iter
= offset_map
.find (builder
.discriminant_offset
);
15468 if (iter
== offset_map
.end ())
15470 result
.discriminant_index
= -1;
15471 /* Doesn't matter. */
15472 result
.is_unsigned
= false;
15476 result
.discriminant_index
= iter
->second
;
15478 = fi
->fields
[result
.discriminant_index
].field
.type ()->is_unsigned ();
15481 size_t n
= builder
.variants
.size ();
15482 variant
*output
= new (obstack
) variant
[n
];
15483 for (size_t i
= 0; i
< n
; ++i
)
15484 create_one_variant (output
[i
], obstack
, offset_map
, fi
,
15485 builder
.variants
[i
]);
15487 result
.variants
= gdb::array_view
<variant
> (output
, n
);
15490 /* Create a vector of variant parts that can be attached to a type.
15491 OBSTACK is where any needed allocations will be done. OFFSET_MAP
15492 holds the mapping from section offsets to fields for the type. FI
15493 describes the fields of the type we're processing. VARIANT_PARTS
15494 is the vector to convert. */
15496 static const gdb::array_view
<variant_part
>
15497 create_variant_parts (struct obstack
*obstack
,
15498 const offset_map_type
&offset_map
,
15499 struct field_info
*fi
,
15500 const std::vector
<variant_part_builder
> &variant_parts
)
15502 if (variant_parts
.empty ())
15505 size_t n
= variant_parts
.size ();
15506 variant_part
*result
= new (obstack
) variant_part
[n
];
15507 for (size_t i
= 0; i
< n
; ++i
)
15508 create_one_variant_part (result
[i
], obstack
, offset_map
, fi
,
15511 return gdb::array_view
<variant_part
> (result
, n
);
15514 /* Compute the variant part vector for FIP, attaching it to TYPE when
15518 add_variant_property (struct field_info
*fip
, struct type
*type
,
15519 struct dwarf2_cu
*cu
)
15521 /* Map section offsets of fields to their field index. Note the
15522 field index here does not take the number of baseclasses into
15524 offset_map_type offset_map
;
15525 for (int i
= 0; i
< fip
->fields
.size (); ++i
)
15526 offset_map
[fip
->fields
[i
].offset
] = i
;
15528 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15529 gdb::array_view
<variant_part
> parts
15530 = create_variant_parts (&objfile
->objfile_obstack
, offset_map
, fip
,
15531 fip
->variant_parts
);
15533 struct dynamic_prop prop
;
15534 prop
.set_variant_parts ((gdb::array_view
<variant_part
> *)
15535 obstack_copy (&objfile
->objfile_obstack
, &parts
,
15538 type
->add_dyn_prop (DYN_PROP_VARIANT_PARTS
, prop
);
15541 /* Create the vector of fields, and attach it to the type. */
15544 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15545 struct dwarf2_cu
*cu
)
15547 int nfields
= fip
->nfields ();
15549 /* Record the field count, allocate space for the array of fields,
15550 and create blank accessibility bitfields if necessary. */
15551 type
->set_num_fields (nfields
);
15553 ((struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
));
15555 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15557 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15559 TYPE_FIELD_PRIVATE_BITS (type
) =
15560 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15561 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15563 TYPE_FIELD_PROTECTED_BITS (type
) =
15564 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15565 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15567 TYPE_FIELD_IGNORE_BITS (type
) =
15568 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15569 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15572 /* If the type has baseclasses, allocate and clear a bit vector for
15573 TYPE_FIELD_VIRTUAL_BITS. */
15574 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15576 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15577 unsigned char *pointer
;
15579 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15580 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15581 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15582 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15583 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15586 if (!fip
->variant_parts
.empty ())
15587 add_variant_property (fip
, type
, cu
);
15589 /* Copy the saved-up fields into the field vector. */
15590 for (int i
= 0; i
< nfields
; ++i
)
15592 struct nextfield
&field
15593 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15594 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15596 type
->field (i
) = field
.field
;
15597 switch (field
.accessibility
)
15599 case DW_ACCESS_private
:
15600 if (cu
->language
!= language_ada
)
15601 SET_TYPE_FIELD_PRIVATE (type
, i
);
15604 case DW_ACCESS_protected
:
15605 if (cu
->language
!= language_ada
)
15606 SET_TYPE_FIELD_PROTECTED (type
, i
);
15609 case DW_ACCESS_public
:
15613 /* Unknown accessibility. Complain and treat it as public. */
15615 complaint (_("unsupported accessibility %d"),
15616 field
.accessibility
);
15620 if (i
< fip
->baseclasses
.size ())
15622 switch (field
.virtuality
)
15624 case DW_VIRTUALITY_virtual
:
15625 case DW_VIRTUALITY_pure_virtual
:
15626 if (cu
->language
== language_ada
)
15627 error (_("unexpected virtuality in component of Ada type"));
15628 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15635 /* Return true if this member function is a constructor, false
15639 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15641 const char *fieldname
;
15642 const char *type_name
;
15645 if (die
->parent
== NULL
)
15648 if (die
->parent
->tag
!= DW_TAG_structure_type
15649 && die
->parent
->tag
!= DW_TAG_union_type
15650 && die
->parent
->tag
!= DW_TAG_class_type
)
15653 fieldname
= dwarf2_name (die
, cu
);
15654 type_name
= dwarf2_name (die
->parent
, cu
);
15655 if (fieldname
== NULL
|| type_name
== NULL
)
15658 len
= strlen (fieldname
);
15659 return (strncmp (fieldname
, type_name
, len
) == 0
15660 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15663 /* Add a member function to the proper fieldlist. */
15666 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15667 struct type
*type
, struct dwarf2_cu
*cu
)
15669 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
15670 struct attribute
*attr
;
15672 struct fnfieldlist
*flp
= nullptr;
15673 struct fn_field
*fnp
;
15674 const char *fieldname
;
15675 struct type
*this_type
;
15677 if (cu
->language
== language_ada
)
15678 error (_("unexpected member function in Ada type"));
15680 /* Get name of member function. */
15681 fieldname
= dwarf2_name (die
, cu
);
15682 if (fieldname
== NULL
)
15685 /* Look up member function name in fieldlist. */
15686 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15688 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15690 flp
= &fip
->fnfieldlists
[i
];
15695 /* Create a new fnfieldlist if necessary. */
15696 if (flp
== nullptr)
15698 fip
->fnfieldlists
.emplace_back ();
15699 flp
= &fip
->fnfieldlists
.back ();
15700 flp
->name
= fieldname
;
15701 i
= fip
->fnfieldlists
.size () - 1;
15704 /* Create a new member function field and add it to the vector of
15706 flp
->fnfields
.emplace_back ();
15707 fnp
= &flp
->fnfields
.back ();
15709 /* Delay processing of the physname until later. */
15710 if (cu
->language
== language_cplus
)
15711 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15715 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15716 fnp
->physname
= physname
? physname
: "";
15719 fnp
->type
= alloc_type (objfile
);
15720 this_type
= read_type_die (die
, cu
);
15721 if (this_type
&& this_type
->code () == TYPE_CODE_FUNC
)
15723 int nparams
= this_type
->num_fields ();
15725 /* TYPE is the domain of this method, and THIS_TYPE is the type
15726 of the method itself (TYPE_CODE_METHOD). */
15727 smash_to_method_type (fnp
->type
, type
,
15728 TYPE_TARGET_TYPE (this_type
),
15729 this_type
->fields (),
15730 this_type
->num_fields (),
15731 this_type
->has_varargs ());
15733 /* Handle static member functions.
15734 Dwarf2 has no clean way to discern C++ static and non-static
15735 member functions. G++ helps GDB by marking the first
15736 parameter for non-static member functions (which is the this
15737 pointer) as artificial. We obtain this information from
15738 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15739 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15740 fnp
->voffset
= VOFFSET_STATIC
;
15743 complaint (_("member function type missing for '%s'"),
15744 dwarf2_full_name (fieldname
, die
, cu
));
15746 /* Get fcontext from DW_AT_containing_type if present. */
15747 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15748 fnp
->fcontext
= die_containing_type (die
, cu
);
15750 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15751 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15753 /* Get accessibility. */
15754 dwarf_access_attribute accessibility
= dwarf2_access_attribute (die
, cu
);
15755 switch (accessibility
)
15757 case DW_ACCESS_private
:
15758 fnp
->is_private
= 1;
15760 case DW_ACCESS_protected
:
15761 fnp
->is_protected
= 1;
15765 /* Check for artificial methods. */
15766 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15767 if (attr
&& attr
->as_boolean ())
15768 fnp
->is_artificial
= 1;
15770 /* Check for defaulted methods. */
15771 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15772 if (attr
!= nullptr)
15773 fnp
->defaulted
= attr
->defaulted ();
15775 /* Check for deleted methods. */
15776 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15777 if (attr
!= nullptr && attr
->as_boolean ())
15778 fnp
->is_deleted
= 1;
15780 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15782 /* Get index in virtual function table if it is a virtual member
15783 function. For older versions of GCC, this is an offset in the
15784 appropriate virtual table, as specified by DW_AT_containing_type.
15785 For everyone else, it is an expression to be evaluated relative
15786 to the object address. */
15788 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15789 if (attr
!= nullptr)
15791 if (attr
->form_is_block () && attr
->as_block ()->size
> 0)
15793 struct dwarf_block
*block
= attr
->as_block ();
15795 if (block
->data
[0] == DW_OP_constu
)
15797 /* Old-style GCC. */
15798 fnp
->voffset
= decode_locdesc (block
, cu
) + 2;
15800 else if (block
->data
[0] == DW_OP_deref
15801 || (block
->size
> 1
15802 && block
->data
[0] == DW_OP_deref_size
15803 && block
->data
[1] == cu
->header
.addr_size
))
15805 fnp
->voffset
= decode_locdesc (block
, cu
);
15806 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15807 dwarf2_complex_location_expr_complaint ();
15809 fnp
->voffset
/= cu
->header
.addr_size
;
15813 dwarf2_complex_location_expr_complaint ();
15815 if (!fnp
->fcontext
)
15817 /* If there is no `this' field and no DW_AT_containing_type,
15818 we cannot actually find a base class context for the
15820 if (this_type
->num_fields () == 0
15821 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15823 complaint (_("cannot determine context for virtual member "
15824 "function \"%s\" (offset %s)"),
15825 fieldname
, sect_offset_str (die
->sect_off
));
15830 = TYPE_TARGET_TYPE (this_type
->field (0).type ());
15834 else if (attr
->form_is_section_offset ())
15836 dwarf2_complex_location_expr_complaint ();
15840 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15846 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15847 if (attr
!= nullptr && attr
->as_virtuality () != DW_VIRTUALITY_none
)
15849 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15850 complaint (_("Member function \"%s\" (offset %s) is virtual "
15851 "but the vtable offset is not specified"),
15852 fieldname
, sect_offset_str (die
->sect_off
));
15853 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15854 TYPE_CPLUS_DYNAMIC (type
) = 1;
15859 /* Create the vector of member function fields, and attach it to the type. */
15862 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15863 struct dwarf2_cu
*cu
)
15865 if (cu
->language
== language_ada
)
15866 error (_("unexpected member functions in Ada type"));
15868 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15869 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15871 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15873 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15875 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15876 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15878 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15879 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15880 fn_flp
->fn_fields
= (struct fn_field
*)
15881 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15883 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15884 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15887 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15890 /* Returns non-zero if NAME is the name of a vtable member in CU's
15891 language, zero otherwise. */
15893 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15895 static const char vptr
[] = "_vptr";
15897 /* Look for the C++ form of the vtable. */
15898 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15904 /* GCC outputs unnamed structures that are really pointers to member
15905 functions, with the ABI-specified layout. If TYPE describes
15906 such a structure, smash it into a member function type.
15908 GCC shouldn't do this; it should just output pointer to member DIEs.
15909 This is GCC PR debug/28767. */
15912 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15914 struct type
*pfn_type
, *self_type
, *new_type
;
15916 /* Check for a structure with no name and two children. */
15917 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
15920 /* Check for __pfn and __delta members. */
15921 if (TYPE_FIELD_NAME (type
, 0) == NULL
15922 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15923 || TYPE_FIELD_NAME (type
, 1) == NULL
15924 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15927 /* Find the type of the method. */
15928 pfn_type
= type
->field (0).type ();
15929 if (pfn_type
== NULL
15930 || pfn_type
->code () != TYPE_CODE_PTR
15931 || TYPE_TARGET_TYPE (pfn_type
)->code () != TYPE_CODE_FUNC
)
15934 /* Look for the "this" argument. */
15935 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15936 if (pfn_type
->num_fields () == 0
15937 /* || pfn_type->field (0).type () == NULL */
15938 || pfn_type
->field (0).type ()->code () != TYPE_CODE_PTR
)
15941 self_type
= TYPE_TARGET_TYPE (pfn_type
->field (0).type ());
15942 new_type
= alloc_type (objfile
);
15943 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15944 pfn_type
->fields (), pfn_type
->num_fields (),
15945 pfn_type
->has_varargs ());
15946 smash_to_methodptr_type (type
, new_type
);
15949 /* Helper for quirk_ada_thick_pointer. If TYPE is an array type that
15950 requires rewriting, then copy it and return the updated copy.
15951 Otherwise return nullptr. */
15953 static struct type
*
15954 rewrite_array_type (struct type
*type
)
15956 if (type
->code () != TYPE_CODE_ARRAY
)
15959 struct type
*index_type
= type
->index_type ();
15960 range_bounds
*current_bounds
= index_type
->bounds ();
15962 /* Handle multi-dimensional arrays. */
15963 struct type
*new_target
= rewrite_array_type (TYPE_TARGET_TYPE (type
));
15964 if (new_target
== nullptr)
15966 /* Maybe we don't need to rewrite this array. */
15967 if (current_bounds
->low
.kind () == PROP_CONST
15968 && current_bounds
->high
.kind () == PROP_CONST
)
15972 /* Either the target type was rewritten, or the bounds have to be
15973 updated. Either way we want to copy the type and update
15975 struct type
*copy
= copy_type (type
);
15976 int nfields
= copy
->num_fields ();
15978 = ((struct field
*) TYPE_ZALLOC (copy
,
15979 nfields
* sizeof (struct field
)));
15980 memcpy (new_fields
, copy
->fields (), nfields
* sizeof (struct field
));
15981 copy
->set_fields (new_fields
);
15982 if (new_target
!= nullptr)
15983 TYPE_TARGET_TYPE (copy
) = new_target
;
15985 struct type
*index_copy
= copy_type (index_type
);
15986 range_bounds
*bounds
15987 = (struct range_bounds
*) TYPE_ZALLOC (index_copy
,
15988 sizeof (range_bounds
));
15989 *bounds
= *current_bounds
;
15990 bounds
->low
.set_const_val (1);
15991 bounds
->high
.set_const_val (0);
15992 index_copy
->set_bounds (bounds
);
15993 copy
->set_index_type (index_copy
);
15998 /* While some versions of GCC will generate complicated DWARF for an
15999 array (see quirk_ada_thick_pointer), more recent versions were
16000 modified to emit an explicit thick pointer structure. However, in
16001 this case, the array still has DWARF expressions for its ranges,
16002 and these must be ignored. */
16005 quirk_ada_thick_pointer_struct (struct die_info
*die
, struct dwarf2_cu
*cu
,
16008 gdb_assert (cu
->language
== language_ada
);
16010 /* Check for a structure with two children. */
16011 if (type
->code () != TYPE_CODE_STRUCT
|| type
->num_fields () != 2)
16014 /* Check for P_ARRAY and P_BOUNDS members. */
16015 if (TYPE_FIELD_NAME (type
, 0) == NULL
16016 || strcmp (TYPE_FIELD_NAME (type
, 0), "P_ARRAY") != 0
16017 || TYPE_FIELD_NAME (type
, 1) == NULL
16018 || strcmp (TYPE_FIELD_NAME (type
, 1), "P_BOUNDS") != 0)
16021 /* Make sure we're looking at a pointer to an array. */
16022 if (type
->field (0).type ()->code () != TYPE_CODE_PTR
)
16025 /* The Ada code already knows how to handle these types, so all that
16026 we need to do is turn the bounds into static bounds. However, we
16027 don't want to rewrite existing array or index types in-place,
16028 because those may be referenced in other contexts where this
16029 rewriting is undesirable. */
16030 struct type
*new_ary_type
16031 = rewrite_array_type (TYPE_TARGET_TYPE (type
->field (0).type ()));
16032 if (new_ary_type
!= nullptr)
16033 type
->field (0).set_type (lookup_pointer_type (new_ary_type
));
16036 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
16037 appropriate error checking and issuing complaints if there is a
16041 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
16043 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
16045 if (attr
== nullptr)
16048 if (!attr
->form_is_constant ())
16050 complaint (_("DW_AT_alignment must have constant form"
16051 " - DIE at %s [in module %s]"),
16052 sect_offset_str (die
->sect_off
),
16053 objfile_name (cu
->per_objfile
->objfile
));
16057 LONGEST val
= attr
->constant_value (0);
16060 complaint (_("DW_AT_alignment value must not be negative"
16061 " - DIE at %s [in module %s]"),
16062 sect_offset_str (die
->sect_off
),
16063 objfile_name (cu
->per_objfile
->objfile
));
16066 ULONGEST align
= val
;
16070 complaint (_("DW_AT_alignment value must not be zero"
16071 " - DIE at %s [in module %s]"),
16072 sect_offset_str (die
->sect_off
),
16073 objfile_name (cu
->per_objfile
->objfile
));
16076 if ((align
& (align
- 1)) != 0)
16078 complaint (_("DW_AT_alignment value must be a power of 2"
16079 " - DIE at %s [in module %s]"),
16080 sect_offset_str (die
->sect_off
),
16081 objfile_name (cu
->per_objfile
->objfile
));
16088 /* If the DIE has a DW_AT_alignment attribute, use its value to set
16089 the alignment for TYPE. */
16092 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
16095 if (!set_type_align (type
, get_alignment (cu
, die
)))
16096 complaint (_("DW_AT_alignment value too large"
16097 " - DIE at %s [in module %s]"),
16098 sect_offset_str (die
->sect_off
),
16099 objfile_name (cu
->per_objfile
->objfile
));
16102 /* Check if the given VALUE is a valid enum dwarf_calling_convention
16103 constant for a type, according to DWARF5 spec, Table 5.5. */
16106 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
16111 case DW_CC_pass_by_reference
:
16112 case DW_CC_pass_by_value
:
16116 complaint (_("unrecognized DW_AT_calling_convention value "
16117 "(%s) for a type"), pulongest (value
));
16122 /* Check if the given VALUE is a valid enum dwarf_calling_convention
16123 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
16124 also according to GNU-specific values (see include/dwarf2.h). */
16127 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
16132 case DW_CC_program
:
16136 case DW_CC_GNU_renesas_sh
:
16137 case DW_CC_GNU_borland_fastcall_i386
:
16138 case DW_CC_GDB_IBM_OpenCL
:
16142 complaint (_("unrecognized DW_AT_calling_convention value "
16143 "(%s) for a subroutine"), pulongest (value
));
16148 /* Called when we find the DIE that starts a structure or union scope
16149 (definition) to create a type for the structure or union. Fill in
16150 the type's name and general properties; the members will not be
16151 processed until process_structure_scope. A symbol table entry for
16152 the type will also not be done until process_structure_scope (assuming
16153 the type has a name).
16155 NOTE: we need to call these functions regardless of whether or not the
16156 DIE has a DW_AT_name attribute, since it might be an anonymous
16157 structure or union. This gets the type entered into our set of
16158 user defined types. */
16160 static struct type
*
16161 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16163 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16165 struct attribute
*attr
;
16168 /* If the definition of this type lives in .debug_types, read that type.
16169 Don't follow DW_AT_specification though, that will take us back up
16170 the chain and we want to go down. */
16171 attr
= die
->attr (DW_AT_signature
);
16172 if (attr
!= nullptr)
16174 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16176 /* The type's CU may not be the same as CU.
16177 Ensure TYPE is recorded with CU in die_type_hash. */
16178 return set_die_type (die
, type
, cu
);
16181 type
= alloc_type (objfile
);
16182 INIT_CPLUS_SPECIFIC (type
);
16184 name
= dwarf2_name (die
, cu
);
16187 if (cu
->language
== language_cplus
16188 || cu
->language
== language_d
16189 || cu
->language
== language_rust
)
16191 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
16193 /* dwarf2_full_name might have already finished building the DIE's
16194 type. If so, there is no need to continue. */
16195 if (get_die_type (die
, cu
) != NULL
)
16196 return get_die_type (die
, cu
);
16198 type
->set_name (full_name
);
16202 /* The name is already allocated along with this objfile, so
16203 we don't need to duplicate it for the type. */
16204 type
->set_name (name
);
16208 if (die
->tag
== DW_TAG_structure_type
)
16210 type
->set_code (TYPE_CODE_STRUCT
);
16212 else if (die
->tag
== DW_TAG_union_type
)
16214 type
->set_code (TYPE_CODE_UNION
);
16218 type
->set_code (TYPE_CODE_STRUCT
);
16221 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
16222 TYPE_DECLARED_CLASS (type
) = 1;
16224 /* Store the calling convention in the type if it's available in
16225 the die. Otherwise the calling convention remains set to
16226 the default value DW_CC_normal. */
16227 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16228 if (attr
!= nullptr
16229 && is_valid_DW_AT_calling_convention_for_type (attr
->constant_value (0)))
16231 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16232 TYPE_CPLUS_CALLING_CONVENTION (type
)
16233 = (enum dwarf_calling_convention
) (attr
->constant_value (0));
16236 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16237 if (attr
!= nullptr)
16239 if (attr
->form_is_constant ())
16240 TYPE_LENGTH (type
) = attr
->constant_value (0);
16243 struct dynamic_prop prop
;
16244 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
16245 type
->add_dyn_prop (DYN_PROP_BYTE_SIZE
, prop
);
16246 TYPE_LENGTH (type
) = 0;
16251 TYPE_LENGTH (type
) = 0;
16254 maybe_set_alignment (cu
, die
, type
);
16256 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16258 /* ICC<14 does not output the required DW_AT_declaration on
16259 incomplete types, but gives them a size of zero. */
16260 type
->set_is_stub (true);
16263 type
->set_stub_is_supported (true);
16265 if (die_is_declaration (die
, cu
))
16266 type
->set_is_stub (true);
16267 else if (attr
== NULL
&& die
->child
== NULL
16268 && producer_is_realview (cu
->producer
))
16269 /* RealView does not output the required DW_AT_declaration
16270 on incomplete types. */
16271 type
->set_is_stub (true);
16273 /* We need to add the type field to the die immediately so we don't
16274 infinitely recurse when dealing with pointers to the structure
16275 type within the structure itself. */
16276 set_die_type (die
, type
, cu
);
16278 /* set_die_type should be already done. */
16279 set_descriptive_type (type
, die
, cu
);
16284 static void handle_struct_member_die
16285 (struct die_info
*child_die
,
16287 struct field_info
*fi
,
16288 std::vector
<struct symbol
*> *template_args
,
16289 struct dwarf2_cu
*cu
);
16291 /* A helper for handle_struct_member_die that handles
16292 DW_TAG_variant_part. */
16295 handle_variant_part (struct die_info
*die
, struct type
*type
,
16296 struct field_info
*fi
,
16297 std::vector
<struct symbol
*> *template_args
,
16298 struct dwarf2_cu
*cu
)
16300 variant_part_builder
*new_part
;
16301 if (fi
->current_variant_part
== nullptr)
16303 fi
->variant_parts
.emplace_back ();
16304 new_part
= &fi
->variant_parts
.back ();
16306 else if (!fi
->current_variant_part
->processing_variant
)
16308 complaint (_("nested DW_TAG_variant_part seen "
16309 "- DIE at %s [in module %s]"),
16310 sect_offset_str (die
->sect_off
),
16311 objfile_name (cu
->per_objfile
->objfile
));
16316 variant_field
¤t
= fi
->current_variant_part
->variants
.back ();
16317 current
.variant_parts
.emplace_back ();
16318 new_part
= ¤t
.variant_parts
.back ();
16321 /* When we recurse, we want callees to add to this new variant
16323 scoped_restore save_current_variant_part
16324 = make_scoped_restore (&fi
->current_variant_part
, new_part
);
16326 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16329 /* It's a univariant form, an extension we support. */
16331 else if (discr
->form_is_ref ())
16333 struct dwarf2_cu
*target_cu
= cu
;
16334 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16336 new_part
->discriminant_offset
= target_die
->sect_off
;
16340 complaint (_("DW_AT_discr does not have DIE reference form"
16341 " - DIE at %s [in module %s]"),
16342 sect_offset_str (die
->sect_off
),
16343 objfile_name (cu
->per_objfile
->objfile
));
16346 for (die_info
*child_die
= die
->child
;
16348 child_die
= child_die
->sibling
)
16349 handle_struct_member_die (child_die
, type
, fi
, template_args
, cu
);
16352 /* A helper for handle_struct_member_die that handles
16356 handle_variant (struct die_info
*die
, struct type
*type
,
16357 struct field_info
*fi
,
16358 std::vector
<struct symbol
*> *template_args
,
16359 struct dwarf2_cu
*cu
)
16361 if (fi
->current_variant_part
== nullptr)
16363 complaint (_("saw DW_TAG_variant outside DW_TAG_variant_part "
16364 "- DIE at %s [in module %s]"),
16365 sect_offset_str (die
->sect_off
),
16366 objfile_name (cu
->per_objfile
->objfile
));
16369 if (fi
->current_variant_part
->processing_variant
)
16371 complaint (_("nested DW_TAG_variant seen "
16372 "- DIE at %s [in module %s]"),
16373 sect_offset_str (die
->sect_off
),
16374 objfile_name (cu
->per_objfile
->objfile
));
16378 scoped_restore save_processing_variant
16379 = make_scoped_restore (&fi
->current_variant_part
->processing_variant
,
16382 fi
->current_variant_part
->variants
.emplace_back ();
16383 variant_field
&variant
= fi
->current_variant_part
->variants
.back ();
16384 variant
.first_field
= fi
->fields
.size ();
16386 /* In a variant we want to get the discriminant and also add a
16387 field for our sole member child. */
16388 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr_value
, cu
);
16389 if (discr
== nullptr || !discr
->form_is_constant ())
16391 discr
= dwarf2_attr (die
, DW_AT_discr_list
, cu
);
16392 if (discr
== nullptr || discr
->as_block ()->size
== 0)
16393 variant
.default_branch
= true;
16395 variant
.discr_list_data
= discr
->as_block ();
16398 variant
.discriminant_value
= discr
->constant_value (0);
16400 for (die_info
*variant_child
= die
->child
;
16401 variant_child
!= NULL
;
16402 variant_child
= variant_child
->sibling
)
16403 handle_struct_member_die (variant_child
, type
, fi
, template_args
, cu
);
16405 variant
.last_field
= fi
->fields
.size ();
16408 /* A helper for process_structure_scope that handles a single member
16412 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16413 struct field_info
*fi
,
16414 std::vector
<struct symbol
*> *template_args
,
16415 struct dwarf2_cu
*cu
)
16417 if (child_die
->tag
== DW_TAG_member
16418 || child_die
->tag
== DW_TAG_variable
)
16420 /* NOTE: carlton/2002-11-05: A C++ static data member
16421 should be a DW_TAG_member that is a declaration, but
16422 all versions of G++ as of this writing (so through at
16423 least 3.2.1) incorrectly generate DW_TAG_variable
16424 tags for them instead. */
16425 dwarf2_add_field (fi
, child_die
, cu
);
16427 else if (child_die
->tag
== DW_TAG_subprogram
)
16429 /* Rust doesn't have member functions in the C++ sense.
16430 However, it does emit ordinary functions as children
16431 of a struct DIE. */
16432 if (cu
->language
== language_rust
)
16433 read_func_scope (child_die
, cu
);
16436 /* C++ member function. */
16437 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16440 else if (child_die
->tag
== DW_TAG_inheritance
)
16442 /* C++ base class field. */
16443 dwarf2_add_field (fi
, child_die
, cu
);
16445 else if (type_can_define_types (child_die
))
16446 dwarf2_add_type_defn (fi
, child_die
, cu
);
16447 else if (child_die
->tag
== DW_TAG_template_type_param
16448 || child_die
->tag
== DW_TAG_template_value_param
)
16450 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16453 template_args
->push_back (arg
);
16455 else if (child_die
->tag
== DW_TAG_variant_part
)
16456 handle_variant_part (child_die
, type
, fi
, template_args
, cu
);
16457 else if (child_die
->tag
== DW_TAG_variant
)
16458 handle_variant (child_die
, type
, fi
, template_args
, cu
);
16461 /* Finish creating a structure or union type, including filling in
16462 its members and creating a symbol for it. */
16465 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16467 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16468 struct die_info
*child_die
;
16471 type
= get_die_type (die
, cu
);
16473 type
= read_structure_type (die
, cu
);
16475 bool has_template_parameters
= false;
16476 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16478 struct field_info fi
;
16479 std::vector
<struct symbol
*> template_args
;
16481 child_die
= die
->child
;
16483 while (child_die
&& child_die
->tag
)
16485 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16486 child_die
= child_die
->sibling
;
16489 /* Attach template arguments to type. */
16490 if (!template_args
.empty ())
16492 has_template_parameters
= true;
16493 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16494 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16495 TYPE_TEMPLATE_ARGUMENTS (type
)
16496 = XOBNEWVEC (&objfile
->objfile_obstack
,
16498 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16499 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16500 template_args
.data (),
16501 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16502 * sizeof (struct symbol
*)));
16505 /* Attach fields and member functions to the type. */
16506 if (fi
.nfields () > 0)
16507 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16508 if (!fi
.fnfieldlists
.empty ())
16510 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16512 /* Get the type which refers to the base class (possibly this
16513 class itself) which contains the vtable pointer for the current
16514 class from the DW_AT_containing_type attribute. This use of
16515 DW_AT_containing_type is a GNU extension. */
16517 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16519 struct type
*t
= die_containing_type (die
, cu
);
16521 set_type_vptr_basetype (type
, t
);
16526 /* Our own class provides vtbl ptr. */
16527 for (i
= t
->num_fields () - 1;
16528 i
>= TYPE_N_BASECLASSES (t
);
16531 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16533 if (is_vtable_name (fieldname
, cu
))
16535 set_type_vptr_fieldno (type
, i
);
16540 /* Complain if virtual function table field not found. */
16541 if (i
< TYPE_N_BASECLASSES (t
))
16542 complaint (_("virtual function table pointer "
16543 "not found when defining class '%s'"),
16544 type
->name () ? type
->name () : "");
16548 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16551 else if (cu
->producer
16552 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16554 /* The IBM XLC compiler does not provide direct indication
16555 of the containing type, but the vtable pointer is
16556 always named __vfp. */
16560 for (i
= type
->num_fields () - 1;
16561 i
>= TYPE_N_BASECLASSES (type
);
16564 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16566 set_type_vptr_fieldno (type
, i
);
16567 set_type_vptr_basetype (type
, type
);
16574 /* Copy fi.typedef_field_list linked list elements content into the
16575 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16576 if (!fi
.typedef_field_list
.empty ())
16578 int count
= fi
.typedef_field_list
.size ();
16580 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16581 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16582 = ((struct decl_field
*)
16584 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16585 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16587 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16588 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16591 /* Copy fi.nested_types_list linked list elements content into the
16592 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16593 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16595 int count
= fi
.nested_types_list
.size ();
16597 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16598 TYPE_NESTED_TYPES_ARRAY (type
)
16599 = ((struct decl_field
*)
16600 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16601 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16603 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16604 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16608 quirk_gcc_member_function_pointer (type
, objfile
);
16609 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16610 cu
->rust_unions
.push_back (type
);
16611 else if (cu
->language
== language_ada
)
16612 quirk_ada_thick_pointer_struct (die
, cu
, type
);
16614 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16615 snapshots) has been known to create a die giving a declaration
16616 for a class that has, as a child, a die giving a definition for a
16617 nested class. So we have to process our children even if the
16618 current die is a declaration. Normally, of course, a declaration
16619 won't have any children at all. */
16621 child_die
= die
->child
;
16623 while (child_die
!= NULL
&& child_die
->tag
)
16625 if (child_die
->tag
== DW_TAG_member
16626 || child_die
->tag
== DW_TAG_variable
16627 || child_die
->tag
== DW_TAG_inheritance
16628 || child_die
->tag
== DW_TAG_template_value_param
16629 || child_die
->tag
== DW_TAG_template_type_param
)
16634 process_die (child_die
, cu
);
16636 child_die
= child_die
->sibling
;
16639 /* Do not consider external references. According to the DWARF standard,
16640 these DIEs are identified by the fact that they have no byte_size
16641 attribute, and a declaration attribute. */
16642 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16643 || !die_is_declaration (die
, cu
)
16644 || dwarf2_attr (die
, DW_AT_signature
, cu
) != NULL
)
16646 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16648 if (has_template_parameters
)
16650 struct symtab
*symtab
;
16651 if (sym
!= nullptr)
16652 symtab
= symbol_symtab (sym
);
16653 else if (cu
->line_header
!= nullptr)
16655 /* Any related symtab will do. */
16657 = cu
->line_header
->file_names ()[0].symtab
;
16662 complaint (_("could not find suitable "
16663 "symtab for template parameter"
16664 " - DIE at %s [in module %s]"),
16665 sect_offset_str (die
->sect_off
),
16666 objfile_name (objfile
));
16669 if (symtab
!= nullptr)
16671 /* Make sure that the symtab is set on the new symbols.
16672 Even though they don't appear in this symtab directly,
16673 other parts of gdb assume that symbols do, and this is
16674 reasonably true. */
16675 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16676 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16682 /* Assuming DIE is an enumeration type, and TYPE is its associated
16683 type, update TYPE using some information only available in DIE's
16684 children. In particular, the fields are computed. */
16687 update_enumeration_type_from_children (struct die_info
*die
,
16689 struct dwarf2_cu
*cu
)
16691 struct die_info
*child_die
;
16692 int unsigned_enum
= 1;
16695 auto_obstack obstack
;
16696 std::vector
<struct field
> fields
;
16698 for (child_die
= die
->child
;
16699 child_die
!= NULL
&& child_die
->tag
;
16700 child_die
= child_die
->sibling
)
16702 struct attribute
*attr
;
16704 const gdb_byte
*bytes
;
16705 struct dwarf2_locexpr_baton
*baton
;
16708 if (child_die
->tag
!= DW_TAG_enumerator
)
16711 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16715 name
= dwarf2_name (child_die
, cu
);
16717 name
= "<anonymous enumerator>";
16719 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16720 &value
, &bytes
, &baton
);
16728 if (count_one_bits_ll (value
) >= 2)
16732 fields
.emplace_back ();
16733 struct field
&field
= fields
.back ();
16734 FIELD_NAME (field
) = dwarf2_physname (name
, child_die
, cu
);
16735 SET_FIELD_ENUMVAL (field
, value
);
16738 if (!fields
.empty ())
16740 type
->set_num_fields (fields
.size ());
16743 TYPE_ALLOC (type
, sizeof (struct field
) * fields
.size ()));
16744 memcpy (type
->fields (), fields
.data (),
16745 sizeof (struct field
) * fields
.size ());
16749 type
->set_is_unsigned (true);
16752 TYPE_FLAG_ENUM (type
) = 1;
16755 /* Given a DW_AT_enumeration_type die, set its type. We do not
16756 complete the type's fields yet, or create any symbols. */
16758 static struct type
*
16759 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16761 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
16763 struct attribute
*attr
;
16766 /* If the definition of this type lives in .debug_types, read that type.
16767 Don't follow DW_AT_specification though, that will take us back up
16768 the chain and we want to go down. */
16769 attr
= die
->attr (DW_AT_signature
);
16770 if (attr
!= nullptr)
16772 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16774 /* The type's CU may not be the same as CU.
16775 Ensure TYPE is recorded with CU in die_type_hash. */
16776 return set_die_type (die
, type
, cu
);
16779 type
= alloc_type (objfile
);
16781 type
->set_code (TYPE_CODE_ENUM
);
16782 name
= dwarf2_full_name (NULL
, die
, cu
);
16784 type
->set_name (name
);
16786 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16789 struct type
*underlying_type
= die_type (die
, cu
);
16791 TYPE_TARGET_TYPE (type
) = underlying_type
;
16794 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16795 if (attr
!= nullptr)
16797 TYPE_LENGTH (type
) = attr
->constant_value (0);
16801 TYPE_LENGTH (type
) = 0;
16804 maybe_set_alignment (cu
, die
, type
);
16806 /* The enumeration DIE can be incomplete. In Ada, any type can be
16807 declared as private in the package spec, and then defined only
16808 inside the package body. Such types are known as Taft Amendment
16809 Types. When another package uses such a type, an incomplete DIE
16810 may be generated by the compiler. */
16811 if (die_is_declaration (die
, cu
))
16812 type
->set_is_stub (true);
16814 /* If this type has an underlying type that is not a stub, then we
16815 may use its attributes. We always use the "unsigned" attribute
16816 in this situation, because ordinarily we guess whether the type
16817 is unsigned -- but the guess can be wrong and the underlying type
16818 can tell us the reality. However, we defer to a local size
16819 attribute if one exists, because this lets the compiler override
16820 the underlying type if needed. */
16821 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_TARGET_TYPE (type
)->is_stub ())
16823 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
16824 underlying_type
= check_typedef (underlying_type
);
16826 type
->set_is_unsigned (underlying_type
->is_unsigned ());
16828 if (TYPE_LENGTH (type
) == 0)
16829 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
16831 if (TYPE_RAW_ALIGN (type
) == 0
16832 && TYPE_RAW_ALIGN (underlying_type
) != 0)
16833 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
16836 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16838 set_die_type (die
, type
, cu
);
16840 /* Finish the creation of this type by using the enum's children.
16841 Note that, as usual, this must come after set_die_type to avoid
16842 infinite recursion when trying to compute the names of the
16844 update_enumeration_type_from_children (die
, type
, cu
);
16849 /* Given a pointer to a die which begins an enumeration, process all
16850 the dies that define the members of the enumeration, and create the
16851 symbol for the enumeration type.
16853 NOTE: We reverse the order of the element list. */
16856 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16858 struct type
*this_type
;
16860 this_type
= get_die_type (die
, cu
);
16861 if (this_type
== NULL
)
16862 this_type
= read_enumeration_type (die
, cu
);
16864 if (die
->child
!= NULL
)
16866 struct die_info
*child_die
;
16869 child_die
= die
->child
;
16870 while (child_die
&& child_die
->tag
)
16872 if (child_die
->tag
!= DW_TAG_enumerator
)
16874 process_die (child_die
, cu
);
16878 name
= dwarf2_name (child_die
, cu
);
16880 new_symbol (child_die
, this_type
, cu
);
16883 child_die
= child_die
->sibling
;
16887 /* If we are reading an enum from a .debug_types unit, and the enum
16888 is a declaration, and the enum is not the signatured type in the
16889 unit, then we do not want to add a symbol for it. Adding a
16890 symbol would in some cases obscure the true definition of the
16891 enum, giving users an incomplete type when the definition is
16892 actually available. Note that we do not want to do this for all
16893 enums which are just declarations, because C++0x allows forward
16894 enum declarations. */
16895 if (cu
->per_cu
->is_debug_types
16896 && die_is_declaration (die
, cu
))
16898 struct signatured_type
*sig_type
;
16900 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16901 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16902 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16906 new_symbol (die
, this_type
, cu
);
16909 /* Helper function for quirk_ada_thick_pointer that examines a bounds
16910 expression for an index type and finds the corresponding field
16911 offset in the hidden "P_BOUNDS" structure. Returns true on success
16912 and updates *FIELD, false if it fails to recognize an
16916 recognize_bound_expression (struct die_info
*die
, enum dwarf_attribute name
,
16917 int *bounds_offset
, struct field
*field
,
16918 struct dwarf2_cu
*cu
)
16920 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
16921 if (attr
== nullptr || !attr
->form_is_block ())
16924 const struct dwarf_block
*block
= attr
->as_block ();
16925 const gdb_byte
*start
= block
->data
;
16926 const gdb_byte
*end
= block
->data
+ block
->size
;
16928 /* The expression to recognize generally looks like:
16930 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16931 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
16933 However, the second "plus_uconst" may be missing:
16935 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
16936 DW_OP_deref_size: 4)
16938 This happens when the field is at the start of the structure.
16940 Also, the final deref may not be sized:
16942 (DW_OP_push_object_address; DW_OP_plus_uconst: 4; DW_OP_deref;
16945 This happens when the size of the index type happens to be the
16946 same as the architecture's word size. This can occur with or
16947 without the second plus_uconst. */
16949 if (end
- start
< 2)
16951 if (*start
++ != DW_OP_push_object_address
)
16953 if (*start
++ != DW_OP_plus_uconst
)
16956 uint64_t this_bound_off
;
16957 start
= gdb_read_uleb128 (start
, end
, &this_bound_off
);
16958 if (start
== nullptr || (int) this_bound_off
!= this_bound_off
)
16960 /* Update *BOUNDS_OFFSET if needed, or alternatively verify that it
16961 is consistent among all bounds. */
16962 if (*bounds_offset
== -1)
16963 *bounds_offset
= this_bound_off
;
16964 else if (*bounds_offset
!= this_bound_off
)
16967 if (start
== end
|| *start
++ != DW_OP_deref
)
16973 else if (*start
== DW_OP_deref_size
|| *start
== DW_OP_deref
)
16975 /* This means an offset of 0. */
16977 else if (*start
++ != DW_OP_plus_uconst
)
16981 /* The size is the parameter to DW_OP_plus_uconst. */
16983 start
= gdb_read_uleb128 (start
, end
, &val
);
16984 if (start
== nullptr)
16986 if ((int) val
!= val
)
16995 if (*start
== DW_OP_deref_size
)
16997 start
= gdb_read_uleb128 (start
+ 1, end
, &size
);
16998 if (start
== nullptr)
17001 else if (*start
== DW_OP_deref
)
17003 size
= cu
->header
.addr_size
;
17009 SET_FIELD_BITPOS (*field
, 8 * offset
);
17010 if (size
!= TYPE_LENGTH (field
->type ()))
17011 FIELD_BITSIZE (*field
) = 8 * size
;
17016 /* With -fgnat-encodings=minimal, gcc will emit some unusual DWARF for
17017 some kinds of Ada arrays:
17019 <1><11db>: Abbrev Number: 7 (DW_TAG_array_type)
17020 <11dc> DW_AT_name : (indirect string, offset: 0x1bb8): string
17021 <11e0> DW_AT_data_location: 2 byte block: 97 6
17022 (DW_OP_push_object_address; DW_OP_deref)
17023 <11e3> DW_AT_type : <0x1173>
17024 <11e7> DW_AT_sibling : <0x1201>
17025 <2><11eb>: Abbrev Number: 8 (DW_TAG_subrange_type)
17026 <11ec> DW_AT_type : <0x1206>
17027 <11f0> DW_AT_lower_bound : 6 byte block: 97 23 8 6 94 4
17028 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
17029 DW_OP_deref_size: 4)
17030 <11f7> DW_AT_upper_bound : 8 byte block: 97 23 8 6 23 4 94 4
17031 (DW_OP_push_object_address; DW_OP_plus_uconst: 8; DW_OP_deref;
17032 DW_OP_plus_uconst: 4; DW_OP_deref_size: 4)
17034 This actually represents a "thick pointer", which is a structure
17035 with two elements: one that is a pointer to the array data, and one
17036 that is a pointer to another structure; this second structure holds
17039 This returns a new type on success, or nullptr if this didn't
17040 recognize the type. */
17042 static struct type
*
17043 quirk_ada_thick_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
,
17046 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
17047 /* So far we've only seen this with block form. */
17048 if (attr
== nullptr || !attr
->form_is_block ())
17051 /* Note that this will fail if the structure layout is changed by
17052 the compiler. However, we have no good way to recognize some
17053 other layout, because we don't know what expression the compiler
17054 might choose to emit should this happen. */
17055 struct dwarf_block
*blk
= attr
->as_block ();
17057 || blk
->data
[0] != DW_OP_push_object_address
17058 || blk
->data
[1] != DW_OP_deref
)
17061 int bounds_offset
= -1;
17062 int max_align
= -1;
17063 std::vector
<struct field
> range_fields
;
17064 for (struct die_info
*child_die
= die
->child
;
17066 child_die
= child_die
->sibling
)
17068 if (child_die
->tag
== DW_TAG_subrange_type
)
17070 struct type
*underlying
= read_subrange_index_type (child_die
, cu
);
17072 int this_align
= type_align (underlying
);
17073 if (this_align
> max_align
)
17074 max_align
= this_align
;
17076 range_fields
.emplace_back ();
17077 range_fields
.emplace_back ();
17079 struct field
&lower
= range_fields
[range_fields
.size () - 2];
17080 struct field
&upper
= range_fields
[range_fields
.size () - 1];
17082 lower
.set_type (underlying
);
17083 FIELD_ARTIFICIAL (lower
) = 1;
17085 upper
.set_type (underlying
);
17086 FIELD_ARTIFICIAL (upper
) = 1;
17088 if (!recognize_bound_expression (child_die
, DW_AT_lower_bound
,
17089 &bounds_offset
, &lower
, cu
)
17090 || !recognize_bound_expression (child_die
, DW_AT_upper_bound
,
17091 &bounds_offset
, &upper
, cu
))
17096 /* This shouldn't really happen, but double-check that we found
17097 where the bounds are stored. */
17098 if (bounds_offset
== -1)
17101 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17102 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
17106 /* Set the name of each field in the bounds. */
17107 xsnprintf (name
, sizeof (name
), "LB%d", i
/ 2);
17108 FIELD_NAME (range_fields
[i
]) = objfile
->intern (name
);
17109 xsnprintf (name
, sizeof (name
), "UB%d", i
/ 2);
17110 FIELD_NAME (range_fields
[i
+ 1]) = objfile
->intern (name
);
17113 struct type
*bounds
= alloc_type (objfile
);
17114 bounds
->set_code (TYPE_CODE_STRUCT
);
17116 bounds
->set_num_fields (range_fields
.size ());
17118 ((struct field
*) TYPE_ALLOC (bounds
, (bounds
->num_fields ()
17119 * sizeof (struct field
))));
17120 memcpy (bounds
->fields (), range_fields
.data (),
17121 bounds
->num_fields () * sizeof (struct field
));
17123 int last_fieldno
= range_fields
.size () - 1;
17124 int bounds_size
= (TYPE_FIELD_BITPOS (bounds
, last_fieldno
) / 8
17125 + TYPE_LENGTH (bounds
->field (last_fieldno
).type ()));
17126 TYPE_LENGTH (bounds
) = align_up (bounds_size
, max_align
);
17128 /* Rewrite the existing array type in place. Specifically, we
17129 remove any dynamic properties we might have read, and we replace
17130 the index types. */
17131 struct type
*iter
= type
;
17132 for (int i
= 0; i
< range_fields
.size (); i
+= 2)
17134 gdb_assert (iter
->code () == TYPE_CODE_ARRAY
);
17135 iter
->main_type
->dyn_prop_list
= nullptr;
17136 iter
->set_index_type
17137 (create_static_range_type (NULL
, bounds
->field (i
).type (), 1, 0));
17138 iter
= TYPE_TARGET_TYPE (iter
);
17141 struct type
*result
= alloc_type (objfile
);
17142 result
->set_code (TYPE_CODE_STRUCT
);
17144 result
->set_num_fields (2);
17146 ((struct field
*) TYPE_ZALLOC (result
, (result
->num_fields ()
17147 * sizeof (struct field
))));
17149 /* The names are chosen to coincide with what the compiler does with
17150 -fgnat-encodings=all, which the Ada code in gdb already
17152 TYPE_FIELD_NAME (result
, 0) = "P_ARRAY";
17153 result
->field (0).set_type (lookup_pointer_type (type
));
17155 TYPE_FIELD_NAME (result
, 1) = "P_BOUNDS";
17156 result
->field (1).set_type (lookup_pointer_type (bounds
));
17157 SET_FIELD_BITPOS (result
->field (1), 8 * bounds_offset
);
17159 result
->set_name (type
->name ());
17160 TYPE_LENGTH (result
) = (TYPE_LENGTH (result
->field (0).type ())
17161 + TYPE_LENGTH (result
->field (1).type ()));
17166 /* Extract all information from a DW_TAG_array_type DIE and put it in
17167 the DIE's type field. For now, this only handles one dimensional
17170 static struct type
*
17171 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17173 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17174 struct die_info
*child_die
;
17176 struct type
*element_type
, *range_type
, *index_type
;
17177 struct attribute
*attr
;
17179 struct dynamic_prop
*byte_stride_prop
= NULL
;
17180 unsigned int bit_stride
= 0;
17182 element_type
= die_type (die
, cu
);
17184 /* The die_type call above may have already set the type for this DIE. */
17185 type
= get_die_type (die
, cu
);
17189 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17193 struct type
*prop_type
= cu
->addr_sized_int_type (false);
17196 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
17197 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
17201 complaint (_("unable to read array DW_AT_byte_stride "
17202 " - DIE at %s [in module %s]"),
17203 sect_offset_str (die
->sect_off
),
17204 objfile_name (cu
->per_objfile
->objfile
));
17205 /* Ignore this attribute. We will likely not be able to print
17206 arrays of this type correctly, but there is little we can do
17207 to help if we cannot read the attribute's value. */
17208 byte_stride_prop
= NULL
;
17212 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17214 bit_stride
= attr
->constant_value (0);
17216 /* Irix 6.2 native cc creates array types without children for
17217 arrays with unspecified length. */
17218 if (die
->child
== NULL
)
17220 index_type
= objfile_type (objfile
)->builtin_int
;
17221 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
17222 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
17223 byte_stride_prop
, bit_stride
);
17224 return set_die_type (die
, type
, cu
);
17227 std::vector
<struct type
*> range_types
;
17228 child_die
= die
->child
;
17229 while (child_die
&& child_die
->tag
)
17231 if (child_die
->tag
== DW_TAG_subrange_type
)
17233 struct type
*child_type
= read_type_die (child_die
, cu
);
17235 if (child_type
!= NULL
)
17237 /* The range type was succesfully read. Save it for the
17238 array type creation. */
17239 range_types
.push_back (child_type
);
17242 child_die
= child_die
->sibling
;
17245 if (range_types
.empty ())
17247 complaint (_("unable to find array range - DIE at %s [in module %s]"),
17248 sect_offset_str (die
->sect_off
),
17249 objfile_name (cu
->per_objfile
->objfile
));
17253 /* Dwarf2 dimensions are output from left to right, create the
17254 necessary array types in backwards order. */
17256 type
= element_type
;
17258 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
17262 while (i
< range_types
.size ())
17264 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
17265 byte_stride_prop
, bit_stride
);
17267 byte_stride_prop
= nullptr;
17272 size_t ndim
= range_types
.size ();
17275 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
17276 byte_stride_prop
, bit_stride
);
17278 byte_stride_prop
= nullptr;
17282 gdb_assert (type
!= element_type
);
17284 /* Understand Dwarf2 support for vector types (like they occur on
17285 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
17286 array type. This is not part of the Dwarf2/3 standard yet, but a
17287 custom vendor extension. The main difference between a regular
17288 array and the vector variant is that vectors are passed by value
17290 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
17291 if (attr
!= nullptr)
17292 make_vector_type (type
);
17294 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
17295 implementation may choose to implement triple vectors using this
17297 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17298 if (attr
!= nullptr && attr
->form_is_unsigned ())
17300 if (attr
->as_unsigned () >= TYPE_LENGTH (type
))
17301 TYPE_LENGTH (type
) = attr
->as_unsigned ();
17303 complaint (_("DW_AT_byte_size for array type smaller "
17304 "than the total size of elements"));
17307 name
= dwarf2_name (die
, cu
);
17309 type
->set_name (name
);
17311 maybe_set_alignment (cu
, die
, type
);
17313 struct type
*replacement_type
= nullptr;
17314 if (cu
->language
== language_ada
)
17316 replacement_type
= quirk_ada_thick_pointer (die
, cu
, type
);
17317 if (replacement_type
!= nullptr)
17318 type
= replacement_type
;
17321 /* Install the type in the die. */
17322 set_die_type (die
, type
, cu
, replacement_type
!= nullptr);
17324 /* set_die_type should be already done. */
17325 set_descriptive_type (type
, die
, cu
);
17330 static enum dwarf_array_dim_ordering
17331 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
17333 struct attribute
*attr
;
17335 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
17337 if (attr
!= nullptr)
17339 LONGEST val
= attr
->constant_value (-1);
17340 if (val
== DW_ORD_row_major
|| val
== DW_ORD_col_major
)
17341 return (enum dwarf_array_dim_ordering
) val
;
17344 /* GNU F77 is a special case, as at 08/2004 array type info is the
17345 opposite order to the dwarf2 specification, but data is still
17346 laid out as per normal fortran.
17348 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
17349 version checking. */
17351 if (cu
->language
== language_fortran
17352 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
17354 return DW_ORD_row_major
;
17357 switch (cu
->language_defn
->array_ordering ())
17359 case array_column_major
:
17360 return DW_ORD_col_major
;
17361 case array_row_major
:
17363 return DW_ORD_row_major
;
17367 /* Extract all information from a DW_TAG_set_type DIE and put it in
17368 the DIE's type field. */
17370 static struct type
*
17371 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17373 struct type
*domain_type
, *set_type
;
17374 struct attribute
*attr
;
17376 domain_type
= die_type (die
, cu
);
17378 /* The die_type call above may have already set the type for this DIE. */
17379 set_type
= get_die_type (die
, cu
);
17383 set_type
= create_set_type (NULL
, domain_type
);
17385 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17386 if (attr
!= nullptr && attr
->form_is_unsigned ())
17387 TYPE_LENGTH (set_type
) = attr
->as_unsigned ();
17389 maybe_set_alignment (cu
, die
, set_type
);
17391 return set_die_type (die
, set_type
, cu
);
17394 /* A helper for read_common_block that creates a locexpr baton.
17395 SYM is the symbol which we are marking as computed.
17396 COMMON_DIE is the DIE for the common block.
17397 COMMON_LOC is the location expression attribute for the common
17399 MEMBER_LOC is the location expression attribute for the particular
17400 member of the common block that we are processing.
17401 CU is the CU from which the above come. */
17404 mark_common_block_symbol_computed (struct symbol
*sym
,
17405 struct die_info
*common_die
,
17406 struct attribute
*common_loc
,
17407 struct attribute
*member_loc
,
17408 struct dwarf2_cu
*cu
)
17410 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
17411 struct objfile
*objfile
= per_objfile
->objfile
;
17412 struct dwarf2_locexpr_baton
*baton
;
17414 unsigned int cu_off
;
17415 enum bfd_endian byte_order
= gdbarch_byte_order (objfile
->arch ());
17416 LONGEST offset
= 0;
17418 gdb_assert (common_loc
&& member_loc
);
17419 gdb_assert (common_loc
->form_is_block ());
17420 gdb_assert (member_loc
->form_is_block ()
17421 || member_loc
->form_is_constant ());
17423 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
17424 baton
->per_objfile
= per_objfile
;
17425 baton
->per_cu
= cu
->per_cu
;
17426 gdb_assert (baton
->per_cu
);
17428 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
17430 if (member_loc
->form_is_constant ())
17432 offset
= member_loc
->constant_value (0);
17433 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
17436 baton
->size
+= member_loc
->as_block ()->size
;
17438 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
17441 *ptr
++ = DW_OP_call4
;
17442 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
17443 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
17446 if (member_loc
->form_is_constant ())
17448 *ptr
++ = DW_OP_addr
;
17449 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
17450 ptr
+= cu
->header
.addr_size
;
17454 /* We have to copy the data here, because DW_OP_call4 will only
17455 use a DW_AT_location attribute. */
17456 struct dwarf_block
*block
= member_loc
->as_block ();
17457 memcpy (ptr
, block
->data
, block
->size
);
17458 ptr
+= block
->size
;
17461 *ptr
++ = DW_OP_plus
;
17462 gdb_assert (ptr
- baton
->data
== baton
->size
);
17464 SYMBOL_LOCATION_BATON (sym
) = baton
;
17465 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
17468 /* Create appropriate locally-scoped variables for all the
17469 DW_TAG_common_block entries. Also create a struct common_block
17470 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
17471 is used to separate the common blocks name namespace from regular
17475 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
17477 struct attribute
*attr
;
17479 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17480 if (attr
!= nullptr)
17482 /* Support the .debug_loc offsets. */
17483 if (attr
->form_is_block ())
17487 else if (attr
->form_is_section_offset ())
17489 dwarf2_complex_location_expr_complaint ();
17494 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17495 "common block member");
17500 if (die
->child
!= NULL
)
17502 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17503 struct die_info
*child_die
;
17504 size_t n_entries
= 0, size
;
17505 struct common_block
*common_block
;
17506 struct symbol
*sym
;
17508 for (child_die
= die
->child
;
17509 child_die
&& child_die
->tag
;
17510 child_die
= child_die
->sibling
)
17513 size
= (sizeof (struct common_block
)
17514 + (n_entries
- 1) * sizeof (struct symbol
*));
17516 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17518 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17519 common_block
->n_entries
= 0;
17521 for (child_die
= die
->child
;
17522 child_die
&& child_die
->tag
;
17523 child_die
= child_die
->sibling
)
17525 /* Create the symbol in the DW_TAG_common_block block in the current
17527 sym
= new_symbol (child_die
, NULL
, cu
);
17530 struct attribute
*member_loc
;
17532 common_block
->contents
[common_block
->n_entries
++] = sym
;
17534 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17538 /* GDB has handled this for a long time, but it is
17539 not specified by DWARF. It seems to have been
17540 emitted by gfortran at least as recently as:
17541 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17542 complaint (_("Variable in common block has "
17543 "DW_AT_data_member_location "
17544 "- DIE at %s [in module %s]"),
17545 sect_offset_str (child_die
->sect_off
),
17546 objfile_name (objfile
));
17548 if (member_loc
->form_is_section_offset ())
17549 dwarf2_complex_location_expr_complaint ();
17550 else if (member_loc
->form_is_constant ()
17551 || member_loc
->form_is_block ())
17553 if (attr
!= nullptr)
17554 mark_common_block_symbol_computed (sym
, die
, attr
,
17558 dwarf2_complex_location_expr_complaint ();
17563 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17564 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17568 /* Create a type for a C++ namespace. */
17570 static struct type
*
17571 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17573 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17574 const char *previous_prefix
, *name
;
17578 /* For extensions, reuse the type of the original namespace. */
17579 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17581 struct die_info
*ext_die
;
17582 struct dwarf2_cu
*ext_cu
= cu
;
17584 ext_die
= dwarf2_extension (die
, &ext_cu
);
17585 type
= read_type_die (ext_die
, ext_cu
);
17587 /* EXT_CU may not be the same as CU.
17588 Ensure TYPE is recorded with CU in die_type_hash. */
17589 return set_die_type (die
, type
, cu
);
17592 name
= namespace_name (die
, &is_anonymous
, cu
);
17594 /* Now build the name of the current namespace. */
17596 previous_prefix
= determine_prefix (die
, cu
);
17597 if (previous_prefix
[0] != '\0')
17598 name
= typename_concat (&objfile
->objfile_obstack
,
17599 previous_prefix
, name
, 0, cu
);
17601 /* Create the type. */
17602 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17604 return set_die_type (die
, type
, cu
);
17607 /* Read a namespace scope. */
17610 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17612 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17615 /* Add a symbol associated to this if we haven't seen the namespace
17616 before. Also, add a using directive if it's an anonymous
17619 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17623 type
= read_type_die (die
, cu
);
17624 new_symbol (die
, type
, cu
);
17626 namespace_name (die
, &is_anonymous
, cu
);
17629 const char *previous_prefix
= determine_prefix (die
, cu
);
17631 std::vector
<const char *> excludes
;
17632 add_using_directive (using_directives (cu
),
17633 previous_prefix
, type
->name (), NULL
,
17634 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17638 if (die
->child
!= NULL
)
17640 struct die_info
*child_die
= die
->child
;
17642 while (child_die
&& child_die
->tag
)
17644 process_die (child_die
, cu
);
17645 child_die
= child_die
->sibling
;
17650 /* Read a Fortran module as type. This DIE can be only a declaration used for
17651 imported module. Still we need that type as local Fortran "use ... only"
17652 declaration imports depend on the created type in determine_prefix. */
17654 static struct type
*
17655 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17657 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17658 const char *module_name
;
17661 module_name
= dwarf2_name (die
, cu
);
17662 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17664 return set_die_type (die
, type
, cu
);
17667 /* Read a Fortran module. */
17670 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17672 struct die_info
*child_die
= die
->child
;
17675 type
= read_type_die (die
, cu
);
17676 new_symbol (die
, type
, cu
);
17678 while (child_die
&& child_die
->tag
)
17680 process_die (child_die
, cu
);
17681 child_die
= child_die
->sibling
;
17685 /* Return the name of the namespace represented by DIE. Set
17686 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17689 static const char *
17690 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17692 struct die_info
*current_die
;
17693 const char *name
= NULL
;
17695 /* Loop through the extensions until we find a name. */
17697 for (current_die
= die
;
17698 current_die
!= NULL
;
17699 current_die
= dwarf2_extension (die
, &cu
))
17701 /* We don't use dwarf2_name here so that we can detect the absence
17702 of a name -> anonymous namespace. */
17703 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17709 /* Is it an anonymous namespace? */
17711 *is_anonymous
= (name
== NULL
);
17713 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17718 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17719 the user defined type vector. */
17721 static struct type
*
17722 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17724 struct gdbarch
*gdbarch
= cu
->per_objfile
->objfile
->arch ();
17725 struct comp_unit_head
*cu_header
= &cu
->header
;
17727 struct attribute
*attr_byte_size
;
17728 struct attribute
*attr_address_class
;
17729 int byte_size
, addr_class
;
17730 struct type
*target_type
;
17732 target_type
= die_type (die
, cu
);
17734 /* The die_type call above may have already set the type for this DIE. */
17735 type
= get_die_type (die
, cu
);
17739 type
= lookup_pointer_type (target_type
);
17741 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17742 if (attr_byte_size
)
17743 byte_size
= attr_byte_size
->constant_value (cu_header
->addr_size
);
17745 byte_size
= cu_header
->addr_size
;
17747 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17748 if (attr_address_class
)
17749 addr_class
= attr_address_class
->constant_value (DW_ADDR_none
);
17751 addr_class
= DW_ADDR_none
;
17753 ULONGEST alignment
= get_alignment (cu
, die
);
17755 /* If the pointer size, alignment, or address class is different
17756 than the default, create a type variant marked as such and set
17757 the length accordingly. */
17758 if (TYPE_LENGTH (type
) != byte_size
17759 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17760 && alignment
!= TYPE_RAW_ALIGN (type
))
17761 || addr_class
!= DW_ADDR_none
)
17763 if (gdbarch_address_class_type_flags_p (gdbarch
))
17765 type_instance_flags type_flags
17766 = gdbarch_address_class_type_flags (gdbarch
, byte_size
,
17768 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17770 type
= make_type_with_address_space (type
, type_flags
);
17772 else if (TYPE_LENGTH (type
) != byte_size
)
17774 complaint (_("invalid pointer size %d"), byte_size
);
17776 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17778 complaint (_("Invalid DW_AT_alignment"
17779 " - DIE at %s [in module %s]"),
17780 sect_offset_str (die
->sect_off
),
17781 objfile_name (cu
->per_objfile
->objfile
));
17785 /* Should we also complain about unhandled address classes? */
17789 TYPE_LENGTH (type
) = byte_size
;
17790 set_type_align (type
, alignment
);
17791 return set_die_type (die
, type
, cu
);
17794 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17795 the user defined type vector. */
17797 static struct type
*
17798 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17801 struct type
*to_type
;
17802 struct type
*domain
;
17804 to_type
= die_type (die
, cu
);
17805 domain
= die_containing_type (die
, cu
);
17807 /* The calls above may have already set the type for this DIE. */
17808 type
= get_die_type (die
, cu
);
17812 if (check_typedef (to_type
)->code () == TYPE_CODE_METHOD
)
17813 type
= lookup_methodptr_type (to_type
);
17814 else if (check_typedef (to_type
)->code () == TYPE_CODE_FUNC
)
17816 struct type
*new_type
= alloc_type (cu
->per_objfile
->objfile
);
17818 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17819 to_type
->fields (), to_type
->num_fields (),
17820 to_type
->has_varargs ());
17821 type
= lookup_methodptr_type (new_type
);
17824 type
= lookup_memberptr_type (to_type
, domain
);
17826 return set_die_type (die
, type
, cu
);
17829 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17830 the user defined type vector. */
17832 static struct type
*
17833 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17834 enum type_code refcode
)
17836 struct comp_unit_head
*cu_header
= &cu
->header
;
17837 struct type
*type
, *target_type
;
17838 struct attribute
*attr
;
17840 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17842 target_type
= die_type (die
, cu
);
17844 /* The die_type call above may have already set the type for this DIE. */
17845 type
= get_die_type (die
, cu
);
17849 type
= lookup_reference_type (target_type
, refcode
);
17850 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17851 if (attr
!= nullptr)
17853 TYPE_LENGTH (type
) = attr
->constant_value (cu_header
->addr_size
);
17857 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17859 maybe_set_alignment (cu
, die
, type
);
17860 return set_die_type (die
, type
, cu
);
17863 /* Add the given cv-qualifiers to the element type of the array. GCC
17864 outputs DWARF type qualifiers that apply to an array, not the
17865 element type. But GDB relies on the array element type to carry
17866 the cv-qualifiers. This mimics section 6.7.3 of the C99
17869 static struct type
*
17870 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17871 struct type
*base_type
, int cnst
, int voltl
)
17873 struct type
*el_type
, *inner_array
;
17875 base_type
= copy_type (base_type
);
17876 inner_array
= base_type
;
17878 while (TYPE_TARGET_TYPE (inner_array
)->code () == TYPE_CODE_ARRAY
)
17880 TYPE_TARGET_TYPE (inner_array
) =
17881 copy_type (TYPE_TARGET_TYPE (inner_array
));
17882 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17885 el_type
= TYPE_TARGET_TYPE (inner_array
);
17886 cnst
|= TYPE_CONST (el_type
);
17887 voltl
|= TYPE_VOLATILE (el_type
);
17888 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17890 return set_die_type (die
, base_type
, cu
);
17893 static struct type
*
17894 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17896 struct type
*base_type
, *cv_type
;
17898 base_type
= die_type (die
, cu
);
17900 /* The die_type call above may have already set the type for this DIE. */
17901 cv_type
= get_die_type (die
, cu
);
17905 /* In case the const qualifier is applied to an array type, the element type
17906 is so qualified, not the array type (section 6.7.3 of C99). */
17907 if (base_type
->code () == TYPE_CODE_ARRAY
)
17908 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17910 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17911 return set_die_type (die
, cv_type
, cu
);
17914 static struct type
*
17915 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17917 struct type
*base_type
, *cv_type
;
17919 base_type
= die_type (die
, cu
);
17921 /* The die_type call above may have already set the type for this DIE. */
17922 cv_type
= get_die_type (die
, cu
);
17926 /* In case the volatile qualifier is applied to an array type, the
17927 element type is so qualified, not the array type (section 6.7.3
17929 if (base_type
->code () == TYPE_CODE_ARRAY
)
17930 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17932 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17933 return set_die_type (die
, cv_type
, cu
);
17936 /* Handle DW_TAG_restrict_type. */
17938 static struct type
*
17939 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17941 struct type
*base_type
, *cv_type
;
17943 base_type
= die_type (die
, cu
);
17945 /* The die_type call above may have already set the type for this DIE. */
17946 cv_type
= get_die_type (die
, cu
);
17950 cv_type
= make_restrict_type (base_type
);
17951 return set_die_type (die
, cv_type
, cu
);
17954 /* Handle DW_TAG_atomic_type. */
17956 static struct type
*
17957 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17959 struct type
*base_type
, *cv_type
;
17961 base_type
= die_type (die
, cu
);
17963 /* The die_type call above may have already set the type for this DIE. */
17964 cv_type
= get_die_type (die
, cu
);
17968 cv_type
= make_atomic_type (base_type
);
17969 return set_die_type (die
, cv_type
, cu
);
17972 /* Extract all information from a DW_TAG_string_type DIE and add to
17973 the user defined type vector. It isn't really a user defined type,
17974 but it behaves like one, with other DIE's using an AT_user_def_type
17975 attribute to reference it. */
17977 static struct type
*
17978 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17980 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
17981 struct gdbarch
*gdbarch
= objfile
->arch ();
17982 struct type
*type
, *range_type
, *index_type
, *char_type
;
17983 struct attribute
*attr
;
17984 struct dynamic_prop prop
;
17985 bool length_is_constant
= true;
17988 /* There are a couple of places where bit sizes might be made use of
17989 when parsing a DW_TAG_string_type, however, no producer that we know
17990 of make use of these. Handling bit sizes that are a multiple of the
17991 byte size is easy enough, but what about other bit sizes? Lets deal
17992 with that problem when we have to. Warn about these attributes being
17993 unsupported, then parse the type and ignore them like we always
17995 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17996 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17998 static bool warning_printed
= false;
17999 if (!warning_printed
)
18001 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
18002 "currently supported on DW_TAG_string_type."));
18003 warning_printed
= true;
18007 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
18008 if (attr
!= nullptr && !attr
->form_is_constant ())
18010 /* The string length describes the location at which the length of
18011 the string can be found. The size of the length field can be
18012 specified with one of the attributes below. */
18013 struct type
*prop_type
;
18014 struct attribute
*len
18015 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
18016 if (len
== nullptr)
18017 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18018 if (len
!= nullptr && len
->form_is_constant ())
18020 /* Pass 0 as the default as we know this attribute is constant
18021 and the default value will not be returned. */
18022 LONGEST sz
= len
->constant_value (0);
18023 prop_type
= cu
->per_objfile
->int_type (sz
, true);
18027 /* If the size is not specified then we assume it is the size of
18028 an address on this target. */
18029 prop_type
= cu
->addr_sized_int_type (true);
18032 /* Convert the attribute into a dynamic property. */
18033 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
18036 length_is_constant
= false;
18038 else if (attr
!= nullptr)
18040 /* This DW_AT_string_length just contains the length with no
18041 indirection. There's no need to create a dynamic property in this
18042 case. Pass 0 for the default value as we know it will not be
18043 returned in this case. */
18044 length
= attr
->constant_value (0);
18046 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
18048 /* We don't currently support non-constant byte sizes for strings. */
18049 length
= attr
->constant_value (1);
18053 /* Use 1 as a fallback length if we have nothing else. */
18057 index_type
= objfile_type (objfile
)->builtin_int
;
18058 if (length_is_constant
)
18059 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
18062 struct dynamic_prop low_bound
;
18064 low_bound
.set_const_val (1);
18065 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
18067 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
18068 type
= create_string_type (NULL
, char_type
, range_type
);
18070 return set_die_type (die
, type
, cu
);
18073 /* Assuming that DIE corresponds to a function, returns nonzero
18074 if the function is prototyped. */
18077 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
18079 struct attribute
*attr
;
18081 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
18082 if (attr
&& attr
->as_boolean ())
18085 /* The DWARF standard implies that the DW_AT_prototyped attribute
18086 is only meaningful for C, but the concept also extends to other
18087 languages that allow unprototyped functions (Eg: Objective C).
18088 For all other languages, assume that functions are always
18090 if (cu
->language
!= language_c
18091 && cu
->language
!= language_objc
18092 && cu
->language
!= language_opencl
)
18095 /* RealView does not emit DW_AT_prototyped. We can not distinguish
18096 prototyped and unprototyped functions; default to prototyped,
18097 since that is more common in modern code (and RealView warns
18098 about unprototyped functions). */
18099 if (producer_is_realview (cu
->producer
))
18105 /* Handle DIES due to C code like:
18109 int (*funcp)(int a, long l);
18113 ('funcp' generates a DW_TAG_subroutine_type DIE). */
18115 static struct type
*
18116 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18118 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18119 struct type
*type
; /* Type that this function returns. */
18120 struct type
*ftype
; /* Function that returns above type. */
18121 struct attribute
*attr
;
18123 type
= die_type (die
, cu
);
18125 /* The die_type call above may have already set the type for this DIE. */
18126 ftype
= get_die_type (die
, cu
);
18130 ftype
= lookup_function_type (type
);
18132 if (prototyped_function_p (die
, cu
))
18133 ftype
->set_is_prototyped (true);
18135 /* Store the calling convention in the type if it's available in
18136 the subroutine die. Otherwise set the calling convention to
18137 the default value DW_CC_normal. */
18138 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
18139 if (attr
!= nullptr
18140 && is_valid_DW_AT_calling_convention_for_subroutine (attr
->constant_value (0)))
18141 TYPE_CALLING_CONVENTION (ftype
)
18142 = (enum dwarf_calling_convention
) attr
->constant_value (0);
18143 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
18144 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
18146 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
18148 /* Record whether the function returns normally to its caller or not
18149 if the DWARF producer set that information. */
18150 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
18151 if (attr
&& attr
->as_boolean ())
18152 TYPE_NO_RETURN (ftype
) = 1;
18154 /* We need to add the subroutine type to the die immediately so
18155 we don't infinitely recurse when dealing with parameters
18156 declared as the same subroutine type. */
18157 set_die_type (die
, ftype
, cu
);
18159 if (die
->child
!= NULL
)
18161 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
18162 struct die_info
*child_die
;
18163 int nparams
, iparams
;
18165 /* Count the number of parameters.
18166 FIXME: GDB currently ignores vararg functions, but knows about
18167 vararg member functions. */
18169 child_die
= die
->child
;
18170 while (child_die
&& child_die
->tag
)
18172 if (child_die
->tag
== DW_TAG_formal_parameter
)
18174 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
18175 ftype
->set_has_varargs (true);
18177 child_die
= child_die
->sibling
;
18180 /* Allocate storage for parameters and fill them in. */
18181 ftype
->set_num_fields (nparams
);
18183 ((struct field
*) TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
)));
18185 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
18186 even if we error out during the parameters reading below. */
18187 for (iparams
= 0; iparams
< nparams
; iparams
++)
18188 ftype
->field (iparams
).set_type (void_type
);
18191 child_die
= die
->child
;
18192 while (child_die
&& child_die
->tag
)
18194 if (child_die
->tag
== DW_TAG_formal_parameter
)
18196 struct type
*arg_type
;
18198 /* DWARF version 2 has no clean way to discern C++
18199 static and non-static member functions. G++ helps
18200 GDB by marking the first parameter for non-static
18201 member functions (which is the this pointer) as
18202 artificial. We pass this information to
18203 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
18205 DWARF version 3 added DW_AT_object_pointer, which GCC
18206 4.5 does not yet generate. */
18207 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
18208 if (attr
!= nullptr)
18209 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = attr
->as_boolean ();
18211 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
18212 arg_type
= die_type (child_die
, cu
);
18214 /* RealView does not mark THIS as const, which the testsuite
18215 expects. GCC marks THIS as const in method definitions,
18216 but not in the class specifications (GCC PR 43053). */
18217 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
18218 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
18221 struct dwarf2_cu
*arg_cu
= cu
;
18222 const char *name
= dwarf2_name (child_die
, cu
);
18224 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
18225 if (attr
!= nullptr)
18227 /* If the compiler emits this, use it. */
18228 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
18231 else if (name
&& strcmp (name
, "this") == 0)
18232 /* Function definitions will have the argument names. */
18234 else if (name
== NULL
&& iparams
== 0)
18235 /* Declarations may not have the names, so like
18236 elsewhere in GDB, assume an artificial first
18237 argument is "this". */
18241 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
18245 ftype
->field (iparams
).set_type (arg_type
);
18248 child_die
= child_die
->sibling
;
18255 static struct type
*
18256 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
18258 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18259 const char *name
= NULL
;
18260 struct type
*this_type
, *target_type
;
18262 name
= dwarf2_full_name (NULL
, die
, cu
);
18263 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
18264 this_type
->set_target_is_stub (true);
18265 set_die_type (die
, this_type
, cu
);
18266 target_type
= die_type (die
, cu
);
18267 if (target_type
!= this_type
)
18268 TYPE_TARGET_TYPE (this_type
) = target_type
;
18271 /* Self-referential typedefs are, it seems, not allowed by the DWARF
18272 spec and cause infinite loops in GDB. */
18273 complaint (_("Self-referential DW_TAG_typedef "
18274 "- DIE at %s [in module %s]"),
18275 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
18276 TYPE_TARGET_TYPE (this_type
) = NULL
;
18280 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
18281 anonymous typedefs, which is, strictly speaking, invalid DWARF.
18282 Handle these by just returning the target type, rather than
18283 constructing an anonymous typedef type and trying to handle this
18285 set_die_type (die
, target_type
, cu
);
18286 return target_type
;
18291 /* Helper for get_dwarf2_rational_constant that computes the value of
18292 a given gmp_mpz given an attribute. */
18295 get_mpz (struct dwarf2_cu
*cu
, gdb_mpz
*value
, struct attribute
*attr
)
18297 /* GCC will sometimes emit a 16-byte constant value as a DWARF
18298 location expression that pushes an implicit value. */
18299 if (attr
->form
== DW_FORM_exprloc
)
18301 dwarf_block
*blk
= attr
->as_block ();
18302 if (blk
->size
> 0 && blk
->data
[0] == DW_OP_implicit_value
)
18305 const gdb_byte
*ptr
= safe_read_uleb128 (blk
->data
+ 1,
18306 blk
->data
+ blk
->size
,
18308 if (ptr
- blk
->data
+ len
<= blk
->size
)
18310 mpz_import (value
->val
, len
,
18311 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
18317 /* On failure set it to 1. */
18318 *value
= gdb_mpz (1);
18320 else if (attr
->form_is_block ())
18322 dwarf_block
*blk
= attr
->as_block ();
18323 mpz_import (value
->val
, blk
->size
,
18324 bfd_big_endian (cu
->per_objfile
->objfile
->obfd
) ? 1 : -1,
18325 1, 0, 0, blk
->data
);
18328 *value
= gdb_mpz (attr
->constant_value (1));
18331 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's
18332 numerator and denominator into NUMERATOR and DENOMINATOR (resp).
18334 If the numerator and/or numerator attribute is missing,
18335 a complaint is filed, and NUMERATOR and DENOMINATOR are left
18339 get_dwarf2_rational_constant (struct die_info
*die
, struct dwarf2_cu
*cu
,
18340 gdb_mpz
*numerator
, gdb_mpz
*denominator
)
18342 struct attribute
*num_attr
, *denom_attr
;
18344 num_attr
= dwarf2_attr (die
, DW_AT_GNU_numerator
, cu
);
18345 if (num_attr
== nullptr)
18346 complaint (_("DW_AT_GNU_numerator missing in %s DIE at %s"),
18347 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18349 denom_attr
= dwarf2_attr (die
, DW_AT_GNU_denominator
, cu
);
18350 if (denom_attr
== nullptr)
18351 complaint (_("DW_AT_GNU_denominator missing in %s DIE at %s"),
18352 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18354 if (num_attr
== nullptr || denom_attr
== nullptr)
18357 get_mpz (cu
, numerator
, num_attr
);
18358 get_mpz (cu
, denominator
, denom_attr
);
18361 /* Same as get_dwarf2_rational_constant, but extracting an unsigned
18362 rational constant, rather than a signed one.
18364 If the rational constant has a negative value, a complaint
18365 is filed, and NUMERATOR and DENOMINATOR are left untouched. */
18368 get_dwarf2_unsigned_rational_constant (struct die_info
*die
,
18369 struct dwarf2_cu
*cu
,
18370 gdb_mpz
*numerator
,
18371 gdb_mpz
*denominator
)
18376 get_dwarf2_rational_constant (die
, cu
, &num
, &denom
);
18377 if (mpz_sgn (num
.val
) == -1 && mpz_sgn (denom
.val
) == -1)
18379 mpz_neg (num
.val
, num
.val
);
18380 mpz_neg (denom
.val
, denom
.val
);
18382 else if (mpz_sgn (num
.val
) == -1)
18384 complaint (_("unexpected negative value for DW_AT_GNU_numerator"
18386 sect_offset_str (die
->sect_off
));
18389 else if (mpz_sgn (denom
.val
) == -1)
18391 complaint (_("unexpected negative value for DW_AT_GNU_denominator"
18393 sect_offset_str (die
->sect_off
));
18397 *numerator
= std::move (num
);
18398 *denominator
= std::move (denom
);
18401 /* Assuming that ENCODING is a string whose contents starting at the
18402 K'th character is "_nn" where "nn" is a decimal number, scan that
18403 number and set RESULT to the value. K is updated to point to the
18404 character immediately following the number.
18406 If the string does not conform to the format described above, false
18407 is returned, and K may or may not be changed. */
18410 ada_get_gnat_encoded_number (const char *encoding
, int &k
, gdb_mpz
*result
)
18412 /* The next character should be an underscore ('_') followed
18414 if (encoding
[k
] != '_' || !isdigit (encoding
[k
+ 1]))
18417 /* Skip the underscore. */
18421 /* Determine the number of digits for our number. */
18422 while (isdigit (encoding
[k
]))
18427 std::string
copy (&encoding
[start
], k
- start
);
18428 if (mpz_set_str (result
->val
, copy
.c_str (), 10) == -1)
18434 /* Scan two numbers from ENCODING at OFFSET, assuming the string is of
18435 the form _NN_DD, where NN and DD are decimal numbers. Set NUM and
18436 DENOM, update OFFSET, and return true on success. Return false on
18440 ada_get_gnat_encoded_ratio (const char *encoding
, int &offset
,
18441 gdb_mpz
*num
, gdb_mpz
*denom
)
18443 if (!ada_get_gnat_encoded_number (encoding
, offset
, num
))
18445 return ada_get_gnat_encoded_number (encoding
, offset
, denom
);
18448 /* Assuming DIE corresponds to a fixed point type, finish the creation
18449 of the corresponding TYPE by setting its type-specific data. CU is
18450 the DIE's CU. SUFFIX is the "XF" type name suffix coming from GNAT
18451 encodings. It is nullptr if the GNAT encoding should be
18455 finish_fixed_point_type (struct type
*type
, const char *suffix
,
18456 struct die_info
*die
, struct dwarf2_cu
*cu
)
18458 gdb_assert (type
->code () == TYPE_CODE_FIXED_POINT
18459 && TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_FIXED_POINT
);
18461 /* If GNAT encodings are preferred, don't examine the
18463 struct attribute
*attr
= nullptr;
18464 if (suffix
== nullptr)
18466 attr
= dwarf2_attr (die
, DW_AT_binary_scale
, cu
);
18467 if (attr
== nullptr)
18468 attr
= dwarf2_attr (die
, DW_AT_decimal_scale
, cu
);
18469 if (attr
== nullptr)
18470 attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18473 /* Numerator and denominator of our fixed-point type's scaling factor.
18474 The default is a scaling factor of 1, which we use as a fallback
18475 when we are not able to decode it (problem with the debugging info,
18476 unsupported forms, bug in GDB, etc...). Using that as the default
18477 allows us to at least print the unscaled value, which might still
18478 be useful to a user. */
18479 gdb_mpz
scale_num (1);
18480 gdb_mpz
scale_denom (1);
18482 if (attr
== nullptr)
18485 if (suffix
!= nullptr
18486 && ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
18488 /* The number might be encoded as _nn_dd_nn_dd, where the
18489 second ratio is the 'small value. In this situation, we
18490 want the second value. */
18491 && (suffix
[offset
] != '_'
18492 || ada_get_gnat_encoded_ratio (suffix
, offset
, &scale_num
,
18499 /* Scaling factor not found. Assume a scaling factor of 1,
18500 and hope for the best. At least the user will be able to
18501 see the encoded value. */
18504 complaint (_("no scale found for fixed-point type (DIE at %s)"),
18505 sect_offset_str (die
->sect_off
));
18508 else if (attr
->name
== DW_AT_binary_scale
)
18510 LONGEST scale_exp
= attr
->constant_value (0);
18511 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18513 mpz_mul_2exp (num_or_denom
->val
, num_or_denom
->val
, std::abs (scale_exp
));
18515 else if (attr
->name
== DW_AT_decimal_scale
)
18517 LONGEST scale_exp
= attr
->constant_value (0);
18518 gdb_mpz
*num_or_denom
= scale_exp
> 0 ? &scale_num
: &scale_denom
;
18520 mpz_ui_pow_ui (num_or_denom
->val
, 10, std::abs (scale_exp
));
18522 else if (attr
->name
== DW_AT_small
)
18524 struct die_info
*scale_die
;
18525 struct dwarf2_cu
*scale_cu
= cu
;
18527 scale_die
= follow_die_ref (die
, attr
, &scale_cu
);
18528 if (scale_die
->tag
== DW_TAG_constant
)
18529 get_dwarf2_unsigned_rational_constant (scale_die
, scale_cu
,
18530 &scale_num
, &scale_denom
);
18532 complaint (_("%s DIE not supported as target of DW_AT_small attribute"
18534 dwarf_tag_name (die
->tag
), sect_offset_str (die
->sect_off
));
18538 complaint (_("unsupported scale attribute %s for fixed-point type"
18540 dwarf_attr_name (attr
->name
),
18541 sect_offset_str (die
->sect_off
));
18544 gdb_mpq
&scaling_factor
= type
->fixed_point_info ().scaling_factor
;
18545 mpz_set (mpq_numref (scaling_factor
.val
), scale_num
.val
);
18546 mpz_set (mpq_denref (scaling_factor
.val
), scale_denom
.val
);
18547 mpq_canonicalize (scaling_factor
.val
);
18550 /* The gnat-encoding suffix for fixed point. */
18552 #define GNAT_FIXED_POINT_SUFFIX "___XF_"
18554 /* If NAME encodes an Ada fixed-point type, return a pointer to the
18555 "XF" suffix of the name. The text after this is what encodes the
18556 'small and 'delta information. Otherwise, return nullptr. */
18558 static const char *
18559 gnat_encoded_fixed_point_type_info (const char *name
)
18561 return strstr (name
, GNAT_FIXED_POINT_SUFFIX
);
18564 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
18565 (which may be different from NAME) to the architecture back-end to allow
18566 it to guess the correct format if necessary. */
18568 static struct type
*
18569 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
18570 const char *name_hint
, enum bfd_endian byte_order
)
18572 struct gdbarch
*gdbarch
= objfile
->arch ();
18573 const struct floatformat
**format
;
18576 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
18578 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
18580 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18585 /* Allocate an integer type of size BITS and name NAME. */
18587 static struct type
*
18588 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
18589 int bits
, int unsigned_p
, const char *name
)
18593 /* Versions of Intel's C Compiler generate an integer type called "void"
18594 instead of using DW_TAG_unspecified_type. This has been seen on
18595 at least versions 14, 17, and 18. */
18596 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
18597 && strcmp (name
, "void") == 0)
18598 type
= objfile_type (objfile
)->builtin_void
;
18600 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
18605 /* Return true if DIE has a DW_AT_small attribute whose value is
18606 a constant rational, where both the numerator and denominator
18609 CU is the DIE's Compilation Unit. */
18612 has_zero_over_zero_small_attribute (struct die_info
*die
,
18613 struct dwarf2_cu
*cu
)
18615 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_small
, cu
);
18616 if (attr
== nullptr)
18619 struct dwarf2_cu
*scale_cu
= cu
;
18620 struct die_info
*scale_die
18621 = follow_die_ref (die
, attr
, &scale_cu
);
18623 if (scale_die
->tag
!= DW_TAG_constant
)
18626 gdb_mpz
num (1), denom (1);
18627 get_dwarf2_rational_constant (scale_die
, cu
, &num
, &denom
);
18628 return mpz_sgn (num
.val
) == 0 && mpz_sgn (denom
.val
) == 0;
18631 /* Initialise and return a floating point type of size BITS suitable for
18632 use as a component of a complex number. The NAME_HINT is passed through
18633 when initialising the floating point type and is the name of the complex
18636 As DWARF doesn't currently provide an explicit name for the components
18637 of a complex number, but it can be helpful to have these components
18638 named, we try to select a suitable name based on the size of the
18640 static struct type
*
18641 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
18642 struct objfile
*objfile
,
18643 int bits
, const char *name_hint
,
18644 enum bfd_endian byte_order
)
18646 gdbarch
*gdbarch
= objfile
->arch ();
18647 struct type
*tt
= nullptr;
18649 /* Try to find a suitable floating point builtin type of size BITS.
18650 We're going to use the name of this type as the name for the complex
18651 target type that we are about to create. */
18652 switch (cu
->language
)
18654 case language_fortran
:
18658 tt
= builtin_f_type (gdbarch
)->builtin_real
;
18661 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
18663 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18665 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
18673 tt
= builtin_type (gdbarch
)->builtin_float
;
18676 tt
= builtin_type (gdbarch
)->builtin_double
;
18678 case 96: /* The x86-32 ABI specifies 96-bit long double. */
18680 tt
= builtin_type (gdbarch
)->builtin_long_double
;
18686 /* If the type we found doesn't match the size we were looking for, then
18687 pretend we didn't find a type at all, the complex target type we
18688 create will then be nameless. */
18689 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
18692 const char *name
= (tt
== nullptr) ? nullptr : tt
->name ();
18693 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
18696 /* Find a representation of a given base type and install
18697 it in the TYPE field of the die. */
18699 static struct type
*
18700 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18702 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
18704 struct attribute
*attr
;
18705 int encoding
= 0, bits
= 0;
18709 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
18710 if (attr
!= nullptr && attr
->form_is_constant ())
18711 encoding
= attr
->constant_value (0);
18712 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18713 if (attr
!= nullptr)
18714 bits
= attr
->constant_value (0) * TARGET_CHAR_BIT
;
18715 name
= dwarf2_name (die
, cu
);
18717 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
18719 arch
= objfile
->arch ();
18720 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
18722 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
18723 if (attr
!= nullptr && attr
->form_is_constant ())
18725 int endianity
= attr
->constant_value (0);
18730 byte_order
= BFD_ENDIAN_BIG
;
18732 case DW_END_little
:
18733 byte_order
= BFD_ENDIAN_LITTLE
;
18736 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
18741 if ((encoding
== DW_ATE_signed_fixed
|| encoding
== DW_ATE_unsigned_fixed
)
18742 && cu
->language
== language_ada
18743 && has_zero_over_zero_small_attribute (die
, cu
))
18745 /* brobecker/2018-02-24: This is a fixed point type for which
18746 the scaling factor is represented as fraction whose value
18747 does not make sense (zero divided by zero), so we should
18748 normally never see these. However, there is a small category
18749 of fixed point types for which GNAT is unable to provide
18750 the scaling factor via the standard DWARF mechanisms, and
18751 for which the info is provided via the GNAT encodings instead.
18752 This is likely what this DIE is about. */
18753 encoding
= (encoding
== DW_ATE_signed_fixed
18755 : DW_ATE_unsigned
);
18758 /* With GNAT encodings, fixed-point information will be encoded in
18759 the type name. Note that this can also occur with the above
18760 zero-over-zero case, which is why this is a separate "if" rather
18761 than an "else if". */
18762 const char *gnat_encoding_suffix
= nullptr;
18763 if ((encoding
== DW_ATE_signed
|| encoding
== DW_ATE_unsigned
)
18764 && cu
->language
== language_ada
18765 && name
!= nullptr)
18767 gnat_encoding_suffix
= gnat_encoded_fixed_point_type_info (name
);
18768 if (gnat_encoding_suffix
!= nullptr)
18770 gdb_assert (startswith (gnat_encoding_suffix
,
18771 GNAT_FIXED_POINT_SUFFIX
));
18772 name
= obstack_strndup (&cu
->per_objfile
->objfile
->objfile_obstack
,
18773 name
, gnat_encoding_suffix
- name
);
18774 /* Use -1 here so that SUFFIX points at the "_" after the
18776 gnat_encoding_suffix
+= strlen (GNAT_FIXED_POINT_SUFFIX
) - 1;
18778 encoding
= (encoding
== DW_ATE_signed
18779 ? DW_ATE_signed_fixed
18780 : DW_ATE_unsigned_fixed
);
18786 case DW_ATE_address
:
18787 /* Turn DW_ATE_address into a void * pointer. */
18788 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
18789 type
= init_pointer_type (objfile
, bits
, name
, type
);
18791 case DW_ATE_boolean
:
18792 type
= init_boolean_type (objfile
, bits
, 1, name
);
18794 case DW_ATE_complex_float
:
18795 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
18797 if (type
->code () == TYPE_CODE_ERROR
)
18799 if (name
== nullptr)
18801 struct obstack
*obstack
18802 = &cu
->per_objfile
->objfile
->objfile_obstack
;
18803 name
= obconcat (obstack
, "_Complex ", type
->name (),
18806 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18809 type
= init_complex_type (name
, type
);
18811 case DW_ATE_decimal_float
:
18812 type
= init_decfloat_type (objfile
, bits
, name
);
18815 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
18817 case DW_ATE_signed
:
18818 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18820 case DW_ATE_unsigned
:
18821 if (cu
->language
== language_fortran
18823 && startswith (name
, "character("))
18824 type
= init_character_type (objfile
, bits
, 1, name
);
18826 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18828 case DW_ATE_signed_char
:
18829 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18830 || cu
->language
== language_pascal
18831 || cu
->language
== language_fortran
)
18832 type
= init_character_type (objfile
, bits
, 0, name
);
18834 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
18836 case DW_ATE_unsigned_char
:
18837 if (cu
->language
== language_ada
|| cu
->language
== language_m2
18838 || cu
->language
== language_pascal
18839 || cu
->language
== language_fortran
18840 || cu
->language
== language_rust
)
18841 type
= init_character_type (objfile
, bits
, 1, name
);
18843 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18848 type
= builtin_type (arch
)->builtin_char16
;
18849 else if (bits
== 32)
18850 type
= builtin_type (arch
)->builtin_char32
;
18853 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
18855 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
18857 return set_die_type (die
, type
, cu
);
18860 case DW_ATE_signed_fixed
:
18861 type
= init_fixed_point_type (objfile
, bits
, 0, name
);
18862 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18864 case DW_ATE_unsigned_fixed
:
18865 type
= init_fixed_point_type (objfile
, bits
, 1, name
);
18866 finish_fixed_point_type (type
, gnat_encoding_suffix
, die
, cu
);
18870 complaint (_("unsupported DW_AT_encoding: '%s'"),
18871 dwarf_type_encoding_name (encoding
));
18872 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
18876 if (name
&& strcmp (name
, "char") == 0)
18877 type
->set_has_no_signedness (true);
18879 maybe_set_alignment (cu
, die
, type
);
18881 type
->set_endianity_is_not_default (gdbarch_byte_order (arch
) != byte_order
);
18883 if (TYPE_SPECIFIC_FIELD (type
) == TYPE_SPECIFIC_INT
)
18885 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
18886 if (attr
!= nullptr && attr
->as_unsigned () <= 8 * TYPE_LENGTH (type
))
18888 unsigned real_bit_size
= attr
->as_unsigned ();
18889 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
18890 /* Only use the attributes if they make sense together. */
18891 if (attr
== nullptr
18892 || (attr
->as_unsigned () + real_bit_size
18893 <= 8 * TYPE_LENGTH (type
)))
18895 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_size
18897 if (attr
!= nullptr)
18898 TYPE_MAIN_TYPE (type
)->type_specific
.int_stuff
.bit_offset
18899 = attr
->as_unsigned ();
18904 return set_die_type (die
, type
, cu
);
18907 /* Parse dwarf attribute if it's a block, reference or constant and put the
18908 resulting value of the attribute into struct bound_prop.
18909 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
18912 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
18913 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
18914 struct type
*default_type
)
18916 struct dwarf2_property_baton
*baton
;
18917 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
18918 struct objfile
*objfile
= per_objfile
->objfile
;
18919 struct obstack
*obstack
= &objfile
->objfile_obstack
;
18921 gdb_assert (default_type
!= NULL
);
18923 if (attr
== NULL
|| prop
== NULL
)
18926 if (attr
->form_is_block ())
18928 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18929 baton
->property_type
= default_type
;
18930 baton
->locexpr
.per_cu
= cu
->per_cu
;
18931 baton
->locexpr
.per_objfile
= per_objfile
;
18933 struct dwarf_block
*block
= attr
->as_block ();
18934 baton
->locexpr
.size
= block
->size
;
18935 baton
->locexpr
.data
= block
->data
;
18936 switch (attr
->name
)
18938 case DW_AT_string_length
:
18939 baton
->locexpr
.is_reference
= true;
18942 baton
->locexpr
.is_reference
= false;
18946 prop
->set_locexpr (baton
);
18947 gdb_assert (prop
->baton () != NULL
);
18949 else if (attr
->form_is_ref ())
18951 struct dwarf2_cu
*target_cu
= cu
;
18952 struct die_info
*target_die
;
18953 struct attribute
*target_attr
;
18955 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18956 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18957 if (target_attr
== NULL
)
18958 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18960 if (target_attr
== NULL
)
18963 switch (target_attr
->name
)
18965 case DW_AT_location
:
18966 if (target_attr
->form_is_section_offset ())
18968 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18969 baton
->property_type
= die_type (target_die
, target_cu
);
18970 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18971 prop
->set_loclist (baton
);
18972 gdb_assert (prop
->baton () != NULL
);
18974 else if (target_attr
->form_is_block ())
18976 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18977 baton
->property_type
= die_type (target_die
, target_cu
);
18978 baton
->locexpr
.per_cu
= cu
->per_cu
;
18979 baton
->locexpr
.per_objfile
= per_objfile
;
18980 struct dwarf_block
*block
= target_attr
->as_block ();
18981 baton
->locexpr
.size
= block
->size
;
18982 baton
->locexpr
.data
= block
->data
;
18983 baton
->locexpr
.is_reference
= true;
18984 prop
->set_locexpr (baton
);
18985 gdb_assert (prop
->baton () != NULL
);
18989 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18990 "dynamic property");
18994 case DW_AT_data_member_location
:
18998 if (!handle_data_member_location (target_die
, target_cu
,
19002 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
19003 baton
->property_type
= read_type_die (target_die
->parent
,
19005 baton
->offset_info
.offset
= offset
;
19006 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
19007 prop
->set_addr_offset (baton
);
19012 else if (attr
->form_is_constant ())
19013 prop
->set_const_val (attr
->constant_value (0));
19016 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
19017 dwarf2_name (die
, cu
));
19027 dwarf2_per_objfile::int_type (int size_in_bytes
, bool unsigned_p
) const
19029 struct type
*int_type
;
19031 /* Helper macro to examine the various builtin types. */
19032 #define TRY_TYPE(F) \
19033 int_type = (unsigned_p \
19034 ? objfile_type (objfile)->builtin_unsigned_ ## F \
19035 : objfile_type (objfile)->builtin_ ## F); \
19036 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
19043 TRY_TYPE (long_long
);
19047 gdb_assert_not_reached ("unable to find suitable integer type");
19053 dwarf2_cu::addr_sized_int_type (bool unsigned_p
) const
19055 int addr_size
= this->per_cu
->addr_size ();
19056 return this->per_objfile
->int_type (addr_size
, unsigned_p
);
19059 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
19060 present (which is valid) then compute the default type based on the
19061 compilation units address size. */
19063 static struct type
*
19064 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19066 struct type
*index_type
= die_type (die
, cu
);
19068 /* Dwarf-2 specifications explicitly allows to create subrange types
19069 without specifying a base type.
19070 In that case, the base type must be set to the type of
19071 the lower bound, upper bound or count, in that order, if any of these
19072 three attributes references an object that has a type.
19073 If no base type is found, the Dwarf-2 specifications say that
19074 a signed integer type of size equal to the size of an address should
19076 For the following C code: `extern char gdb_int [];'
19077 GCC produces an empty range DIE.
19078 FIXME: muller/2010-05-28: Possible references to object for low bound,
19079 high bound or count are not yet handled by this code. */
19080 if (index_type
->code () == TYPE_CODE_VOID
)
19081 index_type
= cu
->addr_sized_int_type (false);
19086 /* Read the given DW_AT_subrange DIE. */
19088 static struct type
*
19089 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19091 struct type
*base_type
, *orig_base_type
;
19092 struct type
*range_type
;
19093 struct attribute
*attr
;
19094 struct dynamic_prop low
, high
;
19095 int low_default_is_valid
;
19096 int high_bound_is_count
= 0;
19098 ULONGEST negative_mask
;
19100 orig_base_type
= read_subrange_index_type (die
, cu
);
19102 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
19103 whereas the real type might be. So, we use ORIG_BASE_TYPE when
19104 creating the range type, but we use the result of check_typedef
19105 when examining properties of the type. */
19106 base_type
= check_typedef (orig_base_type
);
19108 /* The die_type call above may have already set the type for this DIE. */
19109 range_type
= get_die_type (die
, cu
);
19113 high
.set_const_val (0);
19115 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
19116 omitting DW_AT_lower_bound. */
19117 switch (cu
->language
)
19120 case language_cplus
:
19121 low
.set_const_val (0);
19122 low_default_is_valid
= 1;
19124 case language_fortran
:
19125 low
.set_const_val (1);
19126 low_default_is_valid
= 1;
19129 case language_objc
:
19130 case language_rust
:
19131 low
.set_const_val (0);
19132 low_default_is_valid
= (cu
->header
.version
>= 4);
19136 case language_pascal
:
19137 low
.set_const_val (1);
19138 low_default_is_valid
= (cu
->header
.version
>= 4);
19141 low
.set_const_val (0);
19142 low_default_is_valid
= 0;
19146 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
19147 if (attr
!= nullptr)
19148 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
19149 else if (!low_default_is_valid
)
19150 complaint (_("Missing DW_AT_lower_bound "
19151 "- DIE at %s [in module %s]"),
19152 sect_offset_str (die
->sect_off
),
19153 objfile_name (cu
->per_objfile
->objfile
));
19155 struct attribute
*attr_ub
, *attr_count
;
19156 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
19157 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
19159 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
19160 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
19162 /* If bounds are constant do the final calculation here. */
19163 if (low
.kind () == PROP_CONST
&& high
.kind () == PROP_CONST
)
19164 high
.set_const_val (low
.const_val () + high
.const_val () - 1);
19166 high_bound_is_count
= 1;
19170 if (attr_ub
!= NULL
)
19171 complaint (_("Unresolved DW_AT_upper_bound "
19172 "- DIE at %s [in module %s]"),
19173 sect_offset_str (die
->sect_off
),
19174 objfile_name (cu
->per_objfile
->objfile
));
19175 if (attr_count
!= NULL
)
19176 complaint (_("Unresolved DW_AT_count "
19177 "- DIE at %s [in module %s]"),
19178 sect_offset_str (die
->sect_off
),
19179 objfile_name (cu
->per_objfile
->objfile
));
19184 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
19185 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
19186 bias
= bias_attr
->constant_value (0);
19188 /* Normally, the DWARF producers are expected to use a signed
19189 constant form (Eg. DW_FORM_sdata) to express negative bounds.
19190 But this is unfortunately not always the case, as witnessed
19191 with GCC, for instance, where the ambiguous DW_FORM_dataN form
19192 is used instead. To work around that ambiguity, we treat
19193 the bounds as signed, and thus sign-extend their values, when
19194 the base type is signed. */
19196 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
19197 if (low
.kind () == PROP_CONST
19198 && !base_type
->is_unsigned () && (low
.const_val () & negative_mask
))
19199 low
.set_const_val (low
.const_val () | negative_mask
);
19200 if (high
.kind () == PROP_CONST
19201 && !base_type
->is_unsigned () && (high
.const_val () & negative_mask
))
19202 high
.set_const_val (high
.const_val () | negative_mask
);
19204 /* Check for bit and byte strides. */
19205 struct dynamic_prop byte_stride_prop
;
19206 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
19207 if (attr_byte_stride
!= nullptr)
19209 struct type
*prop_type
= cu
->addr_sized_int_type (false);
19210 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
19214 struct dynamic_prop bit_stride_prop
;
19215 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
19216 if (attr_bit_stride
!= nullptr)
19218 /* It only makes sense to have either a bit or byte stride. */
19219 if (attr_byte_stride
!= nullptr)
19221 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
19222 "- DIE at %s [in module %s]"),
19223 sect_offset_str (die
->sect_off
),
19224 objfile_name (cu
->per_objfile
->objfile
));
19225 attr_bit_stride
= nullptr;
19229 struct type
*prop_type
= cu
->addr_sized_int_type (false);
19230 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
19235 if (attr_byte_stride
!= nullptr
19236 || attr_bit_stride
!= nullptr)
19238 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
19239 struct dynamic_prop
*stride
19240 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
19243 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
19244 &high
, bias
, stride
, byte_stride_p
);
19247 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
19249 if (high_bound_is_count
)
19250 range_type
->bounds ()->flag_upper_bound_is_count
= 1;
19252 /* Ada expects an empty array on no boundary attributes. */
19253 if (attr
== NULL
&& cu
->language
!= language_ada
)
19254 range_type
->bounds ()->high
.set_undefined ();
19256 name
= dwarf2_name (die
, cu
);
19258 range_type
->set_name (name
);
19260 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
19261 if (attr
!= nullptr)
19262 TYPE_LENGTH (range_type
) = attr
->constant_value (0);
19264 maybe_set_alignment (cu
, die
, range_type
);
19266 set_die_type (die
, range_type
, cu
);
19268 /* set_die_type should be already done. */
19269 set_descriptive_type (range_type
, die
, cu
);
19274 static struct type
*
19275 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
19279 type
= init_type (cu
->per_objfile
->objfile
, TYPE_CODE_VOID
, 0, NULL
);
19280 type
->set_name (dwarf2_name (die
, cu
));
19282 /* In Ada, an unspecified type is typically used when the description
19283 of the type is deferred to a different unit. When encountering
19284 such a type, we treat it as a stub, and try to resolve it later on,
19286 if (cu
->language
== language_ada
)
19287 type
->set_is_stub (true);
19289 return set_die_type (die
, type
, cu
);
19292 /* Read a single die and all its descendents. Set the die's sibling
19293 field to NULL; set other fields in the die correctly, and set all
19294 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
19295 location of the info_ptr after reading all of those dies. PARENT
19296 is the parent of the die in question. */
19298 static struct die_info
*
19299 read_die_and_children (const struct die_reader_specs
*reader
,
19300 const gdb_byte
*info_ptr
,
19301 const gdb_byte
**new_info_ptr
,
19302 struct die_info
*parent
)
19304 struct die_info
*die
;
19305 const gdb_byte
*cur_ptr
;
19307 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
19310 *new_info_ptr
= cur_ptr
;
19313 store_in_ref_table (die
, reader
->cu
);
19315 if (die
->has_children
)
19316 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
19320 *new_info_ptr
= cur_ptr
;
19323 die
->sibling
= NULL
;
19324 die
->parent
= parent
;
19328 /* Read a die, all of its descendents, and all of its siblings; set
19329 all of the fields of all of the dies correctly. Arguments are as
19330 in read_die_and_children. */
19332 static struct die_info
*
19333 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
19334 const gdb_byte
*info_ptr
,
19335 const gdb_byte
**new_info_ptr
,
19336 struct die_info
*parent
)
19338 struct die_info
*first_die
, *last_sibling
;
19339 const gdb_byte
*cur_ptr
;
19341 cur_ptr
= info_ptr
;
19342 first_die
= last_sibling
= NULL
;
19346 struct die_info
*die
19347 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
19351 *new_info_ptr
= cur_ptr
;
19358 last_sibling
->sibling
= die
;
19360 last_sibling
= die
;
19364 /* Read a die, all of its descendents, and all of its siblings; set
19365 all of the fields of all of the dies correctly. Arguments are as
19366 in read_die_and_children.
19367 This the main entry point for reading a DIE and all its children. */
19369 static struct die_info
*
19370 read_die_and_siblings (const struct die_reader_specs
*reader
,
19371 const gdb_byte
*info_ptr
,
19372 const gdb_byte
**new_info_ptr
,
19373 struct die_info
*parent
)
19375 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
19376 new_info_ptr
, parent
);
19378 if (dwarf_die_debug
)
19380 fprintf_unfiltered (gdb_stdlog
,
19381 "Read die from %s@0x%x of %s:\n",
19382 reader
->die_section
->get_name (),
19383 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19384 bfd_get_filename (reader
->abfd
));
19385 dump_die (die
, dwarf_die_debug
);
19391 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
19393 The caller is responsible for filling in the extra attributes
19394 and updating (*DIEP)->num_attrs.
19395 Set DIEP to point to a newly allocated die with its information,
19396 except for its child, sibling, and parent fields. */
19398 static const gdb_byte
*
19399 read_full_die_1 (const struct die_reader_specs
*reader
,
19400 struct die_info
**diep
, const gdb_byte
*info_ptr
,
19401 int num_extra_attrs
)
19403 unsigned int abbrev_number
, bytes_read
, i
;
19404 struct abbrev_info
*abbrev
;
19405 struct die_info
*die
;
19406 struct dwarf2_cu
*cu
= reader
->cu
;
19407 bfd
*abfd
= reader
->abfd
;
19409 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
19410 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19411 info_ptr
+= bytes_read
;
19412 if (!abbrev_number
)
19418 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
19420 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
19422 bfd_get_filename (abfd
));
19424 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
19425 die
->sect_off
= sect_off
;
19426 die
->tag
= abbrev
->tag
;
19427 die
->abbrev
= abbrev_number
;
19428 die
->has_children
= abbrev
->has_children
;
19430 /* Make the result usable.
19431 The caller needs to update num_attrs after adding the extra
19433 die
->num_attrs
= abbrev
->num_attrs
;
19435 bool any_need_reprocess
= false;
19436 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19438 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
19440 if (die
->attrs
[i
].requires_reprocessing_p ())
19441 any_need_reprocess
= true;
19444 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
19445 if (attr
!= nullptr && attr
->form_is_unsigned ())
19446 cu
->str_offsets_base
= attr
->as_unsigned ();
19448 attr
= die
->attr (DW_AT_loclists_base
);
19449 if (attr
!= nullptr)
19450 cu
->loclist_base
= attr
->as_unsigned ();
19452 auto maybe_addr_base
= die
->addr_base ();
19453 if (maybe_addr_base
.has_value ())
19454 cu
->addr_base
= *maybe_addr_base
;
19456 attr
= die
->attr (DW_AT_rnglists_base
);
19457 if (attr
!= nullptr)
19458 cu
->rnglists_base
= attr
->as_unsigned ();
19460 if (any_need_reprocess
)
19462 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
19464 if (die
->attrs
[i
].requires_reprocessing_p ())
19465 read_attribute_reprocess (reader
, &die
->attrs
[i
], die
->tag
);
19472 /* Read a die and all its attributes.
19473 Set DIEP to point to a newly allocated die with its information,
19474 except for its child, sibling, and parent fields. */
19476 static const gdb_byte
*
19477 read_full_die (const struct die_reader_specs
*reader
,
19478 struct die_info
**diep
, const gdb_byte
*info_ptr
)
19480 const gdb_byte
*result
;
19482 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
19484 if (dwarf_die_debug
)
19486 fprintf_unfiltered (gdb_stdlog
,
19487 "Read die from %s@0x%x of %s:\n",
19488 reader
->die_section
->get_name (),
19489 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
19490 bfd_get_filename (reader
->abfd
));
19491 dump_die (*diep
, dwarf_die_debug
);
19498 /* Returns nonzero if TAG represents a type that we might generate a partial
19502 is_type_tag_for_partial (int tag
, enum language lang
)
19507 /* Some types that would be reasonable to generate partial symbols for,
19508 that we don't at present. Note that normally this does not
19509 matter, mainly because C compilers don't give names to these
19510 types, but instead emit DW_TAG_typedef. */
19511 case DW_TAG_file_type
:
19512 case DW_TAG_ptr_to_member_type
:
19513 case DW_TAG_set_type
:
19514 case DW_TAG_string_type
:
19515 case DW_TAG_subroutine_type
:
19518 /* GNAT may emit an array with a name, but no typedef, so we
19519 need to make a symbol in this case. */
19520 case DW_TAG_array_type
:
19521 return lang
== language_ada
;
19523 case DW_TAG_base_type
:
19524 case DW_TAG_class_type
:
19525 case DW_TAG_interface_type
:
19526 case DW_TAG_enumeration_type
:
19527 case DW_TAG_structure_type
:
19528 case DW_TAG_subrange_type
:
19529 case DW_TAG_typedef
:
19530 case DW_TAG_union_type
:
19537 /* Load all DIEs that are interesting for partial symbols into memory. */
19539 static struct partial_die_info
*
19540 load_partial_dies (const struct die_reader_specs
*reader
,
19541 const gdb_byte
*info_ptr
, int building_psymtab
)
19543 struct dwarf2_cu
*cu
= reader
->cu
;
19544 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19545 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
19546 unsigned int bytes_read
;
19547 unsigned int load_all
= 0;
19548 int nesting_level
= 1;
19553 gdb_assert (cu
->per_cu
!= NULL
);
19554 if (cu
->per_cu
->load_all_dies
)
19558 = htab_create_alloc_ex (cu
->header
.length
/ 12,
19562 &cu
->comp_unit_obstack
,
19563 hashtab_obstack_allocate
,
19564 dummy_obstack_deallocate
);
19568 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
19570 /* A NULL abbrev means the end of a series of children. */
19571 if (abbrev
== NULL
)
19573 if (--nesting_level
== 0)
19576 info_ptr
+= bytes_read
;
19577 last_die
= parent_die
;
19578 parent_die
= parent_die
->die_parent
;
19582 /* Check for template arguments. We never save these; if
19583 they're seen, we just mark the parent, and go on our way. */
19584 if (parent_die
!= NULL
19585 && cu
->language
== language_cplus
19586 && (abbrev
->tag
== DW_TAG_template_type_param
19587 || abbrev
->tag
== DW_TAG_template_value_param
))
19589 parent_die
->has_template_arguments
= 1;
19593 /* We don't need a partial DIE for the template argument. */
19594 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19599 /* We only recurse into c++ subprograms looking for template arguments.
19600 Skip their other children. */
19602 && cu
->language
== language_cplus
19603 && parent_die
!= NULL
19604 && parent_die
->tag
== DW_TAG_subprogram
19605 && abbrev
->tag
!= DW_TAG_inlined_subroutine
)
19607 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19611 /* Check whether this DIE is interesting enough to save. Normally
19612 we would not be interested in members here, but there may be
19613 later variables referencing them via DW_AT_specification (for
19614 static members). */
19616 && !is_type_tag_for_partial (abbrev
->tag
, cu
->language
)
19617 && abbrev
->tag
!= DW_TAG_constant
19618 && abbrev
->tag
!= DW_TAG_enumerator
19619 && abbrev
->tag
!= DW_TAG_subprogram
19620 && abbrev
->tag
!= DW_TAG_inlined_subroutine
19621 && abbrev
->tag
!= DW_TAG_lexical_block
19622 && abbrev
->tag
!= DW_TAG_variable
19623 && abbrev
->tag
!= DW_TAG_namespace
19624 && abbrev
->tag
!= DW_TAG_module
19625 && abbrev
->tag
!= DW_TAG_member
19626 && abbrev
->tag
!= DW_TAG_imported_unit
19627 && abbrev
->tag
!= DW_TAG_imported_declaration
)
19629 /* Otherwise we skip to the next sibling, if any. */
19630 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
19634 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
19637 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
19639 /* This two-pass algorithm for processing partial symbols has a
19640 high cost in cache pressure. Thus, handle some simple cases
19641 here which cover the majority of C partial symbols. DIEs
19642 which neither have specification tags in them, nor could have
19643 specification tags elsewhere pointing at them, can simply be
19644 processed and discarded.
19646 This segment is also optional; scan_partial_symbols and
19647 add_partial_symbol will handle these DIEs if we chain
19648 them in normally. When compilers which do not emit large
19649 quantities of duplicate debug information are more common,
19650 this code can probably be removed. */
19652 /* Any complete simple types at the top level (pretty much all
19653 of them, for a language without namespaces), can be processed
19655 if (parent_die
== NULL
19656 && pdi
.has_specification
== 0
19657 && pdi
.is_declaration
== 0
19658 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
19659 || pdi
.tag
== DW_TAG_base_type
19660 || pdi
.tag
== DW_TAG_array_type
19661 || pdi
.tag
== DW_TAG_subrange_type
))
19663 if (building_psymtab
&& pdi
.raw_name
!= NULL
)
19664 add_partial_symbol (&pdi
, cu
);
19666 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19670 /* The exception for DW_TAG_typedef with has_children above is
19671 a workaround of GCC PR debug/47510. In the case of this complaint
19672 type_name_or_error will error on such types later.
19674 GDB skipped children of DW_TAG_typedef by the shortcut above and then
19675 it could not find the child DIEs referenced later, this is checked
19676 above. In correct DWARF DW_TAG_typedef should have no children. */
19678 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
19679 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
19680 "- DIE at %s [in module %s]"),
19681 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
19683 /* If we're at the second level, and we're an enumerator, and
19684 our parent has no specification (meaning possibly lives in a
19685 namespace elsewhere), then we can add the partial symbol now
19686 instead of queueing it. */
19687 if (pdi
.tag
== DW_TAG_enumerator
19688 && parent_die
!= NULL
19689 && parent_die
->die_parent
== NULL
19690 && parent_die
->tag
== DW_TAG_enumeration_type
19691 && parent_die
->has_specification
== 0)
19693 if (pdi
.raw_name
== NULL
)
19694 complaint (_("malformed enumerator DIE ignored"));
19695 else if (building_psymtab
)
19696 add_partial_symbol (&pdi
, cu
);
19698 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
19702 struct partial_die_info
*part_die
19703 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
19705 /* We'll save this DIE so link it in. */
19706 part_die
->die_parent
= parent_die
;
19707 part_die
->die_sibling
= NULL
;
19708 part_die
->die_child
= NULL
;
19710 if (last_die
&& last_die
== parent_die
)
19711 last_die
->die_child
= part_die
;
19713 last_die
->die_sibling
= part_die
;
19715 last_die
= part_die
;
19717 if (first_die
== NULL
)
19718 first_die
= part_die
;
19720 /* Maybe add the DIE to the hash table. Not all DIEs that we
19721 find interesting need to be in the hash table, because we
19722 also have the parent/sibling/child chains; only those that we
19723 might refer to by offset later during partial symbol reading.
19725 For now this means things that might have be the target of a
19726 DW_AT_specification, DW_AT_abstract_origin, or
19727 DW_AT_extension. DW_AT_extension will refer only to
19728 namespaces; DW_AT_abstract_origin refers to functions (and
19729 many things under the function DIE, but we do not recurse
19730 into function DIEs during partial symbol reading) and
19731 possibly variables as well; DW_AT_specification refers to
19732 declarations. Declarations ought to have the DW_AT_declaration
19733 flag. It happens that GCC forgets to put it in sometimes, but
19734 only for functions, not for types.
19736 Adding more things than necessary to the hash table is harmless
19737 except for the performance cost. Adding too few will result in
19738 wasted time in find_partial_die, when we reread the compilation
19739 unit with load_all_dies set. */
19742 || abbrev
->tag
== DW_TAG_constant
19743 || abbrev
->tag
== DW_TAG_subprogram
19744 || abbrev
->tag
== DW_TAG_variable
19745 || abbrev
->tag
== DW_TAG_namespace
19746 || part_die
->is_declaration
)
19750 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
19751 to_underlying (part_die
->sect_off
),
19756 /* For some DIEs we want to follow their children (if any). For C
19757 we have no reason to follow the children of structures; for other
19758 languages we have to, so that we can get at method physnames
19759 to infer fully qualified class names, for DW_AT_specification,
19760 and for C++ template arguments. For C++, we also look one level
19761 inside functions to find template arguments (if the name of the
19762 function does not already contain the template arguments).
19764 For Ada and Fortran, we need to scan the children of subprograms
19765 and lexical blocks as well because these languages allow the
19766 definition of nested entities that could be interesting for the
19767 debugger, such as nested subprograms for instance. */
19768 if (last_die
->has_children
19770 || last_die
->tag
== DW_TAG_namespace
19771 || last_die
->tag
== DW_TAG_module
19772 || last_die
->tag
== DW_TAG_enumeration_type
19773 || (cu
->language
== language_cplus
19774 && last_die
->tag
== DW_TAG_subprogram
19775 && (last_die
->raw_name
== NULL
19776 || strchr (last_die
->raw_name
, '<') == NULL
))
19777 || (cu
->language
!= language_c
19778 && (last_die
->tag
== DW_TAG_class_type
19779 || last_die
->tag
== DW_TAG_interface_type
19780 || last_die
->tag
== DW_TAG_structure_type
19781 || last_die
->tag
== DW_TAG_union_type
))
19782 || ((cu
->language
== language_ada
19783 || cu
->language
== language_fortran
)
19784 && (last_die
->tag
== DW_TAG_subprogram
19785 || last_die
->tag
== DW_TAG_lexical_block
))))
19788 parent_die
= last_die
;
19792 /* Otherwise we skip to the next sibling, if any. */
19793 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
19795 /* Back to the top, do it again. */
19799 partial_die_info::partial_die_info (sect_offset sect_off_
,
19800 struct abbrev_info
*abbrev
)
19801 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19805 /* See class definition. */
19808 partial_die_info::name (dwarf2_cu
*cu
)
19810 if (!canonical_name
&& raw_name
!= nullptr)
19812 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
19813 raw_name
= dwarf2_canonicalize_name (raw_name
, cu
, objfile
);
19814 canonical_name
= 1;
19820 /* Read a minimal amount of information into the minimal die structure.
19821 INFO_PTR should point just after the initial uleb128 of a DIE. */
19824 partial_die_info::read (const struct die_reader_specs
*reader
,
19825 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19827 struct dwarf2_cu
*cu
= reader
->cu
;
19828 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
19830 int has_low_pc_attr
= 0;
19831 int has_high_pc_attr
= 0;
19832 int high_pc_relative
= 0;
19834 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19837 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
19838 /* String and address offsets that need to do the reprocessing have
19839 already been read at this point, so there is no need to wait until
19840 the loop terminates to do the reprocessing. */
19841 if (attr
.requires_reprocessing_p ())
19842 read_attribute_reprocess (reader
, &attr
, tag
);
19843 /* Store the data if it is of an attribute we want to keep in a
19844 partial symbol table. */
19850 case DW_TAG_compile_unit
:
19851 case DW_TAG_partial_unit
:
19852 case DW_TAG_type_unit
:
19853 /* Compilation units have a DW_AT_name that is a filename, not
19854 a source language identifier. */
19855 case DW_TAG_enumeration_type
:
19856 case DW_TAG_enumerator
:
19857 /* These tags always have simple identifiers already; no need
19858 to canonicalize them. */
19859 canonical_name
= 1;
19860 raw_name
= attr
.as_string ();
19863 canonical_name
= 0;
19864 raw_name
= attr
.as_string ();
19868 case DW_AT_linkage_name
:
19869 case DW_AT_MIPS_linkage_name
:
19870 /* Note that both forms of linkage name might appear. We
19871 assume they will be the same, and we only store the last
19873 linkage_name
= attr
.as_string ();
19876 has_low_pc_attr
= 1;
19877 lowpc
= attr
.as_address ();
19879 case DW_AT_high_pc
:
19880 has_high_pc_attr
= 1;
19881 highpc
= attr
.as_address ();
19882 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
19883 high_pc_relative
= 1;
19885 case DW_AT_location
:
19886 /* Support the .debug_loc offsets. */
19887 if (attr
.form_is_block ())
19889 d
.locdesc
= attr
.as_block ();
19891 else if (attr
.form_is_section_offset ())
19893 dwarf2_complex_location_expr_complaint ();
19897 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19898 "partial symbol information");
19901 case DW_AT_external
:
19902 is_external
= attr
.as_boolean ();
19904 case DW_AT_declaration
:
19905 is_declaration
= attr
.as_boolean ();
19910 case DW_AT_abstract_origin
:
19911 case DW_AT_specification
:
19912 case DW_AT_extension
:
19913 has_specification
= 1;
19914 spec_offset
= attr
.get_ref_die_offset ();
19915 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19916 || cu
->per_cu
->is_dwz
);
19918 case DW_AT_sibling
:
19919 /* Ignore absolute siblings, they might point outside of
19920 the current compile unit. */
19921 if (attr
.form
== DW_FORM_ref_addr
)
19922 complaint (_("ignoring absolute DW_AT_sibling"));
19925 const gdb_byte
*buffer
= reader
->buffer
;
19926 sect_offset off
= attr
.get_ref_die_offset ();
19927 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19929 if (sibling_ptr
< info_ptr
)
19930 complaint (_("DW_AT_sibling points backwards"));
19931 else if (sibling_ptr
> reader
->buffer_end
)
19932 reader
->die_section
->overflow_complaint ();
19934 sibling
= sibling_ptr
;
19937 case DW_AT_byte_size
:
19940 case DW_AT_const_value
:
19941 has_const_value
= 1;
19943 case DW_AT_calling_convention
:
19944 /* DWARF doesn't provide a way to identify a program's source-level
19945 entry point. DW_AT_calling_convention attributes are only meant
19946 to describe functions' calling conventions.
19948 However, because it's a necessary piece of information in
19949 Fortran, and before DWARF 4 DW_CC_program was the only
19950 piece of debugging information whose definition refers to
19951 a 'main program' at all, several compilers marked Fortran
19952 main programs with DW_CC_program --- even when those
19953 functions use the standard calling conventions.
19955 Although DWARF now specifies a way to provide this
19956 information, we support this practice for backward
19958 if (attr
.constant_value (0) == DW_CC_program
19959 && cu
->language
== language_fortran
)
19960 main_subprogram
= 1;
19964 LONGEST value
= attr
.constant_value (-1);
19965 if (value
== DW_INL_inlined
19966 || value
== DW_INL_declared_inlined
)
19967 may_be_inlined
= 1;
19972 if (tag
== DW_TAG_imported_unit
)
19974 d
.sect_off
= attr
.get_ref_die_offset ();
19975 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19976 || cu
->per_cu
->is_dwz
);
19980 case DW_AT_main_subprogram
:
19981 main_subprogram
= attr
.as_boolean ();
19986 /* Offset in the .debug_ranges or .debug_rnglist section (depending
19987 on DWARF version). */
19988 ULONGEST ranges_offset
= attr
.as_unsigned ();
19990 /* See dwarf2_cu::gnu_ranges_base's doc for why we might want to add
19992 if (tag
!= DW_TAG_compile_unit
)
19993 ranges_offset
+= cu
->gnu_ranges_base
;
19995 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
20006 /* For Ada, if both the name and the linkage name appear, we prefer
20007 the latter. This lets "catch exception" work better, regardless
20008 of the order in which the name and linkage name were emitted.
20009 Really, though, this is just a workaround for the fact that gdb
20010 doesn't store both the name and the linkage name. */
20011 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
20012 raw_name
= linkage_name
;
20014 if (high_pc_relative
)
20017 if (has_low_pc_attr
&& has_high_pc_attr
)
20019 /* When using the GNU linker, .gnu.linkonce. sections are used to
20020 eliminate duplicate copies of functions and vtables and such.
20021 The linker will arbitrarily choose one and discard the others.
20022 The AT_*_pc values for such functions refer to local labels in
20023 these sections. If the section from that file was discarded, the
20024 labels are not in the output, so the relocs get a value of 0.
20025 If this is a discarded function, mark the pc bounds as invalid,
20026 so that GDB will ignore it. */
20027 if (lowpc
== 0 && !per_objfile
->per_bfd
->has_section_at_zero
)
20029 struct objfile
*objfile
= per_objfile
->objfile
;
20030 struct gdbarch
*gdbarch
= objfile
->arch ();
20032 complaint (_("DW_AT_low_pc %s is zero "
20033 "for DIE at %s [in module %s]"),
20034 paddress (gdbarch
, lowpc
),
20035 sect_offset_str (sect_off
),
20036 objfile_name (objfile
));
20038 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
20039 else if (lowpc
>= highpc
)
20041 struct objfile
*objfile
= per_objfile
->objfile
;
20042 struct gdbarch
*gdbarch
= objfile
->arch ();
20044 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
20045 "for DIE at %s [in module %s]"),
20046 paddress (gdbarch
, lowpc
),
20047 paddress (gdbarch
, highpc
),
20048 sect_offset_str (sect_off
),
20049 objfile_name (objfile
));
20058 /* Find a cached partial DIE at OFFSET in CU. */
20060 struct partial_die_info
*
20061 dwarf2_cu::find_partial_die (sect_offset sect_off
)
20063 struct partial_die_info
*lookup_die
= NULL
;
20064 struct partial_die_info
part_die (sect_off
);
20066 lookup_die
= ((struct partial_die_info
*)
20067 htab_find_with_hash (partial_dies
, &part_die
,
20068 to_underlying (sect_off
)));
20073 /* Find a partial DIE at OFFSET, which may or may not be in CU,
20074 except in the case of .debug_types DIEs which do not reference
20075 outside their CU (they do however referencing other types via
20076 DW_FORM_ref_sig8). */
20078 static const struct cu_partial_die_info
20079 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
20081 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20082 struct objfile
*objfile
= per_objfile
->objfile
;
20083 struct partial_die_info
*pd
= NULL
;
20085 if (offset_in_dwz
== cu
->per_cu
->is_dwz
20086 && cu
->header
.offset_in_cu_p (sect_off
))
20088 pd
= cu
->find_partial_die (sect_off
);
20091 /* We missed recording what we needed.
20092 Load all dies and try again. */
20096 /* TUs don't reference other CUs/TUs (except via type signatures). */
20097 if (cu
->per_cu
->is_debug_types
)
20099 error (_("Dwarf Error: Type Unit at offset %s contains"
20100 " external reference to offset %s [in module %s].\n"),
20101 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
20102 bfd_get_filename (objfile
->obfd
));
20104 dwarf2_per_cu_data
*per_cu
20105 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
20108 cu
= per_objfile
->get_cu (per_cu
);
20109 if (cu
== NULL
|| cu
->partial_dies
== NULL
)
20110 load_partial_comp_unit (per_cu
, per_objfile
, nullptr);
20112 cu
= per_objfile
->get_cu (per_cu
);
20115 pd
= cu
->find_partial_die (sect_off
);
20118 /* If we didn't find it, and not all dies have been loaded,
20119 load them all and try again. */
20121 if (pd
== NULL
&& cu
->per_cu
->load_all_dies
== 0)
20123 cu
->per_cu
->load_all_dies
= 1;
20125 /* This is nasty. When we reread the DIEs, somewhere up the call chain
20126 THIS_CU->cu may already be in use. So we can't just free it and
20127 replace its DIEs with the ones we read in. Instead, we leave those
20128 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
20129 and clobber THIS_CU->cu->partial_dies with the hash table for the new
20131 load_partial_comp_unit (cu
->per_cu
, per_objfile
, cu
);
20133 pd
= cu
->find_partial_die (sect_off
);
20137 error (_("Dwarf Error: Cannot not find DIE at %s [from module %s]\n"),
20138 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
20142 /* See if we can figure out if the class lives in a namespace. We do
20143 this by looking for a member function; its demangled name will
20144 contain namespace info, if there is any. */
20147 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
20148 struct dwarf2_cu
*cu
)
20150 /* NOTE: carlton/2003-10-07: Getting the info this way changes
20151 what template types look like, because the demangler
20152 frequently doesn't give the same name as the debug info. We
20153 could fix this by only using the demangled name to get the
20154 prefix (but see comment in read_structure_type). */
20156 struct partial_die_info
*real_pdi
;
20157 struct partial_die_info
*child_pdi
;
20159 /* If this DIE (this DIE's specification, if any) has a parent, then
20160 we should not do this. We'll prepend the parent's fully qualified
20161 name when we create the partial symbol. */
20163 real_pdi
= struct_pdi
;
20164 while (real_pdi
->has_specification
)
20166 auto res
= find_partial_die (real_pdi
->spec_offset
,
20167 real_pdi
->spec_is_dwz
, cu
);
20168 real_pdi
= res
.pdi
;
20172 if (real_pdi
->die_parent
!= NULL
)
20175 for (child_pdi
= struct_pdi
->die_child
;
20177 child_pdi
= child_pdi
->die_sibling
)
20179 if (child_pdi
->tag
== DW_TAG_subprogram
20180 && child_pdi
->linkage_name
!= NULL
)
20182 gdb::unique_xmalloc_ptr
<char> actual_class_name
20183 (cu
->language_defn
->class_name_from_physname
20184 (child_pdi
->linkage_name
));
20185 if (actual_class_name
!= NULL
)
20187 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20188 struct_pdi
->raw_name
= objfile
->intern (actual_class_name
.get ());
20189 struct_pdi
->canonical_name
= 1;
20196 /* Return true if a DIE with TAG may have the DW_AT_const_value
20200 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
20204 case DW_TAG_constant
:
20205 case DW_TAG_enumerator
:
20206 case DW_TAG_formal_parameter
:
20207 case DW_TAG_template_value_param
:
20208 case DW_TAG_variable
:
20216 partial_die_info::fixup (struct dwarf2_cu
*cu
)
20218 /* Once we've fixed up a die, there's no point in doing so again.
20219 This also avoids a memory leak if we were to call
20220 guess_partial_die_structure_name multiple times. */
20224 /* If we found a reference attribute and the DIE has no name, try
20225 to find a name in the referred to DIE. */
20227 if (raw_name
== NULL
&& has_specification
)
20229 struct partial_die_info
*spec_die
;
20231 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
20232 spec_die
= res
.pdi
;
20235 spec_die
->fixup (cu
);
20237 if (spec_die
->raw_name
)
20239 raw_name
= spec_die
->raw_name
;
20240 canonical_name
= spec_die
->canonical_name
;
20242 /* Copy DW_AT_external attribute if it is set. */
20243 if (spec_die
->is_external
)
20244 is_external
= spec_die
->is_external
;
20248 if (!has_const_value
&& has_specification
20249 && can_have_DW_AT_const_value_p (tag
))
20251 struct partial_die_info
*spec_die
;
20253 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
20254 spec_die
= res
.pdi
;
20257 spec_die
->fixup (cu
);
20259 if (spec_die
->has_const_value
)
20261 /* Copy DW_AT_const_value attribute if it is set. */
20262 has_const_value
= spec_die
->has_const_value
;
20266 /* Set default names for some unnamed DIEs. */
20268 if (raw_name
== NULL
&& tag
== DW_TAG_namespace
)
20270 raw_name
= CP_ANONYMOUS_NAMESPACE_STR
;
20271 canonical_name
= 1;
20274 /* If there is no parent die to provide a namespace, and there are
20275 children, see if we can determine the namespace from their linkage
20277 if (cu
->language
== language_cplus
20278 && !cu
->per_objfile
->per_bfd
->types
.empty ()
20279 && die_parent
== NULL
20281 && (tag
== DW_TAG_class_type
20282 || tag
== DW_TAG_structure_type
20283 || tag
== DW_TAG_union_type
))
20284 guess_partial_die_structure_name (this, cu
);
20286 /* GCC might emit a nameless struct or union that has a linkage
20287 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20288 if (raw_name
== NULL
20289 && (tag
== DW_TAG_class_type
20290 || tag
== DW_TAG_interface_type
20291 || tag
== DW_TAG_structure_type
20292 || tag
== DW_TAG_union_type
)
20293 && linkage_name
!= NULL
)
20295 gdb::unique_xmalloc_ptr
<char> demangled
20296 (gdb_demangle (linkage_name
, DMGL_TYPES
));
20297 if (demangled
!= nullptr)
20301 /* Strip any leading namespaces/classes, keep only the base name.
20302 DW_AT_name for named DIEs does not contain the prefixes. */
20303 base
= strrchr (demangled
.get (), ':');
20304 if (base
&& base
> demangled
.get () && base
[-1] == ':')
20307 base
= demangled
.get ();
20309 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
20310 raw_name
= objfile
->intern (base
);
20311 canonical_name
= 1;
20318 /* Read the .debug_loclists or .debug_rnglists header (they are the same format)
20319 contents from the given SECTION in the HEADER.
20321 HEADER_OFFSET is the offset of the header in the section. */
20323 read_loclists_rnglists_header (struct loclists_rnglists_header
*header
,
20324 struct dwarf2_section_info
*section
,
20325 sect_offset header_offset
)
20327 unsigned int bytes_read
;
20328 bfd
*abfd
= section
->get_bfd_owner ();
20329 const gdb_byte
*info_ptr
= section
->buffer
+ to_underlying (header_offset
);
20331 header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
20332 info_ptr
+= bytes_read
;
20334 header
->version
= read_2_bytes (abfd
, info_ptr
);
20337 header
->addr_size
= read_1_byte (abfd
, info_ptr
);
20340 header
->segment_collector_size
= read_1_byte (abfd
, info_ptr
);
20343 header
->offset_entry_count
= read_4_bytes (abfd
, info_ptr
);
20346 /* Return the DW_AT_loclists_base value for the CU. */
20348 lookup_loclist_base (struct dwarf2_cu
*cu
)
20350 /* For the .dwo unit, the loclist_base points to the first offset following
20351 the header. The header consists of the following entities-
20352 1. Unit Length (4 bytes for 32 bit DWARF format, and 12 bytes for the 64
20354 2. version (2 bytes)
20355 3. address size (1 byte)
20356 4. segment selector size (1 byte)
20357 5. offset entry count (4 bytes)
20358 These sizes are derived as per the DWARFv5 standard. */
20359 if (cu
->dwo_unit
!= nullptr)
20361 if (cu
->header
.initial_length_size
== 4)
20362 return LOCLIST_HEADER_SIZE32
;
20363 return LOCLIST_HEADER_SIZE64
;
20365 return cu
->loclist_base
;
20368 /* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
20369 array of offsets in the .debug_loclists section. */
20372 read_loclist_index (struct dwarf2_cu
*cu
, ULONGEST loclist_index
)
20374 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20375 struct objfile
*objfile
= per_objfile
->objfile
;
20376 bfd
*abfd
= objfile
->obfd
;
20377 ULONGEST loclist_header_size
=
20378 (cu
->header
.initial_length_size
== 4 ? LOCLIST_HEADER_SIZE32
20379 : LOCLIST_HEADER_SIZE64
);
20380 ULONGEST loclist_base
= lookup_loclist_base (cu
);
20382 /* Offset in .debug_loclists of the offset for LOCLIST_INDEX. */
20383 ULONGEST start_offset
=
20384 loclist_base
+ loclist_index
* cu
->header
.offset_size
;
20386 /* Get loclists section. */
20387 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
20389 /* Read the loclists section content. */
20390 section
->read (objfile
);
20391 if (section
->buffer
== NULL
)
20392 error (_("DW_FORM_loclistx used without .debug_loclists "
20393 "section [in module %s]"), objfile_name (objfile
));
20395 /* DW_AT_loclists_base points after the .debug_loclists contribution header,
20396 so if loclist_base is smaller than the header size, we have a problem. */
20397 if (loclist_base
< loclist_header_size
)
20398 error (_("DW_AT_loclists_base is smaller than header size [in module %s]"),
20399 objfile_name (objfile
));
20401 /* Read the header of the loclists contribution. */
20402 struct loclists_rnglists_header header
;
20403 read_loclists_rnglists_header (&header
, section
,
20404 (sect_offset
) (loclist_base
- loclist_header_size
));
20406 /* Verify the loclist index is valid. */
20407 if (loclist_index
>= header
.offset_entry_count
)
20408 error (_("DW_FORM_loclistx pointing outside of "
20409 ".debug_loclists offset array [in module %s]"),
20410 objfile_name (objfile
));
20412 /* Validate that reading won't go beyond the end of the section. */
20413 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
20414 error (_("Reading DW_FORM_loclistx index beyond end of"
20415 ".debug_loclists section [in module %s]"),
20416 objfile_name (objfile
));
20418 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20420 if (cu
->header
.offset_size
== 4)
20421 return (sect_offset
) (bfd_get_32 (abfd
, info_ptr
) + loclist_base
);
20423 return (sect_offset
) (bfd_get_64 (abfd
, info_ptr
) + loclist_base
);
20426 /* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
20427 array of offsets in the .debug_rnglists section. */
20430 read_rnglist_index (struct dwarf2_cu
*cu
, ULONGEST rnglist_index
,
20433 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
20434 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20435 bfd
*abfd
= objfile
->obfd
;
20436 ULONGEST rnglist_header_size
=
20437 (cu
->header
.initial_length_size
== 4 ? RNGLIST_HEADER_SIZE32
20438 : RNGLIST_HEADER_SIZE64
);
20440 /* When reading a DW_FORM_rnglistx from a DWO, we read from the DWO's
20441 .debug_rnglists.dwo section. The rnglists base given in the skeleton
20443 ULONGEST rnglist_base
=
20444 (cu
->dwo_unit
!= nullptr) ? rnglist_header_size
: cu
->rnglists_base
;
20446 /* Offset in .debug_rnglists of the offset for RNGLIST_INDEX. */
20447 ULONGEST start_offset
=
20448 rnglist_base
+ rnglist_index
* cu
->header
.offset_size
;
20450 /* Get rnglists section. */
20451 struct dwarf2_section_info
*section
= cu_debug_rnglists_section (cu
, tag
);
20453 /* Read the rnglists section content. */
20454 section
->read (objfile
);
20455 if (section
->buffer
== nullptr)
20456 error (_("DW_FORM_rnglistx used without .debug_rnglists section "
20458 objfile_name (objfile
));
20460 /* DW_AT_rnglists_base points after the .debug_rnglists contribution header,
20461 so if rnglist_base is smaller than the header size, we have a problem. */
20462 if (rnglist_base
< rnglist_header_size
)
20463 error (_("DW_AT_rnglists_base is smaller than header size [in module %s]"),
20464 objfile_name (objfile
));
20466 /* Read the header of the rnglists contribution. */
20467 struct loclists_rnglists_header header
;
20468 read_loclists_rnglists_header (&header
, section
,
20469 (sect_offset
) (rnglist_base
- rnglist_header_size
));
20471 /* Verify the rnglist index is valid. */
20472 if (rnglist_index
>= header
.offset_entry_count
)
20473 error (_("DW_FORM_rnglistx index pointing outside of "
20474 ".debug_rnglists offset array [in module %s]"),
20475 objfile_name (objfile
));
20477 /* Validate that reading won't go beyond the end of the section. */
20478 if (start_offset
+ cu
->header
.offset_size
> section
->size
)
20479 error (_("Reading DW_FORM_rnglistx index beyond end of"
20480 ".debug_rnglists section [in module %s]"),
20481 objfile_name (objfile
));
20483 const gdb_byte
*info_ptr
= section
->buffer
+ start_offset
;
20485 if (cu
->header
.offset_size
== 4)
20486 return (sect_offset
) (read_4_bytes (abfd
, info_ptr
) + rnglist_base
);
20488 return (sect_offset
) (read_8_bytes (abfd
, info_ptr
) + rnglist_base
);
20491 /* Process the attributes that had to be skipped in the first round. These
20492 attributes are the ones that need str_offsets_base or addr_base attributes.
20493 They could not have been processed in the first round, because at the time
20494 the values of str_offsets_base or addr_base may not have been known. */
20496 read_attribute_reprocess (const struct die_reader_specs
*reader
,
20497 struct attribute
*attr
, dwarf_tag tag
)
20499 struct dwarf2_cu
*cu
= reader
->cu
;
20500 switch (attr
->form
)
20502 case DW_FORM_addrx
:
20503 case DW_FORM_GNU_addr_index
:
20504 attr
->set_address (read_addr_index (cu
,
20505 attr
->as_unsigned_reprocess ()));
20507 case DW_FORM_loclistx
:
20509 sect_offset loclists_sect_off
20510 = read_loclist_index (cu
, attr
->as_unsigned_reprocess ());
20512 attr
->set_unsigned (to_underlying (loclists_sect_off
));
20515 case DW_FORM_rnglistx
:
20517 sect_offset rnglists_sect_off
20518 = read_rnglist_index (cu
, attr
->as_unsigned_reprocess (), tag
);
20520 attr
->set_unsigned (to_underlying (rnglists_sect_off
));
20524 case DW_FORM_strx1
:
20525 case DW_FORM_strx2
:
20526 case DW_FORM_strx3
:
20527 case DW_FORM_strx4
:
20528 case DW_FORM_GNU_str_index
:
20530 unsigned int str_index
= attr
->as_unsigned_reprocess ();
20531 gdb_assert (!attr
->canonical_string_p ());
20532 if (reader
->dwo_file
!= NULL
)
20533 attr
->set_string_noncanonical (read_dwo_str_index (reader
,
20536 attr
->set_string_noncanonical (read_stub_str_index (cu
,
20541 gdb_assert_not_reached (_("Unexpected DWARF form."));
20545 /* Read an attribute value described by an attribute form. */
20547 static const gdb_byte
*
20548 read_attribute_value (const struct die_reader_specs
*reader
,
20549 struct attribute
*attr
, unsigned form
,
20550 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
20552 struct dwarf2_cu
*cu
= reader
->cu
;
20553 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20554 struct objfile
*objfile
= per_objfile
->objfile
;
20555 bfd
*abfd
= reader
->abfd
;
20556 struct comp_unit_head
*cu_header
= &cu
->header
;
20557 unsigned int bytes_read
;
20558 struct dwarf_block
*blk
;
20560 attr
->form
= (enum dwarf_form
) form
;
20563 case DW_FORM_ref_addr
:
20564 if (cu
->header
.version
== 2)
20565 attr
->set_unsigned (cu
->header
.read_address (abfd
, info_ptr
,
20568 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
20570 info_ptr
+= bytes_read
;
20572 case DW_FORM_GNU_ref_alt
:
20573 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
20575 info_ptr
+= bytes_read
;
20579 struct gdbarch
*gdbarch
= objfile
->arch ();
20580 CORE_ADDR addr
= cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
20581 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
);
20582 attr
->set_address (addr
);
20583 info_ptr
+= bytes_read
;
20586 case DW_FORM_block2
:
20587 blk
= dwarf_alloc_block (cu
);
20588 blk
->size
= read_2_bytes (abfd
, info_ptr
);
20590 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20591 info_ptr
+= blk
->size
;
20592 attr
->set_block (blk
);
20594 case DW_FORM_block4
:
20595 blk
= dwarf_alloc_block (cu
);
20596 blk
->size
= read_4_bytes (abfd
, info_ptr
);
20598 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20599 info_ptr
+= blk
->size
;
20600 attr
->set_block (blk
);
20602 case DW_FORM_data2
:
20603 attr
->set_unsigned (read_2_bytes (abfd
, info_ptr
));
20606 case DW_FORM_data4
:
20607 attr
->set_unsigned (read_4_bytes (abfd
, info_ptr
));
20610 case DW_FORM_data8
:
20611 attr
->set_unsigned (read_8_bytes (abfd
, info_ptr
));
20614 case DW_FORM_data16
:
20615 blk
= dwarf_alloc_block (cu
);
20617 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
20619 attr
->set_block (blk
);
20621 case DW_FORM_sec_offset
:
20622 attr
->set_unsigned (cu
->header
.read_offset (abfd
, info_ptr
,
20624 info_ptr
+= bytes_read
;
20626 case DW_FORM_loclistx
:
20628 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20630 info_ptr
+= bytes_read
;
20633 case DW_FORM_string
:
20634 attr
->set_string_noncanonical (read_direct_string (abfd
, info_ptr
,
20636 info_ptr
+= bytes_read
;
20639 if (!cu
->per_cu
->is_dwz
)
20641 attr
->set_string_noncanonical
20642 (read_indirect_string (per_objfile
,
20643 abfd
, info_ptr
, cu_header
,
20645 info_ptr
+= bytes_read
;
20649 case DW_FORM_line_strp
:
20650 if (!cu
->per_cu
->is_dwz
)
20652 attr
->set_string_noncanonical
20653 (per_objfile
->read_line_string (info_ptr
, cu_header
,
20655 info_ptr
+= bytes_read
;
20659 case DW_FORM_GNU_strp_alt
:
20661 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
20662 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
20665 attr
->set_string_noncanonical
20666 (dwz
->read_string (objfile
, str_offset
));
20667 info_ptr
+= bytes_read
;
20670 case DW_FORM_exprloc
:
20671 case DW_FORM_block
:
20672 blk
= dwarf_alloc_block (cu
);
20673 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20674 info_ptr
+= bytes_read
;
20675 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20676 info_ptr
+= blk
->size
;
20677 attr
->set_block (blk
);
20679 case DW_FORM_block1
:
20680 blk
= dwarf_alloc_block (cu
);
20681 blk
->size
= read_1_byte (abfd
, info_ptr
);
20683 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
20684 info_ptr
+= blk
->size
;
20685 attr
->set_block (blk
);
20687 case DW_FORM_data1
:
20689 attr
->set_unsigned (read_1_byte (abfd
, info_ptr
));
20692 case DW_FORM_flag_present
:
20693 attr
->set_unsigned (1);
20695 case DW_FORM_sdata
:
20696 attr
->set_signed (read_signed_leb128 (abfd
, info_ptr
, &bytes_read
));
20697 info_ptr
+= bytes_read
;
20699 case DW_FORM_rnglistx
:
20701 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20703 info_ptr
+= bytes_read
;
20706 case DW_FORM_udata
:
20707 attr
->set_unsigned (read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
20708 info_ptr
+= bytes_read
;
20711 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20712 + read_1_byte (abfd
, info_ptr
)));
20716 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20717 + read_2_bytes (abfd
, info_ptr
)));
20721 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20722 + read_4_bytes (abfd
, info_ptr
)));
20726 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20727 + read_8_bytes (abfd
, info_ptr
)));
20730 case DW_FORM_ref_sig8
:
20731 attr
->set_signature (read_8_bytes (abfd
, info_ptr
));
20734 case DW_FORM_ref_udata
:
20735 attr
->set_unsigned ((to_underlying (cu
->header
.sect_off
)
20736 + read_unsigned_leb128 (abfd
, info_ptr
,
20738 info_ptr
+= bytes_read
;
20740 case DW_FORM_indirect
:
20741 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20742 info_ptr
+= bytes_read
;
20743 if (form
== DW_FORM_implicit_const
)
20745 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
20746 info_ptr
+= bytes_read
;
20748 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
20751 case DW_FORM_implicit_const
:
20752 attr
->set_signed (implicit_const
);
20754 case DW_FORM_addrx
:
20755 case DW_FORM_GNU_addr_index
:
20756 attr
->set_unsigned_reprocess (read_unsigned_leb128 (abfd
, info_ptr
,
20758 info_ptr
+= bytes_read
;
20761 case DW_FORM_strx1
:
20762 case DW_FORM_strx2
:
20763 case DW_FORM_strx3
:
20764 case DW_FORM_strx4
:
20765 case DW_FORM_GNU_str_index
:
20767 ULONGEST str_index
;
20768 if (form
== DW_FORM_strx1
)
20770 str_index
= read_1_byte (abfd
, info_ptr
);
20773 else if (form
== DW_FORM_strx2
)
20775 str_index
= read_2_bytes (abfd
, info_ptr
);
20778 else if (form
== DW_FORM_strx3
)
20780 str_index
= read_3_bytes (abfd
, info_ptr
);
20783 else if (form
== DW_FORM_strx4
)
20785 str_index
= read_4_bytes (abfd
, info_ptr
);
20790 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
20791 info_ptr
+= bytes_read
;
20793 attr
->set_unsigned_reprocess (str_index
);
20797 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
20798 dwarf_form_name (form
),
20799 bfd_get_filename (abfd
));
20803 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
20804 attr
->form
= DW_FORM_GNU_ref_alt
;
20806 /* We have seen instances where the compiler tried to emit a byte
20807 size attribute of -1 which ended up being encoded as an unsigned
20808 0xffffffff. Although 0xffffffff is technically a valid size value,
20809 an object of this size seems pretty unlikely so we can relatively
20810 safely treat these cases as if the size attribute was invalid and
20811 treat them as zero by default. */
20812 if (attr
->name
== DW_AT_byte_size
20813 && form
== DW_FORM_data4
20814 && attr
->as_unsigned () >= 0xffffffff)
20817 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
20818 hex_string (attr
->as_unsigned ()));
20819 attr
->set_unsigned (0);
20825 /* Read an attribute described by an abbreviated attribute. */
20827 static const gdb_byte
*
20828 read_attribute (const struct die_reader_specs
*reader
,
20829 struct attribute
*attr
, const struct attr_abbrev
*abbrev
,
20830 const gdb_byte
*info_ptr
)
20832 attr
->name
= abbrev
->name
;
20833 attr
->string_is_canonical
= 0;
20834 attr
->requires_reprocessing
= 0;
20835 return read_attribute_value (reader
, attr
, abbrev
->form
,
20836 abbrev
->implicit_const
, info_ptr
);
20839 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20841 static const char *
20842 read_indirect_string_at_offset (dwarf2_per_objfile
*per_objfile
,
20843 LONGEST str_offset
)
20845 return per_objfile
->per_bfd
->str
.read_string (per_objfile
->objfile
,
20846 str_offset
, "DW_FORM_strp");
20849 /* Return pointer to string at .debug_str offset as read from BUF.
20850 BUF is assumed to be in a compilation unit described by CU_HEADER.
20851 Return *BYTES_READ_PTR count of bytes read from BUF. */
20853 static const char *
20854 read_indirect_string (dwarf2_per_objfile
*per_objfile
, bfd
*abfd
,
20855 const gdb_byte
*buf
,
20856 const struct comp_unit_head
*cu_header
,
20857 unsigned int *bytes_read_ptr
)
20859 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20861 return read_indirect_string_at_offset (per_objfile
, str_offset
);
20867 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
20868 const struct comp_unit_head
*cu_header
,
20869 unsigned int *bytes_read_ptr
)
20871 bfd
*abfd
= objfile
->obfd
;
20872 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
20874 return per_bfd
->line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
20877 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20878 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20879 ADDR_SIZE is the size of addresses from the CU header. */
20882 read_addr_index_1 (dwarf2_per_objfile
*per_objfile
, unsigned int addr_index
,
20883 gdb::optional
<ULONGEST
> addr_base
, int addr_size
)
20885 struct objfile
*objfile
= per_objfile
->objfile
;
20886 bfd
*abfd
= objfile
->obfd
;
20887 const gdb_byte
*info_ptr
;
20888 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20890 per_objfile
->per_bfd
->addr
.read (objfile
);
20891 if (per_objfile
->per_bfd
->addr
.buffer
== NULL
)
20892 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20893 objfile_name (objfile
));
20894 if (addr_base_or_zero
+ addr_index
* addr_size
20895 >= per_objfile
->per_bfd
->addr
.size
)
20896 error (_("DW_FORM_addr_index pointing outside of "
20897 ".debug_addr section [in module %s]"),
20898 objfile_name (objfile
));
20899 info_ptr
= (per_objfile
->per_bfd
->addr
.buffer
+ addr_base_or_zero
20900 + addr_index
* addr_size
);
20901 if (addr_size
== 4)
20902 return bfd_get_32 (abfd
, info_ptr
);
20904 return bfd_get_64 (abfd
, info_ptr
);
20907 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20910 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20912 return read_addr_index_1 (cu
->per_objfile
, addr_index
,
20913 cu
->addr_base
, cu
->header
.addr_size
);
20916 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20919 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20920 unsigned int *bytes_read
)
20922 bfd
*abfd
= cu
->per_objfile
->objfile
->obfd
;
20923 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20925 return read_addr_index (cu
, addr_index
);
20931 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
20932 dwarf2_per_objfile
*per_objfile
,
20933 unsigned int addr_index
)
20935 struct dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
20936 gdb::optional
<ULONGEST
> addr_base
;
20939 /* We need addr_base and addr_size.
20940 If we don't have PER_CU->cu, we have to get it.
20941 Nasty, but the alternative is storing the needed info in PER_CU,
20942 which at this point doesn't seem justified: it's not clear how frequently
20943 it would get used and it would increase the size of every PER_CU.
20944 Entry points like dwarf2_per_cu_addr_size do a similar thing
20945 so we're not in uncharted territory here.
20946 Alas we need to be a bit more complicated as addr_base is contained
20949 We don't need to read the entire CU(/TU).
20950 We just need the header and top level die.
20952 IWBN to use the aging mechanism to let us lazily later discard the CU.
20953 For now we skip this optimization. */
20957 addr_base
= cu
->addr_base
;
20958 addr_size
= cu
->header
.addr_size
;
20962 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
20963 addr_base
= reader
.cu
->addr_base
;
20964 addr_size
= reader
.cu
->header
.addr_size
;
20967 return read_addr_index_1 (per_objfile
, addr_index
, addr_base
, addr_size
);
20970 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20971 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20974 static const char *
20975 read_str_index (struct dwarf2_cu
*cu
,
20976 struct dwarf2_section_info
*str_section
,
20977 struct dwarf2_section_info
*str_offsets_section
,
20978 ULONGEST str_offsets_base
, ULONGEST str_index
)
20980 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
20981 struct objfile
*objfile
= per_objfile
->objfile
;
20982 const char *objf_name
= objfile_name (objfile
);
20983 bfd
*abfd
= objfile
->obfd
;
20984 const gdb_byte
*info_ptr
;
20985 ULONGEST str_offset
;
20986 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20988 str_section
->read (objfile
);
20989 str_offsets_section
->read (objfile
);
20990 if (str_section
->buffer
== NULL
)
20991 error (_("%s used without %s section"
20992 " in CU at offset %s [in module %s]"),
20993 form_name
, str_section
->get_name (),
20994 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20995 if (str_offsets_section
->buffer
== NULL
)
20996 error (_("%s used without %s section"
20997 " in CU at offset %s [in module %s]"),
20998 form_name
, str_section
->get_name (),
20999 sect_offset_str (cu
->header
.sect_off
), objf_name
);
21000 info_ptr
= (str_offsets_section
->buffer
21002 + str_index
* cu
->header
.offset_size
);
21003 if (cu
->header
.offset_size
== 4)
21004 str_offset
= bfd_get_32 (abfd
, info_ptr
);
21006 str_offset
= bfd_get_64 (abfd
, info_ptr
);
21007 if (str_offset
>= str_section
->size
)
21008 error (_("Offset from %s pointing outside of"
21009 " .debug_str.dwo section in CU at offset %s [in module %s]"),
21010 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
21011 return (const char *) (str_section
->buffer
+ str_offset
);
21014 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
21016 static const char *
21017 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
21019 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
21020 ? reader
->cu
->header
.addr_size
: 0;
21021 return read_str_index (reader
->cu
,
21022 &reader
->dwo_file
->sections
.str
,
21023 &reader
->dwo_file
->sections
.str_offsets
,
21024 str_offsets_base
, str_index
);
21027 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
21029 static const char *
21030 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
21032 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21033 const char *objf_name
= objfile_name (objfile
);
21034 static const char form_name
[] = "DW_FORM_GNU_str_index";
21035 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
21037 if (!cu
->str_offsets_base
.has_value ())
21038 error (_("%s used in Fission stub without %s"
21039 " in CU at offset 0x%lx [in module %s]"),
21040 form_name
, str_offsets_attr_name
,
21041 (long) cu
->header
.offset_size
, objf_name
);
21043 return read_str_index (cu
,
21044 &cu
->per_objfile
->per_bfd
->str
,
21045 &cu
->per_objfile
->per_bfd
->str_offsets
,
21046 *cu
->str_offsets_base
, str_index
);
21049 /* Return the length of an LEB128 number in BUF. */
21052 leb128_size (const gdb_byte
*buf
)
21054 const gdb_byte
*begin
= buf
;
21060 if ((byte
& 128) == 0)
21061 return buf
- begin
;
21066 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
21075 cu
->language
= language_c
;
21078 case DW_LANG_C_plus_plus
:
21079 case DW_LANG_C_plus_plus_11
:
21080 case DW_LANG_C_plus_plus_14
:
21081 cu
->language
= language_cplus
;
21084 cu
->language
= language_d
;
21086 case DW_LANG_Fortran77
:
21087 case DW_LANG_Fortran90
:
21088 case DW_LANG_Fortran95
:
21089 case DW_LANG_Fortran03
:
21090 case DW_LANG_Fortran08
:
21091 cu
->language
= language_fortran
;
21094 cu
->language
= language_go
;
21096 case DW_LANG_Mips_Assembler
:
21097 cu
->language
= language_asm
;
21099 case DW_LANG_Ada83
:
21100 case DW_LANG_Ada95
:
21101 cu
->language
= language_ada
;
21103 case DW_LANG_Modula2
:
21104 cu
->language
= language_m2
;
21106 case DW_LANG_Pascal83
:
21107 cu
->language
= language_pascal
;
21110 cu
->language
= language_objc
;
21113 case DW_LANG_Rust_old
:
21114 cu
->language
= language_rust
;
21116 case DW_LANG_Cobol74
:
21117 case DW_LANG_Cobol85
:
21119 cu
->language
= language_minimal
;
21122 cu
->language_defn
= language_def (cu
->language
);
21125 /* Return the named attribute or NULL if not there. */
21127 static struct attribute
*
21128 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
21133 struct attribute
*spec
= NULL
;
21135 for (i
= 0; i
< die
->num_attrs
; ++i
)
21137 if (die
->attrs
[i
].name
== name
)
21138 return &die
->attrs
[i
];
21139 if (die
->attrs
[i
].name
== DW_AT_specification
21140 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
21141 spec
= &die
->attrs
[i
];
21147 die
= follow_die_ref (die
, spec
, &cu
);
21153 /* Return the string associated with a string-typed attribute, or NULL if it
21154 is either not found or is of an incorrect type. */
21156 static const char *
21157 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
21159 struct attribute
*attr
;
21160 const char *str
= NULL
;
21162 attr
= dwarf2_attr (die
, name
, cu
);
21166 str
= attr
->as_string ();
21167 if (str
== nullptr)
21168 complaint (_("string type expected for attribute %s for "
21169 "DIE at %s in module %s"),
21170 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
21171 objfile_name (cu
->per_objfile
->objfile
));
21177 /* Return the dwo name or NULL if not present. If present, it is in either
21178 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
21179 static const char *
21180 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21182 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
21183 if (dwo_name
== nullptr)
21184 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
21188 /* Return non-zero iff the attribute NAME is defined for the given DIE,
21189 and holds a non-zero value. This function should only be used for
21190 DW_FORM_flag or DW_FORM_flag_present attributes. */
21193 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
21195 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
21197 return attr
!= nullptr && attr
->as_boolean ();
21201 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
21203 /* A DIE is a declaration if it has a DW_AT_declaration attribute
21204 which value is non-zero. However, we have to be careful with
21205 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
21206 (via dwarf2_flag_true_p) follows this attribute. So we may
21207 end up accidently finding a declaration attribute that belongs
21208 to a different DIE referenced by the specification attribute,
21209 even though the given DIE does not have a declaration attribute. */
21210 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
21211 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
21214 /* Return the die giving the specification for DIE, if there is
21215 one. *SPEC_CU is the CU containing DIE on input, and the CU
21216 containing the return value on output. If there is no
21217 specification, but there is an abstract origin, that is
21220 static struct die_info
*
21221 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
21223 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
21226 if (spec_attr
== NULL
)
21227 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
21229 if (spec_attr
== NULL
)
21232 return follow_die_ref (die
, spec_attr
, spec_cu
);
21235 /* Stub for free_line_header to match void * callback types. */
21238 free_line_header_voidp (void *arg
)
21240 struct line_header
*lh
= (struct line_header
*) arg
;
21245 /* A convenience function to find the proper .debug_line section for a CU. */
21247 static struct dwarf2_section_info
*
21248 get_debug_line_section (struct dwarf2_cu
*cu
)
21250 struct dwarf2_section_info
*section
;
21251 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21253 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
21255 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
21256 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
21257 else if (cu
->per_cu
->is_dwz
)
21259 dwz_file
*dwz
= dwarf2_get_dwz_file (per_objfile
->per_bfd
, true);
21261 section
= &dwz
->line
;
21264 section
= &per_objfile
->per_bfd
->line
;
21269 /* Read the statement program header starting at OFFSET in
21270 .debug_line, or .debug_line.dwo. Return a pointer
21271 to a struct line_header, allocated using xmalloc.
21272 Returns NULL if there is a problem reading the header, e.g., if it
21273 has a version we don't understand.
21275 NOTE: the strings in the include directory and file name tables of
21276 the returned object point into the dwarf line section buffer,
21277 and must not be freed. */
21279 static line_header_up
21280 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
21282 struct dwarf2_section_info
*section
;
21283 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
21285 section
= get_debug_line_section (cu
);
21286 section
->read (per_objfile
->objfile
);
21287 if (section
->buffer
== NULL
)
21289 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
21290 complaint (_("missing .debug_line.dwo section"));
21292 complaint (_("missing .debug_line section"));
21296 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
21297 per_objfile
, section
, &cu
->header
);
21300 /* Subroutine of dwarf_decode_lines to simplify it.
21301 Return the file name of the psymtab for the given file_entry.
21302 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21303 If space for the result is malloc'd, *NAME_HOLDER will be set.
21304 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
21306 static const char *
21307 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
21308 const dwarf2_psymtab
*pst
,
21309 const char *comp_dir
,
21310 gdb::unique_xmalloc_ptr
<char> *name_holder
)
21312 const char *include_name
= fe
.name
;
21313 const char *include_name_to_compare
= include_name
;
21314 const char *pst_filename
;
21317 const char *dir_name
= fe
.include_dir (lh
);
21319 gdb::unique_xmalloc_ptr
<char> hold_compare
;
21320 if (!IS_ABSOLUTE_PATH (include_name
)
21321 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
21323 /* Avoid creating a duplicate psymtab for PST.
21324 We do this by comparing INCLUDE_NAME and PST_FILENAME.
21325 Before we do the comparison, however, we need to account
21326 for DIR_NAME and COMP_DIR.
21327 First prepend dir_name (if non-NULL). If we still don't
21328 have an absolute path prepend comp_dir (if non-NULL).
21329 However, the directory we record in the include-file's
21330 psymtab does not contain COMP_DIR (to match the
21331 corresponding symtab(s)).
21336 bash$ gcc -g ./hello.c
21337 include_name = "hello.c"
21339 DW_AT_comp_dir = comp_dir = "/tmp"
21340 DW_AT_name = "./hello.c"
21344 if (dir_name
!= NULL
)
21346 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
21347 include_name
, (char *) NULL
));
21348 include_name
= name_holder
->get ();
21349 include_name_to_compare
= include_name
;
21351 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
21353 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
21354 include_name
, (char *) NULL
));
21355 include_name_to_compare
= hold_compare
.get ();
21359 pst_filename
= pst
->filename
;
21360 gdb::unique_xmalloc_ptr
<char> copied_name
;
21361 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
21363 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
21364 pst_filename
, (char *) NULL
));
21365 pst_filename
= copied_name
.get ();
21368 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
21372 return include_name
;
21375 /* State machine to track the state of the line number program. */
21377 class lnp_state_machine
21380 /* Initialize a machine state for the start of a line number
21382 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
21383 bool record_lines_p
);
21385 file_entry
*current_file ()
21387 /* lh->file_names is 0-based, but the file name numbers in the
21388 statement program are 1-based. */
21389 return m_line_header
->file_name_at (m_file
);
21392 /* Record the line in the state machine. END_SEQUENCE is true if
21393 we're processing the end of a sequence. */
21394 void record_line (bool end_sequence
);
21396 /* Check ADDRESS is -1, or zero and less than UNRELOCATED_LOWPC, and if true
21397 nop-out rest of the lines in this sequence. */
21398 void check_line_address (struct dwarf2_cu
*cu
,
21399 const gdb_byte
*line_ptr
,
21400 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
21402 void handle_set_discriminator (unsigned int discriminator
)
21404 m_discriminator
= discriminator
;
21405 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21408 /* Handle DW_LNE_set_address. */
21409 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21412 address
+= baseaddr
;
21413 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21416 /* Handle DW_LNS_advance_pc. */
21417 void handle_advance_pc (CORE_ADDR adjust
);
21419 /* Handle a special opcode. */
21420 void handle_special_opcode (unsigned char op_code
);
21422 /* Handle DW_LNS_advance_line. */
21423 void handle_advance_line (int line_delta
)
21425 advance_line (line_delta
);
21428 /* Handle DW_LNS_set_file. */
21429 void handle_set_file (file_name_index file
);
21431 /* Handle DW_LNS_negate_stmt. */
21432 void handle_negate_stmt ()
21434 m_is_stmt
= !m_is_stmt
;
21437 /* Handle DW_LNS_const_add_pc. */
21438 void handle_const_add_pc ();
21440 /* Handle DW_LNS_fixed_advance_pc. */
21441 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21443 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21447 /* Handle DW_LNS_copy. */
21448 void handle_copy ()
21450 record_line (false);
21451 m_discriminator
= 0;
21454 /* Handle DW_LNE_end_sequence. */
21455 void handle_end_sequence ()
21457 m_currently_recording_lines
= true;
21461 /* Advance the line by LINE_DELTA. */
21462 void advance_line (int line_delta
)
21464 m_line
+= line_delta
;
21466 if (line_delta
!= 0)
21467 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21470 struct dwarf2_cu
*m_cu
;
21472 gdbarch
*m_gdbarch
;
21474 /* True if we're recording lines.
21475 Otherwise we're building partial symtabs and are just interested in
21476 finding include files mentioned by the line number program. */
21477 bool m_record_lines_p
;
21479 /* The line number header. */
21480 line_header
*m_line_header
;
21482 /* These are part of the standard DWARF line number state machine,
21483 and initialized according to the DWARF spec. */
21485 unsigned char m_op_index
= 0;
21486 /* The line table index of the current file. */
21487 file_name_index m_file
= 1;
21488 unsigned int m_line
= 1;
21490 /* These are initialized in the constructor. */
21492 CORE_ADDR m_address
;
21494 unsigned int m_discriminator
;
21496 /* Additional bits of state we need to track. */
21498 /* The last file that we called dwarf2_start_subfile for.
21499 This is only used for TLLs. */
21500 unsigned int m_last_file
= 0;
21501 /* The last file a line number was recorded for. */
21502 struct subfile
*m_last_subfile
= NULL
;
21504 /* The address of the last line entry. */
21505 CORE_ADDR m_last_address
;
21507 /* Set to true when a previous line at the same address (using
21508 m_last_address) had m_is_stmt true. This is reset to false when a
21509 line entry at a new address (m_address different to m_last_address) is
21511 bool m_stmt_at_address
= false;
21513 /* When true, record the lines we decode. */
21514 bool m_currently_recording_lines
= false;
21516 /* The last line number that was recorded, used to coalesce
21517 consecutive entries for the same line. This can happen, for
21518 example, when discriminators are present. PR 17276. */
21519 unsigned int m_last_line
= 0;
21520 bool m_line_has_non_zero_discriminator
= false;
21524 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21526 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21527 / m_line_header
->maximum_ops_per_instruction
)
21528 * m_line_header
->minimum_instruction_length
);
21529 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21530 m_op_index
= ((m_op_index
+ adjust
)
21531 % m_line_header
->maximum_ops_per_instruction
);
21535 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21537 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21538 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
21539 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
21540 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
21541 / m_line_header
->maximum_ops_per_instruction
)
21542 * m_line_header
->minimum_instruction_length
);
21543 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21544 m_op_index
= ((m_op_index
+ adj_opcode_d
)
21545 % m_line_header
->maximum_ops_per_instruction
);
21547 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
21548 advance_line (line_delta
);
21549 record_line (false);
21550 m_discriminator
= 0;
21554 lnp_state_machine::handle_set_file (file_name_index file
)
21558 const file_entry
*fe
= current_file ();
21560 dwarf2_debug_line_missing_file_complaint ();
21561 else if (m_record_lines_p
)
21563 const char *dir
= fe
->include_dir (m_line_header
);
21565 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21566 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21567 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21572 lnp_state_machine::handle_const_add_pc ()
21575 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21578 = (((m_op_index
+ adjust
)
21579 / m_line_header
->maximum_ops_per_instruction
)
21580 * m_line_header
->minimum_instruction_length
);
21582 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21583 m_op_index
= ((m_op_index
+ adjust
)
21584 % m_line_header
->maximum_ops_per_instruction
);
21587 /* Return non-zero if we should add LINE to the line number table.
21588 LINE is the line to add, LAST_LINE is the last line that was added,
21589 LAST_SUBFILE is the subfile for LAST_LINE.
21590 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21591 had a non-zero discriminator.
21593 We have to be careful in the presence of discriminators.
21594 E.g., for this line:
21596 for (i = 0; i < 100000; i++);
21598 clang can emit four line number entries for that one line,
21599 each with a different discriminator.
21600 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21602 However, we want gdb to coalesce all four entries into one.
21603 Otherwise the user could stepi into the middle of the line and
21604 gdb would get confused about whether the pc really was in the
21605 middle of the line.
21607 Things are further complicated by the fact that two consecutive
21608 line number entries for the same line is a heuristic used by gcc
21609 to denote the end of the prologue. So we can't just discard duplicate
21610 entries, we have to be selective about it. The heuristic we use is
21611 that we only collapse consecutive entries for the same line if at least
21612 one of those entries has a non-zero discriminator. PR 17276.
21614 Note: Addresses in the line number state machine can never go backwards
21615 within one sequence, thus this coalescing is ok. */
21618 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21619 unsigned int line
, unsigned int last_line
,
21620 int line_has_non_zero_discriminator
,
21621 struct subfile
*last_subfile
)
21623 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21625 if (line
!= last_line
)
21627 /* Same line for the same file that we've seen already.
21628 As a last check, for pr 17276, only record the line if the line
21629 has never had a non-zero discriminator. */
21630 if (!line_has_non_zero_discriminator
)
21635 /* Use the CU's builder to record line number LINE beginning at
21636 address ADDRESS in the line table of subfile SUBFILE. */
21639 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21640 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
21641 struct dwarf2_cu
*cu
)
21643 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21645 if (dwarf_line_debug
)
21647 fprintf_unfiltered (gdb_stdlog
,
21648 "Recording line %u, file %s, address %s\n",
21649 line
, lbasename (subfile
->name
),
21650 paddress (gdbarch
, address
));
21654 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
21657 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21658 Mark the end of a set of line number records.
21659 The arguments are the same as for dwarf_record_line_1.
21660 If SUBFILE is NULL the request is ignored. */
21663 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21664 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21666 if (subfile
== NULL
)
21669 if (dwarf_line_debug
)
21671 fprintf_unfiltered (gdb_stdlog
,
21672 "Finishing current line, file %s, address %s\n",
21673 lbasename (subfile
->name
),
21674 paddress (gdbarch
, address
));
21677 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
21681 lnp_state_machine::record_line (bool end_sequence
)
21683 if (dwarf_line_debug
)
21685 fprintf_unfiltered (gdb_stdlog
,
21686 "Processing actual line %u: file %u,"
21687 " address %s, is_stmt %u, discrim %u%s\n",
21689 paddress (m_gdbarch
, m_address
),
21690 m_is_stmt
, m_discriminator
,
21691 (end_sequence
? "\t(end sequence)" : ""));
21694 file_entry
*fe
= current_file ();
21697 dwarf2_debug_line_missing_file_complaint ();
21698 /* For now we ignore lines not starting on an instruction boundary.
21699 But not when processing end_sequence for compatibility with the
21700 previous version of the code. */
21701 else if (m_op_index
== 0 || end_sequence
)
21703 fe
->included_p
= 1;
21704 if (m_record_lines_p
)
21706 /* When we switch files we insert an end maker in the first file,
21707 switch to the second file and add a new line entry. The
21708 problem is that the end marker inserted in the first file will
21709 discard any previous line entries at the same address. If the
21710 line entries in the first file are marked as is-stmt, while
21711 the new line in the second file is non-stmt, then this means
21712 the end marker will discard is-stmt lines so we can have a
21713 non-stmt line. This means that there are less addresses at
21714 which the user can insert a breakpoint.
21716 To improve this we track the last address in m_last_address,
21717 and whether we have seen an is-stmt at this address. Then
21718 when switching files, if we have seen a stmt at the current
21719 address, and we are switching to create a non-stmt line, then
21720 discard the new line. */
21722 = m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ();
21723 bool ignore_this_line
21724 = ((file_changed
&& !end_sequence
&& m_last_address
== m_address
21725 && !m_is_stmt
&& m_stmt_at_address
)
21726 || (!end_sequence
&& m_line
== 0));
21728 if ((file_changed
&& !ignore_this_line
) || end_sequence
)
21730 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21731 m_currently_recording_lines
? m_cu
: nullptr);
21734 if (!end_sequence
&& !ignore_this_line
)
21736 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
21738 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21739 m_line_has_non_zero_discriminator
,
21742 buildsym_compunit
*builder
= m_cu
->get_builder ();
21743 dwarf_record_line_1 (m_gdbarch
,
21744 builder
->get_current_subfile (),
21745 m_line
, m_address
, is_stmt
,
21746 m_currently_recording_lines
? m_cu
: nullptr);
21748 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21749 m_last_line
= m_line
;
21754 /* Track whether we have seen any m_is_stmt true at m_address in case we
21755 have multiple line table entries all at m_address. */
21756 if (m_last_address
!= m_address
)
21758 m_stmt_at_address
= false;
21759 m_last_address
= m_address
;
21761 m_stmt_at_address
|= m_is_stmt
;
21764 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21765 line_header
*lh
, bool record_lines_p
)
21769 m_record_lines_p
= record_lines_p
;
21770 m_line_header
= lh
;
21772 m_currently_recording_lines
= true;
21774 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21775 was a line entry for it so that the backend has a chance to adjust it
21776 and also record it in case it needs it. This is currently used by MIPS
21777 code, cf. `mips_adjust_dwarf2_line'. */
21778 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21779 m_is_stmt
= lh
->default_is_stmt
;
21780 m_discriminator
= 0;
21782 m_last_address
= m_address
;
21783 m_stmt_at_address
= false;
21787 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21788 const gdb_byte
*line_ptr
,
21789 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21791 /* Linkers resolve a symbolic relocation referencing a GC'd function to 0 or
21792 -1. If ADDRESS is 0, ignoring the opcode will err if the text section is
21793 located at 0x0. In this case, additionally check that if
21794 ADDRESS < UNRELOCATED_LOWPC. */
21796 if ((address
== 0 && address
< unrelocated_lowpc
)
21797 || address
== (CORE_ADDR
) -1)
21799 /* This line table is for a function which has been
21800 GCd by the linker. Ignore it. PR gdb/12528 */
21802 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21803 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21805 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21806 line_offset
, objfile_name (objfile
));
21807 m_currently_recording_lines
= false;
21808 /* Note: m_currently_recording_lines is left as false until we see
21809 DW_LNE_end_sequence. */
21813 /* Subroutine of dwarf_decode_lines to simplify it.
21814 Process the line number information in LH.
21815 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21816 program in order to set included_p for every referenced header. */
21819 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21820 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21822 const gdb_byte
*line_ptr
, *extended_end
;
21823 const gdb_byte
*line_end
;
21824 unsigned int bytes_read
, extended_len
;
21825 unsigned char op_code
, extended_op
;
21826 CORE_ADDR baseaddr
;
21827 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
21828 bfd
*abfd
= objfile
->obfd
;
21829 struct gdbarch
*gdbarch
= objfile
->arch ();
21830 /* True if we're recording line info (as opposed to building partial
21831 symtabs and just interested in finding include files mentioned by
21832 the line number program). */
21833 bool record_lines_p
= !decode_for_pst_p
;
21835 baseaddr
= objfile
->text_section_offset ();
21837 line_ptr
= lh
->statement_program_start
;
21838 line_end
= lh
->statement_program_end
;
21840 /* Read the statement sequences until there's nothing left. */
21841 while (line_ptr
< line_end
)
21843 /* The DWARF line number program state machine. Reset the state
21844 machine at the start of each sequence. */
21845 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21846 bool end_sequence
= false;
21848 if (record_lines_p
)
21850 /* Start a subfile for the current file of the state
21852 const file_entry
*fe
= state_machine
.current_file ();
21855 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21858 /* Decode the table. */
21859 while (line_ptr
< line_end
&& !end_sequence
)
21861 op_code
= read_1_byte (abfd
, line_ptr
);
21864 if (op_code
>= lh
->opcode_base
)
21866 /* Special opcode. */
21867 state_machine
.handle_special_opcode (op_code
);
21869 else switch (op_code
)
21871 case DW_LNS_extended_op
:
21872 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21874 line_ptr
+= bytes_read
;
21875 extended_end
= line_ptr
+ extended_len
;
21876 extended_op
= read_1_byte (abfd
, line_ptr
);
21878 if (DW_LNE_lo_user
<= extended_op
21879 && extended_op
<= DW_LNE_hi_user
)
21881 /* Vendor extension, ignore. */
21882 line_ptr
= extended_end
;
21885 switch (extended_op
)
21887 case DW_LNE_end_sequence
:
21888 state_machine
.handle_end_sequence ();
21889 end_sequence
= true;
21891 case DW_LNE_set_address
:
21894 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
21895 line_ptr
+= bytes_read
;
21897 state_machine
.check_line_address (cu
, line_ptr
,
21898 lowpc
- baseaddr
, address
);
21899 state_machine
.handle_set_address (baseaddr
, address
);
21902 case DW_LNE_define_file
:
21904 const char *cur_file
;
21905 unsigned int mod_time
, length
;
21908 cur_file
= read_direct_string (abfd
, line_ptr
,
21910 line_ptr
+= bytes_read
;
21911 dindex
= (dir_index
)
21912 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21913 line_ptr
+= bytes_read
;
21915 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21916 line_ptr
+= bytes_read
;
21918 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21919 line_ptr
+= bytes_read
;
21920 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21923 case DW_LNE_set_discriminator
:
21925 /* The discriminator is not interesting to the
21926 debugger; just ignore it. We still need to
21927 check its value though:
21928 if there are consecutive entries for the same
21929 (non-prologue) line we want to coalesce them.
21932 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21933 line_ptr
+= bytes_read
;
21935 state_machine
.handle_set_discriminator (discr
);
21939 complaint (_("mangled .debug_line section"));
21942 /* Make sure that we parsed the extended op correctly. If e.g.
21943 we expected a different address size than the producer used,
21944 we may have read the wrong number of bytes. */
21945 if (line_ptr
!= extended_end
)
21947 complaint (_("mangled .debug_line section"));
21952 state_machine
.handle_copy ();
21954 case DW_LNS_advance_pc
:
21957 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21958 line_ptr
+= bytes_read
;
21960 state_machine
.handle_advance_pc (adjust
);
21963 case DW_LNS_advance_line
:
21966 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21967 line_ptr
+= bytes_read
;
21969 state_machine
.handle_advance_line (line_delta
);
21972 case DW_LNS_set_file
:
21974 file_name_index file
21975 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21977 line_ptr
+= bytes_read
;
21979 state_machine
.handle_set_file (file
);
21982 case DW_LNS_set_column
:
21983 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21984 line_ptr
+= bytes_read
;
21986 case DW_LNS_negate_stmt
:
21987 state_machine
.handle_negate_stmt ();
21989 case DW_LNS_set_basic_block
:
21991 /* Add to the address register of the state machine the
21992 address increment value corresponding to special opcode
21993 255. I.e., this value is scaled by the minimum
21994 instruction length since special opcode 255 would have
21995 scaled the increment. */
21996 case DW_LNS_const_add_pc
:
21997 state_machine
.handle_const_add_pc ();
21999 case DW_LNS_fixed_advance_pc
:
22001 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
22004 state_machine
.handle_fixed_advance_pc (addr_adj
);
22009 /* Unknown standard opcode, ignore it. */
22012 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
22014 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
22015 line_ptr
+= bytes_read
;
22022 dwarf2_debug_line_missing_end_sequence_complaint ();
22024 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
22025 in which case we still finish recording the last line). */
22026 state_machine
.record_line (true);
22030 /* Decode the Line Number Program (LNP) for the given line_header
22031 structure and CU. The actual information extracted and the type
22032 of structures created from the LNP depends on the value of PST.
22034 1. If PST is NULL, then this procedure uses the data from the program
22035 to create all necessary symbol tables, and their linetables.
22037 2. If PST is not NULL, this procedure reads the program to determine
22038 the list of files included by the unit represented by PST, and
22039 builds all the associated partial symbol tables.
22041 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
22042 It is used for relative paths in the line table.
22043 NOTE: When processing partial symtabs (pst != NULL),
22044 comp_dir == pst->dirname.
22046 NOTE: It is important that psymtabs have the same file name (via strcmp)
22047 as the corresponding symtab. Since COMP_DIR is not used in the name of the
22048 symtab we don't use it in the name of the psymtabs we create.
22049 E.g. expand_line_sal requires this when finding psymtabs to expand.
22050 A good testcase for this is mb-inline.exp.
22052 LOWPC is the lowest address in CU (or 0 if not known).
22054 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
22055 for its PC<->lines mapping information. Otherwise only the filename
22056 table is read in. */
22059 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
22060 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
22061 CORE_ADDR lowpc
, int decode_mapping
)
22063 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22064 const int decode_for_pst_p
= (pst
!= NULL
);
22066 if (decode_mapping
)
22067 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
22069 if (decode_for_pst_p
)
22071 /* Now that we're done scanning the Line Header Program, we can
22072 create the psymtab of each included file. */
22073 for (auto &file_entry
: lh
->file_names ())
22074 if (file_entry
.included_p
== 1)
22076 gdb::unique_xmalloc_ptr
<char> name_holder
;
22077 const char *include_name
=
22078 psymtab_include_file_name (lh
, file_entry
, pst
,
22079 comp_dir
, &name_holder
);
22080 if (include_name
!= NULL
)
22081 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
22086 /* Make sure a symtab is created for every file, even files
22087 which contain only variables (i.e. no code with associated
22089 buildsym_compunit
*builder
= cu
->get_builder ();
22090 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
22092 for (auto &fe
: lh
->file_names ())
22094 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
22095 if (builder
->get_current_subfile ()->symtab
== NULL
)
22097 builder
->get_current_subfile ()->symtab
22098 = allocate_symtab (cust
,
22099 builder
->get_current_subfile ()->name
);
22101 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
22106 /* Start a subfile for DWARF. FILENAME is the name of the file and
22107 DIRNAME the name of the source directory which contains FILENAME
22108 or NULL if not known.
22109 This routine tries to keep line numbers from identical absolute and
22110 relative file names in a common subfile.
22112 Using the `list' example from the GDB testsuite, which resides in
22113 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
22114 of /srcdir/list0.c yields the following debugging information for list0.c:
22116 DW_AT_name: /srcdir/list0.c
22117 DW_AT_comp_dir: /compdir
22118 files.files[0].name: list0.h
22119 files.files[0].dir: /srcdir
22120 files.files[1].name: list0.c
22121 files.files[1].dir: /srcdir
22123 The line number information for list0.c has to end up in a single
22124 subfile, so that `break /srcdir/list0.c:1' works as expected.
22125 start_subfile will ensure that this happens provided that we pass the
22126 concatenation of files.files[1].dir and files.files[1].name as the
22130 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
22131 const char *dirname
)
22133 gdb::unique_xmalloc_ptr
<char> copy
;
22135 /* In order not to lose the line information directory,
22136 we concatenate it to the filename when it makes sense.
22137 Note that the Dwarf3 standard says (speaking of filenames in line
22138 information): ``The directory index is ignored for file names
22139 that represent full path names''. Thus ignoring dirname in the
22140 `else' branch below isn't an issue. */
22142 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
22144 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
22145 filename
= copy
.get ();
22148 cu
->get_builder ()->start_subfile (filename
);
22151 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
22152 buildsym_compunit constructor. */
22154 struct compunit_symtab
*
22155 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
22158 gdb_assert (m_builder
== nullptr);
22160 m_builder
.reset (new struct buildsym_compunit
22161 (this->per_objfile
->objfile
,
22162 name
, comp_dir
, language
, low_pc
));
22164 list_in_scope
= get_builder ()->get_file_symbols ();
22166 get_builder ()->record_debugformat ("DWARF 2");
22167 get_builder ()->record_producer (producer
);
22169 processing_has_namespace_info
= false;
22171 return get_builder ()->get_compunit_symtab ();
22175 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
22176 struct dwarf2_cu
*cu
)
22178 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22179 struct comp_unit_head
*cu_header
= &cu
->header
;
22181 /* NOTE drow/2003-01-30: There used to be a comment and some special
22182 code here to turn a symbol with DW_AT_external and a
22183 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
22184 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
22185 with some versions of binutils) where shared libraries could have
22186 relocations against symbols in their debug information - the
22187 minimal symbol would have the right address, but the debug info
22188 would not. It's no longer necessary, because we will explicitly
22189 apply relocations when we read in the debug information now. */
22191 /* A DW_AT_location attribute with no contents indicates that a
22192 variable has been optimized away. */
22193 if (attr
->form_is_block () && attr
->as_block ()->size
== 0)
22195 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22199 /* Handle one degenerate form of location expression specially, to
22200 preserve GDB's previous behavior when section offsets are
22201 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
22202 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
22204 if (attr
->form_is_block ())
22206 struct dwarf_block
*block
= attr
->as_block ();
22208 if ((block
->data
[0] == DW_OP_addr
22209 && block
->size
== 1 + cu_header
->addr_size
)
22210 || ((block
->data
[0] == DW_OP_GNU_addr_index
22211 || block
->data
[0] == DW_OP_addrx
)
22213 == 1 + leb128_size (&block
->data
[1]))))
22215 unsigned int dummy
;
22217 if (block
->data
[0] == DW_OP_addr
)
22218 SET_SYMBOL_VALUE_ADDRESS
22219 (sym
, cu
->header
.read_address (objfile
->obfd
,
22223 SET_SYMBOL_VALUE_ADDRESS
22224 (sym
, read_addr_index_from_leb128 (cu
, block
->data
+ 1,
22226 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
22227 fixup_symbol_section (sym
, objfile
);
22228 SET_SYMBOL_VALUE_ADDRESS
22230 SYMBOL_VALUE_ADDRESS (sym
)
22231 + objfile
->section_offsets
[sym
->section_index ()]);
22236 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
22237 expression evaluator, and use LOC_COMPUTED only when necessary
22238 (i.e. when the value of a register or memory location is
22239 referenced, or a thread-local block, etc.). Then again, it might
22240 not be worthwhile. I'm assuming that it isn't unless performance
22241 or memory numbers show me otherwise. */
22243 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
22245 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
22246 cu
->has_loclist
= true;
22249 /* Given a pointer to a DWARF information entry, figure out if we need
22250 to make a symbol table entry for it, and if so, create a new entry
22251 and return a pointer to it.
22252 If TYPE is NULL, determine symbol type from the die, otherwise
22253 used the passed type.
22254 If SPACE is not NULL, use it to hold the new symbol. If it is
22255 NULL, allocate a new symbol on the objfile's obstack. */
22257 static struct symbol
*
22258 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
22259 struct symbol
*space
)
22261 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22262 struct objfile
*objfile
= per_objfile
->objfile
;
22263 struct gdbarch
*gdbarch
= objfile
->arch ();
22264 struct symbol
*sym
= NULL
;
22266 struct attribute
*attr
= NULL
;
22267 struct attribute
*attr2
= NULL
;
22268 CORE_ADDR baseaddr
;
22269 struct pending
**list_to_add
= NULL
;
22271 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
22273 baseaddr
= objfile
->text_section_offset ();
22275 name
= dwarf2_name (die
, cu
);
22278 int suppress_add
= 0;
22283 sym
= new (&objfile
->objfile_obstack
) symbol
;
22284 OBJSTAT (objfile
, n_syms
++);
22286 /* Cache this symbol's name and the name's demangled form (if any). */
22287 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
22288 /* Fortran does not have mangling standard and the mangling does differ
22289 between gfortran, iFort etc. */
22290 const char *physname
22291 = (cu
->language
== language_fortran
22292 ? dwarf2_full_name (name
, die
, cu
)
22293 : dwarf2_physname (name
, die
, cu
));
22294 const char *linkagename
= dw2_linkage_name (die
, cu
);
22296 if (linkagename
== nullptr || cu
->language
== language_ada
)
22297 sym
->set_linkage_name (physname
);
22300 sym
->set_demangled_name (physname
, &objfile
->objfile_obstack
);
22301 sym
->set_linkage_name (linkagename
);
22304 /* Default assumptions.
22305 Use the passed type or decode it from the die. */
22306 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22307 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22309 SYMBOL_TYPE (sym
) = type
;
22311 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
22312 attr
= dwarf2_attr (die
,
22313 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
22315 if (attr
!= nullptr)
22316 SYMBOL_LINE (sym
) = attr
->constant_value (0);
22318 attr
= dwarf2_attr (die
,
22319 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
22321 if (attr
!= nullptr && attr
->is_nonnegative ())
22323 file_name_index file_index
22324 = (file_name_index
) attr
->as_nonnegative ();
22325 struct file_entry
*fe
;
22327 if (cu
->line_header
!= NULL
)
22328 fe
= cu
->line_header
->file_name_at (file_index
);
22333 complaint (_("file index out of range"));
22335 symbol_set_symtab (sym
, fe
->symtab
);
22341 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
22342 if (attr
!= nullptr)
22346 addr
= attr
->as_address ();
22347 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
22348 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
22349 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
22352 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
22353 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
22354 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
22355 add_symbol_to_list (sym
, cu
->list_in_scope
);
22357 case DW_TAG_subprogram
:
22358 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22360 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22361 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22362 if ((attr2
!= nullptr && attr2
->as_boolean ())
22363 || cu
->language
== language_ada
22364 || cu
->language
== language_fortran
)
22366 /* Subprograms marked external are stored as a global symbol.
22367 Ada and Fortran subprograms, whether marked external or
22368 not, are always stored as a global symbol, because we want
22369 to be able to access them globally. For instance, we want
22370 to be able to break on a nested subprogram without having
22371 to specify the context. */
22372 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22376 list_to_add
= cu
->list_in_scope
;
22379 case DW_TAG_inlined_subroutine
:
22380 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22382 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22383 SYMBOL_INLINED (sym
) = 1;
22384 list_to_add
= cu
->list_in_scope
;
22386 case DW_TAG_template_value_param
:
22388 /* Fall through. */
22389 case DW_TAG_constant
:
22390 case DW_TAG_variable
:
22391 case DW_TAG_member
:
22392 /* Compilation with minimal debug info may result in
22393 variables with missing type entries. Change the
22394 misleading `void' type to something sensible. */
22395 if (SYMBOL_TYPE (sym
)->code () == TYPE_CODE_VOID
)
22396 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
22398 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22399 /* In the case of DW_TAG_member, we should only be called for
22400 static const members. */
22401 if (die
->tag
== DW_TAG_member
)
22403 /* dwarf2_add_field uses die_is_declaration,
22404 so we do the same. */
22405 gdb_assert (die_is_declaration (die
, cu
));
22408 if (attr
!= nullptr)
22410 dwarf2_const_value (attr
, sym
, cu
);
22411 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22414 if (attr2
!= nullptr && attr2
->as_boolean ())
22415 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22417 list_to_add
= cu
->list_in_scope
;
22421 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22422 if (attr
!= nullptr)
22424 var_decode_location (attr
, sym
, cu
);
22425 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22427 /* Fortran explicitly imports any global symbols to the local
22428 scope by DW_TAG_common_block. */
22429 if (cu
->language
== language_fortran
&& die
->parent
22430 && die
->parent
->tag
== DW_TAG_common_block
)
22433 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22434 && SYMBOL_VALUE_ADDRESS (sym
) == 0
22435 && !per_objfile
->per_bfd
->has_section_at_zero
)
22437 /* When a static variable is eliminated by the linker,
22438 the corresponding debug information is not stripped
22439 out, but the variable address is set to null;
22440 do not add such variables into symbol table. */
22442 else if (attr2
!= nullptr && attr2
->as_boolean ())
22444 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22445 && (objfile
->flags
& OBJF_MAINLINE
) == 0
22446 && per_objfile
->per_bfd
->can_copy
)
22448 /* A global static variable might be subject to
22449 copy relocation. We first check for a local
22450 minsym, though, because maybe the symbol was
22451 marked hidden, in which case this would not
22453 bound_minimal_symbol found
22454 = (lookup_minimal_symbol_linkage
22455 (sym
->linkage_name (), objfile
));
22456 if (found
.minsym
!= nullptr)
22457 sym
->maybe_copied
= 1;
22460 /* A variable with DW_AT_external is never static,
22461 but it may be block-scoped. */
22463 = ((cu
->list_in_scope
22464 == cu
->get_builder ()->get_file_symbols ())
22465 ? cu
->get_builder ()->get_global_symbols ()
22466 : cu
->list_in_scope
);
22469 list_to_add
= cu
->list_in_scope
;
22473 /* We do not know the address of this symbol.
22474 If it is an external symbol and we have type information
22475 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22476 The address of the variable will then be determined from
22477 the minimal symbol table whenever the variable is
22479 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22481 /* Fortran explicitly imports any global symbols to the local
22482 scope by DW_TAG_common_block. */
22483 if (cu
->language
== language_fortran
&& die
->parent
22484 && die
->parent
->tag
== DW_TAG_common_block
)
22486 /* SYMBOL_CLASS doesn't matter here because
22487 read_common_block is going to reset it. */
22489 list_to_add
= cu
->list_in_scope
;
22491 else if (attr2
!= nullptr && attr2
->as_boolean ()
22492 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22494 /* A variable with DW_AT_external is never static, but it
22495 may be block-scoped. */
22497 = ((cu
->list_in_scope
22498 == cu
->get_builder ()->get_file_symbols ())
22499 ? cu
->get_builder ()->get_global_symbols ()
22500 : cu
->list_in_scope
);
22502 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22504 else if (!die_is_declaration (die
, cu
))
22506 /* Use the default LOC_OPTIMIZED_OUT class. */
22507 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22509 list_to_add
= cu
->list_in_scope
;
22513 case DW_TAG_formal_parameter
:
22515 /* If we are inside a function, mark this as an argument. If
22516 not, we might be looking at an argument to an inlined function
22517 when we do not have enough information to show inlined frames;
22518 pretend it's a local variable in that case so that the user can
22520 struct context_stack
*curr
22521 = cu
->get_builder ()->get_current_context_stack ();
22522 if (curr
!= nullptr && curr
->name
!= nullptr)
22523 SYMBOL_IS_ARGUMENT (sym
) = 1;
22524 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22525 if (attr
!= nullptr)
22527 var_decode_location (attr
, sym
, cu
);
22529 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22530 if (attr
!= nullptr)
22532 dwarf2_const_value (attr
, sym
, cu
);
22535 list_to_add
= cu
->list_in_scope
;
22538 case DW_TAG_unspecified_parameters
:
22539 /* From varargs functions; gdb doesn't seem to have any
22540 interest in this information, so just ignore it for now.
22543 case DW_TAG_template_type_param
:
22545 /* Fall through. */
22546 case DW_TAG_class_type
:
22547 case DW_TAG_interface_type
:
22548 case DW_TAG_structure_type
:
22549 case DW_TAG_union_type
:
22550 case DW_TAG_set_type
:
22551 case DW_TAG_enumeration_type
:
22552 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22553 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22556 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22557 really ever be static objects: otherwise, if you try
22558 to, say, break of a class's method and you're in a file
22559 which doesn't mention that class, it won't work unless
22560 the check for all static symbols in lookup_symbol_aux
22561 saves you. See the OtherFileClass tests in
22562 gdb.c++/namespace.exp. */
22566 buildsym_compunit
*builder
= cu
->get_builder ();
22568 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22569 && cu
->language
== language_cplus
22570 ? builder
->get_global_symbols ()
22571 : cu
->list_in_scope
);
22573 /* The semantics of C++ state that "struct foo {
22574 ... }" also defines a typedef for "foo". */
22575 if (cu
->language
== language_cplus
22576 || cu
->language
== language_ada
22577 || cu
->language
== language_d
22578 || cu
->language
== language_rust
)
22580 /* The symbol's name is already allocated along
22581 with this objfile, so we don't need to
22582 duplicate it for the type. */
22583 if (SYMBOL_TYPE (sym
)->name () == 0)
22584 SYMBOL_TYPE (sym
)->set_name (sym
->search_name ());
22589 case DW_TAG_typedef
:
22590 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22591 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22592 list_to_add
= cu
->list_in_scope
;
22594 case DW_TAG_array_type
:
22595 case DW_TAG_base_type
:
22596 case DW_TAG_subrange_type
:
22597 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22598 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22599 list_to_add
= cu
->list_in_scope
;
22601 case DW_TAG_enumerator
:
22602 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22603 if (attr
!= nullptr)
22605 dwarf2_const_value (attr
, sym
, cu
);
22608 /* NOTE: carlton/2003-11-10: See comment above in the
22609 DW_TAG_class_type, etc. block. */
22612 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22613 && cu
->language
== language_cplus
22614 ? cu
->get_builder ()->get_global_symbols ()
22615 : cu
->list_in_scope
);
22618 case DW_TAG_imported_declaration
:
22619 case DW_TAG_namespace
:
22620 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22621 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22623 case DW_TAG_module
:
22624 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22625 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22626 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22628 case DW_TAG_common_block
:
22629 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22630 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22631 add_symbol_to_list (sym
, cu
->list_in_scope
);
22634 /* Not a tag we recognize. Hopefully we aren't processing
22635 trash data, but since we must specifically ignore things
22636 we don't recognize, there is nothing else we should do at
22638 complaint (_("unsupported tag: '%s'"),
22639 dwarf_tag_name (die
->tag
));
22645 sym
->hash_next
= objfile
->template_symbols
;
22646 objfile
->template_symbols
= sym
;
22647 list_to_add
= NULL
;
22650 if (list_to_add
!= NULL
)
22651 add_symbol_to_list (sym
, list_to_add
);
22653 /* For the benefit of old versions of GCC, check for anonymous
22654 namespaces based on the demangled name. */
22655 if (!cu
->processing_has_namespace_info
22656 && cu
->language
== language_cplus
)
22657 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22662 /* Given an attr with a DW_FORM_dataN value in host byte order,
22663 zero-extend it as appropriate for the symbol's type. The DWARF
22664 standard (v4) is not entirely clear about the meaning of using
22665 DW_FORM_dataN for a constant with a signed type, where the type is
22666 wider than the data. The conclusion of a discussion on the DWARF
22667 list was that this is unspecified. We choose to always zero-extend
22668 because that is the interpretation long in use by GCC. */
22671 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22672 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22674 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22675 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22676 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22677 LONGEST l
= attr
->constant_value (0);
22679 if (bits
< sizeof (*value
) * 8)
22681 l
&= ((LONGEST
) 1 << bits
) - 1;
22684 else if (bits
== sizeof (*value
) * 8)
22688 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22689 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22696 /* Read a constant value from an attribute. Either set *VALUE, or if
22697 the value does not fit in *VALUE, set *BYTES - either already
22698 allocated on the objfile obstack, or newly allocated on OBSTACK,
22699 or, set *BATON, if we translated the constant to a location
22703 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22704 const char *name
, struct obstack
*obstack
,
22705 struct dwarf2_cu
*cu
,
22706 LONGEST
*value
, const gdb_byte
**bytes
,
22707 struct dwarf2_locexpr_baton
**baton
)
22709 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22710 struct objfile
*objfile
= per_objfile
->objfile
;
22711 struct comp_unit_head
*cu_header
= &cu
->header
;
22712 struct dwarf_block
*blk
;
22713 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22714 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22720 switch (attr
->form
)
22723 case DW_FORM_addrx
:
22724 case DW_FORM_GNU_addr_index
:
22728 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22729 dwarf2_const_value_length_mismatch_complaint (name
,
22730 cu_header
->addr_size
,
22731 TYPE_LENGTH (type
));
22732 /* Symbols of this form are reasonably rare, so we just
22733 piggyback on the existing location code rather than writing
22734 a new implementation of symbol_computed_ops. */
22735 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22736 (*baton
)->per_objfile
= per_objfile
;
22737 (*baton
)->per_cu
= cu
->per_cu
;
22738 gdb_assert ((*baton
)->per_cu
);
22740 (*baton
)->size
= 2 + cu_header
->addr_size
;
22741 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22742 (*baton
)->data
= data
;
22744 data
[0] = DW_OP_addr
;
22745 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22746 byte_order
, attr
->as_address ());
22747 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22750 case DW_FORM_string
:
22753 case DW_FORM_GNU_str_index
:
22754 case DW_FORM_GNU_strp_alt
:
22755 /* The string is already allocated on the objfile obstack, point
22757 *bytes
= (const gdb_byte
*) attr
->as_string ();
22759 case DW_FORM_block1
:
22760 case DW_FORM_block2
:
22761 case DW_FORM_block4
:
22762 case DW_FORM_block
:
22763 case DW_FORM_exprloc
:
22764 case DW_FORM_data16
:
22765 blk
= attr
->as_block ();
22766 if (TYPE_LENGTH (type
) != blk
->size
)
22767 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22768 TYPE_LENGTH (type
));
22769 *bytes
= blk
->data
;
22772 /* The DW_AT_const_value attributes are supposed to carry the
22773 symbol's value "represented as it would be on the target
22774 architecture." By the time we get here, it's already been
22775 converted to host endianness, so we just need to sign- or
22776 zero-extend it as appropriate. */
22777 case DW_FORM_data1
:
22778 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22780 case DW_FORM_data2
:
22781 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22783 case DW_FORM_data4
:
22784 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22786 case DW_FORM_data8
:
22787 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22790 case DW_FORM_sdata
:
22791 case DW_FORM_implicit_const
:
22792 *value
= attr
->as_signed ();
22795 case DW_FORM_udata
:
22796 *value
= attr
->as_unsigned ();
22800 complaint (_("unsupported const value attribute form: '%s'"),
22801 dwarf_form_name (attr
->form
));
22808 /* Copy constant value from an attribute to a symbol. */
22811 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22812 struct dwarf2_cu
*cu
)
22814 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22816 const gdb_byte
*bytes
;
22817 struct dwarf2_locexpr_baton
*baton
;
22819 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22820 sym
->print_name (),
22821 &objfile
->objfile_obstack
, cu
,
22822 &value
, &bytes
, &baton
);
22826 SYMBOL_LOCATION_BATON (sym
) = baton
;
22827 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22829 else if (bytes
!= NULL
)
22831 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22832 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22836 SYMBOL_VALUE (sym
) = value
;
22837 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22841 /* Return the type of the die in question using its DW_AT_type attribute. */
22843 static struct type
*
22844 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22846 struct attribute
*type_attr
;
22848 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22851 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22852 /* A missing DW_AT_type represents a void type. */
22853 return objfile_type (objfile
)->builtin_void
;
22856 return lookup_die_type (die
, type_attr
, cu
);
22859 /* True iff CU's producer generates GNAT Ada auxiliary information
22860 that allows to find parallel types through that information instead
22861 of having to do expensive parallel lookups by type name. */
22864 need_gnat_info (struct dwarf2_cu
*cu
)
22866 /* Assume that the Ada compiler was GNAT, which always produces
22867 the auxiliary information. */
22868 return (cu
->language
== language_ada
);
22871 /* Return the auxiliary type of the die in question using its
22872 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22873 attribute is not present. */
22875 static struct type
*
22876 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22878 struct attribute
*type_attr
;
22880 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22884 return lookup_die_type (die
, type_attr
, cu
);
22887 /* If DIE has a descriptive_type attribute, then set the TYPE's
22888 descriptive type accordingly. */
22891 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22892 struct dwarf2_cu
*cu
)
22894 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22896 if (descriptive_type
)
22898 ALLOCATE_GNAT_AUX_TYPE (type
);
22899 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22903 /* Return the containing type of the die in question using its
22904 DW_AT_containing_type attribute. */
22906 static struct type
*
22907 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22909 struct attribute
*type_attr
;
22910 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
22912 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22914 error (_("Dwarf Error: Problem turning containing type into gdb type "
22915 "[in module %s]"), objfile_name (objfile
));
22917 return lookup_die_type (die
, type_attr
, cu
);
22920 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22922 static struct type
*
22923 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22925 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22926 struct objfile
*objfile
= per_objfile
->objfile
;
22929 std::string message
22930 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22931 objfile_name (objfile
),
22932 sect_offset_str (cu
->header
.sect_off
),
22933 sect_offset_str (die
->sect_off
));
22934 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22936 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22939 /* Look up the type of DIE in CU using its type attribute ATTR.
22940 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22941 DW_AT_containing_type.
22942 If there is no type substitute an error marker. */
22944 static struct type
*
22945 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22946 struct dwarf2_cu
*cu
)
22948 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
22949 struct objfile
*objfile
= per_objfile
->objfile
;
22950 struct type
*this_type
;
22952 gdb_assert (attr
->name
== DW_AT_type
22953 || attr
->name
== DW_AT_GNAT_descriptive_type
22954 || attr
->name
== DW_AT_containing_type
);
22956 /* First see if we have it cached. */
22958 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22960 struct dwarf2_per_cu_data
*per_cu
;
22961 sect_offset sect_off
= attr
->get_ref_die_offset ();
22963 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1, per_objfile
);
22964 this_type
= get_die_type_at_offset (sect_off
, per_cu
, per_objfile
);
22966 else if (attr
->form_is_ref ())
22968 sect_offset sect_off
= attr
->get_ref_die_offset ();
22970 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
, per_objfile
);
22972 else if (attr
->form
== DW_FORM_ref_sig8
)
22974 ULONGEST signature
= attr
->as_signature ();
22976 return get_signatured_type (die
, signature
, cu
);
22980 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22981 " at %s [in module %s]"),
22982 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22983 objfile_name (objfile
));
22984 return build_error_marker_type (cu
, die
);
22987 /* If not cached we need to read it in. */
22989 if (this_type
== NULL
)
22991 struct die_info
*type_die
= NULL
;
22992 struct dwarf2_cu
*type_cu
= cu
;
22994 if (attr
->form_is_ref ())
22995 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22996 if (type_die
== NULL
)
22997 return build_error_marker_type (cu
, die
);
22998 /* If we find the type now, it's probably because the type came
22999 from an inter-CU reference and the type's CU got expanded before
23001 this_type
= read_type_die (type_die
, type_cu
);
23004 /* If we still don't have a type use an error marker. */
23006 if (this_type
== NULL
)
23007 return build_error_marker_type (cu
, die
);
23012 /* Return the type in DIE, CU.
23013 Returns NULL for invalid types.
23015 This first does a lookup in die_type_hash,
23016 and only reads the die in if necessary.
23018 NOTE: This can be called when reading in partial or full symbols. */
23020 static struct type
*
23021 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
23023 struct type
*this_type
;
23025 this_type
= get_die_type (die
, cu
);
23029 return read_type_die_1 (die
, cu
);
23032 /* Read the type in DIE, CU.
23033 Returns NULL for invalid types. */
23035 static struct type
*
23036 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
23038 struct type
*this_type
= NULL
;
23042 case DW_TAG_class_type
:
23043 case DW_TAG_interface_type
:
23044 case DW_TAG_structure_type
:
23045 case DW_TAG_union_type
:
23046 this_type
= read_structure_type (die
, cu
);
23048 case DW_TAG_enumeration_type
:
23049 this_type
= read_enumeration_type (die
, cu
);
23051 case DW_TAG_subprogram
:
23052 case DW_TAG_subroutine_type
:
23053 case DW_TAG_inlined_subroutine
:
23054 this_type
= read_subroutine_type (die
, cu
);
23056 case DW_TAG_array_type
:
23057 this_type
= read_array_type (die
, cu
);
23059 case DW_TAG_set_type
:
23060 this_type
= read_set_type (die
, cu
);
23062 case DW_TAG_pointer_type
:
23063 this_type
= read_tag_pointer_type (die
, cu
);
23065 case DW_TAG_ptr_to_member_type
:
23066 this_type
= read_tag_ptr_to_member_type (die
, cu
);
23068 case DW_TAG_reference_type
:
23069 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
23071 case DW_TAG_rvalue_reference_type
:
23072 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
23074 case DW_TAG_const_type
:
23075 this_type
= read_tag_const_type (die
, cu
);
23077 case DW_TAG_volatile_type
:
23078 this_type
= read_tag_volatile_type (die
, cu
);
23080 case DW_TAG_restrict_type
:
23081 this_type
= read_tag_restrict_type (die
, cu
);
23083 case DW_TAG_string_type
:
23084 this_type
= read_tag_string_type (die
, cu
);
23086 case DW_TAG_typedef
:
23087 this_type
= read_typedef (die
, cu
);
23089 case DW_TAG_subrange_type
:
23090 this_type
= read_subrange_type (die
, cu
);
23092 case DW_TAG_base_type
:
23093 this_type
= read_base_type (die
, cu
);
23095 case DW_TAG_unspecified_type
:
23096 this_type
= read_unspecified_type (die
, cu
);
23098 case DW_TAG_namespace
:
23099 this_type
= read_namespace_type (die
, cu
);
23101 case DW_TAG_module
:
23102 this_type
= read_module_type (die
, cu
);
23104 case DW_TAG_atomic_type
:
23105 this_type
= read_tag_atomic_type (die
, cu
);
23108 complaint (_("unexpected tag in read_type_die: '%s'"),
23109 dwarf_tag_name (die
->tag
));
23116 /* See if we can figure out if the class lives in a namespace. We do
23117 this by looking for a member function; its demangled name will
23118 contain namespace info, if there is any.
23119 Return the computed name or NULL.
23120 Space for the result is allocated on the objfile's obstack.
23121 This is the full-die version of guess_partial_die_structure_name.
23122 In this case we know DIE has no useful parent. */
23124 static const char *
23125 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23127 struct die_info
*spec_die
;
23128 struct dwarf2_cu
*spec_cu
;
23129 struct die_info
*child
;
23130 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23133 spec_die
= die_specification (die
, &spec_cu
);
23134 if (spec_die
!= NULL
)
23140 for (child
= die
->child
;
23142 child
= child
->sibling
)
23144 if (child
->tag
== DW_TAG_subprogram
)
23146 const char *linkage_name
= dw2_linkage_name (child
, cu
);
23148 if (linkage_name
!= NULL
)
23150 gdb::unique_xmalloc_ptr
<char> actual_name
23151 (cu
->language_defn
->class_name_from_physname (linkage_name
));
23152 const char *name
= NULL
;
23154 if (actual_name
!= NULL
)
23156 const char *die_name
= dwarf2_name (die
, cu
);
23158 if (die_name
!= NULL
23159 && strcmp (die_name
, actual_name
.get ()) != 0)
23161 /* Strip off the class name from the full name.
23162 We want the prefix. */
23163 int die_name_len
= strlen (die_name
);
23164 int actual_name_len
= strlen (actual_name
.get ());
23165 const char *ptr
= actual_name
.get ();
23167 /* Test for '::' as a sanity check. */
23168 if (actual_name_len
> die_name_len
+ 2
23169 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
23170 name
= obstack_strndup (
23171 &objfile
->per_bfd
->storage_obstack
,
23172 ptr
, actual_name_len
- die_name_len
- 2);
23183 /* GCC might emit a nameless typedef that has a linkage name. Determine the
23184 prefix part in such case. See
23185 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23187 static const char *
23188 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
23190 struct attribute
*attr
;
23193 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
23194 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
23197 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
23200 attr
= dw2_linkage_name_attr (die
, cu
);
23201 const char *attr_name
= attr
->as_string ();
23202 if (attr
== NULL
|| attr_name
== NULL
)
23205 /* dwarf2_name had to be already called. */
23206 gdb_assert (attr
->canonical_string_p ());
23208 /* Strip the base name, keep any leading namespaces/classes. */
23209 base
= strrchr (attr_name
, ':');
23210 if (base
== NULL
|| base
== attr_name
|| base
[-1] != ':')
23213 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23214 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
23216 &base
[-1] - attr_name
);
23219 /* Return the name of the namespace/class that DIE is defined within,
23220 or "" if we can't tell. The caller should not xfree the result.
23222 For example, if we're within the method foo() in the following
23232 then determine_prefix on foo's die will return "N::C". */
23234 static const char *
23235 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
23237 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23238 struct die_info
*parent
, *spec_die
;
23239 struct dwarf2_cu
*spec_cu
;
23240 struct type
*parent_type
;
23241 const char *retval
;
23243 if (cu
->language
!= language_cplus
23244 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
23245 && cu
->language
!= language_rust
)
23248 retval
= anonymous_struct_prefix (die
, cu
);
23252 /* We have to be careful in the presence of DW_AT_specification.
23253 For example, with GCC 3.4, given the code
23257 // Definition of N::foo.
23261 then we'll have a tree of DIEs like this:
23263 1: DW_TAG_compile_unit
23264 2: DW_TAG_namespace // N
23265 3: DW_TAG_subprogram // declaration of N::foo
23266 4: DW_TAG_subprogram // definition of N::foo
23267 DW_AT_specification // refers to die #3
23269 Thus, when processing die #4, we have to pretend that we're in
23270 the context of its DW_AT_specification, namely the contex of die
23273 spec_die
= die_specification (die
, &spec_cu
);
23274 if (spec_die
== NULL
)
23275 parent
= die
->parent
;
23278 parent
= spec_die
->parent
;
23282 if (parent
== NULL
)
23284 else if (parent
->building_fullname
)
23287 const char *parent_name
;
23289 /* It has been seen on RealView 2.2 built binaries,
23290 DW_TAG_template_type_param types actually _defined_ as
23291 children of the parent class:
23294 template class <class Enum> Class{};
23295 Class<enum E> class_e;
23297 1: DW_TAG_class_type (Class)
23298 2: DW_TAG_enumeration_type (E)
23299 3: DW_TAG_enumerator (enum1:0)
23300 3: DW_TAG_enumerator (enum2:1)
23302 2: DW_TAG_template_type_param
23303 DW_AT_type DW_FORM_ref_udata (E)
23305 Besides being broken debug info, it can put GDB into an
23306 infinite loop. Consider:
23308 When we're building the full name for Class<E>, we'll start
23309 at Class, and go look over its template type parameters,
23310 finding E. We'll then try to build the full name of E, and
23311 reach here. We're now trying to build the full name of E,
23312 and look over the parent DIE for containing scope. In the
23313 broken case, if we followed the parent DIE of E, we'd again
23314 find Class, and once again go look at its template type
23315 arguments, etc., etc. Simply don't consider such parent die
23316 as source-level parent of this die (it can't be, the language
23317 doesn't allow it), and break the loop here. */
23318 name
= dwarf2_name (die
, cu
);
23319 parent_name
= dwarf2_name (parent
, cu
);
23320 complaint (_("template param type '%s' defined within parent '%s'"),
23321 name
? name
: "<unknown>",
23322 parent_name
? parent_name
: "<unknown>");
23326 switch (parent
->tag
)
23328 case DW_TAG_namespace
:
23329 parent_type
= read_type_die (parent
, cu
);
23330 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
23331 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
23332 Work around this problem here. */
23333 if (cu
->language
== language_cplus
23334 && strcmp (parent_type
->name (), "::") == 0)
23336 /* We give a name to even anonymous namespaces. */
23337 return parent_type
->name ();
23338 case DW_TAG_class_type
:
23339 case DW_TAG_interface_type
:
23340 case DW_TAG_structure_type
:
23341 case DW_TAG_union_type
:
23342 case DW_TAG_module
:
23343 parent_type
= read_type_die (parent
, cu
);
23344 if (parent_type
->name () != NULL
)
23345 return parent_type
->name ();
23347 /* An anonymous structure is only allowed non-static data
23348 members; no typedefs, no member functions, et cetera.
23349 So it does not need a prefix. */
23351 case DW_TAG_compile_unit
:
23352 case DW_TAG_partial_unit
:
23353 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
23354 if (cu
->language
== language_cplus
23355 && !per_objfile
->per_bfd
->types
.empty ()
23356 && die
->child
!= NULL
23357 && (die
->tag
== DW_TAG_class_type
23358 || die
->tag
== DW_TAG_structure_type
23359 || die
->tag
== DW_TAG_union_type
))
23361 const char *name
= guess_full_die_structure_name (die
, cu
);
23366 case DW_TAG_subprogram
:
23367 /* Nested subroutines in Fortran get a prefix with the name
23368 of the parent's subroutine. */
23369 if (cu
->language
== language_fortran
)
23371 if ((die
->tag
== DW_TAG_subprogram
)
23372 && (dwarf2_name (parent
, cu
) != NULL
))
23373 return dwarf2_name (parent
, cu
);
23375 return determine_prefix (parent
, cu
);
23376 case DW_TAG_enumeration_type
:
23377 parent_type
= read_type_die (parent
, cu
);
23378 if (TYPE_DECLARED_CLASS (parent_type
))
23380 if (parent_type
->name () != NULL
)
23381 return parent_type
->name ();
23384 /* Fall through. */
23386 return determine_prefix (parent
, cu
);
23390 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
23391 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
23392 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
23393 an obconcat, otherwise allocate storage for the result. The CU argument is
23394 used to determine the language and hence, the appropriate separator. */
23396 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
23399 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
23400 int physname
, struct dwarf2_cu
*cu
)
23402 const char *lead
= "";
23405 if (suffix
== NULL
|| suffix
[0] == '\0'
23406 || prefix
== NULL
|| prefix
[0] == '\0')
23408 else if (cu
->language
== language_d
)
23410 /* For D, the 'main' function could be defined in any module, but it
23411 should never be prefixed. */
23412 if (strcmp (suffix
, "D main") == 0)
23420 else if (cu
->language
== language_fortran
&& physname
)
23422 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
23423 DW_AT_MIPS_linkage_name is preferred and used instead. */
23431 if (prefix
== NULL
)
23433 if (suffix
== NULL
)
23440 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
23442 strcpy (retval
, lead
);
23443 strcat (retval
, prefix
);
23444 strcat (retval
, sep
);
23445 strcat (retval
, suffix
);
23450 /* We have an obstack. */
23451 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
23455 /* Get name of a die, return NULL if not found. */
23457 static const char *
23458 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
23459 struct objfile
*objfile
)
23461 if (name
&& cu
->language
== language_cplus
)
23463 gdb::unique_xmalloc_ptr
<char> canon_name
23464 = cp_canonicalize_string (name
);
23466 if (canon_name
!= nullptr)
23467 name
= objfile
->intern (canon_name
.get ());
23473 /* Get name of a die, return NULL if not found.
23474 Anonymous namespaces are converted to their magic string. */
23476 static const char *
23477 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23479 struct attribute
*attr
;
23480 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
23482 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23483 const char *attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23484 if (attr_name
== nullptr
23485 && die
->tag
!= DW_TAG_namespace
23486 && die
->tag
!= DW_TAG_class_type
23487 && die
->tag
!= DW_TAG_interface_type
23488 && die
->tag
!= DW_TAG_structure_type
23489 && die
->tag
!= DW_TAG_union_type
)
23494 case DW_TAG_compile_unit
:
23495 case DW_TAG_partial_unit
:
23496 /* Compilation units have a DW_AT_name that is a filename, not
23497 a source language identifier. */
23498 case DW_TAG_enumeration_type
:
23499 case DW_TAG_enumerator
:
23500 /* These tags always have simple identifiers already; no need
23501 to canonicalize them. */
23504 case DW_TAG_namespace
:
23505 if (attr_name
!= nullptr)
23507 return CP_ANONYMOUS_NAMESPACE_STR
;
23509 case DW_TAG_class_type
:
23510 case DW_TAG_interface_type
:
23511 case DW_TAG_structure_type
:
23512 case DW_TAG_union_type
:
23513 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23514 structures or unions. These were of the form "._%d" in GCC 4.1,
23515 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23516 and GCC 4.4. We work around this problem by ignoring these. */
23517 if (attr_name
!= nullptr
23518 && (startswith (attr_name
, "._")
23519 || startswith (attr_name
, "<anonymous")))
23522 /* GCC might emit a nameless typedef that has a linkage name. See
23523 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23524 if (!attr
|| attr_name
== NULL
)
23526 attr
= dw2_linkage_name_attr (die
, cu
);
23527 attr_name
= attr
== nullptr ? nullptr : attr
->as_string ();
23528 if (attr
== NULL
|| attr_name
== NULL
)
23531 /* Avoid demangling attr_name the second time on a second
23532 call for the same DIE. */
23533 if (!attr
->canonical_string_p ())
23535 gdb::unique_xmalloc_ptr
<char> demangled
23536 (gdb_demangle (attr_name
, DMGL_TYPES
));
23537 if (demangled
== nullptr)
23540 attr
->set_string_canonical (objfile
->intern (demangled
.get ()));
23541 attr_name
= attr
->as_string ();
23544 /* Strip any leading namespaces/classes, keep only the
23545 base name. DW_AT_name for named DIEs does not
23546 contain the prefixes. */
23547 const char *base
= strrchr (attr_name
, ':');
23548 if (base
&& base
> attr_name
&& base
[-1] == ':')
23559 if (!attr
->canonical_string_p ())
23560 attr
->set_string_canonical (dwarf2_canonicalize_name (attr_name
, cu
,
23562 return attr
->as_string ();
23565 /* Return the die that this die in an extension of, or NULL if there
23566 is none. *EXT_CU is the CU containing DIE on input, and the CU
23567 containing the return value on output. */
23569 static struct die_info
*
23570 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23572 struct attribute
*attr
;
23574 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23578 return follow_die_ref (die
, attr
, ext_cu
);
23582 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23586 print_spaces (indent
, f
);
23587 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23588 dwarf_tag_name (die
->tag
), die
->abbrev
,
23589 sect_offset_str (die
->sect_off
));
23591 if (die
->parent
!= NULL
)
23593 print_spaces (indent
, f
);
23594 fprintf_unfiltered (f
, " parent at offset: %s\n",
23595 sect_offset_str (die
->parent
->sect_off
));
23598 print_spaces (indent
, f
);
23599 fprintf_unfiltered (f
, " has children: %s\n",
23600 dwarf_bool_name (die
->child
!= NULL
));
23602 print_spaces (indent
, f
);
23603 fprintf_unfiltered (f
, " attributes:\n");
23605 for (i
= 0; i
< die
->num_attrs
; ++i
)
23607 print_spaces (indent
, f
);
23608 fprintf_unfiltered (f
, " %s (%s) ",
23609 dwarf_attr_name (die
->attrs
[i
].name
),
23610 dwarf_form_name (die
->attrs
[i
].form
));
23612 switch (die
->attrs
[i
].form
)
23615 case DW_FORM_addrx
:
23616 case DW_FORM_GNU_addr_index
:
23617 fprintf_unfiltered (f
, "address: ");
23618 fputs_filtered (hex_string (die
->attrs
[i
].as_address ()), f
);
23620 case DW_FORM_block2
:
23621 case DW_FORM_block4
:
23622 case DW_FORM_block
:
23623 case DW_FORM_block1
:
23624 fprintf_unfiltered (f
, "block: size %s",
23625 pulongest (die
->attrs
[i
].as_block ()->size
));
23627 case DW_FORM_exprloc
:
23628 fprintf_unfiltered (f
, "expression: size %s",
23629 pulongest (die
->attrs
[i
].as_block ()->size
));
23631 case DW_FORM_data16
:
23632 fprintf_unfiltered (f
, "constant of 16 bytes");
23634 case DW_FORM_ref_addr
:
23635 fprintf_unfiltered (f
, "ref address: ");
23636 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23638 case DW_FORM_GNU_ref_alt
:
23639 fprintf_unfiltered (f
, "alt ref address: ");
23640 fputs_filtered (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
23646 case DW_FORM_ref_udata
:
23647 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23648 (long) (die
->attrs
[i
].as_unsigned ()));
23650 case DW_FORM_data1
:
23651 case DW_FORM_data2
:
23652 case DW_FORM_data4
:
23653 case DW_FORM_data8
:
23654 case DW_FORM_udata
:
23655 fprintf_unfiltered (f
, "constant: %s",
23656 pulongest (die
->attrs
[i
].as_unsigned ()));
23658 case DW_FORM_sec_offset
:
23659 fprintf_unfiltered (f
, "section offset: %s",
23660 pulongest (die
->attrs
[i
].as_unsigned ()));
23662 case DW_FORM_ref_sig8
:
23663 fprintf_unfiltered (f
, "signature: %s",
23664 hex_string (die
->attrs
[i
].as_signature ()));
23666 case DW_FORM_string
:
23668 case DW_FORM_line_strp
:
23670 case DW_FORM_GNU_str_index
:
23671 case DW_FORM_GNU_strp_alt
:
23672 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23673 die
->attrs
[i
].as_string ()
23674 ? die
->attrs
[i
].as_string () : "",
23675 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
23678 if (die
->attrs
[i
].as_boolean ())
23679 fprintf_unfiltered (f
, "flag: TRUE");
23681 fprintf_unfiltered (f
, "flag: FALSE");
23683 case DW_FORM_flag_present
:
23684 fprintf_unfiltered (f
, "flag: TRUE");
23686 case DW_FORM_indirect
:
23687 /* The reader will have reduced the indirect form to
23688 the "base form" so this form should not occur. */
23689 fprintf_unfiltered (f
,
23690 "unexpected attribute form: DW_FORM_indirect");
23692 case DW_FORM_sdata
:
23693 case DW_FORM_implicit_const
:
23694 fprintf_unfiltered (f
, "constant: %s",
23695 plongest (die
->attrs
[i
].as_signed ()));
23698 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23699 die
->attrs
[i
].form
);
23702 fprintf_unfiltered (f
, "\n");
23707 dump_die_for_error (struct die_info
*die
)
23709 dump_die_shallow (gdb_stderr
, 0, die
);
23713 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23715 int indent
= level
* 4;
23717 gdb_assert (die
!= NULL
);
23719 if (level
>= max_level
)
23722 dump_die_shallow (f
, indent
, die
);
23724 if (die
->child
!= NULL
)
23726 print_spaces (indent
, f
);
23727 fprintf_unfiltered (f
, " Children:");
23728 if (level
+ 1 < max_level
)
23730 fprintf_unfiltered (f
, "\n");
23731 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23735 fprintf_unfiltered (f
,
23736 " [not printed, max nesting level reached]\n");
23740 if (die
->sibling
!= NULL
&& level
> 0)
23742 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23746 /* This is called from the pdie macro in gdbinit.in.
23747 It's not static so gcc will keep a copy callable from gdb. */
23750 dump_die (struct die_info
*die
, int max_level
)
23752 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23756 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23760 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23761 to_underlying (die
->sect_off
),
23767 /* Follow reference or signature attribute ATTR of SRC_DIE.
23768 On entry *REF_CU is the CU of SRC_DIE.
23769 On exit *REF_CU is the CU of the result. */
23771 static struct die_info
*
23772 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23773 struct dwarf2_cu
**ref_cu
)
23775 struct die_info
*die
;
23777 if (attr
->form_is_ref ())
23778 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23779 else if (attr
->form
== DW_FORM_ref_sig8
)
23780 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23783 dump_die_for_error (src_die
);
23784 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23785 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
23791 /* Follow reference OFFSET.
23792 On entry *REF_CU is the CU of the source die referencing OFFSET.
23793 On exit *REF_CU is the CU of the result.
23794 Returns NULL if OFFSET is invalid. */
23796 static struct die_info
*
23797 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23798 struct dwarf2_cu
**ref_cu
)
23800 struct die_info temp_die
;
23801 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23802 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
23804 gdb_assert (cu
->per_cu
!= NULL
);
23808 dwarf_read_debug_printf_v ("source CU offset: %s, target offset: %s, "
23809 "source CU contains target offset: %d",
23810 sect_offset_str (cu
->per_cu
->sect_off
),
23811 sect_offset_str (sect_off
),
23812 cu
->header
.offset_in_cu_p (sect_off
));
23814 if (cu
->per_cu
->is_debug_types
)
23816 /* .debug_types CUs cannot reference anything outside their CU.
23817 If they need to, they have to reference a signatured type via
23818 DW_FORM_ref_sig8. */
23819 if (!cu
->header
.offset_in_cu_p (sect_off
))
23822 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23823 || !cu
->header
.offset_in_cu_p (sect_off
))
23825 struct dwarf2_per_cu_data
*per_cu
;
23827 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23830 dwarf_read_debug_printf_v ("target CU offset: %s, "
23831 "target CU DIEs loaded: %d",
23832 sect_offset_str (per_cu
->sect_off
),
23833 per_objfile
->get_cu (per_cu
) != nullptr);
23835 /* If necessary, add it to the queue and load its DIEs.
23837 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
23838 it doesn't mean they are currently loaded. Since we require them
23839 to be loaded, we must check for ourselves. */
23840 if (maybe_queue_comp_unit (cu
, per_cu
, per_objfile
, cu
->language
)
23841 || per_objfile
->get_cu (per_cu
) == nullptr)
23842 load_full_comp_unit (per_cu
, per_objfile
, per_objfile
->get_cu (per_cu
),
23843 false, cu
->language
);
23845 target_cu
= per_objfile
->get_cu (per_cu
);
23846 gdb_assert (target_cu
!= nullptr);
23848 else if (cu
->dies
== NULL
)
23850 /* We're loading full DIEs during partial symbol reading. */
23851 gdb_assert (per_objfile
->per_bfd
->reading_partial_symbols
);
23852 load_full_comp_unit (cu
->per_cu
, per_objfile
, cu
, false,
23856 *ref_cu
= target_cu
;
23857 temp_die
.sect_off
= sect_off
;
23859 if (target_cu
!= cu
)
23860 target_cu
->ancestor
= cu
;
23862 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23864 to_underlying (sect_off
));
23867 /* Follow reference attribute ATTR of SRC_DIE.
23868 On entry *REF_CU is the CU of SRC_DIE.
23869 On exit *REF_CU is the CU of the result. */
23871 static struct die_info
*
23872 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23873 struct dwarf2_cu
**ref_cu
)
23875 sect_offset sect_off
= attr
->get_ref_die_offset ();
23876 struct dwarf2_cu
*cu
= *ref_cu
;
23877 struct die_info
*die
;
23879 die
= follow_die_offset (sect_off
,
23880 (attr
->form
== DW_FORM_GNU_ref_alt
23881 || cu
->per_cu
->is_dwz
),
23884 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23885 "at %s [in module %s]"),
23886 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23887 objfile_name (cu
->per_objfile
->objfile
));
23894 struct dwarf2_locexpr_baton
23895 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23896 dwarf2_per_cu_data
*per_cu
,
23897 dwarf2_per_objfile
*per_objfile
,
23898 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
23899 bool resolve_abstract_p
)
23901 struct die_info
*die
;
23902 struct attribute
*attr
;
23903 struct dwarf2_locexpr_baton retval
;
23904 struct objfile
*objfile
= per_objfile
->objfile
;
23906 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
23908 cu
= load_cu (per_cu
, per_objfile
, false);
23912 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23913 Instead just throw an error, not much else we can do. */
23914 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23915 sect_offset_str (sect_off
), objfile_name (objfile
));
23918 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23920 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23921 sect_offset_str (sect_off
), objfile_name (objfile
));
23923 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23924 if (!attr
&& resolve_abstract_p
23925 && (per_objfile
->per_bfd
->abstract_to_concrete
.find (die
->sect_off
)
23926 != per_objfile
->per_bfd
->abstract_to_concrete
.end ()))
23928 CORE_ADDR pc
= get_frame_pc ();
23929 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23930 struct gdbarch
*gdbarch
= objfile
->arch ();
23932 for (const auto &cand_off
23933 : per_objfile
->per_bfd
->abstract_to_concrete
[die
->sect_off
])
23935 struct dwarf2_cu
*cand_cu
= cu
;
23936 struct die_info
*cand
23937 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23940 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23943 CORE_ADDR pc_low
, pc_high
;
23944 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23945 if (pc_low
== ((CORE_ADDR
) -1))
23947 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23948 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23949 if (!(pc_low
<= pc
&& pc
< pc_high
))
23953 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23960 /* DWARF: "If there is no such attribute, then there is no effect.".
23961 DATA is ignored if SIZE is 0. */
23963 retval
.data
= NULL
;
23966 else if (attr
->form_is_section_offset ())
23968 struct dwarf2_loclist_baton loclist_baton
;
23969 CORE_ADDR pc
= get_frame_pc ();
23972 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23974 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23976 retval
.size
= size
;
23980 if (!attr
->form_is_block ())
23981 error (_("Dwarf Error: DIE at %s referenced in module %s "
23982 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23983 sect_offset_str (sect_off
), objfile_name (objfile
));
23985 struct dwarf_block
*block
= attr
->as_block ();
23986 retval
.data
= block
->data
;
23987 retval
.size
= block
->size
;
23989 retval
.per_objfile
= per_objfile
;
23990 retval
.per_cu
= cu
->per_cu
;
23992 per_objfile
->age_comp_units ();
23999 struct dwarf2_locexpr_baton
24000 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
24001 dwarf2_per_cu_data
*per_cu
,
24002 dwarf2_per_objfile
*per_objfile
,
24003 gdb::function_view
<CORE_ADDR ()> get_frame_pc
)
24005 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
24007 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, per_objfile
,
24011 /* Write a constant of a given type as target-ordered bytes into
24014 static const gdb_byte
*
24015 write_constant_as_bytes (struct obstack
*obstack
,
24016 enum bfd_endian byte_order
,
24023 *len
= TYPE_LENGTH (type
);
24024 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
24025 store_unsigned_integer (result
, *len
, byte_order
, value
);
24033 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
24034 dwarf2_per_cu_data
*per_cu
,
24035 dwarf2_per_objfile
*per_objfile
,
24039 struct die_info
*die
;
24040 struct attribute
*attr
;
24041 const gdb_byte
*result
= NULL
;
24044 enum bfd_endian byte_order
;
24045 struct objfile
*objfile
= per_objfile
->objfile
;
24047 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
24049 cu
= load_cu (per_cu
, per_objfile
, false);
24053 /* We shouldn't get here for a dummy CU, but don't crash on the user.
24054 Instead just throw an error, not much else we can do. */
24055 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
24056 sect_offset_str (sect_off
), objfile_name (objfile
));
24059 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
24061 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
24062 sect_offset_str (sect_off
), objfile_name (objfile
));
24064 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
24068 byte_order
= (bfd_big_endian (objfile
->obfd
)
24069 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
24071 switch (attr
->form
)
24074 case DW_FORM_addrx
:
24075 case DW_FORM_GNU_addr_index
:
24079 *len
= cu
->header
.addr_size
;
24080 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
24081 store_unsigned_integer (tem
, *len
, byte_order
, attr
->as_address ());
24085 case DW_FORM_string
:
24088 case DW_FORM_GNU_str_index
:
24089 case DW_FORM_GNU_strp_alt
:
24090 /* The string is already allocated on the objfile obstack, point
24093 const char *attr_name
= attr
->as_string ();
24094 result
= (const gdb_byte
*) attr_name
;
24095 *len
= strlen (attr_name
);
24098 case DW_FORM_block1
:
24099 case DW_FORM_block2
:
24100 case DW_FORM_block4
:
24101 case DW_FORM_block
:
24102 case DW_FORM_exprloc
:
24103 case DW_FORM_data16
:
24105 struct dwarf_block
*block
= attr
->as_block ();
24106 result
= block
->data
;
24107 *len
= block
->size
;
24111 /* The DW_AT_const_value attributes are supposed to carry the
24112 symbol's value "represented as it would be on the target
24113 architecture." By the time we get here, it's already been
24114 converted to host endianness, so we just need to sign- or
24115 zero-extend it as appropriate. */
24116 case DW_FORM_data1
:
24117 type
= die_type (die
, cu
);
24118 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
24119 if (result
== NULL
)
24120 result
= write_constant_as_bytes (obstack
, byte_order
,
24123 case DW_FORM_data2
:
24124 type
= die_type (die
, cu
);
24125 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
24126 if (result
== NULL
)
24127 result
= write_constant_as_bytes (obstack
, byte_order
,
24130 case DW_FORM_data4
:
24131 type
= die_type (die
, cu
);
24132 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
24133 if (result
== NULL
)
24134 result
= write_constant_as_bytes (obstack
, byte_order
,
24137 case DW_FORM_data8
:
24138 type
= die_type (die
, cu
);
24139 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
24140 if (result
== NULL
)
24141 result
= write_constant_as_bytes (obstack
, byte_order
,
24145 case DW_FORM_sdata
:
24146 case DW_FORM_implicit_const
:
24147 type
= die_type (die
, cu
);
24148 result
= write_constant_as_bytes (obstack
, byte_order
,
24149 type
, attr
->as_signed (), len
);
24152 case DW_FORM_udata
:
24153 type
= die_type (die
, cu
);
24154 result
= write_constant_as_bytes (obstack
, byte_order
,
24155 type
, attr
->as_unsigned (), len
);
24159 complaint (_("unsupported const value attribute form: '%s'"),
24160 dwarf_form_name (attr
->form
));
24170 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
24171 dwarf2_per_cu_data
*per_cu
,
24172 dwarf2_per_objfile
*per_objfile
)
24174 struct die_info
*die
;
24176 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
24178 cu
= load_cu (per_cu
, per_objfile
, false);
24183 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
24187 return die_type (die
, cu
);
24193 dwarf2_get_die_type (cu_offset die_offset
,
24194 dwarf2_per_cu_data
*per_cu
,
24195 dwarf2_per_objfile
*per_objfile
)
24197 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
24198 return get_die_type_at_offset (die_offset_sect
, per_cu
, per_objfile
);
24201 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
24202 On entry *REF_CU is the CU of SRC_DIE.
24203 On exit *REF_CU is the CU of the result.
24204 Returns NULL if the referenced DIE isn't found. */
24206 static struct die_info
*
24207 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
24208 struct dwarf2_cu
**ref_cu
)
24210 struct die_info temp_die
;
24211 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
24212 struct die_info
*die
;
24213 dwarf2_per_objfile
*per_objfile
= (*ref_cu
)->per_objfile
;
24216 /* While it might be nice to assert sig_type->type == NULL here,
24217 we can get here for DW_AT_imported_declaration where we need
24218 the DIE not the type. */
24220 /* If necessary, add it to the queue and load its DIEs.
24222 Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
24223 it doesn't mean they are currently loaded. Since we require them
24224 to be loaded, we must check for ourselves. */
24225 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, per_objfile
,
24227 || per_objfile
->get_cu (&sig_type
->per_cu
) == nullptr)
24228 read_signatured_type (sig_type
, per_objfile
);
24230 sig_cu
= per_objfile
->get_cu (&sig_type
->per_cu
);
24231 gdb_assert (sig_cu
!= NULL
);
24232 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
24233 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
24234 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
24235 to_underlying (temp_die
.sect_off
));
24238 /* For .gdb_index version 7 keep track of included TUs.
24239 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
24240 if (per_objfile
->per_bfd
->index_table
!= NULL
24241 && per_objfile
->per_bfd
->index_table
->version
<= 7)
24243 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
24248 sig_cu
->ancestor
= cu
;
24256 /* Follow signatured type referenced by ATTR in SRC_DIE.
24257 On entry *REF_CU is the CU of SRC_DIE.
24258 On exit *REF_CU is the CU of the result.
24259 The result is the DIE of the type.
24260 If the referenced type cannot be found an error is thrown. */
24262 static struct die_info
*
24263 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
24264 struct dwarf2_cu
**ref_cu
)
24266 ULONGEST signature
= attr
->as_signature ();
24267 struct signatured_type
*sig_type
;
24268 struct die_info
*die
;
24270 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
24272 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
24273 /* sig_type will be NULL if the signatured type is missing from
24275 if (sig_type
== NULL
)
24277 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24278 " from DIE at %s [in module %s]"),
24279 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
24280 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
24283 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
24286 dump_die_for_error (src_die
);
24287 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24288 " from DIE at %s [in module %s]"),
24289 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
24290 objfile_name ((*ref_cu
)->per_objfile
->objfile
));
24296 /* Get the type specified by SIGNATURE referenced in DIE/CU,
24297 reading in and processing the type unit if necessary. */
24299 static struct type
*
24300 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
24301 struct dwarf2_cu
*cu
)
24303 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24304 struct signatured_type
*sig_type
;
24305 struct dwarf2_cu
*type_cu
;
24306 struct die_info
*type_die
;
24309 sig_type
= lookup_signatured_type (cu
, signature
);
24310 /* sig_type will be NULL if the signatured type is missing from
24312 if (sig_type
== NULL
)
24314 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24315 " from DIE at %s [in module %s]"),
24316 hex_string (signature
), sect_offset_str (die
->sect_off
),
24317 objfile_name (per_objfile
->objfile
));
24318 return build_error_marker_type (cu
, die
);
24321 /* If we already know the type we're done. */
24322 type
= per_objfile
->get_type_for_signatured_type (sig_type
);
24323 if (type
!= nullptr)
24327 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
24328 if (type_die
!= NULL
)
24330 /* N.B. We need to call get_die_type to ensure only one type for this DIE
24331 is created. This is important, for example, because for c++ classes
24332 we need TYPE_NAME set which is only done by new_symbol. Blech. */
24333 type
= read_type_die (type_die
, type_cu
);
24336 complaint (_("Dwarf Error: Cannot build signatured type %s"
24337 " referenced from DIE at %s [in module %s]"),
24338 hex_string (signature
), sect_offset_str (die
->sect_off
),
24339 objfile_name (per_objfile
->objfile
));
24340 type
= build_error_marker_type (cu
, die
);
24345 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24346 " from DIE at %s [in module %s]"),
24347 hex_string (signature
), sect_offset_str (die
->sect_off
),
24348 objfile_name (per_objfile
->objfile
));
24349 type
= build_error_marker_type (cu
, die
);
24352 per_objfile
->set_type_for_signatured_type (sig_type
, type
);
24357 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
24358 reading in and processing the type unit if necessary. */
24360 static struct type
*
24361 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
24362 struct dwarf2_cu
*cu
) /* ARI: editCase function */
24364 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
24365 if (attr
->form_is_ref ())
24367 struct dwarf2_cu
*type_cu
= cu
;
24368 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24370 return read_type_die (type_die
, type_cu
);
24372 else if (attr
->form
== DW_FORM_ref_sig8
)
24374 return get_signatured_type (die
, attr
->as_signature (), cu
);
24378 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24380 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24381 " at %s [in module %s]"),
24382 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24383 objfile_name (per_objfile
->objfile
));
24384 return build_error_marker_type (cu
, die
);
24388 /* Load the DIEs associated with type unit PER_CU into memory. */
24391 load_full_type_unit (dwarf2_per_cu_data
*per_cu
,
24392 dwarf2_per_objfile
*per_objfile
)
24394 struct signatured_type
*sig_type
;
24396 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24397 gdb_assert (! per_cu
->type_unit_group_p ());
24399 /* We have the per_cu, but we need the signatured_type.
24400 Fortunately this is an easy translation. */
24401 gdb_assert (per_cu
->is_debug_types
);
24402 sig_type
= (struct signatured_type
*) per_cu
;
24404 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
24406 read_signatured_type (sig_type
, per_objfile
);
24408 gdb_assert (per_objfile
->get_cu (per_cu
) != nullptr);
24411 /* Read in a signatured type and build its CU and DIEs.
24412 If the type is a stub for the real type in a DWO file,
24413 read in the real type from the DWO file as well. */
24416 read_signatured_type (signatured_type
*sig_type
,
24417 dwarf2_per_objfile
*per_objfile
)
24419 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24421 gdb_assert (per_cu
->is_debug_types
);
24422 gdb_assert (per_objfile
->get_cu (per_cu
) == nullptr);
24424 cutu_reader
reader (per_cu
, per_objfile
, nullptr, nullptr, false);
24426 if (!reader
.dummy_p
)
24428 struct dwarf2_cu
*cu
= reader
.cu
;
24429 const gdb_byte
*info_ptr
= reader
.info_ptr
;
24431 gdb_assert (cu
->die_hash
== NULL
);
24433 htab_create_alloc_ex (cu
->header
.length
/ 12,
24437 &cu
->comp_unit_obstack
,
24438 hashtab_obstack_allocate
,
24439 dummy_obstack_deallocate
);
24441 if (reader
.comp_unit_die
->has_children
)
24442 reader
.comp_unit_die
->child
24443 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
24444 reader
.comp_unit_die
);
24445 cu
->dies
= reader
.comp_unit_die
;
24446 /* comp_unit_die is not stored in die_hash, no need. */
24448 /* We try not to read any attributes in this function, because
24449 not all CUs needed for references have been loaded yet, and
24450 symbol table processing isn't initialized. But we have to
24451 set the CU language, or we won't be able to build types
24452 correctly. Similarly, if we do not read the producer, we can
24453 not apply producer-specific interpretation. */
24454 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24459 sig_type
->per_cu
.tu_read
= 1;
24462 /* Decode simple location descriptions.
24463 Given a pointer to a dwarf block that defines a location, compute
24464 the location and return the value. If COMPUTED is non-null, it is
24465 set to true to indicate that decoding was successful, and false
24466 otherwise. If COMPUTED is null, then this function may emit a
24470 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
, bool *computed
)
24472 struct objfile
*objfile
= cu
->per_objfile
->objfile
;
24474 size_t size
= blk
->size
;
24475 const gdb_byte
*data
= blk
->data
;
24476 CORE_ADDR stack
[64];
24478 unsigned int bytes_read
, unsnd
;
24481 if (computed
!= nullptr)
24487 stack
[++stacki
] = 0;
24526 stack
[++stacki
] = op
- DW_OP_lit0
;
24561 stack
[++stacki
] = op
- DW_OP_reg0
;
24564 if (computed
== nullptr)
24565 dwarf2_complex_location_expr_complaint ();
24572 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24574 stack
[++stacki
] = unsnd
;
24577 if (computed
== nullptr)
24578 dwarf2_complex_location_expr_complaint ();
24585 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
24590 case DW_OP_const1u
:
24591 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24595 case DW_OP_const1s
:
24596 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24600 case DW_OP_const2u
:
24601 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24605 case DW_OP_const2s
:
24606 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24610 case DW_OP_const4u
:
24611 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24615 case DW_OP_const4s
:
24616 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24620 case DW_OP_const8u
:
24621 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24626 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24632 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24637 stack
[stacki
+ 1] = stack
[stacki
];
24642 stack
[stacki
- 1] += stack
[stacki
];
24646 case DW_OP_plus_uconst
:
24647 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24653 stack
[stacki
- 1] -= stack
[stacki
];
24658 /* If we're not the last op, then we definitely can't encode
24659 this using GDB's address_class enum. This is valid for partial
24660 global symbols, although the variable's address will be bogus
24664 if (computed
== nullptr)
24665 dwarf2_complex_location_expr_complaint ();
24671 case DW_OP_GNU_push_tls_address
:
24672 case DW_OP_form_tls_address
:
24673 /* The top of the stack has the offset from the beginning
24674 of the thread control block at which the variable is located. */
24675 /* Nothing should follow this operator, so the top of stack would
24677 /* This is valid for partial global symbols, but the variable's
24678 address will be bogus in the psymtab. Make it always at least
24679 non-zero to not look as a variable garbage collected by linker
24680 which have DW_OP_addr 0. */
24683 if (computed
== nullptr)
24684 dwarf2_complex_location_expr_complaint ();
24691 case DW_OP_GNU_uninit
:
24692 if (computed
!= nullptr)
24697 case DW_OP_GNU_addr_index
:
24698 case DW_OP_GNU_const_index
:
24699 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24705 if (computed
== nullptr)
24707 const char *name
= get_DW_OP_name (op
);
24710 complaint (_("unsupported stack op: '%s'"),
24713 complaint (_("unsupported stack op: '%02x'"),
24717 return (stack
[stacki
]);
24720 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24721 outside of the allocated space. Also enforce minimum>0. */
24722 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24724 if (computed
== nullptr)
24725 complaint (_("location description stack overflow"));
24731 if (computed
== nullptr)
24732 complaint (_("location description stack underflow"));
24737 if (computed
!= nullptr)
24739 return (stack
[stacki
]);
24742 /* memory allocation interface */
24744 static struct dwarf_block
*
24745 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24747 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24750 static struct die_info
*
24751 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24753 struct die_info
*die
;
24754 size_t size
= sizeof (struct die_info
);
24757 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24759 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24760 memset (die
, 0, sizeof (struct die_info
));
24766 /* Macro support. */
24768 /* An overload of dwarf_decode_macros that finds the correct section
24769 and ensures it is read in before calling the other overload. */
24772 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24773 int section_is_gnu
)
24775 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24776 struct objfile
*objfile
= per_objfile
->objfile
;
24777 const struct line_header
*lh
= cu
->line_header
;
24778 unsigned int offset_size
= cu
->header
.offset_size
;
24779 struct dwarf2_section_info
*section
;
24780 const char *section_name
;
24782 if (cu
->dwo_unit
!= nullptr)
24784 if (section_is_gnu
)
24786 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24787 section_name
= ".debug_macro.dwo";
24791 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24792 section_name
= ".debug_macinfo.dwo";
24797 if (section_is_gnu
)
24799 section
= &per_objfile
->per_bfd
->macro
;
24800 section_name
= ".debug_macro";
24804 section
= &per_objfile
->per_bfd
->macinfo
;
24805 section_name
= ".debug_macinfo";
24809 section
->read (objfile
);
24810 if (section
->buffer
== nullptr)
24812 complaint (_("missing %s section"), section_name
);
24816 buildsym_compunit
*builder
= cu
->get_builder ();
24818 struct dwarf2_section_info
*str_offsets_section
;
24819 struct dwarf2_section_info
*str_section
;
24820 ULONGEST str_offsets_base
;
24822 if (cu
->dwo_unit
!= nullptr)
24824 str_offsets_section
= &cu
->dwo_unit
->dwo_file
24825 ->sections
.str_offsets
;
24826 str_section
= &cu
->dwo_unit
->dwo_file
->sections
.str
;
24827 str_offsets_base
= cu
->header
.addr_size
;
24831 str_offsets_section
= &per_objfile
->per_bfd
->str_offsets
;
24832 str_section
= &per_objfile
->per_bfd
->str
;
24833 str_offsets_base
= *cu
->str_offsets_base
;
24836 dwarf_decode_macros (per_objfile
, builder
, section
, lh
,
24837 offset_size
, offset
, str_section
, str_offsets_section
,
24838 str_offsets_base
, section_is_gnu
);
24841 /* Return the .debug_loc section to use for CU.
24842 For DWO files use .debug_loc.dwo. */
24844 static struct dwarf2_section_info
*
24845 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24847 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24851 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24853 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24855 return (cu
->header
.version
>= 5 ? &per_objfile
->per_bfd
->loclists
24856 : &per_objfile
->per_bfd
->loc
);
24859 /* Return the .debug_rnglists section to use for CU. */
24860 static struct dwarf2_section_info
*
24861 cu_debug_rnglists_section (struct dwarf2_cu
*cu
, dwarf_tag tag
)
24863 if (cu
->header
.version
< 5)
24864 error (_(".debug_rnglists section cannot be used in DWARF %d"),
24865 cu
->header
.version
);
24866 struct dwarf2_per_objfile
*dwarf2_per_objfile
= cu
->per_objfile
;
24868 /* Make sure we read the .debug_rnglists section from the file that
24869 contains the DW_AT_ranges attribute we are reading. Normally that
24870 would be the .dwo file, if there is one. However for DW_TAG_compile_unit
24871 or DW_TAG_skeleton unit, we always want to read from objfile/linked
24873 if (cu
->dwo_unit
!= nullptr
24874 && tag
!= DW_TAG_compile_unit
24875 && tag
!= DW_TAG_skeleton_unit
)
24877 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24879 if (sections
->rnglists
.size
> 0)
24880 return §ions
->rnglists
;
24882 error (_(".debug_rnglists section is missing from .dwo file."));
24884 return &dwarf2_per_objfile
->per_bfd
->rnglists
;
24887 /* A helper function that fills in a dwarf2_loclist_baton. */
24890 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24891 struct dwarf2_loclist_baton
*baton
,
24892 const struct attribute
*attr
)
24894 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24895 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24897 section
->read (per_objfile
->objfile
);
24899 baton
->per_objfile
= per_objfile
;
24900 baton
->per_cu
= cu
->per_cu
;
24901 gdb_assert (baton
->per_cu
);
24902 /* We don't know how long the location list is, but make sure we
24903 don't run off the edge of the section. */
24904 baton
->size
= section
->size
- attr
->as_unsigned ();
24905 baton
->data
= section
->buffer
+ attr
->as_unsigned ();
24906 if (cu
->base_address
.has_value ())
24907 baton
->base_address
= *cu
->base_address
;
24909 baton
->base_address
= 0;
24910 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24914 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24915 struct dwarf2_cu
*cu
, int is_block
)
24917 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
24918 struct objfile
*objfile
= per_objfile
->objfile
;
24919 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24921 if (attr
->form_is_section_offset ()
24922 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24923 the section. If so, fall through to the complaint in the
24925 && attr
->as_unsigned () < section
->get_size (objfile
))
24927 struct dwarf2_loclist_baton
*baton
;
24929 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24931 fill_in_loclist_baton (cu
, baton
, attr
);
24933 if (!cu
->base_address
.has_value ())
24934 complaint (_("Location list used without "
24935 "specifying the CU base address."));
24937 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24938 ? dwarf2_loclist_block_index
24939 : dwarf2_loclist_index
);
24940 SYMBOL_LOCATION_BATON (sym
) = baton
;
24944 struct dwarf2_locexpr_baton
*baton
;
24946 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24947 baton
->per_objfile
= per_objfile
;
24948 baton
->per_cu
= cu
->per_cu
;
24949 gdb_assert (baton
->per_cu
);
24951 if (attr
->form_is_block ())
24953 /* Note that we're just copying the block's data pointer
24954 here, not the actual data. We're still pointing into the
24955 info_buffer for SYM's objfile; right now we never release
24956 that buffer, but when we do clean up properly this may
24958 struct dwarf_block
*block
= attr
->as_block ();
24959 baton
->size
= block
->size
;
24960 baton
->data
= block
->data
;
24964 dwarf2_invalid_attrib_class_complaint ("location description",
24965 sym
->natural_name ());
24969 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24970 ? dwarf2_locexpr_block_index
24971 : dwarf2_locexpr_index
);
24972 SYMBOL_LOCATION_BATON (sym
) = baton
;
24978 const comp_unit_head
*
24979 dwarf2_per_cu_data::get_header () const
24981 if (!m_header_read_in
)
24983 const gdb_byte
*info_ptr
24984 = this->section
->buffer
+ to_underlying (this->sect_off
);
24986 memset (&m_header
, 0, sizeof (m_header
));
24988 read_comp_unit_head (&m_header
, info_ptr
, this->section
,
24989 rcuh_kind::COMPILE
);
24998 dwarf2_per_cu_data::addr_size () const
25000 return this->get_header ()->addr_size
;
25006 dwarf2_per_cu_data::offset_size () const
25008 return this->get_header ()->offset_size
;
25014 dwarf2_per_cu_data::ref_addr_size () const
25016 const comp_unit_head
*header
= this->get_header ();
25018 if (header
->version
== 2)
25019 return header
->addr_size
;
25021 return header
->offset_size
;
25027 dwarf2_cu::addr_type () const
25029 struct objfile
*objfile
= this->per_objfile
->objfile
;
25030 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25031 struct type
*addr_type
= lookup_pointer_type (void_type
);
25032 int addr_size
= this->per_cu
->addr_size ();
25034 if (TYPE_LENGTH (addr_type
) == addr_size
)
25037 addr_type
= addr_sized_int_type (addr_type
->is_unsigned ());
25041 /* A helper function for dwarf2_find_containing_comp_unit that returns
25042 the index of the result, and that searches a vector. It will
25043 return a result even if the offset in question does not actually
25044 occur in any CU. This is separate so that it can be unit
25048 dwarf2_find_containing_comp_unit
25049 (sect_offset sect_off
,
25050 unsigned int offset_in_dwz
,
25051 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
25056 high
= all_comp_units
.size () - 1;
25059 struct dwarf2_per_cu_data
*mid_cu
;
25060 int mid
= low
+ (high
- low
) / 2;
25062 mid_cu
= all_comp_units
[mid
];
25063 if (mid_cu
->is_dwz
> offset_in_dwz
25064 || (mid_cu
->is_dwz
== offset_in_dwz
25065 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
25070 gdb_assert (low
== high
);
25074 /* Locate the .debug_info compilation unit from CU's objfile which contains
25075 the DIE at OFFSET. Raises an error on failure. */
25077 static struct dwarf2_per_cu_data
*
25078 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25079 unsigned int offset_in_dwz
,
25080 dwarf2_per_objfile
*per_objfile
)
25082 int low
= dwarf2_find_containing_comp_unit
25083 (sect_off
, offset_in_dwz
, per_objfile
->per_bfd
->all_comp_units
);
25084 dwarf2_per_cu_data
*this_cu
= per_objfile
->per_bfd
->all_comp_units
[low
];
25086 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25088 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25089 error (_("Dwarf Error: could not find partial DIE containing "
25090 "offset %s [in module %s]"),
25091 sect_offset_str (sect_off
),
25092 bfd_get_filename (per_objfile
->objfile
->obfd
));
25094 gdb_assert (per_objfile
->per_bfd
->all_comp_units
[low
-1]->sect_off
25096 return per_objfile
->per_bfd
->all_comp_units
[low
-1];
25100 if (low
== per_objfile
->per_bfd
->all_comp_units
.size () - 1
25101 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25102 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25103 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25110 namespace selftests
{
25111 namespace find_containing_comp_unit
{
25116 struct dwarf2_per_cu_data one
{};
25117 struct dwarf2_per_cu_data two
{};
25118 struct dwarf2_per_cu_data three
{};
25119 struct dwarf2_per_cu_data four
{};
25122 two
.sect_off
= sect_offset (one
.length
);
25127 four
.sect_off
= sect_offset (three
.length
);
25131 std::vector
<dwarf2_per_cu_data
*> units
;
25132 units
.push_back (&one
);
25133 units
.push_back (&two
);
25134 units
.push_back (&three
);
25135 units
.push_back (&four
);
25139 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
25140 SELF_CHECK (units
[result
] == &one
);
25141 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
25142 SELF_CHECK (units
[result
] == &one
);
25143 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
25144 SELF_CHECK (units
[result
] == &two
);
25146 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
25147 SELF_CHECK (units
[result
] == &three
);
25148 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
25149 SELF_CHECK (units
[result
] == &three
);
25150 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
25151 SELF_CHECK (units
[result
] == &four
);
25157 #endif /* GDB_SELF_TEST */
25159 /* Initialize dwarf2_cu to read PER_CU, in the context of PER_OBJFILE. */
25161 dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data
*per_cu
,
25162 dwarf2_per_objfile
*per_objfile
)
25164 per_objfile (per_objfile
),
25166 has_loclist (false),
25167 checked_producer (false),
25168 producer_is_gxx_lt_4_6 (false),
25169 producer_is_gcc_lt_4_3 (false),
25170 producer_is_icc (false),
25171 producer_is_icc_lt_14 (false),
25172 producer_is_codewarrior (false),
25173 processing_has_namespace_info (false)
25177 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25180 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25181 enum language pretend_language
)
25183 struct attribute
*attr
;
25185 /* Set the language we're debugging. */
25186 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25187 if (attr
!= nullptr)
25188 set_cu_language (attr
->constant_value (0), cu
);
25191 cu
->language
= pretend_language
;
25192 cu
->language_defn
= language_def (cu
->language
);
25195 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25201 dwarf2_per_objfile::get_cu (dwarf2_per_cu_data
*per_cu
)
25203 auto it
= m_dwarf2_cus
.find (per_cu
);
25204 if (it
== m_dwarf2_cus
.end ())
25213 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data
*per_cu
, dwarf2_cu
*cu
)
25215 gdb_assert (this->get_cu (per_cu
) == nullptr);
25217 m_dwarf2_cus
[per_cu
] = cu
;
25223 dwarf2_per_objfile::age_comp_units ()
25225 dwarf_read_debug_printf_v ("running");
25227 /* This is not expected to be called in the middle of CU expansion. There is
25228 an invariant that if a CU is in the CUs-to-expand queue, its DIEs are
25229 loaded in memory. Calling age_comp_units while the queue is in use could
25230 make us free the DIEs for a CU that is in the queue and therefore break
25232 gdb_assert (!this->per_bfd
->queue
.has_value ());
25234 /* Start by clearing all marks. */
25235 for (auto pair
: m_dwarf2_cus
)
25236 pair
.second
->mark
= false;
25238 /* Traverse all CUs, mark them and their dependencies if used recently
25240 for (auto pair
: m_dwarf2_cus
)
25242 dwarf2_cu
*cu
= pair
.second
;
25245 if (cu
->last_used
<= dwarf_max_cache_age
)
25249 /* Delete all CUs still not marked. */
25250 for (auto it
= m_dwarf2_cus
.begin (); it
!= m_dwarf2_cus
.end ();)
25252 dwarf2_cu
*cu
= it
->second
;
25256 dwarf_read_debug_printf_v ("deleting old CU %s",
25257 sect_offset_str (cu
->per_cu
->sect_off
));
25259 it
= m_dwarf2_cus
.erase (it
);
25269 dwarf2_per_objfile::remove_cu (dwarf2_per_cu_data
*per_cu
)
25271 auto it
= m_dwarf2_cus
.find (per_cu
);
25272 if (it
== m_dwarf2_cus
.end ())
25277 m_dwarf2_cus
.erase (it
);
25280 dwarf2_per_objfile::~dwarf2_per_objfile ()
25285 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25286 We store these in a hash table separate from the DIEs, and preserve them
25287 when the DIEs are flushed out of cache.
25289 The CU "per_cu" pointer is needed because offset alone is not enough to
25290 uniquely identify the type. A file may have multiple .debug_types sections,
25291 or the type may come from a DWO file. Furthermore, while it's more logical
25292 to use per_cu->section+offset, with Fission the section with the data is in
25293 the DWO file but we don't know that section at the point we need it.
25294 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25295 because we can enter the lookup routine, get_die_type_at_offset, from
25296 outside this file, and thus won't necessarily have PER_CU->cu.
25297 Fortunately, PER_CU is stable for the life of the objfile. */
25299 struct dwarf2_per_cu_offset_and_type
25301 const struct dwarf2_per_cu_data
*per_cu
;
25302 sect_offset sect_off
;
25306 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25309 per_cu_offset_and_type_hash (const void *item
)
25311 const struct dwarf2_per_cu_offset_and_type
*ofs
25312 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25314 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25317 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25320 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25322 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25323 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25324 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25325 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25327 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25328 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25331 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25332 table if necessary. For convenience, return TYPE.
25334 The DIEs reading must have careful ordering to:
25335 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25336 reading current DIE.
25337 * Not trying to dereference contents of still incompletely read in types
25338 while reading in other DIEs.
25339 * Enable referencing still incompletely read in types just by a pointer to
25340 the type without accessing its fields.
25342 Therefore caller should follow these rules:
25343 * Try to fetch any prerequisite types we may need to build this DIE type
25344 before building the type and calling set_die_type.
25345 * After building type call set_die_type for current DIE as soon as
25346 possible before fetching more types to complete the current type.
25347 * Make the type as complete as possible before fetching more types. */
25349 static struct type
*
25350 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
25351 bool skip_data_location
)
25353 dwarf2_per_objfile
*per_objfile
= cu
->per_objfile
;
25354 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25355 struct objfile
*objfile
= per_objfile
->objfile
;
25356 struct attribute
*attr
;
25357 struct dynamic_prop prop
;
25359 /* For Ada types, make sure that the gnat-specific data is always
25360 initialized (if not already set). There are a few types where
25361 we should not be doing so, because the type-specific area is
25362 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25363 where the type-specific area is used to store the floatformat).
25364 But this is not a problem, because the gnat-specific information
25365 is actually not needed for these types. */
25366 if (need_gnat_info (cu
)
25367 && type
->code () != TYPE_CODE_FUNC
25368 && type
->code () != TYPE_CODE_FLT
25369 && type
->code () != TYPE_CODE_METHODPTR
25370 && type
->code () != TYPE_CODE_MEMBERPTR
25371 && type
->code () != TYPE_CODE_METHOD
25372 && type
->code () != TYPE_CODE_FIXED_POINT
25373 && !HAVE_GNAT_AUX_INFO (type
))
25374 INIT_GNAT_SPECIFIC (type
);
25376 /* Read DW_AT_allocated and set in type. */
25377 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25380 struct type
*prop_type
= cu
->addr_sized_int_type (false);
25381 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25382 type
->add_dyn_prop (DYN_PROP_ALLOCATED
, prop
);
25385 /* Read DW_AT_associated and set in type. */
25386 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25389 struct type
*prop_type
= cu
->addr_sized_int_type (false);
25390 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25391 type
->add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
);
25394 /* Read DW_AT_data_location and set in type. */
25395 if (!skip_data_location
)
25397 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25398 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, cu
->addr_type ()))
25399 type
->add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
);
25402 if (per_objfile
->die_type_hash
== NULL
)
25403 per_objfile
->die_type_hash
25404 = htab_up (htab_create_alloc (127,
25405 per_cu_offset_and_type_hash
,
25406 per_cu_offset_and_type_eq
,
25407 NULL
, xcalloc
, xfree
));
25409 ofs
.per_cu
= cu
->per_cu
;
25410 ofs
.sect_off
= die
->sect_off
;
25412 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25413 htab_find_slot (per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
25415 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25416 sect_offset_str (die
->sect_off
));
25417 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25418 struct dwarf2_per_cu_offset_and_type
);
25423 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25424 or return NULL if the die does not have a saved type. */
25426 static struct type
*
25427 get_die_type_at_offset (sect_offset sect_off
,
25428 dwarf2_per_cu_data
*per_cu
,
25429 dwarf2_per_objfile
*per_objfile
)
25431 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25433 if (per_objfile
->die_type_hash
== NULL
)
25436 ofs
.per_cu
= per_cu
;
25437 ofs
.sect_off
= sect_off
;
25438 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25439 htab_find (per_objfile
->die_type_hash
.get (), &ofs
));
25446 /* Look up the type for DIE in CU in die_type_hash,
25447 or return NULL if DIE does not have a saved type. */
25449 static struct type
*
25450 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25452 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
, cu
->per_objfile
);
25455 /* Add a dependence relationship from CU to REF_PER_CU. */
25458 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25459 struct dwarf2_per_cu_data
*ref_per_cu
)
25463 if (cu
->dependencies
== NULL
)
25465 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25466 NULL
, &cu
->comp_unit_obstack
,
25467 hashtab_obstack_allocate
,
25468 dummy_obstack_deallocate
);
25470 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25472 *slot
= ref_per_cu
;
25475 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25476 Set the mark field in every compilation unit in the
25477 cache that we must keep because we are keeping CU.
25479 DATA is the dwarf2_per_objfile object in which to look up CUs. */
25482 dwarf2_mark_helper (void **slot
, void *data
)
25484 dwarf2_per_cu_data
*per_cu
= (dwarf2_per_cu_data
*) *slot
;
25485 dwarf2_per_objfile
*per_objfile
= (dwarf2_per_objfile
*) data
;
25486 dwarf2_cu
*cu
= per_objfile
->get_cu (per_cu
);
25488 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25489 reading of the chain. As such dependencies remain valid it is not much
25490 useful to track and undo them during QUIT cleanups. */
25499 if (cu
->dependencies
!= nullptr)
25500 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, per_objfile
);
25505 /* Set the mark field in CU and in every other compilation unit in the
25506 cache that we must keep because we are keeping CU. */
25509 dwarf2_mark (struct dwarf2_cu
*cu
)
25516 if (cu
->dependencies
!= nullptr)
25517 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, cu
->per_objfile
);
25520 /* Trivial hash function for partial_die_info: the hash value of a DIE
25521 is its offset in .debug_info for this objfile. */
25524 partial_die_hash (const void *item
)
25526 const struct partial_die_info
*part_die
25527 = (const struct partial_die_info
*) item
;
25529 return to_underlying (part_die
->sect_off
);
25532 /* Trivial comparison function for partial_die_info structures: two DIEs
25533 are equal if they have the same offset. */
25536 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25538 const struct partial_die_info
*part_die_lhs
25539 = (const struct partial_die_info
*) item_lhs
;
25540 const struct partial_die_info
*part_die_rhs
25541 = (const struct partial_die_info
*) item_rhs
;
25543 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25546 struct cmd_list_element
*set_dwarf_cmdlist
;
25547 struct cmd_list_element
*show_dwarf_cmdlist
;
25550 show_check_physname (struct ui_file
*file
, int from_tty
,
25551 struct cmd_list_element
*c
, const char *value
)
25553 fprintf_filtered (file
,
25554 _("Whether to check \"physname\" is %s.\n"),
25558 void _initialize_dwarf2_read ();
25560 _initialize_dwarf2_read ()
25562 add_basic_prefix_cmd ("dwarf", class_maintenance
, _("\
25563 Set DWARF specific variables.\n\
25564 Configure DWARF variables such as the cache size."),
25565 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25566 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25568 add_show_prefix_cmd ("dwarf", class_maintenance
, _("\
25569 Show DWARF specific variables.\n\
25570 Show DWARF variables such as the cache size."),
25571 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25572 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25574 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25575 &dwarf_max_cache_age
, _("\
25576 Set the upper bound on the age of cached DWARF compilation units."), _("\
25577 Show the upper bound on the age of cached DWARF compilation units."), _("\
25578 A higher limit means that cached compilation units will be stored\n\
25579 in memory longer, and more total memory will be used. Zero disables\n\
25580 caching, which can slow down startup."),
25582 show_dwarf_max_cache_age
,
25583 &set_dwarf_cmdlist
,
25584 &show_dwarf_cmdlist
);
25586 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25587 Set debugging of the DWARF reader."), _("\
25588 Show debugging of the DWARF reader."), _("\
25589 When enabled (non-zero), debugging messages are printed during DWARF\n\
25590 reading and symtab expansion. A value of 1 (one) provides basic\n\
25591 information. A value greater than 1 provides more verbose information."),
25594 &setdebuglist
, &showdebuglist
);
25596 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25597 Set debugging of the DWARF DIE reader."), _("\
25598 Show debugging of the DWARF DIE reader."), _("\
25599 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25600 The value is the maximum depth to print."),
25603 &setdebuglist
, &showdebuglist
);
25605 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25606 Set debugging of the dwarf line reader."), _("\
25607 Show debugging of the dwarf line reader."), _("\
25608 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25609 A value of 1 (one) provides basic information.\n\
25610 A value greater than 1 provides more verbose information."),
25613 &setdebuglist
, &showdebuglist
);
25615 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25616 Set cross-checking of \"physname\" code against demangler."), _("\
25617 Show cross-checking of \"physname\" code against demangler."), _("\
25618 When enabled, GDB's internal \"physname\" code is checked against\n\
25620 NULL
, show_check_physname
,
25621 &setdebuglist
, &showdebuglist
);
25623 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25624 no_class
, &use_deprecated_index_sections
, _("\
25625 Set whether to use deprecated gdb_index sections."), _("\
25626 Show whether to use deprecated gdb_index sections."), _("\
25627 When enabled, deprecated .gdb_index sections are used anyway.\n\
25628 Normally they are ignored either because of a missing feature or\n\
25629 performance issue.\n\
25630 Warning: This option must be enabled before gdb reads the file."),
25633 &setlist
, &showlist
);
25635 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25636 &dwarf2_locexpr_funcs
);
25637 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25638 &dwarf2_loclist_funcs
);
25640 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25641 &dwarf2_block_frame_base_locexpr_funcs
);
25642 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25643 &dwarf2_block_frame_base_loclist_funcs
);
25646 selftests::register_test ("dw2_expand_symtabs_matching",
25647 selftests::dw2_expand_symtabs_matching::run_test
);
25648 selftests::register_test ("dwarf2_find_containing_comp_unit",
25649 selftests::find_containing_comp_unit::run_test
);